-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
68 lines (59 loc) · 1.6 KB
/
Copy pathPlayer.java
File metadata and controls
68 lines (59 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.Random;
public class Player {
private int points;
private Choice choice;
private boolean computer;
private String name;
public Player(String name, boolean computer) {
this.name = name;
this.computer = computer;
this.choice = Choice.ROCK;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Choice getChoice() {
return choice;
}
public void setChoice(Choice choice) {
if (choice.equals(Choice.ROCK)) {
this.choice = Choice.ROCK;
}
else if (choice.equals(Choice.PAPER)) {
this.choice = Choice.PAPER;
}
else if (choice.equals(Choice.SCISSORS)) {
this.choice = Choice.SCISSORS;
}
else {
throw new IllegalArgumentException("Supported Choices: Paper, Rock, Scissors.");
}
}
public void setChoice() {
if (computer) {
Random random = new Random();
int selection = random.nextInt(3);
if (selection == 0) {
this.choice = Choice.ROCK;
}
else if (selection == 1) {
this.choice = Choice.PAPER;
}
else {
this.choice = Choice.SCISSORS;
}
}
else {
throw new IllegalStateException("Must send input to set choice for non-computer player.");
}
}
public int getPoints() {
return points;
}
public void addPoint() {
this.points += 1;
}
}