Bonjour,
Je suis débutante en langage informatique et j’ai du programmer un jeu Yhatzee à l’aide d’un TP et des diagrammes de classe qui sont dans le TP. J’aurais besoin d’une vérification, de recommandations, conseils. Il y aura quelque fois des oublis de méthodes c’est dut à une incapacité de le coder. Je ne sais pas comment le coder. En vous remerciant d’avance pour vos investissements.
Bien à vous, Chyne
public class Die {
private int MAX = 6; // maximum face value
private int faceValue; // current value showing on the die
private static Random generator = new Random();
private boolean Blocked;
public Die() {
faceValue = 1;
}
public boolean isBlocked() {
return false;
}
public void unblock(int value) {
int var = 1;
}
public void block(int value) {
int var = 0;
}
// Rolls the die and returns the result.public
int rollDie() {
faceValue = (int) (Math.random() * MAX) + 1;
return faceValue;
}
// Face value mutator.
public void setFaceValue(int faceValue) {
if( faceValue >0 && faceValue <= MAX)
this.faceValue = faceValue;
}
// Face value accessor.
public int getFaceValue() {
return faceValue;
}
// Returns a string representation of this die.
public String toString() {
String result = Integer.toString(faceValue);
return result;
}
}
Die
package model;
import java.util.ArrayList;
import java.util.stream.IntStream;
public class DiceHand {
ArrayList<Die> savedDice = new ArrayList<Die>();
// Constructor
private DiceHand(){}
public static void main(String[] args){
int ROLLS = 100000;
int count = 0;
Die die1 = new Die();
Die die2 = new Die();
for (int i = 0; i < ROLLS; i++){
if (die1.rollDie() == 1 && die2.rollDie() == 1) {
count++;
}
System.out.println("”snake eyes probability:" +(float)count / ROLLS);
}
public String getDie() {
return die;
}
int[] die = {1,2,3,4,5,6};
int sum = IntStream.of(die).sum();
System.out.println("The sum is" + sum);
}
}
DiceHand
package model;
import java.util.ArrayList;
import java.util.List;
public class Game {
ArrayList<Die> dice = new ArrayList<Die>();
for(
int i = 0;
i< 6;i++)
{
dice.add(new Die());
}
public int[] ReRollDice(int[] dice) {
System.out.println("What dices do you want to reroll?");
int diceToReRoll = keyboard.nextInt();
}
Die DieObject = new Die();
public List<Die> getDice() {
if (lost) return new ArrayList<Die>();
return dice;
}
public List<ScoreRow> getRows() {
return sheet.getRows(); // ou return list of
}
public boolean choose(ScoreRow scoreRow) {
return false;
}
public void reRoll() {
for (int i = 0; i < die.length; i++) {
die[i] = (int) (Math.random() * 6) + 1;
}
public void initialRoll () {
int initialRoll;
initialRoll = die1.roll();
System.out.print("Initial roll = " + initialRoll +
"\nRolling to match:");
}
public boolean isOver () {
return one.getHand().empty() || two.getHand().empty();
}
private int List<Die > getHand() {
return hand;
}
}
}
Game
package model;
public class Chance implements Chance {
public interface Combination {
public static int getScore(int roundNumber, int dice5, int dice2, int dice3) {
int score = 21;
//sommes des valeurs des dés(1+2+3+4+5+6)
public String description (String Chance){
return Chance;
}
}
}
} // @ache: J'ai ajouté cette accolade
Chance
package model;
public class ScoreRow {
private boolean filled;
private static void main(String[] args) {
int score = 0;
System.out.println(score);
}
public boolean isFilled() {
return filled;
}
public void reset() {
// TODO
}
public String description(String Chance) {
return "Chance";
}
public boolean isAvailable() {
return false;
}
public int getScore() {
return 0;
}
}
ScoreRow
Les diagrammes de classes images
+0
-0