This commit is contained in:
2025-11-03 10:50:15 +01:00
parent 63475a0c07
commit 271c81f90c
2 changed files with 88 additions and 44 deletions

View File

@@ -4,16 +4,9 @@ import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.control.Label;
import javafx.scene.shape.Circle;
import java.util.HashSet;
/**
*
* Beschreibung
*
* @version 1.0 vom 30.09.2025
* @author
*/
public class Game {
public int[][] win_comb = {{0,3,6},{9,4,12}
@@ -52,8 +45,33 @@ public class Game {
setLabelText("White Turn");
}
public void restart() {
for (int i = 0; i < chips.size(); i++) {
game_board.getChildren().remove(chips.get(i).getShape());
}
chips.clear();
for (int i = 0; i < buttons.size(); i++) {
buttons.get(i).setActive(true);
buttons.get(i).create();
}
white_chips = 9;
black_chips = 9;
setChipCount(white_chips, "White");
setChipCount(black_chips, "Black");
game_state = 0;
currentTurnPlayer = "White";
setLabelText("White Turn");
}
public void chip_button_clicked(MuehleButton button) {
System.out.println("id" + button.id);
if (game_state == 0) {
Chip newChip;
if (currentTurnPlayer == "White") {
@@ -108,13 +126,6 @@ public class Game {
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();
}
@@ -150,7 +161,7 @@ public class Game {
}
public void chip_clicked(Chip chip) {
System.out.println("Chipd id: " + chip.id);
if (game_state == 1) {
if(currentTurnPlayer == "White" && chip.color == Color.WHITE) {
@@ -201,8 +212,16 @@ public class Game {
} // end of if
}
}
public void drawAllButtons() {
for (int i = 0; i < buttons.size(); i++) {
if (!buttons.get(i).isDestroyed) {
buttons.get(i).setActive(true);
}
} // end of for
}
public void drawAvaibleMoves(Chip chip) {
if(getAmouuntOfColorChips(chip.color) > 3) {
if(getAmountOfColorChips(chip.color) > 3) {
drawAvaibleButtons(chip);
}
else {
@@ -222,13 +241,7 @@ 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
}
@@ -245,7 +258,7 @@ public class Game {
public void removeChipTurn() {
if (white_combos > 0 || black_combos > 0) {
hideAllButtons();
hideAllButtons();
if (white_combos > 0) {
setLabelText("White, You can remove "+ white_combos + " Black Pieces");
game_state = 2;
@@ -270,11 +283,11 @@ public class Game {
current_selection = null;
}
if(getAmouuntOfColorChips(Color.BLACK) == 2) {
if(getAmountOfColorChips(Color.BLACK) == 2) {
setLabelText("White won!!!");
game_state = 4;
}
if(getAmouuntOfColorChips(Color.WHITE) == 2) {
if(getAmountOfColorChips(Color.WHITE) == 2) {
setLabelText("Black won!!!");
game_state = 4;
}
@@ -282,7 +295,8 @@ public class Game {
}
else {
if (game_state != 4) {
game_state = 0;
game_state = 0;
drawAllButtons();
} // end of if
}
@@ -297,7 +311,7 @@ public class Game {
setLabelText("White Turn");
}
}
}
@@ -312,7 +326,7 @@ public class Game {
for (int j = 0; j < win_comb[i].length; j++) {
if (win_comb[i][j] == id) {
Chip[] chips_to_check = {getChipById(win_comb[i][0]),getChipById(win_comb[i][1]),getChipById(win_comb[i][2])};
//System.out.println("ID: " +id + " 0:"+win_comb[i][0]+" 1:"+win_comb[i][1]+" 2:"+win_comb[i][2]);
if (checkChipsColor(chips_to_check)) {
if (getChipById(id).color == Color.WHITE) {
white_combos++;
@@ -367,8 +381,11 @@ public class Game {
}
public void setChipCount(int value, String player) {
System.out.println(white_chips-1);
if (player == "White") {
for (int i = 0; i < white_player_chips.length; i++) {
white_player_chips[i].setVisible(true);
} // end of for
if (white_chips == 0) {
for (int i = 0; i < white_player_chips.length -1; i++) {
white_player_chips[i].setVisible(false);
@@ -380,7 +397,11 @@ public class Game {
}
else {
{
for (int i = 0; i < black_player_chips.length; i++) {
black_player_chips[i].setVisible(true);
}
if (white_chips == 0) {
for (int i = 0; i < black_player_chips.length -1; i++) {
black_player_chips[i].setVisible(false);
@@ -394,7 +415,7 @@ public class Game {
} // end of if-else
}
public int getAmouuntOfColorChips(Color color) {
public int getAmountOfColorChips(Color color) {
int result = 0;
for (int i = 0; i < chips.size(); i++) {
if (chips.get(i).color == color) {

View File

@@ -19,6 +19,10 @@ import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.input.KeyEvent;
import javafx.scene.control.Button;
import javafx.event.ActionEvent;
/**
*
* Beschreibung
@@ -31,6 +35,8 @@ public class Muehle extends Application {
// start attributes
// end attributes
private Label lTop = new Label();
private Button restart_button;
private Pane game_board;
private Game game;
@@ -38,16 +44,28 @@ public class Muehle extends Application {
VBox root = new VBox();
game = new Game();
// lTop.setMaxWidth(1080);
HBox label_box = new HBox(lTop);
label_box.setAlignment(Pos.CENTER);
lTop.setFont(Font.font("Roboto",FontWeight.BOLD,40));
game_board = draw_game_board();
root.getChildren().addAll(label_box,game_board);
restart_button = new Button("Restart");
restart_button.setStyle("-fx-background-color: rgb(255,255,0); -fx-padding: 20px; -fx-text-fill: rgb(255,0,0);");
restart_button.addEventHandler(ActionEvent.ACTION, restart_event);
root.getChildren().addAll(label_box,game_board, restart_button);
// game_board.addEventHandler(KeyEvent.KEY_PRESSED, restart_event);
root.setStyle("-fx-background-color: rgb(255, 190, 0)");
Scene scene = new Scene(root, 1080, 820);
@@ -58,7 +76,7 @@ public class Muehle extends Application {
drawPlayerChips();
//lTop.setAlignment();
// setTopLabel("Test Label");
// setTopLabel("Test Label");
primaryStage.setOnCloseRequest(e -> System.exit(0));
@@ -142,7 +160,7 @@ public class Muehle extends Application {
return board;
}
public void drawMuehleButtons(Pane board, double topLeftX,double topLeftY,double topRightX,double topRightY) {
ArrayList<MuehleButton> buttons = new ArrayList<MuehleButton>();
@@ -185,7 +203,7 @@ public class Muehle extends Application {
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(id_count,topLeftX +200,topLeftY+ i*130 +200,game);
id_count++;
buttons.add(button);
@@ -237,9 +255,14 @@ public class Muehle extends Application {
}
// end methods
} // end of class Muehle
public EventHandler<ActionEvent> restart_event = new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
game.restart();
}
};
// end methods
} // end of class Muehle