Facade and Domain 2

main
Jens 2024-05-06 13:44:17 +02:00
parent 6f3922e24f
commit 40ff3b0779
3 changed files with 62 additions and 24 deletions

View File

@ -4,13 +4,13 @@ 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(){
@ -21,7 +21,7 @@ public class Player {
// return sheet; // return sheet;
// } // }
// public Dice getDice(){ public Dice getDice(){
// return dice; return dice;
// } }
} }

View File

@ -15,6 +15,21 @@ public class Yatzy_Sheet {
} }
} }
//WICHTIG!!!
//
//Methode für bonuspunkte hinzufügen
//
//
public boolean fullArray(){
for(int i = 0; i < tabelle.length - 2; i++){
if(tabelle[i] > 0){
return true;
}
}
return false;
}
//counts all the //counts all the
public int getSumOne(){ public int getSumOne(){
int sum = 0; int sum = 0;
@ -37,4 +52,8 @@ public class Yatzy_Sheet {
int sumTwo = getSumTwo(); int sumTwo = getSumTwo();
return sumOne += sumTwo; return sumOne += sumTwo;
} }
public int[] getTabelle(){
return tabelle;
}
} }

View File

@ -2,30 +2,14 @@ package Facade;
import java.util.ArrayList; import java.util.ArrayList;
import Domain.Dice; import Domain.*;
import Domain.Fives;
import Domain.FourPairs;
import Domain.Fours;
import Domain.FullHouse;
import Domain.Ones;
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;
public class Game { public class Game {
private ArrayList<Player> player = new ArrayList<>(); private ArrayList<Player> players = new ArrayList<>();
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 Player player1;
private Yatzy_Sheet sheet = new Yatzy_Sheet(); private Yatzy_Sheet sheet = new Yatzy_Sheet();
@ -47,7 +31,7 @@ public class Game {
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++){
player1 = new Player(name[i], sheet, dice); player1 = new Player(name[i], sheet, dice);
player.add(player1); players.add(player1);
} }
} }
@ -62,42 +46,77 @@ public class Game {
case 1: case 1:
ones.correctCategory(diceValues); ones.correctCategory(diceValues);
sheet.addScore(0, ones.getScore()); sheet.addScore(0, ones.getScore());
break;
case 2: case 2:
twos.correctCategory(diceValues); twos.correctCategory(diceValues);
sheet.addScore(1, twos.getScore()); sheet.addScore(1, twos.getScore());
break;
case 3: case 3:
threes.correctCategory(diceValues); threes.correctCategory(diceValues);
sheet.addScore(2, threes.getScore()); sheet.addScore(2, threes.getScore());
break;
case 4: case 4:
fours.correctCategory(diceValues); fours.correctCategory(diceValues);
sheet.addScore(3, fours.getScore()); sheet.addScore(3, fours.getScore());
break;
case 5: case 5:
fives.correctCategory(diceValues); fives.correctCategory(diceValues);
sheet.addScore(4, fives.getScore()); sheet.addScore(4, fives.getScore());
break;
case 6: case 6:
sixes.correctCategory(diceValues); sixes.correctCategory(diceValues);
sheet.addScore(5, sixes.getScore()); sheet.addScore(5, sixes.getScore());
break;
case 7: case 7:
twoPairs.correctCategory(diceValues); twoPairs.correctCategory(diceValues);
sheet.addScore(6, twoPairs.getScore()); sheet.addScore(6, twoPairs.getScore());
break;
case 8: case 8:
threePairs.correctCategory(diceValues); threePairs.correctCategory(diceValues);
sheet.addScore(7, threePairs.getScore()); sheet.addScore(7, threePairs.getScore());
break;
case 9: case 9:
fourPairs.correctCategory(diceValues); fourPairs.correctCategory(diceValues);
sheet.addScore(8, fourPairs.getScore()); sheet.addScore(8, fourPairs.getScore());
break;
case 10: case 10:
fullHouse.correctCategory(diceValues); fullHouse.correctCategory(diceValues);
sheet.addScore(9, fullHouse.getScore()); sheet.addScore(9, fullHouse.getScore());
break;
case 11: case 11:
straightFlush.correctCategory(diceValues); straightFlush.correctCategory(diceValues);
sheet.addScore(10, straightFlush.getScore()); sheet.addScore(10, straightFlush.getScore());
break;
case 12: case 12:
royalStraightFlush.correctCategory(diceValues); royalStraightFlush.correctCategory(diceValues);
sheet.addScore(11, royalStraightFlush.getScore()); sheet.addScore(11, royalStraightFlush.getScore());
break;
case 13: case 13:
yatzy.correctCategory(diceValues); yatzy.correctCategory(diceValues);
sheet.addScore(12, yatzy.getScore()); sheet.addScore(12, yatzy.getScore());
break;
} }
} }
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 "";
}
} }