This commit is contained in:
2025-10-22 10:50:52 +02:00
parent e3421d4783
commit 8622783206
4 changed files with 708 additions and 708 deletions

150
Chip.java
View File

@@ -1,75 +1,75 @@
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Shape; import javafx.scene.shape.Shape;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.event.Event; import javafx.event.Event;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
/** /**
* *
* Beschreibung * Beschreibung
* *
* @version 1.0 vom 30.09.2025 * @version 1.0 vom 30.09.2025
* @author * @author
*/ */
public class Chip { public class Chip {
public Game game; public Game game;
public Color color; public Color color;
public int relativeX; public int relativeX;
public int relativeY; public int relativeY;
public double absoluteX; public double absoluteX;
public double absoluteY; public double absoluteY;
public double radius; public double radius;
public Circle circle; public Circle circle;
public int id; public int id;
public Chip(int id, int relX, int relY,double absX, double absY, Color color, Game game) { public Chip(int id, int relX, int relY,double absX, double absY, Color color, Game game) {
this.id = id; this.id = id;
relativeX = relX; relativeX = relX;
relativeY = relY; relativeY = relY;
absoluteX = absX; absoluteX = absX;
absoluteY = absY; absoluteY = absY;
this.color = color; this.color = color;
radius = 20; radius = 20;
this.color = color; this.color = color;
circle = new Circle(absoluteX, absoluteY, radius); circle = new Circle(absoluteX, absoluteY, radius);
circle.setFill(this.color); circle.setFill(this.color);
this.game = game; this.game = game;
circle.addEventHandler(MouseEvent.MOUSE_CLICKED, mouse_clicked); circle.addEventHandler(MouseEvent.MOUSE_CLICKED, mouse_clicked);
} }
public void setPositionX(double X) { public void setPositionX(double X) {
absoluteX = X; absoluteX = X;
circle.setCenterX(absoluteX); circle.setCenterX(absoluteX);
} }
public void setPositionY(double Y) { public void setPositionY(double Y) {
absoluteY = Y; absoluteY = Y;
circle.setCenterY(absoluteY); circle.setCenterY(absoluteY);
} }
public Shape getShape() { public Shape getShape() {
return circle; return circle;
} }
EventHandler<MouseEvent> mouse_clicked = new EventHandler<MouseEvent>() { EventHandler<MouseEvent> mouse_clicked = new EventHandler<MouseEvent>() {
public void handle(MouseEvent handle) { public void handle(MouseEvent handle) {
chip_clicked(); chip_clicked();
} }
}; };
public void chip_clicked() { public void chip_clicked() {
game.chip_clicked(this); game.chip_clicked(this);
} }
} // end of Chip } // end of Chip

630
Game.java
View File

@@ -1,316 +1,316 @@
import javafx.scene.shape.Shape; import javafx.scene.shape.Shape;
import java.util.ArrayList; import java.util.ArrayList;
import javafx.scene.layout.Pane; 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;
/** /**
* *
* Beschreibung * Beschreibung
* *
* @version 1.0 vom 30.09.2025 * @version 1.0 vom 30.09.2025
* @author * @author
*/ */
public class Game { public class Game {
public int[][] win_comb = {{0,3,6},{9,4,12} public int[][] win_comb = {{0,3,6},{9,4,12}
,{18,5,21},{1,10,19},{22,13,7},{20,15,23},{11,16,14},{2,17,8} ,{18,5,21},{1,10,19},{22,13,7},{20,15,23},{11,16,14},{2,17,8}
,{0,1,2},{9,10,11},{18,19,20},{3,4,5},{12,13,14},{6,7,8},{21,22,23},{15,16,17} ,{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,6},{3,5,9,12},{18,21} public int[][] close_chips = {{1,3},{0,2,10},{1,17},{0,6},{3,5,9,12},{18,21}
,{3,7},{6,8},{7,17},{4,10},{9,11,19,1},{10,16},{4,13},{7,12,14,22},{13,16} ,{3,7},{6,8},{7,17},{4,10},{9,11,19,1},{10,16},{4,13},{7,12,14,22},{13,16}
,{20,23},{15,17,11,14},{2,16,8},{3,19},{18,20,10},{19,15},{5,22},{21,13,23} ,{20,23},{15,17,11,14},{2,16,8},{3,19},{18,20,10},{19,15},{5,22},{21,13,23}
,{22,15} ,{22,15}
}; };
public String currentTurnPlayer = "White"; 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 game_state = 0; // 0 == players placing their chips; 1 = players moving their chips; 2,3 = player can remove chip
public int white_chips = 4; public int white_chips = 4;
public int black_chips = 4; public int black_chips = 4;
public int white_combos = 0; public int white_combos = 0;
public int black_combos = 0; public int black_combos = 0;
public ArrayList<MuehleButton> buttons = new ArrayList<MuehleButton>(); public ArrayList<MuehleButton> buttons = new ArrayList<MuehleButton>();
public ArrayList<Chip> chips = new ArrayList<Chip>(); public ArrayList<Chip> chips = new ArrayList<Chip>();
public Pane game_board; public Pane game_board;
public Chip current_selection; public Chip current_selection;
public Label LTop; public Label LTop;
public Circle[] white_player_chips = new Circle[9]; public Circle[] white_player_chips = new Circle[9];
public Circle[] black_player_chips = new Circle[9]; public Circle[] black_player_chips = new Circle[9];
public void start(Pane gameBoard, Label label) { public void start(Pane gameBoard, Label label) {
game_board = gameBoard; game_board = gameBoard;
LTop = label; LTop = label;
setLabelText("White Turn"); setLabelText("White Turn");
} }
public void chip_button_clicked(MuehleButton button) { public void chip_button_clicked(MuehleButton button) {
System.out.println("id" + button.id); System.out.println("id" + button.id);
if (game_state == 0) { if (game_state == 0) {
Chip newChip; Chip newChip;
if (currentTurnPlayer == "White") { if (currentTurnPlayer == "White") {
newChip = addChip(button.id,button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.WHITE); newChip = addChip(button.id,button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.WHITE);
white_chips--; white_chips--;
setChipCount(white_chips,"White"); setChipCount(white_chips,"White");
} }
else { else {
newChip = addChip(button.id,button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.BLACK); newChip = addChip(button.id,button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.BLACK);
black_chips--; black_chips--;
setChipCount(white_chips,"Black"); setChipCount(white_chips,"Black");
} }
checkCombo(newChip); checkCombo(newChip);
removeChipTurn(); removeChipTurn();
game_board.getChildren().remove(button); game_board.getChildren().remove(button);
} }
if(game_state == 1) { if(game_state == 1) {
// second state of game // second state of game
if(current_selection != null) { if(current_selection != null) {
moveChip(current_selection, button); moveChip(current_selection, button);
} }
//setLabelText("Second State"); //setLabelText("Second State");
} }
} }
public void moveChip(Chip chip,MuehleButton target) { 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,0,0,target.absoluteX,target.absoluteY,chip.color,chip.game);
MuehleButton newButton = new MuehleButton(chip.id,0,0,chip.absoluteX, chip.absoluteY,chip.game); MuehleButton newButton = new MuehleButton(chip.id,0,0,chip.absoluteX, chip.absoluteY,chip.game);
buttons.add(newButton); buttons.add(newButton);
chips.add(newChip); chips.add(newChip);
addShape(newButton.getShape()); addShape(newButton.getShape());
addShape(newChip.getShape()); addShape(newChip.getShape());
buttons.remove(target); buttons.remove(target);
chips.remove(chip); chips.remove(chip);
game_board.getChildren().remove(target.getShape()); game_board.getChildren().remove(target.getShape());
game_board.getChildren().remove(chip.getShape()); game_board.getChildren().remove(chip.getShape());
checkCombo(newChip); checkCombo(newChip);
removeChipTurn(); removeChipTurn();
} }
public Chip addChip(int id,int relX, int relY,double absX, double absY, Color color) { 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); Chip chip = new Chip(id,relX,relY,absX,absY,color,this);
chips.add(chip); chips.add(chip);
addShape(chip.getShape()); addShape(chip.getShape());
return chip; return chip;
} }
public void removeChip(Chip chip) { public void removeChip(Chip chip) {
MuehleButton newButton = new MuehleButton(chip.id,0,0,chip.absoluteX,chip.absoluteY,chip.game); MuehleButton newButton = new MuehleButton(chip.id,0,0,chip.absoluteX,chip.absoluteY,chip.game);
buttons.add(newButton); buttons.add(newButton);
game_board.getChildren().add(newButton.getShape()); game_board.getChildren().add(newButton.getShape());
chips.remove(chip); chips.remove(chip);
game_board.getChildren().remove(chip.getShape()); game_board.getChildren().remove(chip.getShape());
} }
public void addShape(Shape newShape) { public void addShape(Shape newShape) {
game_board.getChildren().add(newShape); game_board.getChildren().add(newShape);
} }
public void chip_clicked(Chip chip) { public void chip_clicked(Chip chip) {
if(game_state == 2 && chip.color == Color.BLACK) { if(game_state == 2 && chip.color == Color.BLACK) {
removeChip(chip); removeChip(chip);
white_combos--; white_combos--;
removeChipTurn(); removeChipTurn();
} }
else if (game_state == 3 && chip.color == Color.WHITE) { else if (game_state == 3 && chip.color == Color.WHITE) {
removeChip(chip); removeChip(chip);
black_combos--; black_combos--;
removeChipTurn(); removeChipTurn();
} }
if (game_state == 1) { if (game_state == 1) {
if(currentTurnPlayer == "White" && chip.color == Color.WHITE) { if(currentTurnPlayer == "White" && chip.color == Color.WHITE) {
if(current_selection == null) { if(current_selection == null) {
current_selection = chip; current_selection = chip;
drawAvaibleButtons(current_selection); drawAvaibleButtons(current_selection);
} }
else { else {
current_selection = chip; current_selection = chip;
hideAllButtons(); hideAllButtons();
drawAvaibleButtons(current_selection); drawAvaibleButtons(current_selection);
} // end of if-else } // end of if-else
} }
else if (currentTurnPlayer == "Black" && chip.color == Color.BLACK){ else if (currentTurnPlayer == "Black" && chip.color == Color.BLACK){
if(current_selection == null) { if(current_selection == null) {
current_selection = chip; current_selection = chip;
drawAvaibleButtons(current_selection); drawAvaibleButtons(current_selection);
} }
else { else {
current_selection = chip; current_selection = chip;
hideAllButtons(); hideAllButtons();
drawAvaibleButtons(current_selection); drawAvaibleButtons(current_selection);
} }
} // end of if-else } // end of if-else
} }
} }
public void hideAllButtons() { public void hideAllButtons() {
for (int i = 0; i < buttons.size(); i++) { for (int i = 0; i < buttons.size(); i++) {
buttons.get(i).setActive(false); buttons.get(i).setActive(false);
} }
} }
public void drawAvaibleButtons(Chip chip) { public void drawAvaibleButtons(Chip chip) {
ArrayList<MuehleButton> avaible_buttons = new ArrayList<MuehleButton>(); ArrayList<MuehleButton> avaible_buttons = new ArrayList<MuehleButton>();
for (int i = 0; i < close_chips[chip.id].length ;i++ ) { for (int i = 0; i < close_chips[chip.id].length ;i++ ) {
if (!isItTaken(close_chips[chip.id][i])) { if (!isItTaken(close_chips[chip.id][i])) {
avaible_buttons.add(getButtonById(close_chips[chip.id][i])); avaible_buttons.add(getButtonById(close_chips[chip.id][i]));
} // end of if } // end of if
} // end of for } // end of for
if(avaible_buttons.size() > 0) { if(avaible_buttons.size() > 0) {
for (int i = 0; i < avaible_buttons.size(); i++) { for (int i = 0; i < avaible_buttons.size(); i++) {
avaible_buttons.get(i).setActive(true); avaible_buttons.get(i).setActive(true);
} // end of for } // end of for
} }
} }
public void removeChipTurn() { public void removeChipTurn() {
if (white_combos > 0 || black_combos > 0) { if (white_combos > 0 || black_combos > 0) {
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;
} }
if (black_combos > 0) { if (black_combos > 0) {
setLabelText("Black, You can remove "+ black_combos + " White Pieces"); setLabelText("Black, You can remove "+ black_combos + " White Pieces");
game_state = 3; game_state = 3;
} }
} }
else { else {
nextTurn(); nextTurn();
} // end of if-else } // end of if-else
} }
public void nextTurn() { public void nextTurn() {
if (white_chips == 0 && black_chips == 0) { if (white_chips == 0 && black_chips == 0) {
game_state = 1; game_state = 1;
hideAllButtons(); hideAllButtons();
if (current_selection != null) { if (current_selection != null) {
current_selection = null; current_selection = null;
} // end of if } // end of if
} }
else { else {
game_state = 0; game_state = 0;
} }
if (currentTurnPlayer == "White") { if (currentTurnPlayer == "White") {
setLabelText("Black Turn"); setLabelText("Black Turn");
currentTurnPlayer = "Black"; currentTurnPlayer = "Black";
} }
else { else {
currentTurnPlayer = "White"; currentTurnPlayer = "White";
setLabelText("White Turn"); setLabelText("White Turn");
} // end of if-else } // end of if-else
} }
public void setLabelText(String value) { public void setLabelText(String value) {
LTop.setText(value); LTop.setText(value);
} }
public void checkCombo(Chip chip) { public void checkCombo(Chip chip) {
checkCombo(chip.id); checkCombo(chip.id);
} }
public void checkCombo(int id) { public void checkCombo(int id) {
for (int i = 0; i < win_comb.length ;i++ ) { for (int i = 0; i < win_comb.length ;i++ ) {
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]); //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++;
} }
else { else {
black_combos++; black_combos++;
} // end of if-else } // end of if-else
} // end of if } // end of if
} }
} }
} }
} }
public boolean checkChipsColor(Chip[] chips) { public boolean checkChipsColor(Chip[] chips) {
if (chips[0] != null && chips[1] != null && chips[2] != null) { if (chips[0] != null && chips[1] != null && chips[2] != null) {
if (chips[0].color == chips[1].color && chips[0].color == chips[2].color) { if (chips[0].color == chips[1].color && chips[0].color == chips[2].color) {
return true; return true;
} }
else { else {
return false; return false;
} }
} }
else { else {
return false; return false;
} // end of if-else } // end of if-else
} }
public Chip getChipById(int id) { public Chip getChipById(int id) {
for (int i = 0; i < chips.size(); i++) { for (int i = 0; i < chips.size(); i++) {
if (chips.get(i).id == id) { if (chips.get(i).id == id) {
return chips.get(i); return chips.get(i);
} // end of if } // end of if
} // end of for } // end of for
return null; return null;
} }
public MuehleButton getButtonById(int id) { public MuehleButton getButtonById(int id) {
for (int i = 0; i < buttons.size(); i++) { for (int i = 0; i < buttons.size(); i++) {
if (buttons.get(i).id == id) { if (buttons.get(i).id == id) {
return buttons.get(i); return buttons.get(i);
} // end of if } // end of if
} // end of for } // end of for
return null; return null;
} }
public boolean isItTaken(int id) { public boolean isItTaken(int id) {
for (int i = 0; i < chips.size(); i++) { for (int i = 0; i < chips.size(); i++) {
if (chips.get(i).id == id) { if (chips.get(i).id == id) {
return true; return true;
} // end of if } // end of if
} // end of for } // end of for
return false; return false;
} }
public void setChipCount(int value, String player) { public void setChipCount(int value, String player) {
System.out.println(white_chips-1); System.out.println(white_chips-1);
if (player == "White") { if (player == "White") {
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);
} }
} }
for (int i = white_player_chips.length-1; i >= value; i--) { for (int i = white_player_chips.length-1; i >= value; i--) {
white_player_chips[i].setVisible(false); white_player_chips[i].setVisible(false);
} }
} }
else { else {
{ {
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);
} // end of for } // end of for
} // end of if } // end of if
for (int i = black_player_chips.length-1; i >= value; i--) { for (int i = black_player_chips.length-1; i >= value; i--) {
black_player_chips[i].setVisible(false); black_player_chips[i].setVisible(false);
} }
} }
} // end of if-else } // end of if-else
} }
} }

