hills
This commit is contained in:
parent
3c4dc154b1
commit
27ac1468c6
40
src/Game.cpp
40
src/Game.cpp
@ -45,22 +45,24 @@ void Game::Run() {
|
|||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
Game game;
|
{
|
||||||
bool quit = false;
|
Game game;
|
||||||
SDL_Event event;
|
bool quit = false;
|
||||||
while (!quit) {
|
SDL_Event event;
|
||||||
game.draw(renderer);
|
while (!quit) {
|
||||||
while (SDL_WaitEvent(&event)) {
|
game.draw(renderer);
|
||||||
switch (event.type) {
|
while (SDL_WaitEvent(&event)) {
|
||||||
case SDL_QUIT:
|
switch (event.type) {
|
||||||
quit = true;
|
case SDL_QUIT:
|
||||||
break;
|
quit = true;
|
||||||
case SDL_KEYDOWN :
|
break;
|
||||||
game.handle_key(event.key.keysym.sym);
|
case SDL_KEYDOWN :
|
||||||
game.draw(renderer);
|
game.handle_key(event.key.keysym.sym);
|
||||||
|
game.draw(renderer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
@ -69,7 +71,10 @@ void Game::Run() {
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::Game() : m_wrong_guesses(0), m_game_state(State::PLAY) {
|
Game::Game() :
|
||||||
|
m_wrong_guesses(0),
|
||||||
|
m_game_state(State::PLAY),
|
||||||
|
m_hills(get_hills()) {
|
||||||
const char *defaultFontPath = getDefaultFontPath();
|
const char *defaultFontPath = getDefaultFontPath();
|
||||||
if (defaultFontPath == nullptr) {
|
if (defaultFontPath == nullptr) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@ -167,3 +172,8 @@ void Game::draw_guesses(SDL_Renderer *renderer) {
|
|||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Game::~Game() {
|
||||||
|
for (SDL_Surface *surface: m_hills)
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
}
|
||||||
|
@ -19,11 +19,13 @@ private:
|
|||||||
_TTF_Font *font;
|
_TTF_Font *font;
|
||||||
int m_wrong_guesses;
|
int m_wrong_guesses;
|
||||||
State m_game_state;
|
State m_game_state;
|
||||||
|
std::vector<SDL_Surface *> m_hills;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void Run();
|
static void Run();
|
||||||
|
|
||||||
Game();
|
Game();
|
||||||
|
~Game();
|
||||||
|
|
||||||
void handle_key(SDL_Keycode event);
|
void handle_key(SDL_Keycode event);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user