Facade and Domain

main
Jens 2024-05-06 13:18:10 +02:00
parent 2ce4931c19
commit 6f3922e24f
3 changed files with 93 additions and 30 deletions

View File

@ -3,25 +3,25 @@ package Domain;
public class Player { public class Player {
private String name; private String name;
private Yatzy_Sheet sheet; // private Yatzy_Sheet sheet;
private Dice dice; // private Dice dice;
public Player(String name, Yatzy_Sheet sheet, Dice dice){ public Player(String name, Yatzy_Sheet sheet, Dice dice){
this.name = name; this.name = name;
this.sheet = sheet; // this.sheet = sheet;
this.dice = dice; // this.dice = dice;
} }
public String getName(){ public String getName(){
return name; return name;
} }
public Yatzy_Sheet getSheet(){ // public Yatzy_Sheet getSheet(){
return sheet; // return sheet;
} // }
public Dice getDice(){ // public Dice getDice(){
return dice; // return dice;
} // }
} }

View File

@ -1,12 +1,20 @@
package Domain; package Domain;
public class Yatzy_Sheet { public class Yatzy_Sheet {
private int[] tabelle; private int[] tabelle = new int[15];
public Yatzy_Sheet(){ public Yatzy_Sheet(){
} }
public void addScore(int categoryNumber, int score){
for(int i = 0; i < 14; i++){
if(i == categoryNumber){
tabelle[i] = categoryNumber;
}
}
}
//counts all the //counts all the
public int getSumOne(){ public int getSumOne(){
int sum = 0; int sum = 0;

View File

@ -3,7 +3,20 @@ package Facade;
import java.util.ArrayList; import java.util.ArrayList;
import Domain.Dice; import Domain.Dice;
import Domain.Fives;
import Domain.FourPairs;
import Domain.Fours;
import Domain.FullHouse;
import Domain.Ones;
import Domain.Player; import Domain.Player;
import Domain.RoyalStraightFlush;
import Domain.Sixes;
import Domain.StraightFlush;
import Domain.ThreePairs;
import Domain.Threes;
import Domain.TwoPairs;
import Domain.Twos;
import Domain.Yatzy;
import Domain.Yatzy_Sheet; import Domain.Yatzy_Sheet;
public class Game { public class Game {
@ -12,26 +25,28 @@ public class Game {
private int numberOfDice; private int numberOfDice;
private Dice dice = new Dice(numberOfDice); private Dice dice = new Dice(numberOfDice);
private int[] diceValues; private int[] diceValues;
private int category;
private Player player1;
private Yatzy_Sheet sheet = new Yatzy_Sheet();
public ArrayList<Player> newPlayer(int playerCount, String name){ private Ones ones = new Ones(player1);
private Twos twos = new Twos(player1);
for(int i = 0; i < playerCount; i++){ private Threes threes = new Threes(player1);
Player p1 = new Player(name, null); private Fours fours = new Fours(player1);
player.add(p1); private Fives fives = new Fives(player1);
} private Sixes sixes = new Sixes(player1);
return player; private TwoPairs twoPairs = new TwoPairs(player1);
} private ThreePairs threePairs = new ThreePairs(player1);
private FourPairs fourPairs = new FourPairs(player1);
public int showScore(){ private FullHouse fullHouse = new FullHouse(player1);
Player secondPlayer = player.get(1); private StraightFlush straightFlush = new StraightFlush(player1);
return secondPlayer.getSheet(); private RoyalStraightFlush royalStraightFlush = new RoyalStraightFlush(player1);
} private Yatzy yatzy = new Yatzy(player1);
public void startgame(int playerCount, String[] name, int numberOfDice){ public void startgame(int playerCount, String[] name, int numberOfDice){
for(int i = 0; i < playerCount; i++){ for(int i = 0; i < playerCount; i++){
Yatzy_Sheet sheet = new Yatzy_Sheet(); player1 = new Player(name[i], sheet, dice);
Player player1 = new Player(name[i], sheet, dice);
player.add(player1); player.add(player1);
} }
} }
@ -42,7 +57,47 @@ public class Game {
return diceValues; return diceValues;
} }
public void choosCategory(int diceValues){ public void choosCategory(int category){
switch(category){
case 1:
ones.correctCategory(diceValues);
sheet.addScore(0, ones.getScore());
case 2:
twos.correctCategory(diceValues);
sheet.addScore(1, twos.getScore());
case 3:
threes.correctCategory(diceValues);
sheet.addScore(2, threes.getScore());
case 4:
fours.correctCategory(diceValues);
sheet.addScore(3, fours.getScore());
case 5:
fives.correctCategory(diceValues);
sheet.addScore(4, fives.getScore());
case 6:
sixes.correctCategory(diceValues);
sheet.addScore(5, sixes.getScore());
case 7:
twoPairs.correctCategory(diceValues);
sheet.addScore(6, twoPairs.getScore());
case 8:
threePairs.correctCategory(diceValues);
sheet.addScore(7, threePairs.getScore());
case 9:
fourPairs.correctCategory(diceValues);
sheet.addScore(8, fourPairs.getScore());
case 10:
fullHouse.correctCategory(diceValues);
sheet.addScore(9, fullHouse.getScore());
case 11:
straightFlush.correctCategory(diceValues);
sheet.addScore(10, straightFlush.getScore());
case 12:
royalStraightFlush.correctCategory(diceValues);
sheet.addScore(11, royalStraightFlush.getScore());
case 13:
yatzy.correctCategory(diceValues);
sheet.addScore(12, yatzy.getScore());
}
} }
} }