Yatzy/Facade/Game.java

151 lines
4.8 KiB
Java
Raw Normal View History

2024-05-02 12:46:36 +02:00
package Facade;
import java.util.ArrayList;
2024-05-06 13:44:17 +02:00
import Domain.*;
2024-05-02 12:46:36 +02:00
public class Game {
2024-05-06 13:44:17 +02:00
private ArrayList<Player> players = new ArrayList<>();
2024-05-06 12:28:18 +02:00
private int numberOfDice;
private Dice dice = new Dice(numberOfDice);
private int[] diceValues;
2024-05-06 13:18:10 +02:00
private Yatzy_Sheet sheet = new Yatzy_Sheet();
2024-05-02 12:46:36 +02:00
2024-05-06 16:03:55 +02:00
private Ones ones = new Ones();
private Twos twos = new Twos();
private Threes threes = new Threes();
private Fours fours = new Fours();
private Fives fives = new Fives();
private Sixes sixes = new Sixes();
private TwoPairs twoPairs = new TwoPairs();
private ThreePairs threePairs = new ThreePairs();
private FourPairs fourPairs = new FourPairs();
private FullHouse fullHouse = new FullHouse();
private StraightFlush straightFlush = new StraightFlush();
private RoyalStraightFlush royalStraightFlush = new RoyalStraightFlush();
private Yatzy yatzy = new Yatzy();
2024-05-06 12:28:18 +02:00
2024-05-06 13:18:10 +02:00
2024-05-06 12:28:18 +02:00
public void startgame(int playerCount, String[] name, int numberOfDice){
for(int i = 0; i < playerCount; i++){
2024-05-06 16:33:54 +02:00
Player player1 = new Player(name[i], sheet, dice);
2024-05-06 13:44:17 +02:00
players.add(player1);
2024-05-06 12:28:18 +02:00
}
}
2024-05-06 16:33:54 +02:00
// public void startgame(int playerCount, String[] name, int numberOfDice){
// this.numberOfDice = numberOfDice;
// dice = new Dice(numberOfDice);
// for(int i = 0; i < playerCount; i++){
// Player player = new Player(name[i], sheet, dice);
// players.add(player);
// }
// }
2024-05-06 12:28:18 +02:00
public int[] rollDice(Dice dice){
dice.rollDice(numberOfDice);
int[] diceValues = dice.getValues();
return diceValues;
}
2024-05-06 13:18:10 +02:00
public void choosCategory(int category){
switch(category){
case 1:
ones.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(0, ones.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 2:
twos.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(1, twos.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 3:
threes.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(2, threes.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 4:
fours.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(3, fours.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 5:
fives.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(4, fives.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 6:
sixes.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(5, sixes.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 7:
twoPairs.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(6, twoPairs.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 8:
threePairs.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(7, threePairs.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 9:
fourPairs.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(8, fourPairs.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 10:
fullHouse.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(9, fullHouse.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 11:
straightFlush.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(10, straightFlush.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 12:
royalStraightFlush.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(11, royalStraightFlush.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 13:
yatzy.correctCategory(diceValues);
2024-05-06 16:03:55 +02:00
sheet.addScore(12, yatzy.getScore(diceValues));
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
}
2024-05-06 12:28:18 +02:00
}
2024-05-06 13:44:17 +02:00
public boolean isGameOver(){
if(sheet.fullArray() == true){
return true;
}
return false;
}
public int getScore(){
return sheet.getSum();
}
public int[] getCategoryScore(){
return sheet.getTabelle();
}
public String getPlayerName(int playerIndex) {
if (playerIndex >= 0 && playerIndex < players.size()) {
return players.get(playerIndex).getName();
}
return "";
}
2024-05-06 16:33:54 +02:00
public String getCategoryNames(){
String[] categorynames = new String[13];
categorynames[0] = "Ones";
categorynames[1] = "Twos";
categorynames[2] = "Threes";
categorynames[3] = "Fours";
categorynames[4] = "Fives";
categorynames[5] = "Sixes";
categorynames[6] = "Two Pairs";
categorynames[7] = "Three Pairs";
categorynames[8] = "Four Pairs";
categorynames[9] = "Full House";
categorynames[10] = "Straight Flush";
categorynames[11] = "Royal Straight Flush";
categorynames[12] = "Yatzy";
return categorynames.toString();
}
2024-05-02 12:46:36 +02:00
}