Commit a70c6aab authored by Weber Rodolphe's avatar Weber Rodolphe

Delete YamsDices.java

parent 7ff80940
/**
* @file
* @author WEBER rodolphe <rodolphe.weber@univ-orleans.fr>
* @version 1.0
* @date 22/07/2021
*
* @section LICENSE
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @section DESCRIPTION
*
* This java file represents a java lab for the 4th year students of Polytech Orleans.
*/
import java.util.Arrays;
import java.util.Scanner;
/**
* @brief manages the 5 dices of a Yam's game
*/
public class YamsDices {
private static final String textDice = "Dice n° 1 2 3 4 5"; /**< print header */
private Dice[] dice5 = new Dice[5];/**< the 5 dices */
private int[] numberOf = new int[6]; /**< number of each dice number */
YamsDices(){ // constructor
for (int i=0;i<=4;i++){
dice5[i]= new Dice();
}
countNumber();
}
public void printYams(){ // print dice diceValues
System.out.println(textDice);
System.out.println(" " + dice5[0].diceValue+' '+dice5[1].diceValue+' '+dice5[2].diceValue+' '+dice5[3].diceValue+' '+dice5[4].diceValue+' ');
}
public String askDice(Scanner sc){
System.out.println("Indicates the dices you want to roll (12345):");
String position = sc.nextLine();
return(position);
}
public void rollYams(String position){ // roll the selected dices
int valPosition ;
if (!position.isEmpty()) {
for (int idx=0; idx< position.length();idx++) {
valPosition=position.charAt(idx)-'0';
if (((valPosition)>=1) && ((valPosition)<=5)) {
dice5[valPosition-1].roll();
}
}
}
countNumber();
}
public int sumDice(){
int sum = 0;
for (int idx=0;idx<5;idx++){
sum=sum+dice5[idx].diceValue;
}
return(sum);
}
public int sumValDice(int val){
return numberOf[val-1]*val;
}
private void countNumber(){
Arrays.fill(numberOf,0);
for(int idx=0; idx<5 ; idx++){
numberOf[dice5[idx].diceValue-1]++;
}
}
public int checkBrelan(){
int score=0;
for (int idx=0 ; idx<6 ; idx++){
score=(numberOf[idx]>=3)?3*(idx+1):score;
}
return score;
}
public int checkFull(){
int score=0;
for (int idx=0 ; idx<6 ; idx++){
score=(numberOf[idx]==2)?1:score;
}
return ((score>0)&&(checkBrelan()>0))?25:0;
}
public int checkCarre(){
int score=0;
for (int idx=0 ; idx<6 ; idx++){
score=(numberOf[idx]>=4)?4*(idx+1):score;
}
return score;
}
public int checkYams(){
int score=0;
for (int idx=0 ; idx<6 ; idx++){
score=(numberOf[idx]>=5)?50:score;
}
return score;
}
public int checkPetiteSuite() {
boolean ps1234 = (numberOf[0] !=0) && (numberOf[1] !=0) && (numberOf[2] !=0) && (numberOf[3] !=0);
boolean ps2345 = (numberOf[1] !=0) && (numberOf[2] !=0) && (numberOf[3] !=0) && (numberOf[4] !=0);
boolean ps3456 = (numberOf[2] !=0) && (numberOf[3] !=0) && (numberOf[4] !=0) && (numberOf[5] !=0);
return (ps1234 || ps2345 || ps3456)?30:0;
}
public int checkGrandeSuite() {
int[] sortedDices = new int[5];
for(int idx=0 ; idx<5 ; idx++){
sortedDices[idx]=dice5[idx].diceValue;
}
Arrays.sort(sortedDices);
System.out.println(Arrays.toString(sortedDices));
return (Arrays.toString(sortedDices).equals("[1, 2, 3, 4, 5]")||Arrays.toString(sortedDices).equals("[2, 3, 4, 5, 6]"))?40:0;
}
public int getScore(int figureIndex){
int score=0;
switch (figureIndex){
case 0: score= sumValDice(1); break;
case 1: score= sumValDice(2); break;
case 2: score= sumValDice(3); break;
case 3: score= sumValDice(4); break;
case 4: score= sumValDice(5); break;
case 5: score= sumValDice(6); break;
case 6: score= checkBrelan(); break;
case 7: score= checkFull(); break;
case 8: score= checkCarre(); break;
case 9: score= checkPetiteSuite(); break;
case 10: score= checkGrandeSuite(); break;
case 11: score= checkYams(); break;
case 12: score= sumDice(); break;
}
return score;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment