-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFortuneWheel.java
More file actions
253 lines (247 loc) · 7.36 KB
/
Copy pathFortuneWheel.java
File metadata and controls
253 lines (247 loc) · 7.36 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// Class - AP Computer Science A
// Date - 10/12/2022
// Name - Cody Washington
//Packages
import java.lang.*;
import java.util.Scanner;
//Main Class
public class FortuneWheel
{
//Instance Variables
private String phrase;
//Special Characters Already Added for Conveience
private String letterlist = " !@#$%^&*()[]{}|:;?/+=~-_'";
private boolean game_status = false;
private int guess_count;
//CONSTRUCTORS
//Constructor given Phrase.
public FortuneWheel(String p)
{
//Set Instance
phrase = p.toLowerCase();
guess_count = (phrase.length() + 1);
titlecard();
}
//Constructor not given Phrase.
public FortuneWheel()
{
//Set Instance
phrase = "cody is cool";
guess_count = (phrase.length() + 1);
titlecard();
}
//Replay the game without instantiating a new game given Phrase.
public void Replay(String p)
{
phrase = p.toLowerCase();
guess_count = (phrase.length() + 1);
letterlist = " !@#$%^&*()[]{}|:;?/+=~-_'";
game_status = false;
titlecard();
}
//Replay the game without instantiating a new game not given Phrase.
public void Replay()
{
//Credit
System.out.println("[Cody Washington | 10/12/2022 | Wheel of Fortune]");
//Spacing
for(int i = 0; i <= 4; i++)
{
System.out.println();
}
//Setup
Scanner input = new Scanner(System.in);
//Input the Phrase
System.out.print("\033[H\033[2J");
System.out.print("Your Phrase :: ");
phrase = input.nextLine().toLowerCase();
//Clear Console
System.out.print("\033[H\033[2J");
guess_count = (phrase.length() + 1);
letterlist = " !@#$%^&*()[]{}|:;?/+=~-_'";
game_status = false;
titlecard();
}
//LOGICAL METHODS
//Displays Phrase Based on Letter List
public String displayPhrase()
{
String Displayed_Phrase = "";
for(int i = 0; i <= (phrase.length()-1); i++)
{
char phrase_character = phrase.charAt(i);
for(int j = 0; j <= (letterlist.length()-1); j++)
{
char letterlist_character = letterlist.charAt(j);
//The Iterating Letterlist character
if(letterlist_character == phrase_character)
{
//Add character to return string
Displayed_Phrase += phrase_character;
break;
}
//The terating Letterlist character is last checked
else if(j == (letterlist.length()-1))
{
//Add aterisk to return string
Displayed_Phrase += "*";
}
}
}
//Win Checking
if(Displayed_Phrase == phrase)
{
game_status = true;
}
//Return results
return Displayed_Phrase;
}
//Takes in a Guess String, adds to letterlist and Substracts from Guess.
public int Guess(String guess)
{
//Clear Screen
System.out.print("\033[H\033[2J");
//Variables
int guess_length = (guess.length()-1);
String Previous_DisplayPhrase = displayPhrase();
//Convert Lower
guess = guess.toLowerCase();
//Guess is a Character
if(guess_length == 0)
{
//Check against letterlist
for(int i = 0; i <= (letterlist.length()-1); i++)
{
//Previously Guessed
if(guess.charAt(0) == letterlist.charAt(i))
{
return 0;
}
}
//Newly Guessed
letterlist+= guess;
guess_count--;
//DisplayPhrase Unaffected
if(displayPhrase().equals(Previous_DisplayPhrase))
{
return 2;
}
//DisplayPhrase affected
else
{
//Check if the Updated Display equals the phrase
if(displayPhrase().equals(phrase))
{
//All Characters Gussed
game_status = true;
return 5;
}
//Does not equal phrase
else
{
//Guess was in the phrase, but not all guessed.
return 1;
}
}
}
//Guess is a phrase
else if(guess_length >= 1)
{
guess_count -= 3;
//Guess is Phrase
if(guess.equals(phrase))
{
letterlist+=guess;
return 4;
}
//Guess is not phrase
else
{
return 3;
}
}
//Guess invalid
return 6;
}
//Displays game information
public void graphics()
{
//Variables
int phrase_length = (phrase.length()-1);
String Spacing = "";
//FORMATING
System.out.println();
System.out.println("[Remaining Guesses : "+getGuessCount()+"]");
System.out.println();
System.out.println();
//Top Box Bar
System.out.print("__");
for(int i = 0; i <= (phrase_length +2); i++)
{
System.out.print("_");
Spacing += " ";
}
System.out.print("\n");
//Middle
System.out.println("|"+Spacing+"|");
System.out.println("| "+displayPhrase()+" |");
System.out.println("|"+Spacing+"|");
//Bottom Box Bar
System.out.print("‾‾");
for(int i = 0; i <= (phrase_length + 2); i++)
{
System.out.print("‾");
}
//Spacing
for(int i = 0; i <= 3; i++)
{
System.out.println();
}
}
//Prints out a title card for WOF.
public void titlecard()
{
//Game title and Credits
System.out.println("____________________");
System.out.println("|------------------|");
System.out.println("| WHEEL-OF-FORTUNE |");
System.out.println("|------------------|");
System.out.println("‾‾‾|=[CODY W.]=|‾‾‾");
System.out.println(" ‾‾‾‾‾‾‾‾‾‾‾‾‾‾");
//Spacing
System.out.println();
}
public void continueplaying()
{
//Clear Screen
System.out.print("\033[H\033[2J");
System.out.println("[Game over, Would you like to keep playing?]");
System.out.println();
Scanner input = new Scanner(System.in);
if(input.next().toLowerCase().charAt(0) == 'n')
{
guess_count = 0;
}
else
{
Replay();
}
}
//ACESSOR METHODS
public String getPhrase()
{
return phrase;
}
public String getLetterList()
{
return letterlist;
}
public int getGuessCount()
{
return guess_count;
}
public boolean getGameStatus()
{
return game_status;
}
}