sliding-puzzle/application.h

43 lines
874 B
C
Raw Normal View History

2020-12-13 19:45:52 +01:00
#pragma once
#include <SFML/Window/Keyboard.hpp>
#include "board.h"
class Application
{
public:
2021-01-08 22:14:28 +01:00
enum class STATE
{
PLAY,
WIN
} current_state;
2020-12-20 14:49:24 +01:00
explicit Application(unsigned int window_width, unsigned int window_height);
2020-12-13 19:45:52 +01:00
// Init game
2020-12-18 21:12:28 +01:00
bool init(const std::string& path, int splitting);
2020-12-14 20:22:52 +01:00
// Launch game
2020-12-13 19:45:52 +01:00
void run();
2020-12-14 20:22:52 +01:00
// Refresh render_window to actual state
2020-12-13 19:45:52 +01:00
void draw();
2020-12-14 20:22:52 +01:00
// Handle keyboard commands
void processInput();
2020-12-13 19:45:52 +01:00
2021-01-08 22:14:28 +01:00
// Handle events for player to move cursor and swap tiles
void onGameState(sf::Event& event);
// Handle events for winning state after the image gets assembled
void onWinState(sf::Event& event);
2020-12-13 19:45:52 +01:00
private:
2020-12-14 20:22:52 +01:00
// Convert keyboard keys into moving direction
2020-12-13 19:45:52 +01:00
DIRECTION getDirection(sf::Keyboard::Key &key) const;
Board board;
sf::RenderWindow render_window;
};