-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
141 lines (129 loc) · 3.37 KB
/
Game.java
File metadata and controls
141 lines (129 loc) · 3.37 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
import java.util.*;
/**
* Logic for the game, sequences, levels, comparing inputs and sequences.
*/
public class Game {
private int level;
private int blinks;
// original challenge
private ArrayList<Integer> challenge = new ArrayList<>();
// player input challenge
private ArrayList<Integer> playerInput = new ArrayList<>();
private Random random;
private int difficulty;
/**
* Creates a newGame.
*/
public Game() {
newGame();
}
/**
* Returns the current difficulty of the game.
*/
public int getDifficulty() {
return difficulty;
}
/**
* Sets the difficulty to the specified difficulty.
* @param d The difficult to change to.
*/
public void setDifficulty(int d) {
difficulty = d;
}
/**
* clears the challenge, clears the player inputs, creates a random challenge by choosing a random button
using the difficulty to ensure new challenge is within the limits of the difficulty.
Repeats for each blink required until challenge is completed.
*/
public void challenge() {
challenge.clear();
playerInput.clear();
random = new Random();
for (int i = 0; i < blinks; i++) {
challenge.add(random.nextInt(3 * difficulty) + 1);
}
}
/**
* Player win checker,
* returns 0 if they have lost, 1 if they have won.
*/
public int win() {
if (level < 0) {
return 0;
} else if (level == 10) {
return 1;
} else {
return 2;
}
}
/**
* Sets the current level of the game to the specified level.
* @param i The level to change to.
*/
public void setLevel(int i) {
level = i;
}
/**
* Returns the challenge sequence.
*/
public ArrayList<Integer> returnOriginalchallenge() {
return challenge;
}
/**
* Adds the chosen button to the players sequence, to compare to the challenged array.
*/
public void playerchallenge(int i) {
playerInput.add(i);
}
/**
* Sets level back to 0.
*/
public void newGame() {
level = 0;
blinks();
}
/**
* Checks to see the player has finished entering the challenge and calls
* another method to see if they have leveled.
*/
public boolean finished() {
if (playerInput.size() == challenge.size()) {
level();
return true;
} else {
return false;
}
}
/**
* Checks to see the player has entered the challenge correctly.
*/
private boolean compareList() {
return challenge.toString().contentEquals(playerInput.toString()) ? true : false;
}
/**
* Increases the level if the player was correct, decrease level if they got it wrong.
*/
private void level() {
if (compareList()) {
level++;
challenge();
blinks();
} else {
level--;
blinks();
}
}
/**
* Returns the current level.
*/
public int returnlevel() {
return level;
}
/**
* Switch number of blinks based on level and difficulty.
* Number of blinks increases by difficulty every 3 levels.
*/
private void blinks() {
blinks = difficulty + level / (5 - difficulty);
}
}