final
This commit is contained in:
83
Game.java
83
Game.java
@@ -4,15 +4,8 @@ import javafx.scene.layout.Pane;
|
|||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.shape.Circle;
|
import javafx.scene.shape.Circle;
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Beschreibung
|
|
||||||
*
|
|
||||||
* @version 1.0 vom 30.09.2025
|
|
||||||
* @author
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Game {
|
public class Game {
|
||||||
|
|
||||||
@@ -52,8 +45,33 @@ public class Game {
|
|||||||
setLabelText("White Turn");
|
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) {
|
public void chip_button_clicked(MuehleButton button) {
|
||||||
System.out.println("id" + button.id);
|
|
||||||
if (game_state == 0) {
|
if (game_state == 0) {
|
||||||
Chip newChip;
|
Chip newChip;
|
||||||
if (currentTurnPlayer == "White") {
|
if (currentTurnPlayer == "White") {
|
||||||
@@ -108,13 +126,6 @@ public class Game {
|
|||||||
addShape(newChip.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);
|
checkCombo(newChip);
|
||||||
removeChipTurn();
|
removeChipTurn();
|
||||||
}
|
}
|
||||||
@@ -150,7 +161,7 @@ public class Game {
|
|||||||
|
|
||||||
}
|
}
|
||||||
public void chip_clicked(Chip chip) {
|
public void chip_clicked(Chip chip) {
|
||||||
System.out.println("Chipd id: " + chip.id);
|
|
||||||
|
|
||||||
if (game_state == 1) {
|
if (game_state == 1) {
|
||||||
if(currentTurnPlayer == "White" && chip.color == Color.WHITE) {
|
if(currentTurnPlayer == "White" && chip.color == Color.WHITE) {
|
||||||
@@ -201,8 +212,16 @@ public class Game {
|
|||||||
} // end of if
|
} // 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) {
|
public void drawAvaibleMoves(Chip chip) {
|
||||||
if(getAmouuntOfColorChips(chip.color) > 3) {
|
if(getAmountOfColorChips(chip.color) > 3) {
|
||||||
drawAvaibleButtons(chip);
|
drawAvaibleButtons(chip);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -222,13 +241,7 @@ public class Game {
|
|||||||
avaible_buttons.get(i).setActive(true);
|
avaible_buttons.get(i).setActive(true);
|
||||||
} // end of for
|
} // 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() {
|
public void removeChipTurn() {
|
||||||
if (white_combos > 0 || black_combos > 0) {
|
if (white_combos > 0 || black_combos > 0) {
|
||||||
hideAllButtons();
|
hideAllButtons();
|
||||||
if (white_combos > 0) {
|
if (white_combos > 0) {
|
||||||
setLabelText("White, You can remove "+ white_combos + " Black Pieces");
|
setLabelText("White, You can remove "+ white_combos + " Black Pieces");
|
||||||
game_state = 2;
|
game_state = 2;
|
||||||
@@ -270,11 +283,11 @@ public class Game {
|
|||||||
current_selection = null;
|
current_selection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getAmouuntOfColorChips(Color.BLACK) == 2) {
|
if(getAmountOfColorChips(Color.BLACK) == 2) {
|
||||||
setLabelText("White won!!!");
|
setLabelText("White won!!!");
|
||||||
game_state = 4;
|
game_state = 4;
|
||||||
}
|
}
|
||||||
if(getAmouuntOfColorChips(Color.WHITE) == 2) {
|
if(getAmountOfColorChips(Color.WHITE) == 2) {
|
||||||
setLabelText("Black won!!!");
|
setLabelText("Black won!!!");
|
||||||
game_state = 4;
|
game_state = 4;
|
||||||
}
|
}
|
||||||
@@ -283,6 +296,7 @@ public class Game {
|
|||||||
else {
|
else {
|
||||||
if (game_state != 4) {
|
if (game_state != 4) {
|
||||||
game_state = 0;
|
game_state = 0;
|
||||||
|
drawAllButtons();
|
||||||
} // end of if
|
} // end of if
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -312,7 +326,7 @@ public class Game {
|
|||||||
for (int j = 0; j < win_comb[i].length; j++) {
|
for (int j = 0; j < win_comb[i].length; j++) {
|
||||||
if (win_comb[i][j] == id) {
|
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])};
|
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 (checkChipsColor(chips_to_check)) {
|
||||||
if (getChipById(id).color == Color.WHITE) {
|
if (getChipById(id).color == Color.WHITE) {
|
||||||
white_combos++;
|
white_combos++;
|
||||||
@@ -367,8 +381,11 @@ public class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setChipCount(int value, String player) {
|
public void setChipCount(int value, String player) {
|
||||||
System.out.println(white_chips-1);
|
|
||||||
if (player == "White") {
|
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) {
|
if (white_chips == 0) {
|
||||||
for (int i = 0; i < white_player_chips.length -1; i++) {
|
for (int i = 0; i < white_player_chips.length -1; i++) {
|
||||||
white_player_chips[i].setVisible(false);
|
white_player_chips[i].setVisible(false);
|
||||||
@@ -380,7 +397,11 @@ public class Game {
|
|||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < black_player_chips.length; i++) {
|
||||||
|
black_player_chips[i].setVisible(true);
|
||||||
|
}
|
||||||
if (white_chips == 0) {
|
if (white_chips == 0) {
|
||||||
for (int i = 0; i < black_player_chips.length -1; i++) {
|
for (int i = 0; i < black_player_chips.length -1; i++) {
|
||||||
black_player_chips[i].setVisible(false);
|
black_player_chips[i].setVisible(false);
|
||||||
@@ -394,7 +415,7 @@ public class Game {
|
|||||||
} // end of if-else
|
} // end of if-else
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAmouuntOfColorChips(Color color) {
|
public int getAmountOfColorChips(Color color) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (int i = 0; i < chips.size(); i++) {
|
for (int i = 0; i < chips.size(); i++) {
|
||||||
if (chips.get(i).color == color) {
|
if (chips.get(i).color == color) {
|
||||||
|
|||||||
35
Muehle.java
35
Muehle.java
@@ -19,6 +19,10 @@ import javafx.scene.layout.HBox;
|
|||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import javafx.scene.text.FontWeight;
|
import javafx.scene.text.FontWeight;
|
||||||
import javafx.scene.layout.BackgroundFill;
|
import javafx.scene.layout.BackgroundFill;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Beschreibung
|
* Beschreibung
|
||||||
@@ -31,6 +35,8 @@ public class Muehle extends Application {
|
|||||||
// start attributes
|
// start attributes
|
||||||
// end attributes
|
// end attributes
|
||||||
private Label lTop = new Label();
|
private Label lTop = new Label();
|
||||||
|
private Button restart_button;
|
||||||
|
|
||||||
private Pane game_board;
|
private Pane game_board;
|
||||||
private Game game;
|
private Game game;
|
||||||
|
|
||||||
@@ -38,16 +44,28 @@ public class Muehle extends Application {
|
|||||||
|
|
||||||
|
|
||||||
VBox root = new VBox();
|
VBox root = new VBox();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
game = new Game();
|
game = new Game();
|
||||||
|
|
||||||
// lTop.setMaxWidth(1080);
|
|
||||||
HBox label_box = new HBox(lTop);
|
HBox label_box = new HBox(lTop);
|
||||||
label_box.setAlignment(Pos.CENTER);
|
label_box.setAlignment(Pos.CENTER);
|
||||||
|
|
||||||
lTop.setFont(Font.font("Roboto",FontWeight.BOLD,40));
|
lTop.setFont(Font.font("Roboto",FontWeight.BOLD,40));
|
||||||
|
|
||||||
|
|
||||||
game_board = draw_game_board();
|
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)");
|
root.setStyle("-fx-background-color: rgb(255, 190, 0)");
|
||||||
Scene scene = new Scene(root, 1080, 820);
|
Scene scene = new Scene(root, 1080, 820);
|
||||||
@@ -58,7 +76,7 @@ public class Muehle extends Application {
|
|||||||
drawPlayerChips();
|
drawPlayerChips();
|
||||||
|
|
||||||
//lTop.setAlignment();
|
//lTop.setAlignment();
|
||||||
// setTopLabel("Test Label");
|
// setTopLabel("Test Label");
|
||||||
|
|
||||||
|
|
||||||
primaryStage.setOnCloseRequest(e -> System.exit(0));
|
primaryStage.setOnCloseRequest(e -> System.exit(0));
|
||||||
@@ -237,9 +255,14 @@ public class Muehle extends Application {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EventHandler<ActionEvent> restart_event = new EventHandler<ActionEvent>() {
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
game.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// end methods
|
||||||
// end methods
|
} // end of class Muehle
|
||||||
} // end of class Muehle
|
|
||||||
|
|||||||
Reference in New Issue
Block a user