Files
basic-computer-games/15_Boxing/java/Player.java
Chris Reuter d26dbf036a Removed spaces from top-level directory names.
Spaces tend to cause annoyances in a Unix-style shell environment.
This change fixes that.
2021-11-21 18:30:21 -05:00

42 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;
}
}