diff --git a/Game.class b/Game.class index 330f55a..943e150 100644 Binary files a/Game.class and b/Game.class differ diff --git a/Game.java b/Game.java index 4af8618..6c46613 100644 --- a/Game.java +++ b/Game.java @@ -2,6 +2,9 @@ import javafx.scene.shape.Shape; import java.util.ArrayList; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; +import javafx.scene.control.Label; +import javafx.scene.shape.Circle; +import java.util.AbstractList; /** * * Beschreibung @@ -22,31 +25,50 @@ public class Game { public Pane game_board; public Chip current_selection; - public void start(Pane gameBoard) { + public Label LTop; + + public Circle[] white_player_chips = new Circle[9]; + public Circle[] black_player_chips = new Circle[9]; + + + public void start(Pane gameBoard, Label label) { game_board = gameBoard; + LTop = label; + + setLabelText("White Turn"); } public void chip_button_clicked(MuehleButton button) { if (game_state == 0) { + Chip newChip; if (currentTurnPlayer == "White") { - addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.WHITE); + newChip = addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.WHITE); white_chips--; + setChipCount(white_chips,"White"); } else { - addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.BLACK); + newChip = addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.BLACK); black_chips--; + setChipCount(white_chips,"Black"); } + if (checkCombo(newChip)) { + System.out.println("Comb!"); + } // end of if(newChip); game_board.getChildren().remove(button.getShape()); nextTurn(); - } // end of if - - + } + if(game_state == 1) { + // second state of game + setLabelText("Second State"); + } } - public void addChip(int relX, int relY,double absX, double absY, Color color) { - Chip chip = new Chip(relX,relY,absX,absY,color,this); + public Chip addChip(int relX, int relY,double absX, double absY, Color color) { + Chip chip = new Chip(relX,relY,absX,absY,color,this); + chips.add(chip); addShape(chip.getShape()); + return chip; } public void addShape(Shape newShape) { game_board.getChildren().add(newShape); @@ -57,11 +79,108 @@ public class Game { } public void nextTurn() { + if (white_chips == 0 && black_chips == 0) { + game_state = 1; + } + if (currentTurnPlayer == "White") { + setLabelText("Black Turn"); currentTurnPlayer = "Black"; } else { currentTurnPlayer = "White"; + setLabelText("White Turn"); + } // end of if-else + } + + + public void setLabelText(String value) { + LTop.setText(value); + } + public boolean checkCombo(Chip chip) { + return checkCombo(chip.relativeX, chip.relativeY); + } + public boolean checkCombo(int relX, int relY) { + ArrayList hChips = getHorizontalCloseChips(relX,relY); + ArrayList vChips = getHorizontalCloseChips(relX,relY); + System.out.println(hChips.get(0).relativeX); + Chip start_chip = getChipByPos(relX,relY); + + if (start_chip.color == hChips.get(0).color && start_chip.color == hChips.get(1).color) { + return true; + } + if (start_chip.color == vChips.get(0).color && start_chip.color == vChips.get(1).color) { + return true; + } + return false; + } + + public ArrayList getHorizontalCloseChips(int relX, int relY) { + ArrayList result = new ArrayList(); + if (relX == 0) { + result.add(getChipByPos(1,relY)); + result.add(getChipByPos(2,relY)); + } + else if ( relX == 1) { + result.add(getChipByPos(0,relY)); + result.add(getChipByPos(2,relY)); + } + else { + result.add(getChipByPos(0,relY)); + result.add(getChipByPos(1,relY)); + } // end of if-else + return result; + } + public ArrayList getVerticalCloseChips(int relX, int relY) { + ArrayList result = new ArrayList(); + if (relY == 0) { + result.add(getChipByPos(relX,1)); + result.add(getChipByPos(relX,2)); + } + else if ( relY == 1) { + result.add(getChipByPos(relX,0)); + result.add(getChipByPos(relX,2)); + } + else { + result.add(getChipByPos(relX,0)); + result.add(getChipByPos(relX,1)); + } // end of if-else + return result; + } + public Chip getChipByPos(int relX, int relY) { + + for (int i = 0; i < chips.size()-1; i++) { + if (chips.get(i).relativeX == relX && chips.get(i).relativeY == relY ) { + return chips.get(i); + } // end of if + } + return null; + } + public void setChipCount(int value, String player) { + System.out.println(white_chips-1); + if (player == "White") { + if (white_chips == 0) { + for (int i = 0; i < white_player_chips.length -1; i++) { + white_player_chips[i].setVisible(false); + } + } + for (int i = white_player_chips.length-1; i >= value; i--) { + white_player_chips[i].setVisible(false); + } + + } + else { + { + if (white_chips == 0) { + for (int i = 0; i < black_player_chips.length -1; i++) { + black_player_chips[i].setVisible(false); + } // end of for + } // end of if + for (int i = black_player_chips.length-1; i >= value; i--) { + black_player_chips[i].setVisible(false); + } + + } } // end of if-else } } \ No newline at end of file diff --git a/Game.~ava b/Game.~ava index e1dfaa6..318e4c2 100644 --- a/Game.~ava +++ b/Game.~ava @@ -2,6 +2,9 @@ import javafx.scene.shape.Shape; import java.util.ArrayList; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; +import javafx.scene.control.Label; +import javafx.scene.shape.Circle; +import java.util.AbstractList; /** * * Beschreibung @@ -13,7 +16,7 @@ import javafx.scene.paint.Color; public class Game { public String currentTurnPlayer = "White"; - public int game_state = 0; // 0 == players placing their chips; 1 = players moving their chips + 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; @@ -22,31 +25,50 @@ public class Game { public Pane game_board; public Chip current_selection; - public void start(Pane gameBoard) { + public Label LTop; + + public Circle[] white_player_chips = new Circle[9]; + public Circle[] black_player_chips = new Circle[9]; + + + public void start(Pane gameBoard, Label label) { game_board = gameBoard; + LTop = label; + + setLabelText("White Turn"); } public void chip_button_clicked(MuehleButton button) { if (game_state == 0) { + Chip newChip; if (currentTurnPlayer == "White") { - addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.WHITE); + newChip = addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.WHITE); white_chips--; + setChipCount(white_chips,"White"); } else { - addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.BLACK); + newChip = addChip(button.relativeX,button.relativeY,button.absoluteX,button.absoluteY,Color.BLACK); black_chips--; + setChipCount(white_chips,"Black"); } + if (checkCombo(newChip)) { + System.out.println("Comb!"); + } // end of if(newChip); game_board.getChildren().remove(button.getShape()); nextTurn(); - } // end of if - - + } + if(game_state == 1) { + // second state of game + setLabelText("Second State"); + } } - public void addChip(int relX, int relY,double absX, double absY, Color color) { - Chip chip = new Chip(relX,relY,absX,absY,color,this); + public Chip addChip(int relX, int relY,double absX, double absY, Color color) { + Chip chip = new Chip(relX,relY,absX,absY,color,this); + chips.add(chip); addShape(chip.getShape()); + return chip; } public void addShape(Shape newShape) { game_board.getChildren().add(newShape); @@ -57,11 +79,110 @@ public class Game { } public void nextTurn() { + if (white_chips == 0 && black_chips == 0) { + game_state = 1; + } + if (currentTurnPlayer == "White") { + setLabelText("Black Turn"); currentTurnPlayer = "Black"; } else { currentTurnPlayer = "White"; + setLabelText("White Turn"); + } // end of if-else + } + + + public void setLabelText(String value) { + LTop.setText(value); + } + public boolean checkCombo(Chip chip) { + return checkCombo(chip.relativeX, chip.relativeY); + } + public boolean checkCombo(int relX, int relY) { + ArrayList hChips = getHorizontalCloseChips(relX,relY); + ArrayList vChips = getHorizontalCloseChips(relX,relY); + System.out.println(hChips.get(0).relativeX); + Chip start_chip = getChipByPos(relX,relY); + + if (start_chip.color == hChips.get(0).color && start_chip.color == hChips.get(1).color) { + return true; + } + if (start_chip.color == vChips.get(0).color && start_chip.color == vChips.get(1).color) { + return true; + } + return false; + } + + public ArrayList getHorizontalCloseChips(int relX, int relY) { + ArrayList result = new ArrayList(); + if (relX == 0) { + result.add(getChipByPos(1,relY)); + result.add(getChipByPos(2,relY)); + } + else if ( relX == 1) { + result.add(getChipByPos(0,relY)); + result.add(getChipByPos(2,relY)); + } + else { + result.add(getChipByPos(0,relY)); + result.add(getChipByPos(1,relY)); + } // end of if-else + return result; + } + public ArrayList getVerticalCloseChips(int relX, int relY) { + ArrayList result = new ArrayList(); + if (relY == 0) { + result.add(getChipByPos(relX,1)); + result.add(getChipByPos(relX,2)); + } + else if ( relY == 1) { + result.add(getChipByPos(relX,0)); + result.add(getChipByPos(relX,2)); + } + else { + result.add(getChipByPos(relX,0)); + result.add(getChipByPos(relX,1)); + } // end of if-else + return result; + } + public Chip getChipByPos(int relX, int relY) { + + for (int i = 0; i < chips.size()-1; i++) { + System.out.println(i); + if (chips.get(i).relativeX == relX && chips.get(i).relativeY == relY ) { + System.out.println("Found"); + return chips.get(i); + } // end of if + } + return null; + } + public void setChipCount(int value, String player) { + System.out.println(white_chips-1); + if (player == "White") { + if (white_chips == 0) { + for (int i = 0; i < white_player_chips.length -1; i++) { + white_player_chips[i].setVisible(false); + } + } + for (int i = white_player_chips.length-1; i >= value; i--) { + white_player_chips[i].setVisible(false); + } + + } + else { + { + if (white_chips == 0) { + for (int i = 0; i < black_player_chips.length -1; i++) { + black_player_chips[i].setVisible(false); + } // end of for + } // end of if + for (int i = black_player_chips.length-1; i >= value; i--) { + black_player_chips[i].setVisible(false); + } + + } } // end of if-else } } \ No newline at end of file diff --git a/Muehle.class b/Muehle.class index 693f132..b24a464 100644 Binary files a/Muehle.class and b/Muehle.class differ diff --git a/Muehle.java b/Muehle.java index 2097ed4..6fbad44 100644 --- a/Muehle.java +++ b/Muehle.java @@ -12,6 +12,7 @@ import javafx.scene.shape.Line; import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.input.MouseEvent; +import javafx.scene.shape.Circle; /** * * Beschreibung @@ -38,7 +39,9 @@ public class Muehle extends Application { Scene scene = new Scene(root, 1080, 820); - game.start(game_board); + game.start(game_board,lTop); + + drawPlayerChips(); //lTop.setAlignment(); setTopLabel("Test Label"); @@ -131,42 +134,42 @@ public class Muehle extends Application { 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()); + 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()); + 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 +40,topLeftY+ i*220 +100,button_color,game); - shapes.add(button.getShape()); + 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(1,i,topRightX -230,topLeftY+ i*100 +460,button_color,game); - shapes.add(button.getShape()); + 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(0,i,topLeftX +200,topLeftY+ i*130 +200,button_color,game); - shapes.add(button.getShape()); + 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(2,i,topLeftX +540,topLeftY+ i*130 +200,button_color,game); - shapes.add(button.getShape()); + 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); @@ -175,6 +178,35 @@ public class Muehle extends Application { } + } + + public void drawPlayerChips() { + Circle[] white_player_chips = new Circle[9]; + Circle[] black_player_chips = new Circle[9]; + + Color stroke_color = Color.BLACK; + double stroke_width = 2; + double radius = 20; + + for (int i = 0; i < 9; i++) { + white_player_chips[i] = new Circle(radius*2 +20,50*i+ 200,radius); + white_player_chips[i].setStroke(stroke_color); + white_player_chips[i].setStrokeWidth(stroke_width); + white_player_chips[i].setFill(Color.WHITE); + addShape(white_player_chips[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].setStroke(stroke_color); + black_player_chips[i].setStrokeWidth(stroke_width); + black_player_chips[i].setFill(Color.BLACK); + addShape(black_player_chips[i]); + } + + game.white_player_chips = white_player_chips; + game.black_player_chips = black_player_chips; + } public void addShape(Shape newShape) { game_board.getChildren().add(newShape); diff --git a/Muehle.~ava b/Muehle.~ava index 208e656..d2e12c5 100644 --- a/Muehle.~ava +++ b/Muehle.~ava @@ -12,6 +12,7 @@ import javafx.scene.shape.Line; import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.input.MouseEvent; +import javafx.scene.shape.Circle; /** * * Beschreibung @@ -38,7 +39,9 @@ public class Muehle extends Application { Scene scene = new Scene(root, 1080, 820); - game.start(game_board); + game.start(game_board,lTop); + + drawPlayerChips(); //lTop.setAlignment(); setTopLabel("Test Label"); @@ -131,49 +134,77 @@ public class Muehle extends Application { 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()); + 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()); + 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 +40,topLeftY+ i*220 +100,button_color,game); - shapes.add(button.getShape()); + 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(1,i,topRightX -230,topLeftY+ i*100 +460,button_color,game); - shapes.add(button.getShape()); + 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(0,i,topLeftX +200,topLeftY+ i*130 +200,button_color,game); - shapes.add(button.getShape()); + 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(2,i,topLeftX +540,topLeftY+ i*130 +200,button_color,game); - shapes.add(button.getShape()); + 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 drawPlayerChips() { + Circle[] white_player_chips = new Circle[9]; + Circle[] black_player_chips = new Circle[9]; + + Color stroke_color = Color.BLACK; + double stroke_width = 2; + double radius = 20; + + for (int i = 0; i < 9; i++) { + white_player_chips[i] = new Circle(radius*2 +20,50*i+ 200,radius); + white_player_chips[i].setStroke(stroke_color); + white_player_chips[i].setStrokeWidth(stroke_width); + white_player_chips[i].setFill(Color.WHITE); + addShape(white_player_chips[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].setStroke(stroke_color); + black_player_chips[i].setStrokeWidth(stroke_width); + black_player_chips[i].setFill(Color.BLACK); + addShape(black_player_chips[i]); + } + + } public void addShape(Shape newShape) { game_board.getChildren().add(newShape);