30.09 ptp

This commit is contained in:
Mykola Fesenko
2025-09-30 10:51:52 +02:00
parent c94eb0f036
commit 5de88e7fae
12 changed files with 408 additions and 175 deletions

BIN
Chip$1.class Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -1,6 +1,9 @@
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.EventHandler;
import javafx.scene.input.MouseEvent;
/** /**
* *
* Beschreibung * Beschreibung
@@ -10,6 +13,7 @@ import javafx.scene.shape.Circle;
*/ */
public class Chip { public class Chip {
public Game game;
public Color color; public Color color;
@@ -24,7 +28,7 @@ public class Chip {
public Circle circle; public Circle circle;
public Chip(relX,relY,absX,absY, Color color) { public Chip(int relX, int relY,double absX, double absY, Color color, Game game) {
relativeX = relX; relativeX = relX;
relativeY = relY; relativeY = relY;
@@ -39,9 +43,29 @@ public class Chip {
circle = new Circle(absoluteX, absoluteY, radius); circle = new Circle(absoluteX, absoluteY, radius);
circle.setFill(this.color); circle.setFill(this.color);
this.game = game;
circle.addEventHandler(MouseEvent.MOUSE_CLICKED, mouse_clicked);
}
public void setPositionX(double X) {
absoluteX = X;
circle.setCenterX(absoluteX);
}
public void setPositionY(double Y) {
absoluteY = Y;
circle.setCenterY(absoluteY);
} }
public Shape getShape() { public Shape getShape() {
return circle; return circle;
} }
EventHandler<MouseEvent> mouse_clicked = new EventHandler<MouseEvent>() {
public void handle(MouseEvent handle) {
chip_clicked();
}
};
public void chip_clicked() {
game.chip_clicked(this);
}
} // end of Chip } // end of Chip

View File

@@ -1,6 +1,9 @@
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.EventHandler;
import javafx.scene.input.MouseEvent;
/** /**
* *
* Beschreibung * Beschreibung
@@ -10,6 +13,7 @@ import javafx.scene.shape.Circle;
*/ */
public class Chip { public class Chip {
public Game game;
public Color color; public Color color;
@@ -24,7 +28,7 @@ public class Chip {
public Circle circle; public Circle circle;
public Chip(relX,relY,absX,absY, Color color) { public Chip(int relX, int relY,double absX, double absY, Color color, Game game) {
relativeX = relX; relativeX = relX;
relativeY = relY; relativeY = relY;
@@ -35,11 +39,33 @@ public class Chip {
radius = 20; radius = 20;
circle = new Circle(absoluteX,absoluteY,radius); this.color = color;
circle = new Circle(absoluteX, absoluteY, radius);
circle.setFill(this.color);
this.game = game;
circle.addEventHandler(MouseEvent.MOUSE_CLICKED, mouse_clicked);
}
public void setPositionX(double X) {
absoluteX = X;
circle.setCenterX(absoluteX);
}
public void setPositionY(double Y) {
absoluteX = Y;
circle.setCenterX(absoluteY);
} }
public Shape getShape() { public Shape getShape() {
return circle; return circle;
} }
EventHandler<MouseEvent> mouse_clicked = new EventHandler<MouseEvent>() {
public void handle(MouseEvent handle) {
chip_clicked();
}
};
public void chip_clicked() {
game.chip_clicked(this);
}
} // end of Chip } // end of Chip

Binary file not shown.

View File

@@ -1,4 +1,7 @@
import javafx.scene.shape.Shape; import javafx.scene.shape.Shape;
import java.util.ArrayList;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
/** /**
* *
* Beschreibung * Beschreibung
@@ -10,17 +13,55 @@ import javafx.scene.shape.Shape;
public class Game { public class Game {
public String currentTurnPlayer = "White"; public String currentTurnPlayer = "White";
public int white_chips = 7; public int game_state = 0; // 0 == players placing their chips; 1 = players moving their chips; 2 = player can remove chip
public int black_chips = 7; public int white_chips = 9;
public int black_chips = 9;
public void addShape(Shape shape); public ArrayList<Shape> buttons = new ArrayList<Shape>();
public ArrayList<Chip> chips = new ArrayList<Chip>();
public void start() { public Pane game_board;
public Chip current_selection;
public void start(Pane gameBoard) {
game_board = gameBoard;
} }
public void chip_button_clicked(MuehleButton button) { public void chip_button_clicked(MuehleButton button) {
System.out.println(button.absoluteX); if (game_state == 0) {
} if (currentTurnPlayer == "White") {
addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.WHITE);
white_chips--;
}
else {
addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.BLACK);
black_chips--;
}
game_board.getChildren().remove(button.getShape());
nextTurn();
} // end of if
}
public void addChip(int relX, int relY,double absX, double absY, Color color) {
Chip chip = new Chip(relX,relY,absX,absY,color,this);
addShape(chip.getShape());
}
public void addShape(Shape newShape) {
game_board.getChildren().add(newShape);
}
public void chip_clicked(Chip chip) {
System.out.println(chip.relativeX);
}
public void nextTurn() {
if (currentTurnPlayer == "White") {
currentTurnPlayer = "Black";
}
else {
currentTurnPlayer = "White";
} // end of if-else
}
} }

View File

@@ -1,3 +1,7 @@
import javafx.scene.shape.Shape;
import java.util.ArrayList;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
/** /**
* *
* Beschreibung * Beschreibung
@@ -9,17 +13,55 @@
public class Game { public class Game {
public String currentTurnPlayer = "White"; public String currentTurnPlayer = "White";
public int white_chips = 7; public int game_state = 0; // 0 == players placing their chips; 1 = players moving their chips
public int black_chips = 7; public int white_chips = 9;
public int black_chips = 9;
public void addShape; public ArrayList<Shape> buttons = new ArrayList<Shape>();
public ArrayList<Chip> chips = new ArrayList<Chip>();
public void start() { public Pane game_board;
public Chip current_selection;
public void start(Pane gameBoard) {
game_board = gameBoard;
} }
public void chip_button_clicked(MuehleButton button) { public void chip_button_clicked(MuehleButton button) {
System.out.println(button.absoluteX); if (game_state == 0) {
} if (currentTurnPlayer == "White") {
addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.WHITE);
white_chips--;
}
else {
addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.BLACK);
black_chips--;
}
game_board.getChildren().remove(button.getShape());
nextTurn();
} // end of if
}
public void addChip(int relX, int relY,double absX, double absY, Color color) {
Chip chip = new Chip(relX,relY,absX,absY,color,this);
addShape(chip.getShape());
}
public void addShape(Shape newShape) {
game_board.getChildren().add(newShape);
}
public void chip_clicked(Chip chip) {
System.out.println(chip.relativeX);
}
public void nextTurn() {
if (currentTurnPlayer == "White") {
currentTurnPlayer = "Black";
}
else {
currentTurnPlayer = "White";
} // end of if-else
}
} }

Binary file not shown.

View File

@@ -29,16 +29,17 @@ public class Muehle extends Application {
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
game = new Game();
game.addShape = addShape;
game.start();
Pane root = new Pane(); Pane root = new Pane();
game = new Game();
game_board = draw_game_board(); game_board = draw_game_board();
root.getChildren().addAll(lTop,game_board); root.getChildren().addAll(lTop,game_board);
Scene scene = new Scene(root, 1080, 820); Scene scene = new Scene(root, 1080, 820);
game.start(game_board);
//lTop.setAlignment(); //lTop.setAlignment();
setTopLabel("Test Label"); setTopLabel("Test Label");
@@ -113,19 +114,68 @@ public class Muehle extends Application {
shapes.add(line4); shapes.add(line4);
MuehleButton button1 = new MuehleButton(0,0,100,100,Color.BLUE,game);
shapes.add(button1.getShape());
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);
return board; return board;
} }
public void drawMuehleButtons(Pane board, double topLeftX,double topLeftY,double topRightX,double topRightY) {
ArrayList<Shape> shapes = new ArrayList<Shape>();
Color button_color = Color.BLUE;
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(0,i,topLeftX,topLeftY+ i*325,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(1,i,topRightX -230,topLeftY+ i*100,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(2,i,topRightX + 140,topLeftY+ i*325,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(0,i,topLeftX + 100,topLeftY+ i*220 +100,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(2,i,topRightX +40,topLeftY+ i*220 +100,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(1,i,topRightX -230,topLeftY+ i*100 +460,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(0,i,topLeftX +200,topLeftY+ i*130 +200,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(2,i,topLeftX +540,topLeftY+ i*130 +200,button_color,game);
shapes.add(button.getShape());
}
game.buttons.addAll(shapes);
for (int i = 0; i < shapes.size() ;i++ ) {
board.getChildren().add(shapes.get(i));
}
}
public void addShape(Shape newShape) { public void addShape(Shape newShape) {
game_board.getChildren().add(newShape); game_board.getChildren().add(newShape);

View File

@@ -29,15 +29,17 @@ public class Muehle extends Application {
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
game = new Game();
game.start();
Pane root = new Pane(); Pane root = new Pane();
game = new Game();
game_board = draw_game_board(); game_board = draw_game_board();
root.getChildren().addAll(lTop,game_board); root.getChildren().addAll(lTop,game_board);
Scene scene = new Scene(root, 1080, 820); Scene scene = new Scene(root, 1080, 820);
game.start(game_board);
//lTop.setAlignment(); //lTop.setAlignment();
setTopLabel("Test Label"); setTopLabel("Test Label");
@@ -112,19 +114,67 @@ public class Muehle extends Application {
shapes.add(line4); shapes.add(line4);
MuehleButton button1 = new MuehleButton(0,0,100,100,Color.BLUE,game);
shapes.add(button1.getShape());
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);
return board; return board;
} }
public void drawMuehleButtons(Pane board, double topLeftX,double topLeftY,double topRightX,double topRightY) {
ArrayList<Shape> shapes = new ArrayList<Shape>();
Color button_color = Color.BLUE;
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(0,i,topLeftX,topLeftY+ i*325,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(1,i,topRightX -230,topLeftY+ i*100,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(2,i,topRightX + 140,topLeftY+ i*325,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(0,i,topLeftX + 100,topLeftY+ i*220 +100,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(2,i,topRightX +40,topLeftY+ i*220 +100,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(1,i,topRightX -230,topLeftY+ i*100 +460,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(0,i,topLeftX +200,topLeftY+ i*130 +200,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < 3; i++) {
MuehleButton button = new MuehleButton(2,i,topLeftX +540,topLeftY+ i*130 +200,button_color,game);
shapes.add(button.getShape());
}
for (int i = 0; i < shapes.size() ;i++ ) {
board.getChildren().add(shapes.get(i));
}
}
public void addShape(Shape newShape) { public void addShape(Shape newShape) {
game_board.getChildren().add(newShape); game_board.getChildren().add(newShape);

View File

@@ -1,4 +1,4 @@
object FGUIForm_1: TFXGUIForm object FGUIForm: TFXGUIForm
Tag = 180 Tag = 180
Left = 240 Left = 240
Top = 154 Top = 154

Binary file not shown.