diff --git a/Game.java b/Game.java index b0175fd..57d2fc4 100644 --- a/Game.java +++ b/Game.java @@ -20,9 +20,9 @@ public class Game { ,{18,5,21},{1,10,19},{22,13,7},{20,15,23},{11,16,14},{2,17,8} ,{0,1,2},{9,10,11},{18,19,20},{3,4,5},{12,13,14},{6,7,8},{21,22,23},{15,16,17} }; - public int[][] close_chips = {{1,3},{0,2,10},{1,17},{0,6},{3,5,9,12},{18,21} // 0 1 2 3 4 5 + public int[][] close_chips = {{1,3},{0,2,10},{1,17},{0,4,6},{3,5,9,12},{4,18,21} // 0 1 2 3 4 5 ,{3,7},{6,8},{7,17},{4,10},{9,11,19,1},{10,16},{4,13},{7,12,14,22},{13,16} // 6 7 8 9 10 11 12 13 14 - ,{20,23},{15,17,11,14},{2,16,8},{3,19},{18,20,10},{19,15},{5,22},{21,13,23} // 15 16 17 18 19 20 21 22 22 + ,{16,20,23},{15,17,11,14},{2,16,8},{5,19},{18,20,10},{19,15},{5,22},{21,13,23} // 15 16 17 18 19 20 21 22 22 ,{22,15} }; public String currentTurnPlayer = "White"; @@ -30,9 +30,10 @@ public class Game { public int white_chips = 3; public int black_chips = 3; + public int white_combos = 0; public int black_combos = 0; - + public ArrayList buttons = new ArrayList(); public ArrayList chips = new ArrayList(); public Pane game_board; @@ -137,13 +138,13 @@ public class Game { } public void removeMuehleButton(MuehleButton button) { - for (int i = 0; i < buttons.size(); i++) { - if (buttons.get(i).id == button.id) { - //buttons.remove(i); - button.destroy(); - } // end of if - } // end of for - } + for (int i = 0; i < buttons.size(); i++) { + if (buttons.get(i).id == button.id) { + //buttons.remove(i); + button.destroy(); + } // end of if + } // end of for + } public void addShape(Shape newShape) { game_board.getChildren().add(newShape); @@ -166,23 +167,23 @@ public class Game { if(currentTurnPlayer == "White" && chip.color == Color.WHITE) { if(current_selection == null) { current_selection = chip; - drawAvaibleButtons(current_selection); + drawAvaibleMoves(current_selection); } else { current_selection = chip; hideAllButtons(); - drawAvaibleButtons(current_selection); + drawAvaibleMoves(current_selection); } // end of if-else } else if (currentTurnPlayer == "Black" && chip.color == Color.BLACK){ if(current_selection == null) { current_selection = chip; - drawAvaibleButtons(current_selection); + drawAvaibleMoves(current_selection); } else { current_selection = chip; hideAllButtons(); - drawAvaibleButtons(current_selection); + drawAvaibleMoves(current_selection); } } // end of if-else @@ -192,10 +193,18 @@ public class Game { public void hideAllButtons() { for (int i = 0; i < buttons.size(); i++) { if (!buttons.get(i).isDestroyed) { - buttons.get(i).setActive(false); + buttons.get(i).setActive(false); } // end of if } } + public void drawAvaibleMoves(Chip chip) { + if(getAmouuntOfColorChips(chip.color) > 3) { + drawAvaibleMoves(chip); + } + else { + drawAllAvaibleButtons(chip); + } + } public void drawAvaibleButtons(Chip chip) { ArrayList avaible_buttons = new ArrayList(); for (int i = 0; i < close_chips[chip.id].length ;i++ ) { @@ -219,6 +228,17 @@ public class Game { } + public void drawAllAvaibleButtons(Chip chip) { + //ArrayList avaible_buttons = new ArrayList(); + + for (int i = 0; i < buttons.size(); i++) { + if(isItTaken(buttons.get(i).id) == false) { + //avaible_buttons.add(buttons.get(i)); + buttons.get(i).setActive(true); + } + } // end of for + } + public void removeChipTurn() { if (white_combos > 0 || black_combos > 0) { if (white_combos > 0) { @@ -243,7 +263,17 @@ public class Game { hideAllButtons(); if (current_selection != null) { current_selection = null; - } // end of if + } + + if(getAmouuntOfColorChips(Color.BLACK) == 2) { + setLabelText("White won!!!"); + game_state = 4; + } + if(getAmouuntOfColorChips(Color.WHITE) == 2) { + setLabelText("Black won!!!"); + game_state = 4; + } + } else { game_state = 0; @@ -352,4 +382,14 @@ public class Game { } } // end of if-else } + + public int getAmouuntOfColorChips(Color color) { + int result = 0; + for (int i = 0; i < chips.size(); i++) { + if (chips.get(i).color == color) { + result++; + } // end of if + } + return result; + } } \ No newline at end of file