-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserInput.java
97 lines (79 loc) · 2.61 KB
/
UserInput.java
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package Lab4;
/*
* User Input:
* This class collects the User's moves, and sends them back to either
* the Easy or Hard class, depending on difficulty.
*/
import javax.swing.JOptionPane;
public class UserInput {
//Constructor
static Speech aiSays = new Speech();
//Alternative text for JOptionPane buttons
static Object[] options = {"Rock", "Paper", "Scissors"};
//Variable to track rounds
static int round;
// Hub method
public int prompt(boolean hard, int turn, int cMove)
{
int result;
round = turn;
if (hard)
{result = hard(cMove, turn);}
else
{result = easy();}
return result;
}
//Method to collect user's choice for Easy difficulty
public int easy()
{
int choose=0;
int move = JOptionPane.showOptionDialog(null,
"Please choose your move.",
"digiRPS - Game " + round,
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE,
null,
options,
options[0]);
switch (move)
{
case JOptionPane.YES_OPTION:
choose = 3; //R
return choose;
case JOptionPane.NO_OPTION:
choose = 2; //P
return choose;
case JOptionPane.CANCEL_OPTION:
choose = 1; //S
return choose;
}
return choose;
}
//Method to collect user's choice for Hard difficulty
public int hard(int cMove, int turn)
{
int tauntCode=1; //Taunt Code "1" = UI Taunts
int choose=0;
int move = JOptionPane.showOptionDialog(null,
aiSays.taunt(tauntCode, cMove, turn),
"digiRPS - Game " + round,
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE,
null,
options,
options[0]);
switch (move)
{
case JOptionPane.YES_OPTION:
choose = 3; //R
return choose;
case JOptionPane.NO_OPTION:
choose = 2; //P
return choose;
case JOptionPane.CANCEL_OPTION:
choose = 1; //S
return choose;
}
return choose;
}
}