-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordGuess.java
More file actions
93 lines (74 loc) · 1.98 KB
/
WordGuess.java
File metadata and controls
93 lines (74 loc) · 1.98 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
/**
* Word Guess/ Hangman
*
* @author Maricel Vicente
* @version 2/6/2019
*/
public class WordGuess {
public static String makeUserWord(String theWord)
{
String userWord = "";
for (int count = 0; count < theWord.length(); count++)
{
userWord = userWord + "*";
}
return userWord;
}
public static boolean isInWord(char guess, String theWord)
{
boolean found = false;
for (int i = 0; i < theWord.length(); i++)
{
if (guess == theWord.charAt(i))
{
found = true;
}
}
return found;
}
public static String updateUserWord(char guess, String userWord, String theWord)
{
String updateWord = "";
for (int i = 0; i < theWord.length(); i++)
{
if (theWord.charAt(i) == guess)
{
updateWord = updateWord + guess;
}
else
{
updateWord = updateWord + userWord.charAt(i);
}
}
return updateWord;
}
public static String updateGuesses(String guesses, char guess)
{
if (isInWord(guess, guesses) == false)
{
guesses = guesses + guess + " ";
}
return guesses;
}
public static String displayUserWord(String userWord)
{
String displayWord = "";
for (int i = 0; i < userWord.length(); i++)
{
if (userWord.charAt(i) == '*')
{
displayWord = displayWord + " _ ";
}
else
{
displayWord = displayWord + userWord.charAt(i);
}
}
return displayWord;
}
public static String displayGuesses(int strikes, String guesses)
{
String displayGuess = String.format("Strikes: %d" + "\t Guesses: %s", strikes, guesses);
return displayGuess;
}
}