-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGame.java
222 lines (177 loc) · 6.84 KB
/
Game.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
219
220
221
222
package org.academniadecodigo.dancedance;
import org.academiadecodigo.simplegraphics.graphics.Text;
import org.academniadecodigo.dancedance.gameobjects.GameObjectFactory;
import org.academniadecodigo.dancedance.keyboard.KeysType;
import org.academniadecodigo.dancedance.simplegfx.StageSgfx;
import org.academniadecodigo.dancedance.simplegfx.KeyboardSgfx;
import org.academniadecodigo.dancedance.stage.Music;
/**
* Created by codecadet on 20/10/16.
*/
public class Game {
//private StageSgfx stageSgfx;
private GameObjectFactory objects;
private KeyboardSgfx keyboard;
private Music music;
private Music wrongSound; //change song
private Music correctSound;
private Music comboSound; //TODO fix this shit == too many Music variables
private Music startSong;
private Music gameOverSong;
private Text totalScore;
private boolean spacePressed;
private int health;
private int correctCounter;
private int failCounter;
private int beat;
private int score;
public Game() {
keyboard = new KeyboardSgfx();
//stageSgfx = new StageSgfx(85, 47);
objects = new GameObjectFactory();
music = new Music();
objects.createEffects();
correctSound = new Music();
wrongSound = new Music();
comboSound = new Music();
startSong = new Music();
gameOverSong = new Music();
spacePressed = false;
beat = Music.MUSIC_BEATS;
}
public void startGame() throws InterruptedException {
//stageSgfx.init();
objects.background().showBackground();
startSong.playSound("resources/music/START_MUSIC.wav");
Thread.sleep(StageSgfx.ANIMATION_SLEEP);
objects.createAnimation().startAnimation();
startSong.stopMusic();
startLevel();
}
public void startLevel() throws InterruptedException {
// TODO Level Constructor and implement multiple levels
health = 20;
score = 0;
correctCounter = 0;
failCounter = 0;
totalScore = new Text( 680, 43, "SCORE:" + score);
totalScore.grow(70,20);
objects.newDancer().loadDancerPictures();
objects.createHealthBar().showHealthBar();
totalScore.draw();
music.playSound("resources/music/Eric_Prydz_-_Call_On_Me_483ms_beat.wav");
while (true) {
if (health > 0) {
KeysType randomKey = KeysType.getRandomKey();
askKey(randomKey);
checkKey(randomKey);
} else {
music.stopMusic();
endGame();
break;
}
}
}
public void askKey(KeysType randomKey) throws InterruptedException {
switch (randomKey) {
case UP:
objects.newArrow().showUpArrow();
Thread.sleep(Music.MUSIC_BEATS);
objects.getArrow().hideUpArrow();
objects.getEffects().deleteEffects();
break;
case DOWN:
objects.newArrow().showDownArrow();
Thread.sleep(Music.MUSIC_BEATS);
objects.getArrow().hideDownArrow();
objects.getEffects().deleteEffects();
break;
case LEFT:
objects.newArrow().showLeftArrow();
Thread.sleep(Music.MUSIC_BEATS);
objects.getArrow().hideLeftArrow();
objects.getEffects().deleteEffects();
break;
case RIGHT:
objects.newArrow().showRightArrow();
Thread.sleep(Music.MUSIC_BEATS);
objects.getArrow().hideRightArrow();
objects.getEffects().deleteEffects();
break;
default:
System.out.println("something is not ok.");
}
}
public void checkKey(KeysType randomKey) throws InterruptedException {
/*
RESET BUTTON
if (keyboard.verifyKeyPressed(KeysType.SPACE.ordinal())){
music.stopMusic();
objects.getDancer().hideDancer();
*/
if (keyboard.verifyKeyPressed(randomKey.ordinal())) {
switch (randomKey) {
case UP:
objects.getDancer().changeMovement(KeysType.UP);
correctSound.playSound("resources/SOUND_FX/CORRECT_SOUND_01.wav");
break;
case DOWN:
objects.getDancer().changeMovement(KeysType.DOWN);
correctSound.playSound("resources/SOUND_FX/CORRECT_SOUND_01.wav");
break;
case LEFT:
objects.getDancer().changeMovement(KeysType.LEFT);
correctSound.playSound("resources/SOUND_FX/CORRECT_SOUND_01.wav");
break;
case RIGHT:
objects.getDancer().changeMovement(KeysType.RIGHT);
correctSound.playSound("resources/SOUND_FX/CORRECT_SOUND_01.wav");
break;
default:
System.out.println("something is not ok.");
}
failCounter = 0;
correctCounter++;
score++;
totalScore.delete();
totalScore = new Text( 680, 43, "SCORE:" + score);
totalScore.grow(70,20);
totalScore.draw();
if (correctCounter == 5) {
objects.getEffects().showCombo();
comboSound.playSound("resources/SOUND_FX/COMBO_SOUND_01.wav");
Music.MUSIC_BEATS = beat / 2;
score += 2;
totalScore.delete();
totalScore = new Text( 680, 43, "SCORE:" + score);
totalScore.grow(70,20);
totalScore.draw();
}
System.out.println(correctCounter);
System.out.println("well done");
} else {
objects.getDancer().changeMovement(KeysType.SPACE); // KeysType.SPACE = Wrong Movement
health--;
objects.getHealthBar().decreaseHealthBar();
objects.getEffects().showWrongKey();
correctCounter = 0;
failCounter++;
if (failCounter == 3) {
Music.MUSIC_BEATS = beat;
}
System.out.println(failCounter);
System.out.println("shit, my health is: " + health);
}
}
public void endGame() throws InterruptedException {
System.out.println("Health: " + health + " Game Over!\n" + "score: " + score);
objects.getEffects().deleteEffects();
objects.getDancer().hideDancer();
gameOverSong.playSound("resources/music/GAME_OVER.wav");
objects.createAnimation().youLoseAnimation();
objects.getHealthBar().hidehealthBar();
gameOverSong.stopMusic();
startGame();
return;
}
}