From 7e803d7a56c4bdae43b7dbd68c223b258aabec02 Mon Sep 17 00:00:00 2001 From: Jens <3007492@hs-mannheim.de> Date: Fri, 3 May 2024 21:44:06 +0200 Subject: [PATCH] Update 2 --- Domain/FourPairs.java | 54 ++++++++++++++++++++++++++++++++++++++- Domain/ThreePairs.java | 53 ++++++++++++++++++++++++++++++++++++--- Domain/TwoPairs.java | 57 ++++++++++++++++++++++++++++++------------ 3 files changed, 144 insertions(+), 20 deletions(-) diff --git a/Domain/FourPairs.java b/Domain/FourPairs.java index 48a12ab..a373d23 100644 --- a/Domain/FourPairs.java +++ b/Domain/FourPairs.java @@ -1,5 +1,57 @@ package Domain; -public class FourPairs { +public class FourPairs extends Category{ + private Player player; + private int one = 0, two = 0, three = 0, four = 0, five = 0; + + public FourPairs(Player player) { + super("Four Pairs", "Four times the same dice"); + this.player = player; + } + + @Override + public boolean correctCategory(int[] values){ + + for(int i = 0; i < values.length; i++){ + switch(i){ + case 1: + one += 1; + case 2: + two += 1; + case 3: + three += 1; + case 4: + four += 1; + case 5: + five += 1; + break; + } + } + if(one == 4 || two == 4 || three == 4 || four == 4 || five == 4){ + return true; + } + + return false; + } + + @Override + public int getScore(){ + if(one == 4){ + return 4; + } + else if(two == 4){ + return 8; + } + else if(three == 4){ + return 12; + } + else if(four == 4){ + return 16; + } + else if(five == 4){ + return 20; + } + return 0; + } } diff --git a/Domain/ThreePairs.java b/Domain/ThreePairs.java index ca63f24..38723b8 100644 --- a/Domain/ThreePairs.java +++ b/Domain/ThreePairs.java @@ -2,9 +2,56 @@ package Domain; public class ThreePairs extends Category{ - public ThreePairs(String name, String description) { - super(name, description); - //TODO Auto-generated constructor stub + private int one = 0, two = 0, three = 0, four = 0, five = 0; + + public ThreePairs(Player player) { + super("Three Pairs", "Three times the same dice"); + } + + @Override + public boolean correctCategory(int[] values){ + + for(int i = 0; i < values.length; i++){ + switch(i){ + case 1: + one += 1; + case 2: + two += 1; + case 3: + three += 1; + case 4: + four += 1; + case 5: + five += 1; + break; + } + } + if(one == 3 || two == 3 || three == 3 || four == 3 || five == 3){ + return true; + } + + return false; + } + + @Override + public int getScore(){ + + if(one == 4){ + return 4; + } + else if(two == 4){ + return 8; + } + else if(three == 4){ + return 12; + } + else if(four == 4){ + return 16; + } + else if(five == 4){ + return 20; + } + return 0; } } diff --git a/Domain/TwoPairs.java b/Domain/TwoPairs.java index 2ed22c2..822b133 100644 --- a/Domain/TwoPairs.java +++ b/Domain/TwoPairs.java @@ -1,33 +1,58 @@ package Domain; public class TwoPairs extends Category{ - - private Player player; + + private int one = 0, two = 0, three = 0, four = 0, five = 0; public TwoPairs(Player player) { - super("Twos", "Score of all the twos rolled."); - this.player = player; + super("Two Pairs", "Two times the same dice"); } + //Weitere methode einfügen falls mehrere paare vorhanden sind + @Override public boolean correctCategory(int[] values){ - int[] arr = new int[values.length]; - int counter = 0; - for(int i : values){ - - + + for(int i = 0; i < values.length; i++){ + switch(i){ + case 1: + one += 1; + case 2: + two += 1; + case 3: + three += 1; + case 4: + four += 1; + case 5: + five += 1; + break; + } } - return false; + if(one == 2 || two == 2 || three == 2 || four == 2 || five == 2){ + return true; + } + + return false; } @Override public int getScore(){ - int score = 0; - for(int i : player.getDice().getValues()){ - if( i == 2 ){ - score += i; - } + + if(one == 2){ + return 2; } - return score; + else if(two == 2){ + return 4; + } + else if(three == 2){ + return 16; + } + else if(four == 2){ + return 8; + } + else if(five == 2){ + return 10; + } + return 0; } }