-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUGG.java
More file actions
47 lines (43 loc) · 1.16 KB
/
UGG.java
File metadata and controls
47 lines (43 loc) · 1.16 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
package UnrestrictedGame;
import restrictedGame.RGG;
/**
* This class extends restricted guessing game. Unrestricted guessing game
* allows player to enter their answer and update the tree
*
* @author Ching2 Huang
*
*/
public class UGG extends RGG {
/**
* Constructed changes the title of the frame and hide possible answers
*/
public UGG() {
// change the name
setTitle("Unrestrcited Guessing Game");
// hide the possible answers
answers.setVisible(false);
}
/**
* override actions for no button
*/
public void no() {
// if the node has right child
if (current.getRightChild() != null) {
// if the right child is not a lead
if (!current.getRightChild().isLeaf()) {
// update current and the question
current = current.getRightChild();
question.setText(current.getData());
} else {// if right child is a leaf, the node is an answer
// update current
current = current.getRightChild();
// print the answer
question.setText("Is your answer: " + current.getData() + "?");
}
} else {
// pop up a new frame for the player to add their option
new AddOpt(current);
restart(); // restart the game
}
}
}