Yatzy/Domain/TwoPairs.java

59 lines
1.2 KiB
Java
Raw Normal View History

2024-05-03 21:10:44 +02:00
package Domain;
public class TwoPairs extends Category{
2024-05-03 21:44:06 +02:00
private int one = 0, two = 0, three = 0, four = 0, five = 0;
2024-05-03 21:10:44 +02:00
2024-05-06 16:03:55 +02:00
public TwoPairs() {
2024-05-03 21:44:06 +02:00
super("Two Pairs", "Two times the same dice");
2024-05-03 21:10:44 +02:00
}
2024-05-03 21:44:06 +02:00
//Weitere methode einfügen falls mehrere paare vorhanden sind
2024-05-03 21:10:44 +02:00
@Override
public boolean correctCategory(int[] values){
2024-05-03 21:44:06 +02:00
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 == 2 || two == 2 || three == 2 || four == 2 || five == 2){
return true;
2024-05-03 21:10:44 +02:00
}
2024-05-03 21:44:06 +02:00
return false;
2024-05-03 21:10:44 +02:00
}
@Override
2024-05-06 15:57:22 +02:00
public int getScore(int[] values){
2024-05-03 21:44:06 +02:00
if(one == 2){
return 2;
}
else if(two == 2){
return 4;
}
else if(three == 2){
return 16;
}
else if(four == 2){
return 8;
}
else if(five == 2){
return 10;
2024-05-03 21:10:44 +02:00
}
2024-05-03 21:44:06 +02:00
return 0;
2024-05-03 21:10:44 +02:00
}
}