-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameCheck.java
More file actions
92 lines (79 loc) · 2.71 KB
/
gameCheck.java
File metadata and controls
92 lines (79 loc) · 2.71 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
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
public class gameCheck {
private class ProduceAwnsers {
// private class for the awnser
private String[] awnser = { "dog", "bumblebee", "bird" };
private String text = " ";
public void Random() {
// randomizes the awnser
int random = ThreadLocalRandom.current().nextInt(0, 3);
text = awnser[random];
}
public String GetAwnser() {
// gets the awnser created from the random method
String correctAwnser = text;
return correctAwnser;
}
}
ProduceAwnsers awnser = new ProduceAwnsers();
private static char[] awnserArr = {};
private static List<Character> charList = new ArrayList<Character>();
private static int success = 0;
public void Setup() {
// method to setup different variables when the game starts
awnser.Random();
awnserArr = awnser.GetAwnser().toCharArray();
charList.clear();
for (int i = 0; i < awnser.GetAwnser().length(); i++) {
charList.add(i, '*');
}
}
public void Guess(char guess) {
// method for char guesses
for (int i = 0; i < awnser.GetAwnser().length(); i++) {
if (guess == awnserArr[i]) {
charList.set(i, guess);
success = 1;
}
}
System.out.println(GetCharList());
}
public void WordGuess(String guess) {
// method for guessing the whole word
if (guess.equals(awnser.GetAwnser())) {
char[] guessCharArr = guess.toCharArray();
for (int i = 0; i < awnser.GetAwnser().length(); i++) {
charList.set(i, guessCharArr[i]);
success = 1;
}
} else {
success = 2;
}
}
public int Success() {
// method for reaching the different states of success
return success;
}
public void ResetSucces() {
// resets success
success = 0;
}
public String Awnser() {
// makes the awnser available to other classes and methods
return awnser.GetAwnser();
}
public String GetCharList() {
// method that shows the right guessed char's
// types * otherwise
String charToString = " ";
char a = ' ';
char[] x = new char[awnser.GetAwnser().length()];
for (int i = 0; i < awnser.GetAwnser().length(); i++) {
a = charList.get(i);
x[i] = a;
charToString = String.valueOf(x);
}
return charToString;
}
}