diff --git a/Chip$1.class b/Chip$1.class new file mode 100644 index 0000000..2374eda Binary files /dev/null and b/Chip$1.class differ diff --git a/Chip.class b/Chip.class index 9099b76..3590f97 100644 Binary files a/Chip.class and b/Chip.class differ diff --git a/Chip.java b/Chip.java index 878ec49..0d502c4 100644 --- a/Chip.java +++ b/Chip.java @@ -1,6 +1,9 @@ import javafx.scene.paint.Color; import javafx.scene.shape.Shape; import javafx.scene.shape.Circle; +import javafx.event.Event; +import javafx.event.EventHandler; +import javafx.scene.input.MouseEvent; /** * * Beschreibung @@ -10,6 +13,7 @@ import javafx.scene.shape.Circle; */ public class Chip { + public Game game; public Color color; @@ -24,7 +28,7 @@ public class Chip { 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; relativeY = relY; @@ -39,9 +43,29 @@ public class Chip { 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) { + absoluteY = Y; + circle.setCenterY(absoluteY); + } public Shape getShape() { return circle; } + EventHandler mouse_clicked = new EventHandler() { + public void handle(MouseEvent handle) { + chip_clicked(); + } + + }; + public void chip_clicked() { + game.chip_clicked(this); +} } // end of Chip diff --git a/Chip.~ava b/Chip.~ava index c960522..dee2eb1 100644 --- a/Chip.~ava +++ b/Chip.~ava @@ -1,6 +1,9 @@ import javafx.scene.paint.Color; import javafx.scene.shape.Shape; import javafx.scene.shape.Circle; +import javafx.event.Event; +import javafx.event.EventHandler; +import javafx.scene.input.MouseEvent; /** * * Beschreibung @@ -10,6 +13,7 @@ import javafx.scene.shape.Circle; */ public class Chip { + public Game game; public Color color; @@ -24,7 +28,7 @@ public class Chip { 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; relativeY = relY; @@ -35,11 +39,33 @@ public class Chip { 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() { return circle; } + EventHandler mouse_clicked = new EventHandler() { + public void handle(MouseEvent handle) { + chip_clicked(); + } + + }; + public void chip_clicked() { + game.chip_clicked(this); +} } // end of Chip diff --git a/Game.class b/Game.class index e9f485a..330f55a 100644 Binary files a/Game.class and b/Game.class differ diff --git a/Game.java b/Game.java index e9b3b2d..4af8618 100644 --- a/Game.java +++ b/Game.java @@ -1,4 +1,7 @@ import javafx.scene.shape.Shape; +import java.util.ArrayList; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Color; /** * * Beschreibung @@ -8,19 +11,57 @@ import javafx.scene.shape.Shape; */ public class Game { - + public String currentTurnPlayer = "White"; - public int white_chips = 7; - public int black_chips = 7; + public int game_state = 0; // 0 == players placing their chips; 1 = players moving their chips; 2 = player can remove chip + public int white_chips = 9; + public int black_chips = 9; - public void addShape(Shape shape); + public ArrayList buttons = new ArrayList(); + public ArrayList chips = new ArrayList(); + public Pane game_board; + public Chip current_selection; - public void start() { - + public void start(Pane gameBoard) { + game_board = gameBoard; } 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 + } } \ No newline at end of file diff --git a/Game.~ava b/Game.~ava index d373e68..e1dfaa6 100644 --- a/Game.~ava +++ b/Game.~ava @@ -1,3 +1,7 @@ +import javafx.scene.shape.Shape; +import java.util.ArrayList; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Color; /** * * Beschreibung @@ -7,19 +11,57 @@ */ public class Game { - + public String currentTurnPlayer = "White"; - public int white_chips = 7; - public int black_chips = 7; + public int game_state = 0; // 0 == players placing their chips; 1 = players moving their chips + public int white_chips = 9; + public int black_chips = 9; - public void addShape; + public ArrayList buttons = new ArrayList(); + public ArrayList chips = new ArrayList(); + public Pane game_board; + public Chip current_selection; - public void start() { - + public void start(Pane gameBoard) { + game_board = gameBoard; } 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 + } } \ No newline at end of file diff --git a/Muehle.class b/Muehle.class index 1ac5c90..693f132 100644 Binary files a/Muehle.class and b/Muehle.class differ diff --git a/Muehle.java b/Muehle.java index 1e2adcd..2097ed4 100644 --- a/Muehle.java +++ b/Muehle.java @@ -29,19 +29,20 @@ public class Muehle extends Application { public void start(Stage primaryStage) { - game = new Game(); - game.addShape = addShape; - game.start(); + Pane root = new Pane(); + game = new Game(); game_board = draw_game_board(); root.getChildren().addAll(lTop,game_board); Scene scene = new Scene(root, 1080, 820); + game.start(game_board); + //lTop.setAlignment(); setTopLabel("Test Label"); - + primaryStage.setOnCloseRequest(e -> System.exit(0)); primaryStage.setTitle("Muehle"); @@ -49,87 +50,136 @@ public class Muehle extends Application { primaryStage.show(); } // end of public Muehle public void setTopLabel(String value) { - lTop.setText(value); + lTop.setText(value); } // start methods public Pane draw_game_board() { - - Color bg_color = Color.rgb(255,255,0); - Color stroke_color = Color.RED; - Double circle_offset = 100.0; - - ArrayList shapes = new ArrayList(); - - - - - Pane board = new Pane(); - double topLeftX = (1080/2)-400; - double topLeftY = 720-(720/2)-300; - double topRightX =(1080/2)+200; - double topRightY = (720/2)+300; - - Rectangle bg = new Rectangle(topLeftX,topLeftY,topRightX,topRightY); - bg.setFill(bg_color); - shapes.add(bg); - - - Rectangle circle1 = new Rectangle(topLeftX,topLeftY,topRightX,topRightY); - circle1.setStroke(stroke_color); - circle1.setStrokeWidth(10); - circle1.setFill(new Color(0.0,0.0,0.0,0.0)); - shapes.add(circle1); - - Rectangle circle2 = new Rectangle(topLeftX + 100,topLeftY + 100,topRightX - 200,topRightY - 200); - circle2.setStroke(stroke_color); - circle2.setStrokeWidth(10); - circle2.setFill(new Color(0.0,0.0,0.0,0.0)); - shapes.add(circle2); - - Rectangle circle3 = new Rectangle(topLeftX + 200,topLeftY + 200,topRightX - 400,topRightY - 400); - circle3.setStroke(stroke_color); - circle3.setStrokeWidth(10); - circle3.setFill(new Color(0.0,0.0,0.0,0.0)); - shapes.add(circle3); - - Line line1 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topLeftY,(topLeftX+topRightX) /2 + topLeftX/2,250); - line1.setStroke(stroke_color); - line1.setStrokeWidth(10); - shapes.add(line1); - - Line line2 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topRightY+50,(topLeftX+topRightX) /2 + topLeftX/2,520); - line2.setStroke(stroke_color); - line2.setStrokeWidth(10); - shapes.add(line2); - - Line line3 = new Line(topLeftX,topRightY/2+50,topLeftX+200,topRightY/2+50); - line3.setStroke(stroke_color); - line3.setStrokeWidth(10); - shapes.add(line3); - - Line line4 = new Line(topLeftX+550,topRightY/2+50,topLeftX+200+540,topRightY/2+50); - line4.setStroke(stroke_color); - line4.setStrokeWidth(10); - 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++ ) { - board.getChildren().add(shapes.get(i)); - } // end of for - - - return board; + Color bg_color = Color.rgb(255,255,0); + Color stroke_color = Color.RED; + Double circle_offset = 100.0; + + ArrayList shapes = new ArrayList(); + + + + + Pane board = new Pane(); + double topLeftX = (1080/2)-400; + double topLeftY = 720-(720/2)-300; + double topRightX =(1080/2)+200; + double topRightY = (720/2)+300; + + Rectangle bg = new Rectangle(topLeftX,topLeftY,topRightX,topRightY); + bg.setFill(bg_color); + shapes.add(bg); + + + Rectangle circle1 = new Rectangle(topLeftX,topLeftY,topRightX,topRightY); + circle1.setStroke(stroke_color); + circle1.setStrokeWidth(10); + circle1.setFill(new Color(0.0,0.0,0.0,0.0)); + shapes.add(circle1); + + Rectangle circle2 = new Rectangle(topLeftX + 100,topLeftY + 100,topRightX - 200,topRightY - 200); + circle2.setStroke(stroke_color); + circle2.setStrokeWidth(10); + circle2.setFill(new Color(0.0,0.0,0.0,0.0)); + shapes.add(circle2); + + Rectangle circle3 = new Rectangle(topLeftX + 200,topLeftY + 200,topRightX - 400,topRightY - 400); + circle3.setStroke(stroke_color); + circle3.setStrokeWidth(10); + circle3.setFill(new Color(0.0,0.0,0.0,0.0)); + shapes.add(circle3); + + Line line1 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topLeftY,(topLeftX+topRightX) /2 + topLeftX/2,250); + line1.setStroke(stroke_color); + line1.setStrokeWidth(10); + shapes.add(line1); + + Line line2 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topRightY+50,(topLeftX+topRightX) /2 + topLeftX/2,520); + line2.setStroke(stroke_color); + line2.setStrokeWidth(10); + shapes.add(line2); + + Line line3 = new Line(topLeftX,topRightY/2+50,topLeftX+200,topRightY/2+50); + line3.setStroke(stroke_color); + line3.setStrokeWidth(10); + shapes.add(line3); + + Line line4 = new Line(topLeftX+550,topRightY/2+50,topLeftX+200+540,topRightY/2+50); + line4.setStroke(stroke_color); + line4.setStrokeWidth(10); + shapes.add(line4); + + + + + for (int i = 0; i < shapes.size() ;i++ ) { + board.getChildren().add(shapes.get(i)); + + } // end of for + + drawMuehleButtons(board,topLeftX,topLeftY,topRightX,topRightY); + return board; + + } + + public void drawMuehleButtons(Pane board, double topLeftX,double topLeftY,double topRightX,double topRightY) { + ArrayList shapes = new ArrayList(); + 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()); + } - public void addShape(Shape newShape) { - game_board.getChildren().add(newShape); + 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) { + game_board.getChildren().add(newShape); + + } // end methods diff --git a/Muehle.~ava b/Muehle.~ava index 2fc464c..208e656 100644 --- a/Muehle.~ava +++ b/Muehle.~ava @@ -29,18 +29,20 @@ public class Muehle extends Application { public void start(Stage primaryStage) { - game = new Game(); - game.start(); + Pane root = new Pane(); + game = new Game(); game_board = draw_game_board(); root.getChildren().addAll(lTop,game_board); Scene scene = new Scene(root, 1080, 820); + game.start(game_board); + //lTop.setAlignment(); setTopLabel("Test Label"); - + primaryStage.setOnCloseRequest(e -> System.exit(0)); primaryStage.setTitle("Muehle"); @@ -48,87 +50,135 @@ public class Muehle extends Application { primaryStage.show(); } // end of public Muehle public void setTopLabel(String value) { - lTop.setText(value); + lTop.setText(value); } // start methods public Pane draw_game_board() { - - Color bg_color = Color.rgb(255,255,0); - Color stroke_color = Color.RED; - Double circle_offset = 100.0; - - ArrayList shapes = new ArrayList(); - - - - - Pane board = new Pane(); - double topLeftX = (1080/2)-400; - double topLeftY = 720-(720/2)-300; - double topRightX =(1080/2)+200; - double topRightY = (720/2)+300; - - Rectangle bg = new Rectangle(topLeftX,topLeftY,topRightX,topRightY); - bg.setFill(bg_color); - shapes.add(bg); - - - Rectangle circle1 = new Rectangle(topLeftX,topLeftY,topRightX,topRightY); - circle1.setStroke(stroke_color); - circle1.setStrokeWidth(10); - circle1.setFill(new Color(0.0,0.0,0.0,0.0)); - shapes.add(circle1); - - Rectangle circle2 = new Rectangle(topLeftX + 100,topLeftY + 100,topRightX - 200,topRightY - 200); - circle2.setStroke(stroke_color); - circle2.setStrokeWidth(10); - circle2.setFill(new Color(0.0,0.0,0.0,0.0)); - shapes.add(circle2); - - Rectangle circle3 = new Rectangle(topLeftX + 200,topLeftY + 200,topRightX - 400,topRightY - 400); - circle3.setStroke(stroke_color); - circle3.setStrokeWidth(10); - circle3.setFill(new Color(0.0,0.0,0.0,0.0)); - shapes.add(circle3); - - Line line1 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topLeftY,(topLeftX+topRightX) /2 + topLeftX/2,250); - line1.setStroke(stroke_color); - line1.setStrokeWidth(10); - shapes.add(line1); - - Line line2 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topRightY+50,(topLeftX+topRightX) /2 + topLeftX/2,520); - line2.setStroke(stroke_color); - line2.setStrokeWidth(10); - shapes.add(line2); - - Line line3 = new Line(topLeftX,topRightY/2+50,topLeftX+200,topRightY/2+50); - line3.setStroke(stroke_color); - line3.setStrokeWidth(10); - shapes.add(line3); - - Line line4 = new Line(topLeftX+550,topRightY/2+50,topLeftX+200+540,topRightY/2+50); - line4.setStroke(stroke_color); - line4.setStrokeWidth(10); - 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++ ) { - board.getChildren().add(shapes.get(i)); - } // end of for - - - return board; + Color bg_color = Color.rgb(255,255,0); + Color stroke_color = Color.RED; + Double circle_offset = 100.0; + + ArrayList shapes = new ArrayList(); + + + + + Pane board = new Pane(); + double topLeftX = (1080/2)-400; + double topLeftY = 720-(720/2)-300; + double topRightX =(1080/2)+200; + double topRightY = (720/2)+300; + + Rectangle bg = new Rectangle(topLeftX,topLeftY,topRightX,topRightY); + bg.setFill(bg_color); + shapes.add(bg); + + + Rectangle circle1 = new Rectangle(topLeftX,topLeftY,topRightX,topRightY); + circle1.setStroke(stroke_color); + circle1.setStrokeWidth(10); + circle1.setFill(new Color(0.0,0.0,0.0,0.0)); + shapes.add(circle1); + + Rectangle circle2 = new Rectangle(topLeftX + 100,topLeftY + 100,topRightX - 200,topRightY - 200); + circle2.setStroke(stroke_color); + circle2.setStrokeWidth(10); + circle2.setFill(new Color(0.0,0.0,0.0,0.0)); + shapes.add(circle2); + + Rectangle circle3 = new Rectangle(topLeftX + 200,topLeftY + 200,topRightX - 400,topRightY - 400); + circle3.setStroke(stroke_color); + circle3.setStrokeWidth(10); + circle3.setFill(new Color(0.0,0.0,0.0,0.0)); + shapes.add(circle3); + + Line line1 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topLeftY,(topLeftX+topRightX) /2 + topLeftX/2,250); + line1.setStroke(stroke_color); + line1.setStrokeWidth(10); + shapes.add(line1); + + Line line2 = new Line((topLeftX+topRightX) /2 + topLeftX/2,topRightY+50,(topLeftX+topRightX) /2 + topLeftX/2,520); + line2.setStroke(stroke_color); + line2.setStrokeWidth(10); + shapes.add(line2); + + Line line3 = new Line(topLeftX,topRightY/2+50,topLeftX+200,topRightY/2+50); + line3.setStroke(stroke_color); + line3.setStrokeWidth(10); + shapes.add(line3); + + Line line4 = new Line(topLeftX+550,topRightY/2+50,topLeftX+200+540,topRightY/2+50); + line4.setStroke(stroke_color); + line4.setStrokeWidth(10); + shapes.add(line4); + + + + + for (int i = 0; i < shapes.size() ;i++ ) { + board.getChildren().add(shapes.get(i)); + + } // end of for + + drawMuehleButtons(board,topLeftX,topLeftY,topRightX,topRightY); + return board; + + } + + public void drawMuehleButtons(Pane board, double topLeftX,double topLeftY,double topRightX,double topRightY) { + ArrayList shapes = new ArrayList(); + 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()); + } - public void addShape(Shape newShape) { - game_board.getChildren().add(newShape); + 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) { + game_board.getChildren().add(newShape); + + } // end methods diff --git a/Muehle.~fm b/Muehle.~fm index 92bd0a6..67ab3c9 100644 --- a/Muehle.~fm +++ b/Muehle.~fm @@ -1,4 +1,4 @@ -object FGUIForm_1: TFXGUIForm +object FGUIForm: TFXGUIForm Tag = 180 Left = 240 Top = 154 diff --git a/MuehleButton.class b/MuehleButton.class index 47119e0..8e3f9af 100644 Binary files a/MuehleButton.class and b/MuehleButton.class differ