package sample;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.util.Random;
public class Main extends Application {
public static Player currentPlayer;
public static Scene currentScene;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Beatrix Dices");
primaryStage.setOnCloseRequest(e -> {
e.consume();
Boxes.CHOICE("Do you want to quit?", "Yes", "No");
if (Boxes.answer) {
primaryStage.close();
}
});
primaryStage.setScene(Menus.menu(primaryStage));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
package sample;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.util.*;
public class Player {
private String name;
private int topScore;
private int totalScore;
private ArrayList<PointCombo> toDoList = new ArrayList<>();
private ArrayList<PointCombo> doneList = new ArrayList<>();
private ArrayList<PointCombo> lostList = new ArrayList<>();
public ArrayList<PointCombo> chooseList = new ArrayList<>();
private int rollsLeft;
public Player(int n) {
Stage playerInfo = new Stage();
playerInfo.setTitle("Insert Player info");
playerInfo.initModality(Modality.APPLICATION_MODAL);
playerInfo.setOnCloseRequest(e -> {
e.consume();
Boxes.ALERT("Warning", "Must insert player info");
});
Label name = new Label("Insert player " + n + " name:");
TextField inputName = new TextField();
Button confirm = new Button("Confirm");
confirm.setOnAction(e -> {
try {
this.name = inputName.getText();
if (this.name.length() == 0) {
throw new Exception();
}
this.totalScore = 0;
this.topScore = 0;
this.getToDoList().add(new PointCombo(Combos.ones, 0));
this.getToDoList().add(new PointCombo(Combos.twos, 0));
this.getToDoList().add(new PointCombo(Combos.threes, 0));
this.getToDoList().add(new PointCombo(Combos.fours, 0));
this.getToDoList().add(new PointCombo(Combos.fives, 0));
this.getToDoList().add(new PointCombo(Combos.sixs, 0));
this.getToDoList().add(new PointCombo(Combos.tris, 0));
this.getToDoList().add(new PointCombo(Combos.poker, 0));
this.getToDoList().add(new PointCombo(Combos.small_road, 0));
this.getToDoList().add(new PointCombo(Combos.big_road, 0));
this.getToDoList().add(new PointCombo(Combos.full, 0));
this.getToDoList().add(new PointCombo(Combos.pokerer, 0));
this.getToDoList().add(new PointCombo(Combos.possibility, 0));
this.rollsLeft = 2;
playerInfo.close();
} catch (Exception ex) {
Boxes.ALERT("Wanring", "Must have a name");
}
});
VBox main = new VBox();
main.getChildren().addAll(name, inputName, confirm);
main.setSpacing(10);
main.setAlignment(Pos.CENTER);
main.setPadding(new Insets(10, 10, 10, 10));
Scene scene = new Scene(main, 400, 300);
playerInfo.setScene(scene);
playerInfo.showAndWait();
}
public Player(String name, int score) {
this.setName(name);
this.totalScore = score;
this.topScore = 0;
this.getToDoList().add(new PointCombo(Combos.ones, 0));
this.getToDoList().add(new PointCombo(Combos.twos, 0));
this.getToDoList().add(new PointCombo(Combos.threes, 0));
this.getToDoList().add(new PointCombo(Combos.fours, 0));
this.getToDoList().add(new PointCombo(Combos.fives, 0));
this.getToDoList().add(new PointCombo(Combos.sixs, 0));
this.getToDoList().add(new PointCombo(Combos.tris, 0));
this.getToDoList().add(new PointCombo(Combos.poker, 0));
this.getToDoList().add(new PointCombo(Combos.small_road, 0));
this.getToDoList().add(new PointCombo(Combos.big_road, 0));
this.getToDoList().add(new PointCombo(Combos.full, 0));
this.getToDoList().add(new PointCombo(Combos.pokerer, 0));
this.getToDoList().add(new PointCombo(Combos.possibility, 0));
this.rollsLeft = 3;
}
public void addScore(int score) {
this.totalScore += score;
}
public void setName(String name) {
this.name = name;
}
public int getTopScore() {
return topScore;
}
public int getTotalScore() {
return totalScore;
}
public String getName() {
return name;
}
public ArrayList<PointCombo> getToDoList() {
return toDoList;
}
public ArrayList<PointCombo> getDoneList() {
return doneList;
}
public int getRollsLeft() {
return rollsLeft;
}
public ArrayList<PointCombo> getLostList() {
return lostList;
}
public void setRollsLeft(int rollsLeft) {
this.rollsLeft = rollsLeft;
}
public boolean checkBonus() {
return this.getTopScore() >= 63;
}
public Scene getScene(Stage parentStage, Player[] player, Dice[] dices, int playerNumber) {
System.out.println(this.getToDoList().size() == 0);
if (this.getToDoList().size() == 0) {
return Menus.gameOver(parentStage, player);
}
BorderPane mainPane = new BorderPane();
VBox left = new VBox();
VBox right = new VBox();
HBox bottom = new HBox();
GridPane showDices = new GridPane();
Random rnd = new Random(System.currentTimeMillis());
for (int i = 0; i < dices.length; i++) {
if (!dices[i].isHold()) {
dices[i].setValue(rnd.nextInt(6 - 1 + 1) + 1);
} else {
dices[i].setValue(dices[i].getValue());
}
}
Label showName = new Label(this.name);
showName.setAlignment(Pos.CENTER);
showName.setPadding(new Insets(10, 10, 10, 10));
StackPane name = new StackPane();
name.getChildren().add(showName);
mainPane.setTop(name);
Button stop = new Button("Check combos");
stop.setOnAction(event -> {
this.setRollsLeft(2);
this.showCombos(this, dices);
Dice.resetDices(dices);
parentStage.setScene(player[(playerNumber+1)%player.length].getScene(parentStage, player, dices, (playerNumber+1)%player.length));
});
Button roll = new Button("Re-Roll (" + this.getRollsLeft() + " left)");
roll.setOnAction(event -> {
if (this.getRollsLeft() > 0) {
this.setRollsLeft(this.getRollsLeft() - 1);
parentStage.setScene(getScene(parentStage, player, dices, playerNumber));
} else {
this.setRollsLeft(2);
this.showCombos(this, dices);
Dice.resetDices(dices);
parentStage.setScene(player[(playerNumber+1)%player.length].getScene(parentStage, player, dices, (playerNumber+1)%player.length));
}
});
bottom.getChildren().addAll(roll, stop);
bottom.setAlignment(Pos.CENTER);
bottom.setSpacing(50);
bottom.setPadding(new Insets(20, 20, 20, 20));
mainPane.setBottom(bottom);
Label showScore = new Label("Total Score:");
Label showInt = new Label("" + this.totalScore);
Label showBonus = new Label("Bonus related score :");
Label showIntBonus = new Label("" + this.topScore);
left.getChildren().addAll(showScore, showInt, showBonus, showIntBonus);
left.setAlignment(Pos.CENTER);
left.setSpacing(10);
mainPane.setLeft(left);
Label toDo = new Label("To Do Combos:");
Label done = new Label("Combos Done:");
Label lost = new Label("Lost Combos:");
ListView<PointCombo> toDoListView = new ListView<>();
for (PointCombo combo : this.getToDoList()) {
toDoListView.getItems().add(combo);
}
ListView<PointCombo%gt doneListView = new ListView<>();
for (PointCombo combo : this.getDoneList()) {
doneListView.getItems().add(combo);
}
ListView<PointCombo> lostListView = new ListView<>();
for (PointCombo combo : this.getLostList()) {
lostListView.getItems().add(combo);
}
right.getChildren().addAll(toDo, toDoListView, done, doneListView, lost, lostListView);
right.setAlignment(Pos.CENTER);
right.setSpacing(10);
mainPane.setRight(right);
Node[] getDices = new StackPane[6];
for (int i = 0; i < dices.length; i++) {
getDices[i] = dices[i].show();
}
ColumnConstraints col0 = new ColumnConstraints(10);
col0.setHgrow(Priority.ALWAYS);
ColumnConstraints col1 = new ColumnConstraints(150);
col0.setHgrow(Priority.NEVER);
ColumnConstraints col2 = new ColumnConstraints(10);
col0.setHgrow(Priority.ALWAYS);
ColumnConstraints col3 = new ColumnConstraints(150);
col0.setHgrow(Priority.NEVER);
ColumnConstraints col4 = new ColumnConstraints(10);
col0.setHgrow(Priority.ALWAYS);
ColumnConstraints col5 = new ColumnConstraints(150);
col0.setHgrow(Priority.NEVER);
ColumnConstraints col6 = new ColumnConstraints(10);
col0.setHgrow(Priority.ALWAYS);
ColumnConstraints col7 = new ColumnConstraints(150);
col0.setHgrow(Priority.NEVER);
ColumnConstraints col8 = new ColumnConstraints(10);
col0.setHgrow(Priority.ALWAYS);
ColumnConstraints col9 = new ColumnConstraints(150);
col0.setHgrow(Priority.NEVER);
ColumnConstraints col10 = new ColumnConstraints(10);
col0.setHgrow(Priority.ALWAYS);
RowConstraints row0 = new RowConstraints(10);
row0.setVgrow(Priority.ALWAYS);
RowConstraints row1 = new RowConstraints(150);
row0.setVgrow(Priority.NEVER);
RowConstraints row2 = new RowConstraints(10);
row0.setVgrow(Priority.ALWAYS);
RowConstraints row3 = new RowConstraints(150);
row0.setVgrow(Priority.NEVER);
RowConstraints row4 = new RowConstraints(10);
row0.setVgrow(Priority.ALWAYS);
showDices.getColumnConstraints().addAll(col0, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10);
showDices.getRowConstraints().addAll(row0, row1, row2, row3, row4);
showDices.setAlignment(Pos.CENTER);
GridPane.setConstraints(getDices[0], 1, 1);
GridPane.setConstraints(getDices[1], 3, 3);
GridPane.setConstraints(getDices[2], 5, 1);
GridPane.setConstraints(getDices[3], 7, 3);
GridPane.setConstraints(getDices[4], 9, 1);
showDices.getChildren().addAll(getDices[0], getDices[1], getDices[2], getDices[3], getDices[4]);
mainPane.setCenter(showDices);
return new Scene(mainPane, 1200, 800);
}
public void showCombos(Player currentPlayer, Dice[] dices) {
Stage comboStage = new Stage();
comboStage.setTitle("Combos");
comboStage.initModality(Modality.APPLICATION_MODAL);
comboStage.setOnCloseRequest(e -> {
e.consume();
Boxes.ALERT("Warning", "Choose a combo");
});
boolean none = checkCombos(currentPlayer, dices);
if (none) {
comboStage.setScene(this.noneCombos(comboStage, currentPlayer, dices));
} else {
comboStage.setScene(this.someCombos(comboStage, currentPlayer, dices));
}
comboStage.showAndWait();
}
private Scene noneCombos(Stage parentStage, Player currentPlayer, Dice[] dices) {
ListView<PointCombo> lost = new ListView<>();
for(PointCombo combo : this.getToDoList()) {
lost.getItems().add(combo);
}
Button loseBtn = new Button("Lose this combo");
loseBtn.setOnAction(e -> {
PointCombo lostCombo = lost.getSelectionModel().getSelectedItem();
currentPlayer.getToDoList().remove(lostCombo);
currentPlayer.getLostList().add(lostCombo);
currentPlayer.chooseList.clear();
parentStage.close();
});
VBox root = new VBox();
root.setSpacing(10);
root.setAlignment(Pos.CENTER);
root.getChildren().addAll(lost, loseBtn);
return new Scene(root, 800, 600);
}
private Scene someCombos(Stage parentStage, Player currentPlayer, Dice[] dices) {
ListView<PointCombo> chooseCombos = new ListView<>();
for(PointCombo combo : chooseList) {
chooseCombos.getItems().add(combo);
}
Button chooseThis = new Button("Choose this");
chooseThis.setOnAction(e -> {
PointCombo choosen = chooseCombos.getSelectionModel().getSelectedItem();
currentPlayer.getDoneList().add(choosen);
currentPlayer.getToDoList().remove(choosen);
currentPlayer.addScore(choosen.getComboScore());
if (choosen.equals(new PointCombo(Combos.ones, 0)) || choosen.equals(new PointCombo(Combos.twos, 0)) || choosen.equals(new PointCombo(Combos.threes, 0)) || choosen.equals(new PointCombo(Combos.fours, 0)) || choosen.equals(new PointCombo(Combos.fives, 0)) || choosen.equals(new PointCombo(Combos.sixs, 0))) {
currentPlayer.addTopScore(choosen.getComboScore());
}
currentPlayer.chooseList.clear();
parentStage.close();
});
Button lose = new Button("Lose a combo");
lose.setOnAction(e -> {
parentStage.setScene(this.noneCombos(parentStage, currentPlayer, dices));
});
HBox btns = new HBox();
btns.setAlignment(Pos.CENTER);
btns.setSpacing(50);
btns.getChildren().addAll(chooseThis, lose);
VBox main = new VBox();
main.setAlignment(Pos.CENTER);
main.setSpacing(10);
main.getChildren().addAll(chooseCombos, btns);
return new Scene(main, 800, 600);
}
private void addTopScore(int comboScore) {
this.topScore += comboScore;
}
private boolean checkCombos(Player currentPlayer, Dice[] dices) {
boolean ones = Player.hasOnes(currentPlayer, dices);
if (ones) {
int value = Dice.howMany(dices, 1);
currentPlayer.chooseList.add(new PointCombo(Combos.ones, value));
}
boolean twos = Player.hasTwos(currentPlayer, dices);
if (twos) {
int value = Dice.howMany(dices, 2);
currentPlayer.chooseList.add(new PointCombo(Combos.twos, value));
}
boolean threes = Player.hasThrees(currentPlayer, dices);
if (threes) {
int value = Dice.howMany(dices, 3);
currentPlayer.chooseList.add(new PointCombo(Combos.threes, value));
}
boolean fours = Player.hasFours(currentPlayer, dices);
if (fours) {
int value = Dice.howMany(dices, 4);
currentPlayer.chooseList.add(new PointCombo(Combos.fours, value));
}
boolean fives = Player.hasFives(currentPlayer, dices);
if (fives) {
int value = Dice.howMany(dices, 5);
currentPlayer.chooseList.add(new PointCombo(Combos.fives, value));
}
boolean sixs = Player.hasSixes(currentPlayer, dices);
if (sixs) {
int value = Dice.howMany(dices, 6);
currentPlayer.chooseList.add(new PointCombo(Combos.sixs, value));
}
boolean tris = Player.hasTris(currentPlayer, dices);
if (tris)
currentPlayer.chooseList.add(new PointCombo(Combos.tris, Dice.sumValue(dices)));
boolean poker = Player.hasPoker(currentPlayer, dices);
if (poker)
currentPlayer.chooseList.add(new PointCombo(Combos.poker, Dice.sumValue(dices)));
boolean small_road = Player.hasSmallRoad(currentPlayer, dices);
if (small_road)
currentPlayer.chooseList.add(new PointCombo(Combos.small_road, 30));
boolean big_road = Player.hasBigRoad(currentPlayer, dices);
if (big_road)
currentPlayer.chooseList.add(new PointCombo(Combos.big_road, 40));
boolean full = Player.hasFull(currentPlayer, dices);
if (full)
currentPlayer.chooseList.add(new PointCombo(Combos.full, 25));
boolean superpoker = Player.hasSuperpoker(currentPlayer, dices);
if (superpoker)
currentPlayer.chooseList.add(new PointCombo(Combos.pokerer, 50));
boolean possibility = Player.hasPossibility(currentPlayer, dices);
if (possibility)
currentPlayer.chooseList.add(new PointCombo(Combos.possibility, Dice.sumValue(dices)));
return !(ones || twos || threes || fours || fives || sixs || tris || poker || small_road || big_road || full || superpoker || possibility);
}
private static boolean hasOnes(Player currentPlayer, Dice[] dices) {
if(currentPlayer.getDoneList().contains(new PointCombo(Combos.ones, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.ones, 0))) {
return false;
}
return dices[0].getValue() == 1 || dices[1].getValue() == 1 || dices[2].getValue() == 1 || dices[3].getValue() == 1 || dices[4].getValue() == 1;
}
private static boolean hasTwos(Player currentPlayer, Dice[] dices) {
if(currentPlayer.getDoneList().contains(new PointCombo(Combos.twos, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.twos, 0))) {
return false;
}
return dices[0].getValue() == 2 || dices[1].getValue() == 2 || dices[2].getValue() == 2 || dices[3].getValue() == 2 || dices[4].getValue() == 2;
}
private static boolean hasThrees(Player currentPlayer, Dice[] dices) {
if(currentPlayer.getDoneList().contains(new PointCombo(Combos.threes, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.threes, 0))) {
return false;
}
return dices[0].getValue() == 3 || dices[1].getValue() == 3 || dices[2].getValue() == 3 || dices[3].getValue() == 3 || dices[4].getValue() == 3;
}
private static boolean hasFours(Player currentPlayer, Dice[] dices) {
if(currentPlayer.getDoneList().contains(new PointCombo(Combos.fours, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.fours, 0))) {
return false;
}
return dices[0].getValue() == 4 || dices[1].getValue() == 4 || dices[2].getValue() == 4 || dices[3].getValue() == 4 || dices[4].getValue() == 4;
}
private static boolean hasFives(Player currentPlayer, Dice[] dices) {
if(currentPlayer.getDoneList().contains(new PointCombo(Combos.fives, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.fives, 0))) {
return false;
}
return dices[0].getValue() == 5 || dices[1].getValue() == 5 || dices[2].getValue() == 5 || dices[3].getValue() == 5 || dices[4].getValue() == 5;
}
private static boolean hasSixes(Player currentPlayer, Dice[] dices) {
if(currentPlayer.getDoneList().contains(new PointCombo(Combos.sixs, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.sixs, 0))) {
return false;
}
return dices[0].getValue() == 6 || dices[1].getValue() == 6 || dices[2].getValue() == 6 || dices[3].getValue() == 6 || dices[4].getValue() == 6;
}
private static boolean hasTris(Player currentPlayer, Dice[] dices) {
if (currentPlayer.getDoneList().contains(new PointCombo(Combos.tris, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.tris, 0))) {
return false;
}
for (int number = 1; number<=6; number++) {
int count = 0;
for (Dice dice : dices) {
if (dice.getValue() == number)
count += 1;
if (count == 3)
return true;
}
}
return false;
}
private static boolean hasPoker(Player currentPlayer, Dice[] dices) {
if (currentPlayer.getDoneList().contains(new PointCombo(Combos.poker, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.poker, 0))) {
return false;
}
for (int number = 1; number<=6; number++) {
int count = 0;
for (Dice dice : dices) {
if (dice.getValue() == number)
count += 1;
if (count == 4)
return true;
}
}
return false;
}
private static boolean hasSuperpoker(Player currentPlayer, Dice[] dices) {
if (currentPlayer.getDoneList().contains(new PointCombo(Combos.pokerer, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.pokerer, 0))) {
return false;
}
return dices[0].getValue() == dices[1].getValue() && dices[1].getValue() == dices[2].getValue() && dices[2].getValue() == dices[3].getValue() && dices[3].getValue() == dices[4].getValue();
}
//Ogni tanto non trova la small road. La causa?
private static boolean hasSmallRoad(Player currentPlayer, Dice[] dices) {
if (currentPlayer.getDoneList().contains(new PointCombo(Combos.small_road, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.small_road, 0))) {
return false;
}
List<Dice> sortedDices = new ArrayList<Dice>(Arrays.asList(dices));
boolean result = true;
for (int i=0; i<sortedDices.size()-2; i++) {
if (sortedDices.get(i).getValue() != sortedDices.get(i+1).getValue()-1) {
result = false;
break;
}
}
if (!result) {
for (int i=1; i<sortedDices.size()-1; i++) {
if (sortedDices.get(i).getValue() != sortedDices.get(i+1).getValue()-1) {
result = false;
break;
}
}
}
if (!result) {
System.out.println(sortedDices.size() + " size1 in remove");
for (int i = 0; i < sortedDices.size() - 1; i++) {
if (sortedDices.get(i).getValue() == sortedDices.get(i + 1).getValue()) {
System.out.println("Before RMV");
sortedDices.remove(i);
System.out.println("After RMV");
break;
}
}
if (sortedDices.size() == 4) {
System.out.println(sortedDices.size() + " size2");
for (int i = sortedDices.size() - 1; i >= 1; i--) {
if (!(dices[i].getValue() == dices[i - 1].getValue() + 1)) {
return false;
}
}
}
}
return true;
}
private static boolean hasBigRoad(Player currentPlayer, Dice[] dices) {
if (currentPlayer.getDoneList().contains(new PointCombo(Combos.big_road, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.big_road, 0))) {
return false;
}
List<Dice> sortedDices = Arrays.asList(dices);
sortedDices.sort(new byValue());
for(int i=sortedDices.size()-1; i>=1; i--) {
if(!(dices[i].getValue() == dices[i-1].getValue()+1)) {
return false;
}
}
return true;
}
//TO-DO
private static boolean hasFull(Player currentPlayer, Dice[] dices) {
if (currentPlayer.getDoneList().contains(new PointCombo(Combos.full, 0)) || currentPlayer.getLostList().contains(new PointCombo(Combos.full, 0))) {
return false;
}
List<Dice> sortedDices = Arrays.asList(dices);
sortedDices.sort(new byValue());
boolean small_full = sortedDices.get(0).getValue() == sortedDices.get(1).getValue() && sortedDices.get(1).getValue() == sortedDices.get(2).getValue() && sortedDices.get(3).getValue() == sortedDices.get(4).getValue();
boolean big_full = sortedDices.get(2).getValue() == sortedDices.get(3).getValue() && sortedDices.get(3).getValue() == sortedDices.get(4).getValue() && sortedDices.get(0).getValue() == sortedDices.get(1).getValue();
return small_full || big_full;
}
private static boolean hasPossibility(Player currentPlayer, Dice[] dices) {
return currentPlayer.getToDoList().contains(new PointCombo(Combos.possibility, 0)) && !currentPlayer.getLostList().contains(new PointCombo(Combos.possibility, 0));
}
}
package sample;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
public class Dice {
private int value;
private boolean hold = false;
final static private Border blackBorder = new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT));
final static private Border redBorder = new Border(new BorderStroke(Color.RED, BorderStrokeStyle.DASHED, CornerRadii.EMPTY, BorderWidths.DEFAULT));
public Dice (int value) {
this.value = value;
}
public Node show() {
StackPane figure = new StackPane();
if (!this.hold) {
figure.setBorder(Dice.blackBorder);
} else {
figure.setBorder(Dice.redBorder);
}
switch (this.value) {
case 1: {
Circle num = new Circle(10);
num.setFill(Color.BLUE);
figure.setAlignment(Pos.CENTER);
figure.getChildren().add(num);
break;
}
case 2: {
GridPane grid = new GridPane();
grid.getColumnConstraints().addAll(new ColumnConstraints(50), new ColumnConstraints(50), new ColumnConstraints(50));
grid.getRowConstraints().addAll(new RowConstraints(50), new RowConstraints(50), new RowConstraints(50));
BorderPane container1 = new BorderPane();
Circle num1 = new Circle(10);
num1.setFill(Color.RED);
BorderPane container2 = new BorderPane();
Circle num2 = new Circle(10);
num2.setFill(Color.RED);
container1.setCenter(num1);
container2.setCenter(num2);
GridPane.setConstraints(container1, 0, 0);
GridPane.setConstraints(container2, 2, 2);
grid.getChildren().addAll(container1, container2);
figure.setAlignment(Pos.CENTER);
figure.getChildren().add(grid);
break;
}
case 3: {
GridPane grid = new GridPane();
grid.getColumnConstraints().addAll(new ColumnConstraints(50), new ColumnConstraints(50), new ColumnConstraints(50));
grid.getRowConstraints().addAll(new RowConstraints(50), new RowConstraints(50), new RowConstraints(50));
BorderPane container1 = new BorderPane();
Circle num1 = new Circle(10);
num1.setFill(Color.BLUE);
BorderPane container2 = new BorderPane();
Circle num2 = new Circle(10);
num2.setFill(Color.BLUE);
BorderPane container3 = new BorderPane();
Circle num3 = new Circle(10);
num3.setFill(Color.BLUE);
container1.setCenter(num1);
container2.setCenter(num2);
container3.setCenter(num3);
GridPane.setConstraints(container1, 0, 0);
GridPane.setConstraints(container2, 1, 1);
GridPane.setConstraints(container3, 2, 2);
grid.getChildren().addAll(container1, container2, container3);
figure.setAlignment(Pos.CENTER);
figure.getChildren().add(grid);
break;
}
case 4: {
GridPane grid = new GridPane();
grid.getColumnConstraints().addAll(new ColumnConstraints(50), new ColumnConstraints(50), new ColumnConstraints(50));
grid.getRowConstraints().addAll(new RowConstraints(50), new RowConstraints(50), new RowConstraints(50));
BorderPane container1 = new BorderPane();
Circle num1 = new Circle(10);
num1.setFill(Color.RED);
BorderPane container2 = new BorderPane();
Circle num2 = new Circle(10);
num2.setFill(Color.RED);
BorderPane container3 = new BorderPane();
Circle num3 = new Circle(10);
num3.setFill(Color.RED);
BorderPane container4 = new BorderPane();
Circle num4 = new Circle(10);
num4.setFill(Color.RED);
container1.setCenter(num1);
container2.setCenter(num2);
container3.setCenter(num3);
container4.setCenter(num4);
GridPane.setConstraints(container1, 0, 0);
GridPane.setConstraints(container2, 2, 0);
GridPane.setConstraints(container3, 2, 2);
GridPane.setConstraints(container4, 0, 2);
grid.getChildren().addAll(container1, container2, container3, container4);
figure.setAlignment(Pos.CENTER);
figure.getChildren().add(grid);
break;
}
case 5: {
GridPane grid = new GridPane();
grid.getColumnConstraints().addAll(new ColumnConstraints(50), new ColumnConstraints(50), new ColumnConstraints(50));
grid.getRowConstraints().addAll(new RowConstraints(50), new RowConstraints(50), new RowConstraints(50));
BorderPane container1 = new BorderPane();
Circle num1 = new Circle(10);
num1.setFill(Color.BLUE);
BorderPane container2 = new BorderPane();
Circle num2 = new Circle(10);
num2.setFill(Color.BLUE);
BorderPane container3 = new BorderPane();
Circle num3 = new Circle(10);
num3.setFill(Color.BLUE);
BorderPane container4 = new BorderPane();
Circle num4 = new Circle(10);
num4.setFill(Color.BLUE);
BorderPane container5 = new BorderPane();
Circle num5 = new Circle(10);
num5.setFill(Color.BLUE);
container1.setCenter(num1);
container2.setCenter(num2);
container3.setCenter(num3);
container4.setCenter(num4);
container5.setCenter(num5);
GridPane.setConstraints(container1, 0, 0);
GridPane.setConstraints(container2, 2, 0);
GridPane.setConstraints(container3, 2, 2);
GridPane.setConstraints(container4, 0, 2);
GridPane.setConstraints(container5, 1, 1);
grid.getChildren().addAll(container1, container2, container3, container4, container5);
figure.setAlignment(Pos.CENTER);
figure.getChildren().add(grid);
break;
}
case 6: {
GridPane grid = new GridPane();
grid.getColumnConstraints().addAll(new ColumnConstraints(50), new ColumnConstraints(50), new ColumnConstraints(50));
grid.getRowConstraints().addAll(new RowConstraints(50), new RowConstraints(50), new RowConstraints(50));
BorderPane container1 = new BorderPane();
Circle num1 = new Circle(10);
num1.setFill(Color.RED);
BorderPane container2 = new BorderPane();
Circle num2 = new Circle(10);
num2.setFill(Color.RED);
BorderPane container3 = new BorderPane();
Circle num3 = new Circle(10);
num3.setFill(Color.RED);
BorderPane container4 = new BorderPane();
Circle num4 = new Circle(10);
num4.setFill(Color.RED);
BorderPane container5 = new BorderPane();
Circle num5 = new Circle(10);
num5.setFill(Color.RED);
BorderPane container6 = new BorderPane();
Circle num6 = new Circle(10);
num6.setFill(Color.RED);
container1.setCenter(num1);
container2.setCenter(num2);
container3.setCenter(num3);
container4.setCenter(num4);
container5.setCenter(num5);
container6.setCenter(num6);
GridPane.setConstraints(container1, 0, 0);
GridPane.setConstraints(container2, 2, 0);
GridPane.setConstraints(container3, 2, 2);
GridPane.setConstraints(container4, 0, 2);
GridPane.setConstraints(container5, 0, 1);
GridPane.setConstraints(container1, 2, 1);
grid.getChildren().addAll(container1, container2, container3, container4, container5, container6);
figure.setAlignment(Pos.CENTER);
figure.getChildren().add(grid);
break;
}
default: {
Label error = new Label("Error in Dice.show()\nNo value matching\nswitch statement");
figure.setAlignment(Pos.CENTER);
figure.getChildren().add(error);
}
}
figure.setOnMouseClicked(mouseEvent -> {
if (this.hold) {
this.hold = false;
figure.setBorder(Dice.blackBorder);
} else {
this.hold = true;
figure.setBorder(Dice.redBorder);
}
});
return figure;
}
public void setValue(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public boolean isHold() {
return hold;
}
public static int howMany(Dice[] dices, int number) {
int count = 0;
for (Dice d : dices) {
if (d.getValue() == number)
count += 1;
}
return number*count;
}
public static int sumValue(Dice[] dices) {
int sum = 0;
for (Dice d : dices) {
sum += d.getValue();
}
return sum;
}
public static void resetDices(Dice[] dices) {
for(int i=0; i<dices.length; i++) {
dices[i].hold = false;
}
}
}
package sample;
public enum Combos {
ones,
twos,
threes,
fours,
fives,
sixs,
tris,
poker,
small_road,
big_road,
full,
pokerer,
possibility;
@Override
public String toString() {
switch (this) {
case ones: return "Ones";
case twos: return "Twoes";
case threes: return "Threes";
case fours: return "Fours";
case fives: return "Fives";
case sixs: return "Sixs";
case tris: return "Tris";
case poker: return "Poker";
case small_road: return "Small Road";
case big_road: return "Big Road";
case full: return "Full House";
case pokerer: return "Super-Poker";
case possibility: return "Possibility";
default: return "Error in Combos.toString()\nNo matching found\nin switch statement";
}
}
}
package sample;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class Boxes {
static boolean answer = false;
public static void ALERT(String title, String message) {
Stage alertStage = new Stage();
alertStage.setTitle(title);
alertStage.initModality(Modality.APPLICATION_MODAL);
Label msg= new Label(message);
StackPane layout = new StackPane();
layout.getChildren().add(msg);
Scene scene = new Scene(layout, 300, 200, Color.RED);
alertStage.setScene(scene);
alertStage.showAndWait();
}
public static void CHOICE(String question, String trueAns, String falseAns) {
Stage choiceStage = new Stage();
choiceStage.setTitle("Warning");
choiceStage.initModality(Modality.APPLICATION_MODAL);
Label qst = new Label(question);
Button trueBtn = new Button(trueAns);
trueBtn.setOnAction(e -> {
Boxes.answer = true;
choiceStage.close();
});
Button falseBtn = new Button(falseAns);
falseBtn.setOnAction(e -> {
Boxes.answer = false;
choiceStage.close();
});
HBox buttons = new HBox();
buttons.setSpacing(50);
buttons.setAlignment(Pos.CENTER);
buttons.getChildren().addAll(trueBtn, falseBtn);
VBox main = new VBox();
main.setAlignment(Pos.CENTER);
main.setSpacing(10);
main.getChildren().addAll(qst, buttons);
Scene scene = new Scene(main, 300, 200, Color.RED);
choiceStage.setScene(scene);
choiceStage.showAndWait();
}
}