forked from pierront/rock-paper-scissors
test: ajout de l'égalité
This commit is contained in:
@@ -6,8 +6,11 @@ public enum Move {
|
||||
SCISSORS,
|
||||
WELL;
|
||||
|
||||
public boolean beats(Move other) {
|
||||
return switch (this) {
|
||||
public Result beats(Move other) {
|
||||
if(this.equals(other)){
|
||||
return Result.EQUAL;
|
||||
}
|
||||
boolean result = switch (this) {
|
||||
case ROCK -> other == SCISSORS;
|
||||
case PAPER -> other == ROCK || other == WELL;
|
||||
case SCISSORS -> other == PAPER;
|
||||
@@ -15,5 +18,6 @@ public enum Move {
|
||||
|
||||
|
||||
};
|
||||
return result ? Result.WIN : Result.LOOSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
|
||||
|
||||
public enum Result {
|
||||
|
||||
WIN,
|
||||
LOOSE,
|
||||
EQUAL;
|
||||
}
|
||||
@@ -9,17 +9,16 @@ import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatSa
|
||||
@DomainService
|
||||
public record RockPaperScissorsPlayer(CpuPick cpuPick, StatSave statSave) implements RockPaperScissorsPlay {
|
||||
|
||||
public static final String WIN = "WIN";
|
||||
public static final String LOOSE = "LOOSE";
|
||||
|
||||
|
||||
@Override
|
||||
public RoundResult playRound(String name, Move move) {
|
||||
|
||||
var cpuPicked = this.cpuPick.pick();
|
||||
boolean beats = move.beats(cpuPicked);
|
||||
String result = beats ? WIN : LOOSE;
|
||||
if (result.equals(WIN)) {
|
||||
Result beats = move.beats(cpuPicked);
|
||||
if (beats.equals(Result.WIN)) {
|
||||
this.statSave.addWin(name);
|
||||
}
|
||||
return new RoundResult(result, name, cpuPicked);
|
||||
return new RoundResult(beats.toString(), name, cpuPicked);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user