forked from NattyBumppo/Simon-Clone-for-Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modes.h
146 lines (111 loc) · 2.17 KB
/
Modes.h
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
#ifndef MODE_H
#define MODE_H
#include "Arduino.h"
#include "gameplay.h"
// Represents the mode or state of the application
class Mode
{
public:
virtual Mode* Update(int dT)
{
return this;
}
virtual ~Mode() {
}
};
/////////////////////////////////////////////////
// Play some lights, and check for the easter egg code
// This will eventually start the game mode.
class AttractMode :
public Mode
{
public:
AttractMode();
virtual Mode* Update(int dT);
virtual ~AttractMode() {
}
private:
boolean CheckEasterEggCode(int pressed);
void UpdateLights(int dT);
int easterEggPos;
int attractLightPos;
int time;
};
/////////////////////////////////////////////////
class State;
class ShowSeqState;
class ReadSeqState;
// Once the game has started.
class GameMode :
public Mode
{
public:
GameMode(Difficulty difficulty);
virtual Mode* Update(int dT);
virtual ~GameMode() {
}
private:
State* curState;
enum Condition
{
StillPlaying = 0,
Defeat,
Victory
};
Condition condition;
int turnNo;
int turnsUntilWin;
int LEDDisplayTime;
int delayBetweenLights; // Wait this time (ms) between light display; changes depending on difficulty mode
int fireworks;
Color colorChain[100];
friend class ShowSeqState;
friend class ReadSeqState;
};
/////////////////////////////////////////////////
// Causes a delay in transition between modes
class DelayMode :
public Mode
{
public:
DelayMode(int delayTime, Mode* next)
{
mNext = next;
mDelay = delayTime;
}
virtual Mode* Update(int dT)
{
mDelay -= dT;
if(mDelay <= 0)
return mNext;
return this;
}
virtual ~DelayMode() {
}
private:
Mode* mNext;
int mDelay;
};
/////////////////////////////////////////////////
class Note;
// Plays a song and goofs around with lights
class MelodyMode :
public Mode
{
public:
MelodyMode(Melody melody, Mode* next);
virtual Mode* Update(int dT);
private:
Mode* mNext;
const Note* notes;
int tempo;
int length;
Color color;
int note;
int nextTime;
int time;
int fireworks;
void StartTone(int freq, int duration);
void PlayFireworks(int count);
};
#endif