diff --git a/Game.class b/Game.class index 943e150..0a88886 100644 Binary files a/Game.class and b/Game.class differ diff --git a/Game.java b/Game.java index 6c46613..38ee3cc 100644 --- a/Game.java +++ b/Game.java @@ -102,15 +102,19 @@ public class Game { } public boolean checkCombo(int relX, int relY) { ArrayList hChips = getHorizontalCloseChips(relX,relY); - ArrayList vChips = getHorizontalCloseChips(relX,relY); - System.out.println(hChips.get(0).relativeX); - Chip start_chip = getChipByPos(relX,relY); + ArrayList vChips = getVerticalCloseChips(relX,relY); - if (start_chip.color == hChips.get(0).color && start_chip.color == hChips.get(1).color) { - return true; + 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) { + return true; + } } - if (start_chip.color == vChips.get(0).color && start_chip.color == vChips.get(1).color) { - 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) { + return true; + } } return false; } @@ -128,7 +132,8 @@ public class Game { else { result.add(getChipByPos(0,relY)); result.add(getChipByPos(1,relY)); - } // end of if-else + } // end of if-else + System.out.println("Result: " + result.toString()); return result; } public ArrayList getVerticalCloseChips(int relX, int relY) { @@ -148,9 +153,9 @@ public class Game { return result; } 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 ) { + System.out.println("X" + chips.get(i).relativeX); return chips.get(i); } // end of if } diff --git a/Game.~ava b/Game.~ava index 318e4c2..989b478 100644 --- a/Game.~ava +++ b/Game.~ava @@ -102,15 +102,19 @@ public class Game { } public boolean checkCombo(int relX, int relY) { ArrayList hChips = getHorizontalCloseChips(relX,relY); - ArrayList vChips = getHorizontalCloseChips(relX,relY); - System.out.println(hChips.get(0).relativeX); - Chip start_chip = getChipByPos(relX,relY); + ArrayList vChips = getVerticalCloseChips(relX,relY); - if (start_chip.color == hChips.get(0).color && start_chip.color == hChips.get(1).color) { - return true; + 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) { + return true; + } } - if (start_chip.color == vChips.get(0).color && start_chip.color == vChips.get(1).color) { - 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) { + return true; + } } return false; } @@ -148,11 +152,9 @@ public class Game { return result; } public Chip getChipByPos(int relX, int relY) { - - for (int i = 0; i < chips.size()-1; i++) { - System.out.println(i); + for (int i = 0; i <= chips.size() - 1; i++) { 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); } // end of if }