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_RenderPresent(renderer);
|
||||
|
||||
Game game;
|
||||
bool quit = false;
|
||||
SDL_Event event;
|
||||
while (!quit) {
|
||||
game.draw(renderer);
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
quit = true;
|
||||
break;
|
||||
case SDL_KEYDOWN :
|
||||
game.handle_key(event.key.keysym.sym);
|
||||
game.draw(renderer);
|
||||
{
|
||||
Game game;
|
||||
bool quit = false;
|
||||
SDL_Event event;
|
||||
while (!quit) {
|
||||
game.draw(renderer);
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
quit = true;
|
||||
break;
|
||||
case SDL_KEYDOWN :
|
||||
game.handle_key(event.key.keysym.sym);
|
||||
game.draw(renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
@ -69,7 +71,10 @@ void Game::Run() {
|
||||
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();
|
||||
if (defaultFontPath == nullptr) {
|
||||
std::stringstream ss;
|
||||
@ -167,3 +172,8 @@ void Game::draw_guesses(SDL_Renderer *renderer) {
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
Game::~Game() {
|
||||
for (SDL_Surface *surface: m_hills)
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
@ -19,11 +19,13 @@ private:
|
||||
_TTF_Font *font;
|
||||
int m_wrong_guesses;
|
||||
State m_game_state;
|
||||
std::vector<SDL_Surface *> m_hills;
|
||||
|
||||
public:
|
||||
static void Run();
|
||||
|
||||
Game();
|
||||
~Game();
|
||||
|
||||
void handle_key(SDL_Keycode event);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user