From 63475a0c07975f4c1cc56215f45f6fb9092a1a97 Mon Sep 17 00:00:00 2001 From: Nikolai Date: Sat, 1 Nov 2025 11:54:51 +0100 Subject: [PATCH] pre-final --- Chip.java | 8 +++----- Game.java | 45 +++++++++++++++++++++++++-------------------- Muehle.java | 21 ++++++++++++--------- MuehleButton.java | 12 +++++------- 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/Chip.java b/Chip.java index a01de85..db0b087 100644 --- a/Chip.java +++ b/Chip.java @@ -17,8 +17,7 @@ public class Chip { public Color color; - public int relativeX; - public int relativeY; + public double absoluteX; public double absoluteY; @@ -30,11 +29,10 @@ public class Chip { public int id; - public Chip(int id, int relX, int relY,double absX, double absY, Color color, Game game) { + public Chip(int id,double absX, double absY, Color color, Game game) { this.id = id; - relativeX = relX; - relativeY = relY; + absoluteX = absX; absoluteY = absY; diff --git a/Game.java b/Game.java index 91c2d5c..e2293fd 100644 --- a/Game.java +++ b/Game.java @@ -21,14 +21,14 @@ public class Game { ,{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,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 + ,{3,7},{6,8,13},{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 ,{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"; 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 = 3; - public int black_chips = 3; + public int white_chips = 9; + public int black_chips = 9; public int white_combos = 0; @@ -57,13 +57,13 @@ public class Game { if (game_state == 0) { Chip newChip; if (currentTurnPlayer == "White") { - newChip = addChip(button.id,button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.WHITE); + newChip = addChip(button.id,button.absoluteX,button.absoluteY,Color.WHITE); white_chips--; setChipCount(white_chips,"White"); } else { - newChip = addChip(button.id,button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.BLACK); + newChip = addChip(button.id,button.absoluteX,button.absoluteY,Color.BLACK); black_chips--; setChipCount(white_chips,"Black"); } @@ -85,7 +85,7 @@ 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); + Chip newChip = new Chip(target.id,target.absoluteX,target.absoluteY,chip.color,chip.game); //MuehleButton newButton = new MuehleButton(chip.id,0,0,chip.absoluteX, chip.absoluteY,chip.game); //buttons.remove(target); @@ -118,8 +118,8 @@ public class Game { checkCombo(newChip); removeChipTurn(); } - public Chip addChip(int id,int relX, int relY,double absX, double absY, Color color) { - Chip chip = new Chip(id,relX,relY,absX,absY,color,this); + public Chip addChip(int id,double absX, double absY, Color color) { + Chip chip = new Chip(id,absX,absY,color,this); chips.add(chip); addShape(chip.getShape()); return chip; @@ -151,17 +151,6 @@ public class Game { } 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--; - removeChipTurn(); - - } - else if (game_state == 3 && chip.color == Color.WHITE) { - removeChip(chip); - black_combos--; - removeChipTurn(); - } if (game_state == 1) { if(currentTurnPlayer == "White" && chip.color == Color.WHITE) { @@ -189,6 +178,21 @@ public class Game { } + + if(game_state == 2 && chip.color == Color.BLACK) { + removeChip(chip); + white_combos--; + removeChipTurn(); + + + } + else if (game_state == 3 && chip.color == Color.WHITE) { + + removeChip(chip); + black_combos--; + removeChipTurn(); + + } } public void hideAllButtons() { for (int i = 0; i < buttons.size(); i++) { @@ -199,7 +203,7 @@ public class Game { } public void drawAvaibleMoves(Chip chip) { if(getAmouuntOfColorChips(chip.color) > 3) { - drawAvaibleMoves(chip); + drawAvaibleButtons(chip); } else { drawAllAvaibleButtons(chip); @@ -241,6 +245,7 @@ public class Game { public void removeChipTurn() { if (white_combos > 0 || black_combos > 0) { + hideAllButtons(); if (white_combos > 0) { setLabelText("White, You can remove "+ white_combos + " Black Pieces"); game_state = 2; diff --git a/Muehle.java b/Muehle.java index 84974f7..df83d0f 100644 --- a/Muehle.java +++ b/Muehle.java @@ -58,7 +58,7 @@ public class Muehle extends Application { drawPlayerChips(); //lTop.setAlignment(); - setTopLabel("Test Label"); + // setTopLabel("Test Label"); primaryStage.setOnCloseRequest(e -> System.exit(0)); @@ -149,49 +149,49 @@ public class Muehle extends Application { int id_count = 0; for (int i = 0; i < 3; i++) { - MuehleButton button = new MuehleButton(id_count,0,i,topLeftX,topLeftY+ i*325,game); + MuehleButton button = new MuehleButton(id_count,topLeftX,topLeftY+ i*325,game); id_count++; buttons.add(button); } for (int i = 0; i < 3; i++) { - MuehleButton button = new MuehleButton(id_count,1,i,topRightX -230,topLeftY+ i*100,game); + MuehleButton button = new MuehleButton(id_count,topRightX -230,topLeftY+ i*100,game); id_count++; buttons.add(button); } for (int i = 0; i < 3; i++) { - MuehleButton button = new MuehleButton(id_count,2,i,topRightX + 140,topLeftY+ i*325,game); + MuehleButton button = new MuehleButton(id_count,topRightX + 140,topLeftY+ i*325,game); id_count++; buttons.add(button); } for (int i = 0; i < 3; i++) { - MuehleButton button = new MuehleButton(id_count,0,i,topLeftX + 100,topLeftY+ i*220 +100,game); + MuehleButton button = new MuehleButton(id_count,topLeftX + 100,topLeftY+ i*225 +100,game); id_count++; buttons.add(button); } for (int i = 0; i < 3; i++) { - MuehleButton button = new MuehleButton(id_count,2,i,topRightX +40,topLeftY+ i*220 +100,game); + MuehleButton button = new MuehleButton(id_count,topRightX +40,topLeftY+ i*225 +100,game); id_count++; buttons.add(button); } for (int i = 0; i < 3; i++) { - MuehleButton button = new MuehleButton(id_count,1,i,topRightX -230,topLeftY+ i*100 + 460,game); + MuehleButton button = new MuehleButton(id_count,topRightX -230,topLeftY+ i*100 + 460,game); id_count++; buttons.add(button); } for (int i = 0; i < 3; i++) { - MuehleButton button = new MuehleButton(id_count,0,i,topLeftX +200,topLeftY+ i*130 +200,game); + MuehleButton button = new MuehleButton(id_count,topLeftX +200,topLeftY+ i*130 +200,game); id_count++; buttons.add(button); } for (int i = 0; i < 3; i++) { - MuehleButton button = new MuehleButton(id_count,2,i,topLeftX +540,topLeftY+ i*130 +200,game); + MuehleButton button = new MuehleButton(id_count,topLeftX +540,topLeftY+ i*130 +200,game); id_count++; buttons.add(button); } @@ -236,6 +236,9 @@ public class Muehle extends Application { game_board.getChildren().add(newShape); } + + + // end methods diff --git a/MuehleButton.java b/MuehleButton.java index 554cb2f..49f99cb 100644 --- a/MuehleButton.java +++ b/MuehleButton.java @@ -8,8 +8,7 @@ public class MuehleButton { public Game game; - public int relativeX; - public int relativeY; + public double absoluteX; public double absoluteY; @@ -26,11 +25,10 @@ public class MuehleButton { public boolean isDestroyed = false; - public MuehleButton(int id,int relX, int relY, double absX, double absY, Game game) { + public MuehleButton(int id, double absX, double absY, Game game) { this.id = id; - relativeX = relX; - relativeY = relY; + absoluteX = absX; absoluteY = absY; @@ -57,8 +55,8 @@ public class MuehleButton { circle.setFill(this.color); } else { - //circle.setFill(Color.rgb(0,0,0,0)); - circle.setFill(Color.rgb(0,255,0)); + circle.setFill(Color.rgb(0,0,0,0)); + //circle.setFill(Color.rgb(0,255,0)); } } public void destroy( ) {