From 9a81ee736e470c7c37722077608744ff5b4c70ef Mon Sep 17 00:00:00 2001 From: Nikolai Date: Wed, 22 Oct 2025 10:54:21 +0200 Subject: [PATCH] 22.10 --- Game.java | 87 ++++++++++++++++++++++++++++++++++------------- Muehle.java | 2 +- MuehleButton.java | 12 +++++++ 3 files changed, 76 insertions(+), 25 deletions(-) diff --git a/Game.java b/Game.java index 49864f6..b0175fd 100644 --- a/Game.java +++ b/Game.java @@ -4,6 +4,7 @@ import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.control.Label; import javafx.scene.shape.Circle; +import java.util.HashSet; /** * @@ -19,19 +20,19 @@ 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} - ,{3,7},{6,8},{7,17},{4,10},{9,11,19,1},{10,16},{4,13},{7,12,14,22},{13,16} - ,{20,23},{15,17,11,14},{2,16,8},{3,19},{18,20,10},{19,15},{5,22},{21,13,23} + 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 + ,{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 ,{22,15} }; public String currentTurnPlayer = "White"; public int game_state = 0; // 0 == players placing their chips; 1 = players moving their chips; 2,3 = player can remove chip - public int white_chips = 4; - public int black_chips = 4; + 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; @@ -67,8 +68,9 @@ public class Game { } checkCombo(newChip); removeChipTurn(); - game_board.getChildren().remove(button); - + //game_board.getChildren().remove(button); + button.destroy(); + button.setActive(false); } if(game_state == 1) { // second state of game @@ -83,19 +85,35 @@ public class Game { } public void moveChip(Chip chip,MuehleButton target) { Chip newChip = new Chip(target.id,0,0,target.absoluteX,target.absoluteY,chip.color,chip.game); - MuehleButton newButton = new MuehleButton(chip.id,0,0,chip.absoluteX, chip.absoluteY,chip.game); + //MuehleButton newButton = new MuehleButton(chip.id,0,0,chip.absoluteX, chip.absoluteY,chip.game); + + //buttons.remove(target); + //removeMuehleButton(target); + MuehleButton newButton = getButtonById(chip.id); + newButton.create(); + target.destroy(); + chips.remove(chip); + + //buttons.add(newButton); + - buttons.add(newButton); chips.add(newChip); - addShape(newButton.getShape()); - addShape(newChip.getShape()); - buttons.remove(target); - chips.remove(chip); - game_board.getChildren().remove(target.getShape()); + //game_board.getChildren().remove(target.getShape()); game_board.getChildren().remove(chip.getShape()); + //addShape(newButton.getShape()); + addShape(newChip.getShape()); + + + + + + System.out.println("id to del: " + target.id); + for (int i = 0; i < buttons.size() ; i++ ) { + System.out.print("ID: " + buttons.get(i).id + " "); + } // end of for checkCombo(newChip); removeChipTurn(); } @@ -106,19 +124,32 @@ public class Game { return chip; } public void removeChip(Chip chip) { - MuehleButton newButton = new MuehleButton(chip.id,0,0,chip.absoluteX,chip.absoluteY,chip.game); - buttons.add(newButton); - game_board.getChildren().add(newButton.getShape()); - + //MuehleButton newButton = new MuehleButton(chip.id,0,0,chip.absoluteX,chip.absoluteY,chip.game); + //buttons.add(newButton); + //game_board.getChildren().add(newButton.getShape()); + MuehleButton newButton = getButtonById(chip.id); + newButton.create(); chips.remove(chip); game_board.getChildren().remove(chip.getShape()); + if (game_state == 1) { + hideAllButtons(); + } // end of if } + + 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 + } public void addShape(Shape newShape) { game_board.getChildren().add(newShape); } public void chip_clicked(Chip chip) { - + System.out.println("Chipd id: " + chip.id); if(game_state == 2 && chip.color == Color.BLACK) { removeChip(chip); white_combos--; @@ -160,13 +191,15 @@ public class Game { } public void hideAllButtons() { for (int i = 0; i < buttons.size(); i++) { - buttons.get(i).setActive(false); + if (!buttons.get(i).isDestroyed) { + buttons.get(i).setActive(false); + } // end of if } } public void drawAvaibleButtons(Chip chip) { ArrayList avaible_buttons = new ArrayList(); for (int i = 0; i < close_chips[chip.id].length ;i++ ) { - if (!isItTaken(close_chips[chip.id][i])) { + if (!isItTaken(close_chips[chip.id][i]) && getButtonById(close_chips[chip.id][i]).isDestroyed== false) { avaible_buttons.add(getButtonById(close_chips[chip.id][i])); } // end of if @@ -176,7 +209,13 @@ public class Game { avaible_buttons.get(i).setActive(true); } // end of for } - + System.out.println(); + for (int i = 0; i < buttons.size() ; i++ ) { + System.out.print("ID: " + buttons.get(i).id + " "); + } + for (int i = 0; i < avaible_buttons.size(); i++) { + System.out.print(" " + avaible_buttons.get(i).id); + } // end of for } @@ -198,7 +237,7 @@ public class Game { } // end of if-else } public void nextTurn() { - + // end of if if (white_chips == 0 && black_chips == 0) { game_state = 1; hideAllButtons(); diff --git a/Muehle.java b/Muehle.java index 2544ea8..84974f7 100644 --- a/Muehle.java +++ b/Muehle.java @@ -179,7 +179,7 @@ public class Muehle extends Application { buttons.add(button); } for (int i = 0; i < 3; i++) { - MuehleButton button = new MuehleButton(id_count,1,i,topRightX -230,topLeftY+ i*100 + 360,game); + MuehleButton button = new MuehleButton(id_count,1,i,topRightX -230,topLeftY+ i*100 + 460,game); id_count++; buttons.add(button); } diff --git a/MuehleButton.java b/MuehleButton.java index dbd1a24..554cb2f 100644 --- a/MuehleButton.java +++ b/MuehleButton.java @@ -24,6 +24,8 @@ public class MuehleButton { public boolean isActive = true; + public boolean isDestroyed = false; + public MuehleButton(int id,int relX, int relY, double absX, double absY, Game game) { this.id = id; @@ -59,6 +61,16 @@ public class MuehleButton { circle.setFill(Color.rgb(0,255,0)); } } + public void destroy( ) { + isDestroyed = true; + circle.setFill(Color.rgb(0,0,0,0)); + + } // end of if-else + + public void create() { + isDestroyed = false; + circle.setFill(this.color); + } EventHandler mouse_click_target = new EventHandler() { public void handle(MouseEvent event) {