final
This commit is contained in:
87
Game.java
87
Game.java
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user