final
This commit is contained in:
81
Game.java
81
Game.java
@@ -4,15 +4,8 @@ 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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -283,6 +296,7 @@ public class Game {
|
||||
else {
|
||||
if (game_state != 4) {
|
||||
game_state = 0;
|
||||
drawAllButtons();
|
||||
} // end of if
|
||||
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
29
Muehle.java
29
Muehle.java
@@ -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);
|
||||
@@ -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 of class Muehle
|
||||
} // end of class Muehle
|
||||
|
||||
Reference in New Issue
Block a user