Commit 9a85421a authored by Weber Rodolphe's avatar Weber Rodolphe

Delete SheetPlayer.java

parent e15d74a7
/**
* @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","Full","Carré","Petite Suite","Grande Suite","Yams","Chance"};
private String playerName; /**< player name */
private Integer[] scoring = new Integer[13]; /** scoring table */
private int round ; /**< count the number of round */
//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;
}
figureIndex=FIG_INDEX;
round =1;
}
/**
* @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;
}
public int totalScore() {
Integer total =subTotalScore()+bonus();
for (int idx=6; idx<13 ; 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 + " round: " + round);
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-7] + " : " + nullToMinus(scoring[idx-1]));
}
System.out.println( "Total: " + totalScore());
System.out.println(LINE);
round=(round % 3)+1;
}
/**
* @brief put a cross
* @param index int figure index
*/
public void checkFigure(int index){
figureIndex[index]='x';
}
public int askFigure(Scanner sc){
String letter;
do {
System.out.println("Indicates the figure you want to play (a,b ...m):");
letter = sc.nextLine();
} while (!String.valueOf(figureIndex).contains(letter) || (letter ==String.valueOf('x')));
return String.valueOf(figureIndex).indexOf(letter);
}
public void updateScoring(int figureIndex , int score){
scoring[figureIndex]=score;
this.figureIndex[figureIndex]='x';
}
}
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