This commit is contained in:
Mykola Fesenko
2025-10-06 10:59:18 +02:00
parent 0d892f03bb
commit 4504de8c48
3 changed files with 28 additions and 21 deletions

Binary file not shown.

View File

@@ -102,16 +102,20 @@ public class Game {
} }
public boolean checkCombo(int relX, int relY) { public boolean checkCombo(int relX, int relY) {
ArrayList<Chip> hChips = getHorizontalCloseChips(relX,relY); ArrayList<Chip> hChips = getHorizontalCloseChips(relX,relY);
ArrayList<Chip> vChips = getHorizontalCloseChips(relX,relY); ArrayList<Chip> vChips = getVerticalCloseChips(relX,relY);
System.out.println(hChips.get(0).relativeX);
Chip start_chip = getChipByPos(relX,relY);
Chip start_chip = getChipByPos(relX,relY);
System.out.println("Size" + hChips.toString());
if (hChips.get(0) != null && hChips.get(1) != null ) {
if (start_chip.color == hChips.get(0).color && start_chip.color == hChips.get(1).color) { if (start_chip.color == hChips.get(0).color && start_chip.color == hChips.get(1).color) {
return true; return true;
} }
}
if(vChips.get(0) != null && vChips.get(1) != null) {
if (start_chip.color == vChips.get(0).color && start_chip.color == vChips.get(1).color) { if (start_chip.color == vChips.get(0).color && start_chip.color == vChips.get(1).color) {
return true; return true;
} }
}
return false; return false;
} }
@@ -129,6 +133,7 @@ public class Game {
result.add(getChipByPos(0,relY)); result.add(getChipByPos(0,relY));
result.add(getChipByPos(1,relY)); result.add(getChipByPos(1,relY));
} // end of if-else } // end of if-else
System.out.println("Result: " + result.toString());
return result; return result;
} }
public ArrayList<Chip> getVerticalCloseChips(int relX, int relY) { public ArrayList<Chip> getVerticalCloseChips(int relX, int relY) {
@@ -148,9 +153,9 @@ public class Game {
return result; return result;
} }
public Chip getChipByPos(int relX, int relY) { public Chip getChipByPos(int relX, int relY) {
for (int i = 0; i <= chips.size() - 1; i++) {
for (int i = 0; i < chips.size()-1; i++) {
if (chips.get(i).relativeX == relX && chips.get(i).relativeY == relY ) { if (chips.get(i).relativeX == relX && chips.get(i).relativeY == relY ) {
System.out.println("X" + chips.get(i).relativeX);
return chips.get(i); return chips.get(i);
} // end of if } // end of if
} }

View File

@@ -102,16 +102,20 @@ public class Game {
} }
public boolean checkCombo(int relX, int relY) { public boolean checkCombo(int relX, int relY) {
ArrayList<Chip> hChips = getHorizontalCloseChips(relX,relY); ArrayList<Chip> hChips = getHorizontalCloseChips(relX,relY);
ArrayList<Chip> vChips = getHorizontalCloseChips(relX,relY); ArrayList<Chip> vChips = getVerticalCloseChips(relX,relY);
System.out.println(hChips.get(0).relativeX);
Chip start_chip = getChipByPos(relX,relY);
Chip start_chip = getChipByPos(relX,relY);
System.out.println("Size" + hChips.toString());
if (hChips.get(0) != null && hChips.get(1) != null ) {
if (start_chip.color == hChips.get(0).color && start_chip.color == hChips.get(1).color) { if (start_chip.color == hChips.get(0).color && start_chip.color == hChips.get(1).color) {
return true; return true;
} }
}
if(vChips.get(0) != null && vChips.get(1) != null) {
if (start_chip.color == vChips.get(0).color && start_chip.color == vChips.get(1).color) { if (start_chip.color == vChips.get(0).color && start_chip.color == vChips.get(1).color) {
return true; return true;
} }
}
return false; return false;
} }
@@ -148,11 +152,9 @@ public class Game {
return result; return result;
} }
public Chip getChipByPos(int relX, int relY) { public Chip getChipByPos(int relX, int relY) {
for (int i = 0; i <= chips.size() - 1; i++) {
for (int i = 0; i < chips.size()-1; i++) {
System.out.println(i);
if (chips.get(i).relativeX == relX && chips.get(i).relativeY == relY ) { if (chips.get(i).relativeX == relX && chips.get(i).relativeY == relY ) {
System.out.println("Found"); System.out.println("X" + chips.get(i).relativeX);
return chips.get(i); return chips.get(i);
} // end of if } // end of if
} }