Files
Martin Thoma e64fb6795c MAINT: Apply pre-commit
Remove byte-order-marker pre-commit check as there would be
many adjustments necessary
2022-03-05 09:29:23 +01:00

43 lines
1.0 KiB
Java

/**
* The Player class model the user and compuer player
*/
public class Player {
private final String name;
private final Punch bestPunch;
private final Punch vulnerability;
private boolean isPlayer = false;
public Player(String name, Punch bestPunch, Punch vulnerability) {
this.name = name;
this.bestPunch = bestPunch;
this.vulnerability = vulnerability;
this.isPlayer = true;
}
/**
* Player with random Best Punch and Vulnerability
*/
public Player(String name) {
this.name = name;
int b1;
int d1;
do {
b1 = Basic.randomOf(4);
d1 = Basic.randomOf(4);
} while (b1 == d1);
this.bestPunch = Punch.fromCode(b1);
this.vulnerability = Punch.fromCode(d1);
}
public boolean isPlayer() { return isPlayer; }
public String getName() { return name; }
public Punch getBestPunch() { return bestPunch; }
public boolean hitVulnerability(Punch punch) {
return vulnerability == punch;
}
}