-
Notifications
You must be signed in to change notification settings - Fork 0
/
GrammarState.cpp
165 lines (146 loc) · 4.38 KB
/
GrammarState.cpp
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
#include "stdafx.h"
#include "GrammarState.h"
namespace EnglishEducator
{
GrammarState::GrammarState(GameDataRef data) : _data(data)
{
}
void GrammarState::Init()
{
_background.setTexture(_data->assets.GetTexture("Game Background"));
ellenBaker = new EllenBaker(_data);
qAndA = new QandA(_data, GrammarStates::eNone);
}
void GrammarState::HandleInput()
{
sf::Event event;
while (_data->window.pollEvent(event))
{
if (sf::Event::Closed == event.type)
{
_data->window.close();
}
if (_clock.getElapsedTime().asSeconds() > 0.2) // to avoid multiple clicks in one go
{
if (_data->input.IsSpriteClicked(ellenBaker->GetTextBoxSprite(), sf::Mouse::Left, _data->window))
{
ellenBaker->AdvanceText();
_clock.restart();
}
if (_data->input.IsSpriteClicked(ellenBaker->GetTextBoxSprite(), sf::Mouse::Right, _data->window))
{
ellenBaker->RewindText();
_clock.restart();
}
if (_data->input.IsSpriteClicked(ellenBaker->GetSimplePresent(), sf::Mouse::Left, _data->window))
{
/*_grammarState = eSimplePresent;*/
_clock.restart();
qAndA = new QandA(_data, eSimplePresent);
ellenBaker->MakeChoicesAppear(false);
ellenBaker->DeleteTopics();
qAndA->MakeAnswersAppear(true);
qAndA->AdvanceQandA();
}
if (_data->input.IsSpriteClicked(ellenBaker->GetSimplePresent2(), sf::Mouse::Left, _data->window))
{
_clock.restart();
qAndA = new QandA(_data, eSimplePresent);
ellenBaker->MakeChoicesAppear(false);
ellenBaker->DeleteTopics();
qAndA->MakeAnswersAppear(true);
qAndA->AdvanceQandA();
}
if (_data->input.IsSpriteClicked(ellenBaker->GetSimplePast(), sf::Mouse::Left, _data->window))
{
_clock.restart();
qAndA = new QandA(_data, eSimplePast);
ellenBaker->MakeChoicesAppear(false);
ellenBaker->DeleteTopics();
qAndA->MakeAnswersAppear(true);
qAndA->AdvanceQandA();
}
if (_data->input.IsSpriteClicked(ellenBaker->GetSimplePast2(), sf::Mouse::Left, _data->window))
{
_clock.restart();
qAndA = new QandA(_data, eSimplePast2);
ellenBaker->MakeChoicesAppear(false);
ellenBaker->DeleteTopics();
qAndA->MakeAnswersAppear(true);
qAndA->AdvanceQandA();
}
if (_data->input.IsSpriteClicked(ellenBaker->GetSimpleFuture(), sf::Mouse::Left, _data->window))
{
_clock.restart();
qAndA = new QandA(_data, eSimpleFuture);
ellenBaker->MakeChoicesAppear(false);
ellenBaker->DeleteTopics();
qAndA->MakeAnswersAppear(true);
qAndA->AdvanceQandA();
}
if (_data->input.IsSpriteClicked(ellenBaker->GetFutureContinuous(), sf::Mouse::Left, _data->window))
{
_clock.restart();
qAndA = new QandA(_data, eFutureContinuous);
ellenBaker->MakeChoicesAppear(false);
ellenBaker->DeleteTopics();
qAndA->MakeAnswersAppear(true);
qAndA->AdvanceQandA();
}
if (_data->input.IsSpriteClicked(qAndA->GetA1Sprite(), sf::Mouse::Left, _data->window))
{
_clock.restart();
if (qAndA->_a1Text == qAndA->_correctAnswerText)
{
qAndA->IncrementScore();
}
qAndA->AdvanceQandA();
}
if (_data->input.IsSpriteClicked(qAndA->GetA2Sprite(), sf::Mouse::Left, _data->window))
{
_clock.restart();
if (qAndA->_a2Text == qAndA->_correctAnswerText)
{
qAndA->IncrementScore();
}
qAndA->AdvanceQandA();
}
if (_data->input.IsSpriteClicked(qAndA->GetA3Sprite(), sf::Mouse::Left, _data->window))
{
_clock.restart();
if (qAndA->_a3Text == qAndA->_correctAnswerText)
{
qAndA->IncrementScore();
}
qAndA->AdvanceQandA();
}
if (_data->input.IsSpriteClicked(qAndA->GetA4Sprite(), sf::Mouse::Left, _data->window))
{
_clock.restart();
if (qAndA->_a4Text == qAndA->_correctAnswerText)
{
qAndA->IncrementScore();
}
qAndA->AdvanceQandA();
}
}
}
}
void GrammarState::Update(float dt)
{
ellenBaker->Animate(dt);
qAndA->Update();
}
int GrammarState::GetGrammarState()
{
return _grammarState;
}
void GrammarState::Draw(float dt)
{
_data->window.clear();
_data->window.draw(_background);
ellenBaker->Draw();
qAndA->Draw();
_data->window.display();
}
}