View File

@@ -1,242 +1,242 @@
import javafx.application.Application; import javafx.application.Application;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.stage.Window; import javafx.stage.Window;
import javafx.scene.shape.Shape; import javafx.scene.shape.Shape;
import java.util.ArrayList; import java.util.ArrayList;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.shape.Line; import javafx.scene.shape.Line;
import javafx.event.Event; import javafx.event.Event;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox; 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;
/** /**
* *
* Beschreibung * Beschreibung
* *
* @version 1.0 vom 25.09.2025 * @version 1.0 vom 25.09.2025
* @author * @author
*/ */
public class Muehle extends Application { public class Muehle extends Application {
// start attributes // start attributes
// end attributes // end attributes
private Label lTop = new Label(); private Label lTop = new Label();
private Pane game_board; private Pane game_board;
private Game game; private Game game;
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
VBox root = new VBox(); VBox root = new VBox();
game = new Game(); game = new Game();
// lTop.setMaxWidth(1080); // 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); root.getChildren().addAll(label_box,game_board);
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);
game.start(game_board,lTop); game.start(game_board,lTop);
drawPlayerChips(); drawPlayerChips();
//lTop.setAlignment(); //lTop.setAlignment();
setTopLabel("Test Label"); setTopLabel("Test Label");
primaryStage.setOnCloseRequest(e -> System.exit(0)); primaryStage.setOnCloseRequest(e -> System.exit(0));
primaryStage.setTitle("Muehle"); primaryStage.setTitle("Muehle");
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.show(); primaryStage.show();
} // end of public Muehle } // end of public Muehle
public void setTopLabel(String value) { public void setTopLabel(String value) {
lTop.setText(value); lTop.setText(value);
} }
// start methods // start methods
public Pane draw_game_board() { public Pane draw_game_board() {
Color bg_color = Color.rgb(255,255,0); Color bg_color = Color.rgb(255,255,0);
Color stroke_color = Color.RED; Color stroke_color = Color.RED;
Double circle_offset = 100.0; Double circle_offset = 100.0;
ArrayList<Shape> shapes = new ArrayList<Shape>(); ArrayList<Shape> shapes = new ArrayList<Shape>();
Pane board = new Pane(); Pane board = new Pane();
double topLeftX = (1080/2)-400; double topLeftX = (1080/2)-400;
double topLeftY = 720-(720/2)-300; double topLeftY = 720-(720/2)-300;
double topRightX =(1080/2)+200; double topRightX =(1080/2)+200;
double topRightY = (720/2)+300; double topRightY = (720/2)+300;
Rectangle bg = new Rectangle(topLeftX,topLeftY,topRightX,topRightY); Rectangle bg = new Rectangle(topLeftX,topLeftY,topRightX,topRightY);
bg.setFill(bg_color); bg.setFill(bg_color);
shapes.add(bg); shapes.add(bg);
Rectangle circle1 = new Rectangle(topLeftX,topLeftY,topRightX,topRightY); Rectangle circle1 = new Rectangle(topLeftX,topLeftY,topRightX,topRightY);
circle1.setStroke(stroke_color); circle1.setStroke(stroke_color);
circle1.setStrokeWidth(10); circle1.setStrokeWidth(10);
circle1.setFill(new Color(0.0,0.0,0.0,0.0)); circle1.setFill(new Color(0.0,0.0,0.0,0.0));
shapes.add(circle1); shapes.add(circle1);
Rectangle circle2 = new Rectangle(topLeftX + 100,topLeftY + 100,topRightX - 200,topRightY - 200); Rectangle circle2 = new Rectangle(topLeftX + 100,topLeftY + 100,topRightX - 200,topRightY - 200);
circle2.setStroke(stroke_color); circle2.setStroke(stroke_color);
circle2.setStrokeWidth(10); circle2.setStrokeWidth(10);
circle2.setFill(new Color(0.0,0.0,0.0,0.0)); circle2.setFill(new Color(0.0,0.0,0.0,0.0));
shapes.add(circle2); shapes.add(circle2);
Rectangle circle3 = new Rectangle(topLeftX + 200,topLeftY + 200,topRightX - 400,topRightY - 400); Rectangle circle3 = new Rectangle(topLeftX + 200,topLeftY + 200,topRightX - 400,topRightY - 400);
circle3.setStroke(stroke_color); circle3.setStroke(stroke_color);
circle3.setStrokeWidth(10); circle3.setStrokeWidth(10);
circle3.setFill(new Color(0.0,0.0,0.0,0.0)); circle3.setFill(new Color(0.0,0.0,0.0,0.0));
shapes.add(circle3); shapes.add(circle3);
Line line1 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topLeftY,(topLeftX+topRightX) /2 + topLeftX/2,250); Line line1 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topLeftY,(topLeftX+topRightX) /2 + topLeftX/2,250);
line1.setStroke(stroke_color); line1.setStroke(stroke_color);
line1.setStrokeWidth(10); line1.setStrokeWidth(10);
shapes.add(line1); shapes.add(line1);
Line line2 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topRightY+50,(topLeftX+topRightX) /2 + topLeftX/2,520); Line line2 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topRightY+50,(topLeftX+topRightX) /2 + topLeftX/2,520);
line2.setStroke(stroke_color); line2.setStroke(stroke_color);
line2.setStrokeWidth(10); line2.setStrokeWidth(10);
shapes.add(line2); shapes.add(line2);
Line line3 = new Line(topLeftX,topRightY/2+50,topLeftX+200,topRightY/2+50); Line line3 = new Line(topLeftX,topRightY/2+50,topLeftX+200,topRightY/2+50);
line3.setStroke(stroke_color); line3.setStroke(stroke_color);
line3.setStrokeWidth(10); line3.setStrokeWidth(10);
shapes.add(line3); shapes.add(line3);
Line line4 = new Line(topLeftX+550,topRightY/2+50,topLeftX+200+540,topRightY/2+50); Line line4 = new Line(topLeftX+550,topRightY/2+50,topLeftX+200+540,topRightY/2+50);
line4.setStroke(stroke_color); line4.setStroke(stroke_color);
line4.setStrokeWidth(10); line4.setStrokeWidth(10);
shapes.add(line4); shapes.add(line4);
for (int i = 0; i < shapes.size() ;i++ ) { for (int i = 0; i < shapes.size() ;i++ ) {
board.getChildren().add(shapes.get(i)); board.getChildren().add(shapes.get(i));
} // end of for } // end of for
drawMuehleButtons(board,topLeftX,topLeftY,topRightX,topRightY); drawMuehleButtons(board,topLeftX,topLeftY,topRightX,topRightY);
return board; return board;
} }
public void drawMuehleButtons(Pane board, double topLeftX,double topLeftY,double topRightX,double topRightY) { public void drawMuehleButtons(Pane board, double topLeftX,double topLeftY,double topRightX,double topRightY) {
ArrayList<MuehleButton> buttons = new ArrayList<MuehleButton>(); ArrayList<MuehleButton> buttons = new ArrayList<MuehleButton>();
int id_count = 0; int id_count = 0;
for (int i = 0; i < 3; i++) { 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,0,i,topLeftX,topLeftY+ i*325,game);
id_count++; id_count++;
buttons.add(button); buttons.add(button);
} }
for (int i = 0; i < 3; i++) { 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,1,i,topRightX -230,topLeftY+ i*100,game);
id_count++; id_count++;
buttons.add(button); buttons.add(button);
} }
for (int i = 0; i < 3; i++) { 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,2,i,topRightX + 140,topLeftY+ i*325,game);
id_count++; id_count++;
buttons.add(button); buttons.add(button);
} }
for (int i = 0; i < 3; i++) { 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,0,i,topLeftX + 100,topLeftY+ i*220 +100,game);
id_count++; id_count++;
buttons.add(button); buttons.add(button);
} }
for (int i = 0; i < 3; i++) { 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,2,i,topRightX +40,topLeftY+ i*220 +100,game);
id_count++; id_count++;
buttons.add(button); buttons.add(button);
} }
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(id_count,1,i,topRightX -230,topLeftY+ i*100 + 360,game); MuehleButton button = new MuehleButton(id_count,1,i,topRightX -230,topLeftY+ i*100 + 360,game);
id_count++; id_count++;
buttons.add(button); buttons.add(button);
} }
for (int i = 0; i < 3; i++) { 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,0,i,topLeftX +200,topLeftY+ i*130 +200,game);
id_count++; id_count++;
buttons.add(button); buttons.add(button);
} }
for (int i = 0; i < 3; i++) { 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,2,i,topLeftX +540,topLeftY+ i*130 +200,game);
id_count++; id_count++;
buttons.add(button); buttons.add(button);
} }
game.buttons.addAll(buttons); game.buttons.addAll(buttons);
for (int i = 0; i < buttons.size() ;i++ ) { for (int i = 0; i < buttons.size() ;i++ ) {
board.getChildren().add(buttons.get(i).getShape()); board.getChildren().add(buttons.get(i).getShape());
} }
} }
public void drawPlayerChips() { public void drawPlayerChips() {
Circle[] white_player_chips = new Circle[9]; Circle[] white_player_chips = new Circle[9];
Circle[] black_player_chips = new Circle[9]; Circle[] black_player_chips = new Circle[9];
Color stroke_color = Color.BLACK; Color stroke_color = Color.BLACK;
double stroke_width = 2; double stroke_width = 2;
double radius = 20; double radius = 20;
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
white_player_chips[i] = new Circle(radius*2 +20,50*i+ 200,radius); white_player_chips[i] = new Circle(radius*2 +20,50*i+ 200,radius);
white_player_chips[i].setStroke(stroke_color); white_player_chips[i].setStroke(stroke_color);
white_player_chips[i].setStrokeWidth(stroke_width); white_player_chips[i].setStrokeWidth(stroke_width);
white_player_chips[i].setFill(Color.WHITE); white_player_chips[i].setFill(Color.WHITE);
addShape(white_player_chips[i]); addShape(white_player_chips[i]);
} }
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
black_player_chips[i] = new Circle((1080-20) - radius*2,50*i+ 200,radius); black_player_chips[i] = new Circle((1080-20) - radius*2,50*i+ 200,radius);
black_player_chips[i].setStroke(stroke_color); black_player_chips[i].setStroke(stroke_color);
black_player_chips[i].setStrokeWidth(stroke_width); black_player_chips[i].setStrokeWidth(stroke_width);
black_player_chips[i].setFill(Color.BLACK); black_player_chips[i].setFill(Color.BLACK);
addShape(black_player_chips[i]); addShape(black_player_chips[i]);
} }
game.white_player_chips = white_player_chips; game.white_player_chips = white_player_chips;
game.black_player_chips = black_player_chips; game.black_player_chips = black_player_chips;
} }
public void addShape(Shape newShape) { public void addShape(Shape newShape) {
game_board.getChildren().add(newShape); game_board.getChildren().add(newShape);
} }
// end methods // end methods
} // end of class Muehle } // end of class Muehle

