Commit 621b4b46 authored by Weber Rodolphe's avatar Weber Rodolphe

initial commit

parents
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* @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.
*/
/**
* @brief generates a random integer value
*
* the range is between 1 and numberValues
*/
public class Dice {
private int numberValues; /**< range of the dice */
public int diceValue; /**< dice value */
/**
* @brief parametrized constructor
* @param numberValues int indicating the dice range
*/
Dice(int numberValues){
this.numberValues=numberValues;
roll();
}
/**
* @brief default constructor
*/
Dice(){
numberValues=6;
roll();
}
/**
* @brief roll the dice
*/
public void roll(){
diceValue= (int)(Math.random()*(numberValues))+1;
}
/**
* @brief print the dice value
*/
public void printDice(){
System.out.println(diceValue);
}
/**
* @brief get the dice range
* @return int dice range
*/
public int getDiceType(){
return numberValues;
}
}
\ No newline at end of file
/**
* @file SheeetPlayer.java
* @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.Scanner;
/**
* @brief manages the scoring sheet of the players
*/
public class SheetPlayer {
private final String LINE = "--------------------";
private final char[] FIG_INDEX = {'a','b','c','d','e','f','g','h','i','j','k','l','m'};
private final String[] FIG_NAME ={"Brelan","Carré","Full","Petite Suite","Grande Suite","Yams","Chance"};
private String playerName; /**< player name */
private Integer[] scoring = new Integer[13]; /** scoring table */
private int totalScore; /**< final player score */
private char[] figureIndex; /**< letters indicating the figure type */
//private int subTotalScore; /**< all number score */
//private int bonus; /**< bonus score */
/**
* @brief constructor
* @param name
*/
SheetPlayer(String name){
this.playerName=name;
for (int idx=0 ; idx<scoring.length ; idx++){
scoring[idx]=null;
}
totalScore=0;
figureIndex=FIG_INDEX;
//subTotalScore=0;
//bonus=0;
}
/**
* @brief print the formatted score
* @param score Integer
* @return String with '-' or score
*/
private String nullToMinus(Integer score){
return (score==null?"-":score.toString());
}
/**
* @brief compute the bonus
* @return 0 or 35
*/
private int bonus(){
return (subTotalScore()>=63)?35:0;
}
/**
* @brief compute the subtotal
* @return int
*/
private int subTotalScore(){
Integer total =0;
for (int idx=0 ; idx<=5 ; idx++){
total+=(scoring[idx]==null)?0:scoring[idx] ;
}
return (int)total;
}
/**
* @brief print the scoring sheet
*/
public void printScore(){
System.out.println(LINE);
System.out.println( "Player: " + playerName);
System.out.println(LINE);
for (int idx=1 ; idx<=6 ; idx++){
System.out.println("[" + figureIndex[idx-1] + "] sum of " + idx + " : " + nullToMinus(scoring[idx-1]));
}
System.out.println( "----subTotal: " + subTotalScore() + " => bonus : " + bonus());
for (int idx=7 ; idx<13 ; idx++){
System.out.println("[" + figureIndex[idx-1] + "] " + FIG_NAME[idx-6] + " : " + nullToMinus(scoring[idx-1]));
}
System.out.println( "Total: " + totalScore);
System.out.println(LINE);
}
/**
* @brief put a cross
* @param index int figure index
*/
public void checkFigure(int index){
figureIndex[index]='x';
}
public int askFigure(){
String letter;
System.out.println("Indicates the figure you want to play (a,b ...m):");
Scanner sc = new Scanner("a");
do {
letter = sc.nextLine();
System.out.println("-" + letter +"-");
} while (letter != "x");
sc.close();
return 0;
}
}
/**
* @file
* @author WEBER rodolphe <rodolphe.weber@univ-orleans.fr>
* @version 1.0
* @date 22/07/2021
* @mainpage
* @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.
*/
public class Yams{
static void clearScreen(){
System.out.print("\033[H\033[2J");
System.out.flush();
}
public static void main(String[] args) {
YamsDices myDice5 = new YamsDices();
SheetPlayer player1 = new SheetPlayer("rodo");
clearScreen();
player1.printScore();
myDice5.printYams();
myDice5.rollYams(myDice5.askDice());
clearScreen();
player1.printScore();
myDice5.printYams();
myDice5.rollYams(myDice5.askDice());
myDice5.printYams();
//System.out.println(player1.askFigure());
}
}
/**
* @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(){
System.out.println("Indicates the dices you want to roll (12345):");
Scanner sc = new Scanner(System.in);
String position = sc.nextLine();
sc.close();
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)?40: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;
}
}
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