-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathletterGuess.java
218 lines (189 loc) · 8.69 KB
/
letterGuess.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
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
import java.util.Scanner;
import java.util.Random;
public class letterGuess {
public static class player {
String playerName;
int score;
int guesses = 15;
int roundsWon = 0;
int roundGuesses = 0;
}
public static void main(String[] args) {
Scanner ask = new Scanner(System.in);
String[] insultsArr = {"dick", "bitch", "cunt", "asshole", "fart face", "dickhead", "loser", "fuckface", "dipshit", "squazznain", "motherfucker", "cheese-wain", "flarnchalarnchagus", "scrub", "tasteless fool", "Garfunkel", "Captain Pee-Pants", "ya cunt", "ya squankelton"};
String[] backTalkArr = {"That's fine, guess I'll just go f*ck myself then.", "Yeah, I'm sure you totally have better things to do.", "Fine! Go ahead! Leave! See if I care...", "You've really hurt my feelings today...", "I see how it is.", "WOOOOOW. Ok. Fine.", "Just gonna use me up and toss me out, is that it?", "Whatever, you lost anyway.", "Like I care. You suck at this game!", "I was tired of looking at your ugly mug anyway!", "Fuck you."};
String[] lettersArr = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
final String DIVIDER_LINE = "=====================================";
boolean isPlaying = true;
String insult;
String backTalk;
String currentLetter;
String userName;
String response;
String guess;
player user = new player();
Random rand = new Random();
int randNum;
System.out.println(DIVIDER_LINE);
System.out.println("~*~*~*~*~*!!LETTER GUESS!!*~*~*~*~*~");
System.out.println(" ----!AN ALPHABETICAL GOOD TIME!----");
System.out.println(DIVIDER_LINE);
// GETS PLAYER NAME
System.out.println("Enter player name: ");
user.playerName = ask.nextLine();
// VERIFIES PLAYER NAME
System.out.println("Is '" + user.playerName + "' correct? (Enter yes/no): ");
response = ask.nextLine();
while (!response.equalsIgnoreCase("yes")) {
if (!response.equalsIgnoreCase("no")) {
while (!response.equalsIgnoreCase("yes") && !response.equalsIgnoreCase("no")) {
System.out.println("Invalid input.");
System.out.println("Is '" + user.playerName + "' correct? (Enter yes/no): ");
response = ask.nextLine();
}
} else {
System.out.println("Enter player name: ");
user.playerName = ask.nextLine();
System.out.println("Is '" + user.playerName + "' correct? (Enter yes/no): ");
response = ask.nextLine();
}
}
userName = user.playerName;
//GAME DESCRIPTION
System.out.println(DIVIDER_LINE);
System.out.println("--Welcome to the game, " + userName + "!--");
System.out.println(DIVIDER_LINE);
System.out.println("This is a guessing game.");
System.out.println("Try to guess the random letter ");
System.out.println("before your guesses run out.");
System.out.println("If you guess the letter correctly, ");
System.out.println("you win the round and receive points ");
System.out.println("equivalent to your remaining guesses ");
System.out.println("and +5 guesses for the next round.");
System.out.println("If your guesses run out, you lose!");
System.out.println(DIVIDER_LINE);
System.out.println("------------- HAVE FUN! -------------");
System.out.println("A letter has been randomly selected.");
System.out.println("You have " + user.guesses + " guesses remaining.");
//SETS THE RANDOM LETTER
randNum = rand.nextInt(lettersArr.length);
currentLetter = lettersArr[randNum];
while (isPlaying) {
//REPORTS SCORES AT THE START OF EACH ROUND
if (user.roundGuesses == 0) {
System.out.println(DIVIDER_LINE);
System.out.println("Current Round: " + (user.roundsWon + 1));
System.out.println("Rounds Won: " + user.roundsWon);
System.out.println("Current Score: " + user.score);
System.out.println(DIVIDER_LINE);
}
//PLAYER RUNS OUT OF GUESSES
if (user.guesses == 0) {
System.out.println(DIVIDER_LINE);
System.out.println("You are out of guesses.");
System.out.println("!!!GAME OVER!!!");
System.out.println(DIVIDER_LINE);
System.out.println(user.playerName + "'s Final Scores:");
System.out.println(DIVIDER_LINE);
System.out.println("Rounds Won: " + user.roundsWon);
System.out.println("Score: " + user.score);
System.out.println("Thanks for playing, " + user.playerName + "!");
System.out.println(DIVIDER_LINE);
//PLAY AGAIN??
System.out.println("Would you like to play again?");
System.out.println(" (Enter 'yes' or 'no'):");
response = ask.next();
//IF !YES/!NO ENTERED
if (!response.equalsIgnoreCase("yes") && !response.equalsIgnoreCase("no")) {
while (!response.equalsIgnoreCase("yes") && !response.equalsIgnoreCase("no")) {
System.out.println("Please enter either 'yes' or 'no'.");
System.out.println("Would you like to play again?:");
response = ask.next();
}
}
//IF YES OR NO ENTERED
if (response.equalsIgnoreCase("yes")) {
user.score = 0;
user.guesses = 15;
user.roundsWon = 0;
randNum = rand.nextInt(lettersArr.length);
currentLetter = lettersArr[randNum];
System.out.println(DIVIDER_LINE);
System.out.println("---------- GAME RESET ----------");
System.out.println(DIVIDER_LINE);
System.out.println("A letter has been randomly selected.");
System.out.println("You have " + user.guesses + " guesses remaining.");
} else {
isPlaying = false;
break;
}
}
//GETS GUESS FROM USER
System.out.println("Guess a letter: ");
guess = ask.next().toUpperCase();
//CHECKS/ENSURES THAT GUESS IS ONLY ONE CHARACTER
while (guess.length() > 1) {
System.out.println("Please enter a single character.");
System.out.println("Guess a letter: ");
guess = ask.next().toUpperCase();
}
//IF GUESS IS CORRECT, ADDS POINTS TO SCORE AND ADDS GUESSES
if (guess.equals(currentLetter)) {
user.roundsWon++;
user.score += user.guesses;
user.roundGuesses = 0;
System.out.println("You guessed correctly!");
System.out.println(user.guesses + " points have been added to your score.");
user.guesses += 5;
System.out.println("Current Score: " + user.score);
System.out.println(DIVIDER_LINE);
//ASKS USER IF THEY WANT TO CONTINUE TO THE NEXT ROUND
System.out.println("Would you like to continue playing?");
response = ask.next();
//VERIFIES IF RESPONSE IS EITHER YES OR NO
if (!response.equalsIgnoreCase("yes") && !response.equalsIgnoreCase("no")) {
while (!response.equalsIgnoreCase("yes") && !response.equalsIgnoreCase("no")) {
System.out.println("Please enter either 'yes' or 'no'.");
System.out.println("Would you like to continue playing?");
response = ask.next();
}
}
//IF USER ENTERED NO, ENDS GAME
if (response.equalsIgnoreCase("no")) {
isPlaying = false;
System.out.println(DIVIDER_LINE);
System.out.println("Final Score:");
System.out.println("Rounds Won: " + user.roundsWon);
System.out.println("Score: " + user.score);
System.out.println(DIVIDER_LINE);
//IF USER ENTERED YES, RESETS CURRENT LETTER AND STARTS NEXT ROUND
} else if (response.equalsIgnoreCase("yes")) {
user.roundGuesses = 0;
System.out.println("A letter has been randomly selected.");
System.out.println("You have " + user.guesses + " guesses remaining.");
System.out.println(DIVIDER_LINE);
randNum = rand.nextInt(lettersArr.length);
currentLetter = lettersArr[randNum];
}
//IF GUESS IS WRONG, SUBTRACTS 1 POINT AND CONTINUES THE ROUND
} else {
user.guesses--;
user.roundGuesses++;
System.out.println("Incorrect.");
System.out.println("Guesses remaining: " + user.guesses);
}
}
if (!isPlaying) {
randNum = rand.nextInt(backTalkArr.length);
backTalk = backTalkArr[randNum];
System.out.println(backTalk);
randNum = rand.nextInt(insultsArr.length);
insult = insultsArr[randNum];
System.out.println("Later, " + insult + "!");
System.out.println("--program ended with sadness and resentment--");
System.out.println(DIVIDER_LINE);
ask.close();
System.exit(0);
}
}
}