From 711659d67b2f86cb6952b004bcf8894d8a2440df Mon Sep 17 00:00:00 2001 From: Jens <3007492@hs-mannheim.de> Date: Fri, 3 May 2024 12:22:01 +0200 Subject: [PATCH] 1 --- Domain/Category.java | 36 ++++++++++++++++++++++++++++++++++++ Domain/Dice.java | 20 ++++++++++++++++---- Domain/Player.java | 38 ++++++++------------------------------ Domain/Yatzy_Sheet.java | 27 +++++++++++++++++++++++++++ Facade/Game.java | 16 ++++++++++++---- 5 files changed, 99 insertions(+), 38 deletions(-) create mode 100644 Domain/Category.java create mode 100644 Domain/Yatzy_Sheet.java diff --git a/Domain/Category.java b/Domain/Category.java new file mode 100644 index 0000000..6facea9 --- /dev/null +++ b/Domain/Category.java @@ -0,0 +1,36 @@ +package Domain; + +public class Category { + + private String name; + private String description; + private boolean scored; + private int score; + + public Category(String name, String description, boolean scored, int score){ + this.name = name; + this.description = description; + this.scored = false; + this.score = score; + } + + public String getName(){ + return name; + } + + public String getDescription(){ + return description; + } + + public boolean isScored(){ + return scored; + } + + public int getScore(){ + return score; + } + + public boolean correctCategory(){ + return true; + } +} diff --git a/Domain/Dice.java b/Domain/Dice.java index 2edb141..682e78b 100644 --- a/Domain/Dice.java +++ b/Domain/Dice.java @@ -4,18 +4,30 @@ import java.util.Random; public class Dice { private int numberOfDice; + private int[] values; + private Random random; public Dice(int numberOfDice){ this.numberOfDice = numberOfDice; + this.values = new int[5]; + this.random = new Random(); } - public int rollDice(int numberOfDice){ - Random random = new Random(); - numberOfDice = random.nextInt(6); - return numberOfDice + 1; + public void rollDice(int numberOfDice){ + for(int i = 0; i < values.length; i++){ + values[i] = random.nextInt(6) + 1; + } } public int getAugenzahl(){ return numberOfDice; } + + public int getValue(int index){ + return values[index]; + } + + public int[] getValues(){ + return values; + } } diff --git a/Domain/Player.java b/Domain/Player.java index 194a434..d25f44e 100644 --- a/Domain/Player.java +++ b/Domain/Player.java @@ -3,41 +3,19 @@ package Domain; public class Player { private String name; - private int[] tabelle; + private Yatzy_Sheet sheet; + - public Player(String name){ + public Player(String name, Yatzy_Sheet sheet){ this.name = name; - this.tabelle = new int[17]; - } - - //counts all the - public int getSumOne(){ - int sum = 0; - for(int i = 0; i < 6; i++){ - sum += tabelle[i]; - } - return sum; - } - - public int getSumTwo(){ - int sum = 0; - for (int i = 7; i < 17; i++){ - sum += tabelle[i]; - } - return sum; - } - - public int getSum(){ - int sumOne = getSumOne(); - int sumTwo = getSumTwo(); - return sumOne += sumTwo; - } - - public String toString(){ - for (int i = 0; i < ) + this.sheet = sheet; } public String getName(){ return name; } + + public Yatzy_Sheet getSheet(){ + return sheet; + } } diff --git a/Domain/Yatzy_Sheet.java b/Domain/Yatzy_Sheet.java new file mode 100644 index 0000000..ccf27b7 --- /dev/null +++ b/Domain/Yatzy_Sheet.java @@ -0,0 +1,27 @@ +package Domain; + +public class Yatzy_Sheet { + private int[] tabelle; + //counts all the + public int getSumOne(){ + int sum = 0; + for(int i = 0; i < 6; i++){ + sum += tabelle[i]; + } + return sum; + } + + public int getSumTwo(){ + int sum = 0; + for (int i = 7; i < 17; i++){ + sum += tabelle[i]; + } + return sum; + } + + public int getSum(){ + int sumOne = getSumOne(); + int sumTwo = getSumTwo(); + return sumOne += sumTwo; + } +} diff --git a/Facade/Game.java b/Facade/Game.java index 7e0c49f..571b88b 100644 --- a/Facade/Game.java +++ b/Facade/Game.java @@ -13,9 +13,17 @@ public class Game { return 0; } - public Player newPlayer(){ - Player p1 = new Player("Jens"); - player.add(p1); - return p1; + public ArrayList newPlayer(int playerCount, String name){ + + for(int i = 0; i < playerCount; i++){ + Player p1 = new Player(name, null); + player.add(p1); + } + return player; + } + + public int showScore(){ + Player secondPlayer = player.get(1); + return secondPlayer.getSheet(); } }