View File

@@ -1,76 +1,76 @@
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.scene.shape.Shape; import javafx.scene.shape.Shape;
import javafx.event.Event; import javafx.event.Event;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
public class MuehleButton { public class MuehleButton {
public Game game; public Game game;
public int relativeX; public int relativeX;
public int relativeY; public int relativeY;
public double absoluteX; public double absoluteX;
public double absoluteY; public double absoluteY;
public Color color = Color.BLUE; public Color color = Color.BLUE;
public double radius; public double radius;
public Circle circle; public Circle circle;
public int id; public int id;
public boolean isActive = true; public boolean isActive = true;
public MuehleButton(int id,int relX, int relY, double absX, double absY, Game game) { public MuehleButton(int id,int relX, int relY, double absX, double absY, Game game) {
this.id = id; this.id = id;
relativeX = relX; relativeX = relX;
relativeY = relY; relativeY = relY;
absoluteX = absX; absoluteX = absX;
absoluteY = absY; absoluteY = absY;
radius = 20; radius = 20;
this.color = color; this.color = color;
circle = new Circle(absoluteX, absoluteY, radius); circle = new Circle(absoluteX, absoluteY, radius);
circle.setFill(this.color); circle.setFill(this.color);
this.game = game; this.game = game;
circle.addEventHandler(MouseEvent.MOUSE_RELEASED, mouse_click_target); circle.addEventHandler(MouseEvent.MOUSE_RELEASED, mouse_click_target);
setActive(true); setActive(true);
} }
public Shape getShape() { public Shape getShape() {
return circle; return circle;
} }
public void setActive(boolean value) { public void setActive(boolean value) {
isActive = value; isActive = value;
if(value == true) { if(value == true) {
circle.setFill(this.color); circle.setFill(this.color);
} }
else { else {
//circle.setFill(Color.rgb(0,0,0,0)); //circle.setFill(Color.rgb(0,0,0,0));
circle.setFill(Color.rgb(0,255,0)); circle.setFill(Color.rgb(0,255,0));
} }
} }
EventHandler<MouseEvent> mouse_click_target = new EventHandler<MouseEvent>() { EventHandler<MouseEvent> mouse_click_target = new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) { public void handle(MouseEvent event) {
if (isActive) { if (isActive) {
MouseClick(); MouseClick();
} // end of if } // end of if
} }
}; };
public void MouseClick() { public void MouseClick() {
game.chip_button_clicked(this); game.chip_button_clicked(this);
} }
} // end of MuehleButton } // end of MuehleButton