-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEasy.java
99 lines (77 loc) · 2.96 KB
/
Easy.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
98
99
package Lab4;
/*
* Game - Easy Mode:
* This class runs the game at normal difficulty, by pitting the User
* against a Computer player that choose moves at random.
*/
import javax.swing.JOptionPane;
public class Easy {
//Universal Boolean to determine if game is in Hard mode
static boolean hard = false;
//Constructors for AI, Win Calculator, User Input, and Main classes
static Main sys = new Main();
static AI npc = new AI();
static WinCalc wincalc = new WinCalc();
static UserInput user = new UserInput();
//Variable to track rounds played
static int rounds;
static String userName;
static Object[] choices= {"Next Game", "Quit"};
//Method to start the game, or return the user to main menu
public void start()
{
int cont;
do{
name();
//If user cancels out of name input, send them here
cont = JOptionPane.showConfirmDialog(null,
"Return to Main Menu?",
"digiRPS - New Player",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
} while (cont==JOptionPane.NO_OPTION);
sys.menu();
}
//Method to learn user's name
public void name()
{
try{
userName=JOptionPane.showInputDialog(null,
"Please enter your name: ",
"digiRPS - New Player",
JOptionPane.PLAIN_MESSAGE);
if ((userName.length()<1))
{JOptionPane.showMessageDialog(null,
"Error: Please enter a username!",
"digiRPS - Error",
JOptionPane.ERROR_MESSAGE);
name();}
else if ((userName.length()>0)&&(userName!=null))
{game();}
} catch (NullPointerException e){ }
}
//Method for the actual running of the game
public void game()
{
int loop;
do {
rounds++;
//Get the Computer's move
int cMove = npc.easy();
//Get the User's move
int uMove = user.prompt(hard, rounds, cMove);
//Determine the winner and update records
wincalc.start(uMove, cMove, rounds, userName, hard);
loop = JOptionPane.showOptionDialog(null,
"Continue?",
"digiRPS - Continue",
JOptionPane.YES_NO_OPTION,
JOptionPane.PLAIN_MESSAGE,
null,
choices,
choices[0]);
} while (loop == JOptionPane.YES_OPTION);
//At game end, tally final results, and send to endGame method in Main
sys.endGame(wincalc.tally());
}
}