diff options
author | Przemyslaw <prymula76@outlook.com> | 2024-04-18 18:46:24 +0200 |
---|---|---|
committer | Przemyslaw <prymula76@outlook.com> | 2024-04-18 18:46:24 +0200 |
commit | 11818054364b6248be8ff092d2914598f1081dc5 (patch) | |
tree | 361ab82dcba66f79a7cd4f911dc0873a0bf0632a /desktop |
Init
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/samegame/Changelog.txt | 12 | ||||
-rw-r--r-- | desktop/samegame/DEBIAN/HOWTO.txt | 2 | ||||
-rw-r--r-- | desktop/samegame/DEBIAN/debian.changelog | 5 | ||||
-rw-r--r-- | desktop/samegame/DEBIAN/debian.control | 13 | ||||
-rw-r--r-- | desktop/samegame/DEBIAN/debian.rules | 22 | ||||
-rwxr-xr-x | desktop/samegame/DEBIAN/format.sh | 2 | ||||
-rw-r--r-- | desktop/samegame/DEBIAN/samegame.dsc | 40 | ||||
-rw-r--r-- | desktop/samegame/Makefile | 25 | ||||
-rw-r--r-- | desktop/samegame/PKG/PKGBUILD | 23 | ||||
-rw-r--r-- | desktop/samegame/RPM/samegame.spec | 67 | ||||
-rw-r--r-- | desktop/samegame/SameGame.desktop | 13 | ||||
-rw-r--r-- | desktop/samegame/build.xml | 25 | ||||
-rw-r--r-- | desktop/samegame/res/samegame.png | bin | 0 -> 3838 bytes | |||
-rw-r--r-- | desktop/samegame/src/pietraszczyk/samegame/Field.java | 331 | ||||
-rw-r--r-- | desktop/samegame/src/pietraszczyk/samegame/SameGame.java | 408 |
15 files changed, 988 insertions, 0 deletions
diff --git a/desktop/samegame/Changelog.txt b/desktop/samegame/Changelog.txt new file mode 100644 index 0000000..ce437bf --- /dev/null +++ b/desktop/samegame/Changelog.txt @@ -0,0 +1,12 @@ +0.240417-2 - Pakietowanie +0.240417-1 - Poprawki w naliczaniu punktacji z promowaaniem wyższych poziomów +0.240417-0 - Dodalem punktacje oraz poziomy +0.240416-0 - Plik Makefile oraz desktop +0.240414-0 - Dodanie funkcji reset - dla nowego rozdania +0.240412-3 - Chodzi po byku, można resetować grę +0.240412-2 - Prawie dobrze usuwa w pionie, prawie +0.240412-0 - Wyglada na to że już się nie zawiesza, tylko potrafi długo przeliczać +0.240411-1 - Działa czysto, choć dlugo liczy +0.240411-0 - Wychrzania się na drugim dobieraniu, daleko mu do wersji z Androida, szczerze mówiąc +0.240410-0 - Stan podobny do portu z Androida +0.240329-0 - Inicjacja diff --git a/desktop/samegame/DEBIAN/HOWTO.txt b/desktop/samegame/DEBIAN/HOWTO.txt new file mode 100644 index 0000000..a371e0b --- /dev/null +++ b/desktop/samegame/DEBIAN/HOWTO.txt @@ -0,0 +1,2 @@ +foramt zapisu nazwy pliku: + photocrop_0.221225-0~alpha.tar.gz diff --git a/desktop/samegame/DEBIAN/debian.changelog b/desktop/samegame/DEBIAN/debian.changelog new file mode 100644 index 0000000..b05edc8 --- /dev/null +++ b/desktop/samegame/DEBIAN/debian.changelog @@ -0,0 +1,5 @@ +samegame (0.240417-2) unstable; urgency=low + + * Last release + + -- Przemysław R. Pietraszczyk Wed, 17 Apr 2022 14:11:41 +0200 diff --git a/desktop/samegame/DEBIAN/debian.control b/desktop/samegame/DEBIAN/debian.control new file mode 100644 index 0000000..bb02b65 --- /dev/null +++ b/desktop/samegame/DEBIAN/debian.control @@ -0,0 +1,13 @@ +Source: samegame +Section: java +Priority: extra +Maintainer: Przemysław R. Pietraszczyk +Build-Depends: debhelper-compat (= 12), default-jdk, default-jdk-headless, fakeroot, ant +Standards-Version: 0.0000 +Homepage: https://pietraszczyk.smallhost.pl + + +Package: samegame +Architecture: all +Depends: ${misc:Depends}, default-jdk | default-jre +Description: My implementation Same Game diff --git a/desktop/samegame/DEBIAN/debian.rules b/desktop/samegame/DEBIAN/debian.rules new file mode 100644 index 0000000..b7f75b6 --- /dev/null +++ b/desktop/samegame/DEBIAN/debian.rules @@ -0,0 +1,22 @@ +#!/usr/bin/make -f + +export DH_VERBOSE = 1 + +clean: + ant clean + +build: + ant compile + ant jar + +binary: + mkdir -pm 0755 debian/samegame + mkdir -pm 0755 debian/samegame/usr/games + mkdir -pm 0755 debian/samegame/usr/share/samegame + mkdir -pm 0755 debian/samegame/usr/share/applications + cp build/jar/SameGame.jar debian/samegame/usr/games + cp res/samegame.png debian/samegame/usr/share/samegame + cp SameGame.desktop debian/samegame/usr/share/applications + dh_gencontrol + dh_builddeb + diff --git a/desktop/samegame/DEBIAN/format.sh b/desktop/samegame/DEBIAN/format.sh new file mode 100755 index 0000000..7a807b6 --- /dev/null +++ b/desktop/samegame/DEBIAN/format.sh @@ -0,0 +1,2 @@ +mkdir ./exec +exec /usr/lib/build/debtransform ./ ./samegame.dsc ./exec diff --git a/desktop/samegame/DEBIAN/samegame.dsc b/desktop/samegame/DEBIAN/samegame.dsc new file mode 100644 index 0000000..3e2cdc8 --- /dev/null +++ b/desktop/samegame/DEBIAN/samegame.dsc @@ -0,0 +1,40 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA256 + +Format: 1.0 +Source: samegame +Binary: samegame +Architecture: all +Version: 0.210503-2 +Maintainer: Przemysław R. Pietraszczyk <prymula76@outlook.com> +Homepage: https://pietraszczyk.smallhost.pl +DEBTRANSFORM-TAR: samegame-0.240417-2.tar.gz + +Standards-Version: 0.000000 +Build-Depends: debhelper-compat (>= 12), default-jdk, default-jdk-headless, fakeroot, ant +Package-List: +colorsmemory deb x11 optional arch=all +Files: + b31649bc23b2b7bca9ab70ea3410711a 128820 samegame-0.240417-2.tar.gz + 29e7e7e60bc81891e3da3871b9eeb549 764 samegame-0.240417-2.debian.tar.xz + +-----BEGIN PGP SIGNATURE----- + +mQENBGEf/c4BCAC2d4ymW0pRZV36qLtlt/WGb83kos5UX5UbwvkQrbUjAbOPOY8w +DT3M1neYOAPZx38924aPTFKbZPcz+rK/7Wcv1kzgfux5zXQJTLeqpkhUYAgXUg2p +oK9ZXsai82fOicTrClOyJLLYQ8C1vj8yUh7e3ERljEyp5Nxg/lY92rwcZ4WYR193 +nGDInlDl5JlWUcLlk/RFnC5bB+T6ZZr5FBX/eDnKAPEl+N3MWpDs2JLDy7EUPhcG +U/60X0wuXHPTwMoNbB3ep/bWRxwEej0sFad5GXeCh7hKCroi/kLmLTDIxSD8lsRr +Y4H/8H2lBBsQq7bRL88N6ZDGCocPo11V83kFABEBAAG0NmhvbWU6cHJ6ZW0gT0JT +IFByb2plY3QgPGhvbWU6cHJ6ZW1AYnVpbGQub3BlbnN1c2Uub3JnPokBPgQTAQgA +KAUCYR/9zgIbAwUJBB6wAAYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AACgkQcXEc +NPcNefFEAAf+Kg4cs/C99kEIMv/PO85VW+p8rcTwCViOFUX5WrBhwsRyPAKrJPPG +KD6PdnvoplcNQwhQ8nRsRiiaiUtPcj8Bvi6EdPgSgXXObKKJtCyaAa1rURdlb9iW +CfvXA6oW+PGlii9BMnXOAtkeFIzZooO9oXd+wez66P+4VWFiFzxanLfLn/hwbWxQ +68rlO3QNGbrMeODBgwh9s83XGmAg47mn2fldTAmTbJDf9tMi1LhX2MmLyN9wjqsd +4IZ9JMri2JTnIhYfxWdKT9gsu7q0g8LqonaXMvlOEyHFRF1YQ0i7G6fFbvDcKCZN +W1Eja55FdN7smv5Eck6UTIIYyWPuAv45uohGBBMRAgAGBQJhH/3PAAoJEDswEbdr +nWUj4M0AniJ389dyvUjjgS91AcOb08E4moV9AJ9WDL3/7GYYUL/Azw43QucWPnXr +uw== +=+lfH +-----END PGP SIGNATURE----- diff --git a/desktop/samegame/Makefile b/desktop/samegame/Makefile new file mode 100644 index 0000000..980961a --- /dev/null +++ b/desktop/samegame/Makefile @@ -0,0 +1,25 @@ +prefix=/usr + +all: + ant compile + ant jar + +clean: + ant clean + +install: build/jar/SameGame.jar + mkdir -pm 0755 $(DESTDIR)$(prefix)/games + install -m 0644 build/jar/SameGame.jar $(DESTDIR)$(prefix)/games + mkdir -pm 0755 $(DESTDIR)$(prefix)/share/samegame + mkdir -pm 0755 $(DESTDIR)$(prefix)/share/applications + install -m 0644 res/samegame.png $(DESTDIR)$(prefix)/share/samegame + install -m 0644 SameGame.desktop $(DESTDIR)$(prefix)/share/applications + +.PHONY: install + +uninstall: + rm $(prefix)/games/SameGame.jar + rm -r $(prefix)/share/samegame + rm $(prefix)/share/applications/SameGame.desktop + +.PHONY: uninstall diff --git a/desktop/samegame/PKG/PKGBUILD b/desktop/samegame/PKG/PKGBUILD new file mode 100644 index 0000000..d0dbf59 --- /dev/null +++ b/desktop/samegame/PKG/PKGBUILD @@ -0,0 +1,23 @@ +# Maintainer: Przemyslaw R. Pietraszczyk <prymula76@outlook.com> + +pkgname=samegame +pkgver=0.240417 +pkgrel=2 +pkgdesc="My implementation Same Game" +arch=('any') +url="pietraszczyk.smallhost.pl" +license=('GPL3') +provides=('samegame') +depends=('jdk-openjdk') +makedepends=('jdk-openjdk' 'ant') +source=("${pkgname}-${pkgver}-${pkgrel}.tar.gz::file://${pkgname}-${pkgver}-${pkgrel}.tar.gz") +sha256sums=('fee822aff2c249ba0b93b9dad2967442de5c39a4f35fa7cfb125fe590a37d1a8') #generate with 'makepkg -g' || sha256sum +build() { + cd "$srcdir/${pkgname}-${pkgver}-${pkgrel}" + make -f Makefile +} + +package() { + cd "$srcdir/${pkgname}-${pkgver}-${pkgrel}" + make -f Makefile DESTDIR="${pkgdir}" install +} diff --git a/desktop/samegame/RPM/samegame.spec b/desktop/samegame/RPM/samegame.spec new file mode 100644 index 0000000..abca6c8 --- /dev/null +++ b/desktop/samegame/RPM/samegame.spec @@ -0,0 +1,67 @@ +# +# spec file for package samegame +# +# Copyright (c) 2020 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + +%define unmangled_version 0.240417-2 +Name: samegame +Version: 0.240417 +Release: 2 +Summary: My implementation Same Game +License: GPL +URL: https://pietraszczyk.smallhost.pl +Source0: %{name}-%{unmangled_version}.tar.gz +%if 0%{?suse_version}==1530 +BuildRequires: java-11-openjdk, ant +Requires: java-11-openjdk +%else +BuildRequires: java-11-openjdk, ant +Requires: java-11-openjdk +%endif +BuildArch: noarch + +%description + + +%prep +%setup -n %{name}-%{unmangled_version} -n %{name}-%{unmangled_version} + +%build +ant compile +ant jar + +%install +mkdir -p %{buildroot}/usr +mkdir -p %{buildroot}/usr/games +mkdir -p %{buildroot}/usr/share +mkdir -p %{buildroot}/usr/share/samegame +mkdir -p %{buildroot}/usr/share/applications + +#%make_install + +install -m 0644 build/jar/SameGame.jar %{buildroot}/usr/games +install -m 0644 res/samegame.png %{buildroot}/usr/share/samegame +install -m 0644 SameGame.desktop %{buildroot}/usr/share/applications + +%files +%defattr(0755,root,root) +/usr/games/ +%{_datadir}/samegame/ +%defattr(0644,root,root) +/usr/games/SameGame.jar +%{_datadir}/samegame/samegame.png +%{_datadir}/applications/SameGame.desktop + +%changelog diff --git a/desktop/samegame/SameGame.desktop b/desktop/samegame/SameGame.desktop new file mode 100644 index 0000000..0463928 --- /dev/null +++ b/desktop/samegame/SameGame.desktop @@ -0,0 +1,13 @@ +#!/usr/bin/env xdg-open + +[Desktop Entry] +Encoding=UTF-8 +Type=Application +Categories=Game; + +Name=Same Game + +Exec=java -jar /usr/games/SameGame.jar +Terminal=false +Icon=/usr/share/samegame/samegame.png + diff --git a/desktop/samegame/build.xml b/desktop/samegame/build.xml new file mode 100644 index 0000000..ddf813a --- /dev/null +++ b/desktop/samegame/build.xml @@ -0,0 +1,25 @@ +<project> + + <target name="clean"> + <delete dir="build"/> + </target> + + <target name="compile"> + <mkdir dir="build/classes"/> + <javac srcdir="src" destdir="build/classes"/> + </target> + + <target name="jar"> + <mkdir dir="build/jar"/> + <jar destfile="build/jar/SameGame.jar" basedir="build/classes"> + <manifest> + <attribute name="Main-Class" value="pietraszczyk.samegame.SameGame"/> + </manifest> + </jar> + </target> + + <target name="run"> + <java jar="build/jar/SameGame.jar" fork="true"/> + </target> + +</project> diff --git a/desktop/samegame/res/samegame.png b/desktop/samegame/res/samegame.png Binary files differnew file mode 100644 index 0000000..3a978c4 --- /dev/null +++ b/desktop/samegame/res/samegame.png diff --git a/desktop/samegame/src/pietraszczyk/samegame/Field.java b/desktop/samegame/src/pietraszczyk/samegame/Field.java new file mode 100644 index 0000000..17a82ae --- /dev/null +++ b/desktop/samegame/src/pietraszczyk/samegame/Field.java @@ -0,0 +1,331 @@ +/*
+Same Game - My first application built in Kotlin
+date: 19-III-2024
+code: Przemyslaw R. Pietraszczyk
+license: GPL v3
+IDE: Android Studio Iguana
+*/
+package pietraszczyk.samegame;
+
+import java.util.*;
+import java.lang.*;
+import javax.swing.*;
+import java.awt.*;
+
+public class Field {
+ int index;
+ int groupIndex;
+ //String color;
+ //int x, y;
+ boolean visit;
+ public java.util.List<String> groupList = new ArrayList<String>();
+ public java.util.List<Integer> listIndex = new ArrayList<Integer>();
+
+ public int value; // czy kolor (0) czy bialy (1)
+ public int resource;
+
+
+
+ JButton button;
+ private Color colorHide, color;
+ private int x,y;
+ boolean found;
+ //boolean reserve;
+ boolean postReserve;
+
+
+ public Field () {
+ postReserve=false;
+ }
+
+ public Field(int i, int j) {
+
+ visit = false;
+ value = 0;
+
+ button = new JButton("?");
+ color=new Color(255,255,255);
+ y = i;
+ x = j;
+ found=false;
+ // reserve=false;
+ postReserve=false;
+
+ }
+
+ public void reset() {
+ visit = false;
+ value = 0;
+ }
+
+ public void setIndex(int n) {
+ int index = n;
+ }
+
+ public void setGroupIndex(int n) {
+ groupIndex = n;
+ }
+
+ public void setColorName(Color c) {
+ color = c;
+ }
+
+ public void setVelocity(int _x, int _y) {
+ x = _x;
+ y = _y;
+ }
+
+ public int getGroupIndex() {
+ return groupIndex;
+ }
+
+ public int getVelocityY() {
+ return y;
+ }
+
+ public int getVelocityX() {
+ return x;
+ }
+
+ public Color getColorHide(){
+ return colorHide;
+ }
+ public Color getColor() {
+ return color;
+ }
+ public void setColorHide(int r, int g, int b){
+ color=new Color(r,g,b);
+ }
+ public void setFound(boolean f){
+ found=f;
+ }
+ public boolean getFound(){
+ return found;
+ }
+
+
+
+
+ private String toRgb(Color arg){
+ return String.format("%02X%02X%02X", arg.getRed(), arg.getGreen(), arg.getBlue());
+ }
+
+
+
+
+
+ public void like(Color color, Field [][] squares, int y, int x, int origy, int origx){
+
+ Color white = new Color(255,255, 255);
+
+ // if ( squares[y][x].getColor() != white) {
+ // if (squares[y][x].getColor() == color) {
+ //System.out.println("Adr: "+squares[y][x].getColor());
+ if (squares[y][x].visit == false) {
+ if ( (toRgb(squares[y][x].getColor()).equals(toRgb(white))) == false) {
+ if (toRgb(squares[y][x].getColor()).equals(toRgb(color))) {
+
+ //if (squares[y][x].visit == false) {
+ // squares[origy][origx].groupList.add(String.valueOf(squares[y][x].getGroupIndex()));
+ // squares[origy][origx].listIndex.add(squares[y][x].getGroupIndex());
+ //}
+
+
+ if (y >= 1) {
+ if (squares[y - 1][x].visit == false) {
+ squares[origy][origx].groupList.add(String.valueOf(squares[y][x].getGroupIndex()));
+ squares[origy][origx].listIndex.add(squares[y][x].getGroupIndex());
+
+ squares[y][x].visit = true;
+ like(color, squares, y - 1, x, origy, origx);
+ }
+ }
+ if (x >= 1) {
+ if (squares[y][x - 1].visit == false) {
+ squares[origy][origx].groupList.add(String.valueOf(squares[y][x].getGroupIndex()));
+ squares[origy][origx].listIndex.add(squares[y][x].getGroupIndex());
+
+ squares[y][x].visit = true;
+ like(color, squares, y, x - 1, origy, origx);
+ }
+ }
+
+ if (y < 8) {
+ if (squares[y + 1][x].visit == false) {
+ squares[origy][origx].groupList.add(String.valueOf(squares[y][x].getGroupIndex()));
+ squares[origy][origx].listIndex.add(squares[y][x].getGroupIndex());
+
+ squares[y][x].visit = true;
+ like(color, squares, y + 1, x, origy, origx);
+ }
+ }
+
+ if (x < 5) {
+ if (squares[y][x + 1].visit == false) {
+ squares[origy][origx].groupList.add(String.valueOf(squares[y][x].getGroupIndex()));
+ squares[origy][origx].listIndex.add(squares[y][x].getGroupIndex());
+
+ squares[y][x].visit = true;
+ like(color, squares, y, x + 1, origy, origx);
+ }
+ }
+ squares[y][x].visit = false;
+ }
+
+ }
+ }
+ }
+
+ // Mozliwe ze wogole nie potrzebne
+ public void blank() {
+ this.setColorName(new Color(255, 255, 255));
+ this.value = 1;
+
+ }
+
+ public void toUp(Field [][] squares, int y, int x) {
+
+ int n = 9;
+ Color temp; // String
+ int v; // = new Box();
+ for(int i=0; i < n; i++){
+ for(int j=1; j < (n-i); j++){
+ if(squares[j-1][x].value > squares[j][x].value) {
+ //swap elements
+ temp = squares[j-1][x].getColor();
+ v = squares[j-1][x].value;
+ squares[j-1][x].setColorName(squares[j][x].getColor());
+ squares[j-1][x].value = squares[j][x].value;
+ squares[j][x].setColorName(temp);
+ squares[j][x].value = v;
+ }
+
+ }
+ }
+ }
+
+ public void toLeft(Field [][] squares, int y, int x) {
+
+ int n = 6;
+ Color temp; //String
+ int v; // = new Box();
+ for(int i=0; i < n; i++){
+ for(int j=1; j < (n-i); j++){
+ if(squares[y][j-1].value > squares[y][j].value) {
+ //swap elements
+ temp = squares[y][j-1].getColor();
+ v = squares[y][j-1].value;
+ squares[y][j-1].setColorName(squares[y][j].getColor());
+ squares[y][j-1].value = squares[y][j].value;
+ squares[y][j].setColorName(temp);
+ squares[y][j].value = v;
+ }
+
+ }
+ }
+ }
+
+ public void removeDuplicates() {
+
+ java.util.List<String> tmp = new ArrayList<String> ();
+
+ for(String item:this.groupList){
+ boolean find = false;
+ for (String t:tmp) {
+ if (t.equals(item)){
+ find = true;
+ }
+ }
+ if (find == false) {
+ tmp.add(item);
+ }
+ }
+ this.groupList.clear();
+ this.groupList = tmp;
+ }
+
+ public void removeDuplicatesIndex() {
+
+ java.util.List<Integer> tmp = new ArrayList<Integer> ();
+
+ for(Integer item:this.listIndex){
+ boolean find = false;
+ for (Integer t:tmp) {
+ if (t.equals(item)){
+ find = true;
+ }
+ }
+ if (find == false) {
+ tmp.add(item);
+ }
+ }
+ this.listIndex.clear();
+ this.listIndex = tmp;
+ }
+
+ public void clearVisit(){
+ this.visit = false;
+ }
+
+ public void sort() {
+
+ // Zbyt nowe dopiero od API 24
+ //String[] strings = b.groupList.toArray(String[]::new);
+ String[] strings = new String[this.groupList.size()];
+ for (int i = 0; i < this.groupList.size(); i++) {
+ strings[i] = this.groupList.get(i);
+ }
+
+ Integer[] numbers = new Integer[strings.length];
+ for(int i = 0;i < strings.length;i++)
+ {
+ try
+ {
+ numbers[i] = Integer.parseInt(strings[i]);
+ }
+ catch (NumberFormatException nfe)
+ {
+ numbers[i] = null;
+ }
+ }
+
+ Arrays.sort(numbers, Collections.reverseOrder());
+
+ this.groupList.clear();
+ for(int i = 0;i < numbers.length;i++)
+ {
+ try
+ {
+ this.groupList.add(Integer.toString(numbers[i]));
+ }
+ catch (NumberFormatException nfe)
+ {
+ //numbers[i] = null;
+ }
+ }
+
+ }
+
+ public void sortReverseIndex() {
+ // Zbyt nowe dopiero od API 24
+ //String[] strings = b.groupList.toArray(String[]::new);
+ Integer[] integers = new Integer[this.listIndex.size()];
+ for (int i = 0; i < this.listIndex.size(); i++) {
+ integers[i] = this.listIndex.get(i);
+ }
+
+ Arrays.sort(integers, Collections.reverseOrder());
+
+ this.listIndex.clear();
+ for(int i = 0;i < integers.length;i++)
+ {
+ try
+ {
+ this.listIndex.add(integers[i]);
+ }
+ catch (NumberFormatException nfe)
+ {
+ }
+ }
+ }
+}
diff --git a/desktop/samegame/src/pietraszczyk/samegame/SameGame.java b/desktop/samegame/src/pietraszczyk/samegame/SameGame.java new file mode 100644 index 0000000..ae923d8 --- /dev/null +++ b/desktop/samegame/src/pietraszczyk/samegame/SameGame.java @@ -0,0 +1,408 @@ +/*
+ * Same Game - desktop - third approach to the problem
+ * 29-III-2024
+ * code: Przemyslaw R. Pietraszczyk
+ * licence: GPL v3
+ * IDE: Geany
+ */
+package pietraszczyk.samegame;
+
+import java.awt.*; // Toolkit
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+//import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JMenuBar;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.Box;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.util.Timer;
+import java.util.*; //Timer
+import java.lang.*;
+
+public class SameGame extends JPanel
+ implements ActionListener {
+ static JMenuBar menuBar;
+ JMenu menu, info;
+ JMenuItem menuItem, menuExit, menuInfo, l1, l2, l3, l4;
+ static final int NW = 6, NH = 9; //NW=9, NH=6; // weight - height
+ static JFrame frame;
+ static Timer timer;
+ static Field [][]field = new Field[NH][NW];
+ static int []tmpi = new int[2];
+ static int []tmpj = new int[2];
+ static boolean showColor=false;
+ static boolean press=false;
+ static boolean lockClick=false;
+ static int nmove=0;
+ static int nFields; // ilosc pozostalych pol do odkrycia
+ static JLabel label = new JLabel("Witaj w Same Game - poziom 1");
+ static int score;
+ static int level;
+
+ public SameGame() {
+ super(new GridBagLayout());
+ GridBagLayout gridbag = (GridBagLayout)getLayout();
+ GridBagConstraints c = new GridBagConstraints();
+ int i;
+ int j;
+ // int x, y;
+ int k=0;
+ level = 1;
+
+ menuBar = new JMenuBar();
+ menu = new JMenu("Plik");
+ menuBar.add(menu);
+ // przenosi INFO na prawa strone
+ menuBar.add(Box.createHorizontalGlue());
+ info = new JMenu("Info");
+ info.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+ menuBar.add(info);
+ menuItem = new JMenuItem("Nowa Gra", null);
+ menuItem.setActionCommand("NewGame");
+ menuItem.addActionListener(this);
+ menuItem.setToolTipText("Rozpoczyna nowa gre");
+ menu.add(menuItem);
+
+ JMenu med = new JMenu("Poziom");
+ l1 = new JMenuItem("Dwa kolory");
+ l1.setActionCommand("L1");
+ l1.addActionListener(this);
+ med.add(l1);
+ l2 = new JMenuItem("Trzy kolory");
+ l2.setActionCommand("L2");
+ l2.addActionListener(this);
+ med.add(l2);
+ l3 = new JMenuItem("Cztery kolory");
+ l3.setActionCommand("L3");
+ l3.addActionListener(this);
+ med.add(l3);
+ l4 = new JMenuItem("Piec kolorow");
+ l4.setActionCommand("L4");
+ l4.addActionListener(this);
+ med.add(l4);
+
+ menu.add(med);
+
+ menu.addSeparator();
+ menuItem = new JMenuItem("Zakoncz", null);
+ menuItem.setActionCommand("Exit");
+ menuItem.addActionListener(this);
+ menuItem.setToolTipText("Wyjscie z programu");
+ menu.add(menuItem);
+ menuItem = new JMenuItem("O Programie", null);
+ menuItem.setActionCommand("About");
+ menuItem.addActionListener(this);
+ menuItem.setToolTipText("Informacje o programie");
+ info.add(menuItem);
+
+ for (i=0; i<NH;i++) {
+ for (j = 0; j < NW; j++, k++) {
+ field[i][j] = new Field(i, j);
+ field[i][j].button.setActionCommand("colorButton"+k);
+ field[i][j].button.addActionListener(this);
+ }
+ }
+ init();
+
+ for (i=0;i<NH;i++) {
+ for (j=0;j<NW;j++,k++) {
+ field[i][j].button.setPreferredSize(new Dimension(60, 60));
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.gridx = j;
+ c.gridy = i;
+ gridbag.setConstraints(field[i][j].button, c);
+ field[i][j].button.setBackground(field[i][j].getColor());
+ add(field[i][j].button);
+ field[i][j].button.setFont(new Font("Arial", Font.PLAIN, 40));
+ }
+ }
+ label.setPreferredSize(new Dimension(100, 20));
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.gridwidth = 6; //9;
+ c.gridx = 0;
+ c.gridy = 9; //6;
+ gridbag.setConstraints(label, c);
+ add(label);
+ }
+ private void init(){
+ int i,j,x,y,k=0;
+ Random rand = new Random();
+ int cc=-1;
+ score = 0;
+ final int []r={64,96,128,0,178,196,255};
+ final int []g={64,0,0,32,16,128,255,128};
+ final int []b={0,45,128,128,64,32,0,255};
+
+ for (i=0;i<NH;i++) {
+ for (j = 0; j < NW; j++, k++) {
+
+ cc = rand.nextInt(level+1); // max 7
+
+ field[i][j].setColorName(new Color(r[cc], g[cc], b[cc])); // 9
+ field[i][j].setGroupIndex(k);
+ }
+ }
+ nFields=k;
+
+ for (k=0, i=0;i<NH;i++) {
+ for (j = 0; j < NW; j++, k++) {
+ field[i][j].like(field[i][j].getColor(), field, i, j, i, j);
+
+ field[i][j].clearVisit();
+
+ field[i][j].removeDuplicates();
+ field[i][j].sort(); // also reverse
+
+ field[i][j].removeDuplicatesIndex();
+ field[i][j].sortReverseIndex();
+ }
+ }
+ }
+
+ public void actionPerformed(ActionEvent e){
+ int k=0;
+ int _x[] = {0,1,2,3,4,5};
+ int _y[] = {0,1,2,3,4,5,6,7,8};
+ ///if (!lockClick) {
+ for (int i = 0; i < NH; i++) {
+ for (int j = 0; j < NW; j++, k++) {
+ if (e.getActionCommand().equals("colorButton"+k)) {
+ if (field[i][j].groupList.size() > 1) {
+
+ int c = 0;
+ for (int l : field[i][j].listIndex) {
+ int y = l / 6;
+ int x = l % 6;
+ field[y][x].blank();
+ }
+ // Przesuniecie w lerwo
+ for (int l :field[i][j].listIndex) {
+ int y = l / 6;
+ int x = l % 6;
+ field[y][x].toLeft(field, y, x);
+ }
+
+ int s = 0;
+ s = field[i][j].listIndex.size();
+ s = (s * (s -1)) * level * level;
+ score += s;
+ // Usuwanie elementow
+ for (int y : _y) {
+ for (int x : _x) {
+ field[y][x].groupList.clear();
+ field[y][x].listIndex.clear();
+ }
+ }
+
+
+ for (int y=0;y<NH;y++) {
+ for (int x = 0; x < NW; x++) {
+ field[y][x].like(field[y][x].getColor(), field, y, x, y, x);
+
+ field[y][x].clearVisit();
+
+ field[y][x].removeDuplicates();
+ field[y][x].sort(); // also reverse
+
+ field[y][x].removeDuplicatesIndex();
+ field[y][x].sortReverseIndex();
+ field[y][x].button.setBackground(field[y][x].getColor());
+
+ }
+ }
+
+
+ /* Do gory */
+ for (int y=0;y<NH;y++)
+ for (int x = 0; x < NW; x++)
+ field[y][x].toUp(field, y, x);
+
+
+ for (int y : _y) {
+ for (int x : _x) {
+ field[y][x].groupList.clear();
+ field[y][x].listIndex.clear();
+ }
+ }
+
+ for (int y=0;y<NH;y++) {
+ for (int x = 0; x < NW; x++, k++) {
+ field[y][x].like(field[y][x].getColor(), field, y, x, y, x);
+
+ field[y][x].clearVisit();
+
+ field[y][x].removeDuplicates();
+ field[y][x].sort(); // also reverse
+
+ field[y][x].removeDuplicatesIndex();
+ field[y][x].sortReverseIndex();
+ field[y][x].button.setBackground(field[y][x].getColor());
+
+ }
+ }
+
+ boolean game_in_progress = false;
+ int path_to_win = 0;
+ for (int y=0;y<NH;y++) {
+ for (int x = 0; x < NW; x++, k++) {
+ if (field[y][x].groupList.size() >= 2) game_in_progress = true;
+ if (field[y][x].groupList.size() == 0) ++path_to_win;
+ }
+ }
+ if (!game_in_progress){
+ String l = new String("Nieskonczona gra, wynik: ");
+ l += String.valueOf(score * level);
+ label.setText(l);
+ }
+ if (path_to_win == 54) {
+ String l = new String("Wygrana ! wynik: ");
+ l += String.valueOf(2 * (score * level));
+ label.setText(l);
+ }
+ return;
+ }
+ }
+ }
+ }
+ if(e.getActionCommand().equals("NewGame")) {
+ int i,j;
+ for (i=0; i<NH;i++) {
+ for (j = 0; j < NW; j++, k++) {
+ field[i][j].reset();
+ }
+ }
+
+ for (int y : _y) {
+ for (int x : _x) {
+ field[y][x].groupList.clear();
+ field[y][x].listIndex.clear();
+ }
+ }
+ init();
+ for (int y=0;y<NH;y++)
+ for (int x = 0; x < NW; x++)
+ field[y][x].button.setBackground(field[y][x].getColor());
+ nmove=0;
+ score = 0;
+ String g = new String ("Nowa gra - poziom: ");
+ g += String.valueOf(level);
+ label.setText(g);
+ }
+ else if(e.getActionCommand().equals("Exit")) {
+ System.exit(0);
+ }
+ else if(e.getActionCommand().equals("About")) {
+
+ JOptionPane.showMessageDialog(frame,
+ "Moja implementacja gry Same Game\nPrzemyslaw R. Pietraszczyk\nStworzono w oparciu o OpenJDK/ANT\nLicencja: GPL v3\nWiosna 2024",
+ "Same Game 0.240417-2",
+ JOptionPane.PLAIN_MESSAGE);
+
+ }
+ else if(e.getActionCommand().equals("L1")) {
+ level = 1;
+ }
+ else if(e.getActionCommand().equals("L2")) {
+ level = 2;
+ }
+ else if(e.getActionCommand().equals("L3")) {
+ level = 3;
+ }
+ else if(e.getActionCommand().equals("L4")) {
+ level = 4;
+ }
+ }
+
+ private static void createAndShowGUI() {
+ JFrame frame = new JFrame("Same Game");
+ timer = new Timer();
+ int frameWidth = 300;
+ int frameHeight = 400;
+ // ustawia okno po prawe na dole
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ //frame.setBounds((int) screenSize.getWidth()/2 - frameWidth/2,
+ // (int) screenSize.getHeight() - frameHeight, frameWidth, frameHeight);
+ frame.setBounds((int) screenSize.getWidth() - frameWidth,
+ (int) screenSize.getHeight()/2 - frameHeight/2, frameWidth, frameHeight);
+ frame.setResizable(false);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ //Create and set up the content pane.
+ JComponent newContentPane = new SameGame();
+ newContentPane.setOpaque(true); //content panes must be opaque
+ frame.setJMenuBar(menuBar);
+ frame.setContentPane(newContentPane);
+
+
+ //Display the window.
+ frame.pack();
+ frame.setVisible(true);
+
+ //timer.schedule(new ClearField(), 2000, 3000);
+
+ }
+ public static void main(String[] args) {
+ //Schedule a job for the event-dispatching thread:
+ //creating and showing this application's GUI.
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ createAndShowGUI();
+ }
+ });
+ }
+/*
+ static class ClearField extends TimerTask {
+ public void run() {
+ if (nFields!=0) {
+ if (showColor) {
+ System.out.println("show color");
+ press = false;
+ field[tmpi[0]][tmpj[0]].button.setBackground(field[tmpi[0]][tmpj[0]].getColor());
+ field[tmpi[1]][tmpj[1]].button.setBackground(field[tmpi[1]][tmpj[1]].getColor());
+ showColor = false;
+ lockClick = false;
+ //nmove++;
+ //System.out.println("Color 0: "+field[tmpi[0]][tmpj[0]].getColorHide().toString()+" Color 1:"+field[tmpi[1]][tmpj[1]].getColorHide().toString());
+ // zapobiega zanikaniu pojedynczego kafla
+ if (tmpi[0] != tmpi[1] || tmpj[0] != tmpj[1]) {
+ //label.setText(" Odnaleziono !");
+ // jesli te same kolory
+ if (field[tmpi[0]][tmpj[0]].getColorHide().toString().equals(field[tmpi[1]][tmpj[1]].getColorHide().toString())) {
+
+ //field[tmpi[0]][tmpj[0]].setFound(true);
+ //field[tmpi[1]][tmpj[1]].setFound(true);
+ field[tmpi[0]][tmpj[0]].button.setText(" ");
+ field[tmpi[1]][tmpj[1]].button.setText(" ");
+ //Toolkit.getDefaultToolkit().beep();
+
+ label.setText("");
+ nFields -= 2;
+ System.out.println("nFields: " + nFields);
+ } else label.setText("");
+ }
+
+
+ }
+ }
+ else {
+ JOptionPane.showMessageDialog(frame,
+ "Wykonales "+nmove+" posuniec",
+ "Podsumowanie",
+ JOptionPane.PLAIN_MESSAGE);
+ nFields=1; // aby nie wyswietlalo drugi raz
+
+ }
+
+
+ }
+
+ }
+ */
+}
+//}
|