2020-12-13 13:45:52 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <SFML/Window/Keyboard.hpp>
|
|
|
|
#include "board.h"
|
|
|
|
|
|
|
|
class Application
|
|
|
|
{
|
|
|
|
public:
|
2021-01-08 16:14:28 -05:00
|
|
|
|
|
|
|
enum class STATE
|
|
|
|
{
|
|
|
|
PLAY,
|
|
|
|
WIN
|
|
|
|
} current_state;
|
|
|
|
|
2020-12-20 08:49:24 -05:00
|
|
|
explicit Application(unsigned int window_width, unsigned int window_height);
|
2020-12-13 13:45:52 -05:00
|
|
|
|
2020-12-16 17:13:49 -05:00
|
|
|
// Init game
|
2020-12-18 15:12:28 -05:00
|
|
|
bool init(const std::string& path, int splitting);
|
2020-12-16 17:13:49 -05:00
|
|
|
|
2020-12-14 14:22:52 -05:00
|
|
|
// Launch game
|
2020-12-13 13:45:52 -05:00
|
|
|
void run();
|
2020-12-14 14:22:52 -05:00
|
|
|
|
|
|
|
// Refresh render_window to actual state
|
2020-12-13 13:45:52 -05:00
|
|
|
void draw();
|
2020-12-14 14:22:52 -05:00
|
|
|
|
|
|
|
// Handle keyboard commands
|
|
|
|
void processInput();
|
2020-12-13 13:45:52 -05:00
|
|
|
|
2021-01-08 16:14:28 -05: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 13:45:52 -05:00
|
|
|
private:
|
2020-12-14 14:22:52 -05:00
|
|
|
// Convert keyboard keys into moving direction
|
2020-12-13 13:45:52 -05:00
|
|
|
DIRECTION getDirection(sf::Keyboard::Key &key) const;
|
|
|
|
|
|
|
|
Board board;
|
|
|
|
sf::RenderWindow render_window;
|
|
|
|
};
|