Yatzy/Facade/Game.java

123 lines
3.9 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 Player player1;
private Yatzy_Sheet sheet = new Yatzy_Sheet();
2024-05-02 12:46:36 +02:00
2024-05-06 13:18:10 +02:00
private Ones ones = new Ones(player1);
private Twos twos = new Twos(player1);
private Threes threes = new Threes(player1);
private Fours fours = new Fours(player1);
private Fives fives = new Fives(player1);
private Sixes sixes = new Sixes(player1);
private TwoPairs twoPairs = new TwoPairs(player1);
private ThreePairs threePairs = new ThreePairs(player1);
private FourPairs fourPairs = new FourPairs(player1);
private FullHouse fullHouse = new FullHouse(player1);
private StraightFlush straightFlush = new StraightFlush(player1);
private RoyalStraightFlush royalStraightFlush = new RoyalStraightFlush(player1);
private Yatzy yatzy = new Yatzy(player1);
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 13:18:10 +02:00
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
}
}
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);
sheet.addScore(0, ones.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 2:
twos.correctCategory(diceValues);
sheet.addScore(1, twos.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 3:
threes.correctCategory(diceValues);
sheet.addScore(2, threes.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 4:
fours.correctCategory(diceValues);
sheet.addScore(3, fours.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 5:
fives.correctCategory(diceValues);
sheet.addScore(4, fives.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 6:
sixes.correctCategory(diceValues);
sheet.addScore(5, sixes.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 7:
twoPairs.correctCategory(diceValues);
sheet.addScore(6, twoPairs.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 8:
threePairs.correctCategory(diceValues);
sheet.addScore(7, threePairs.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 9:
fourPairs.correctCategory(diceValues);
sheet.addScore(8, fourPairs.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 10:
fullHouse.correctCategory(diceValues);
sheet.addScore(9, fullHouse.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 11:
straightFlush.correctCategory(diceValues);
sheet.addScore(10, straightFlush.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 12:
royalStraightFlush.correctCategory(diceValues);
sheet.addScore(11, royalStraightFlush.getScore());
2024-05-06 13:44:17 +02:00
break;
2024-05-06 13:18:10 +02:00
case 13:
yatzy.correctCategory(diceValues);
sheet.addScore(12, yatzy.getScore());
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-02 12:46:36 +02:00
}