forked from pierront/rock-paper-scissors
test: ajout de l'égalité
This commit is contained in:
@@ -6,8 +6,11 @@ public enum Move {
|
|||||||
SCISSORS,
|
SCISSORS,
|
||||||
WELL;
|
WELL;
|
||||||
|
|
||||||
public boolean beats(Move other) {
|
public Result beats(Move other) {
|
||||||
return switch (this) {
|
if(this.equals(other)){
|
||||||
|
return Result.EQUAL;
|
||||||
|
}
|
||||||
|
boolean result = switch (this) {
|
||||||
case ROCK -> other == SCISSORS;
|
case ROCK -> other == SCISSORS;
|
||||||
case PAPER -> other == ROCK || other == WELL;
|
case PAPER -> other == ROCK || other == WELL;
|
||||||
case SCISSORS -> other == PAPER;
|
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
|
@DomainService
|
||||||
public record RockPaperScissorsPlayer(CpuPick cpuPick, StatSave statSave) implements RockPaperScissorsPlay {
|
public record RockPaperScissorsPlayer(CpuPick cpuPick, StatSave statSave) implements RockPaperScissorsPlay {
|
||||||
|
|
||||||
public static final String WIN = "WIN";
|
|
||||||
public static final String LOOSE = "LOOSE";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RoundResult playRound(String name, Move move) {
|
public RoundResult playRound(String name, Move move) {
|
||||||
|
|
||||||
var cpuPicked = this.cpuPick.pick();
|
var cpuPicked = this.cpuPick.pick();
|
||||||
boolean beats = move.beats(cpuPicked);
|
Result beats = move.beats(cpuPicked);
|
||||||
String result = beats ? WIN : LOOSE;
|
if (beats.equals(Result.WIN)) {
|
||||||
if (result.equals(WIN)) {
|
|
||||||
this.statSave.addWin(name);
|
this.statSave.addWin(name);
|
||||||
}
|
}
|
||||||
return new RoundResult(result, name, cpuPicked);
|
return new RoundResult(beats.toString(), name, cpuPicked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user