2023-04-06 19:27:10 -05:00
|
|
|
// GameState.h
|
|
|
|
#ifndef GAMESTATE_HPP
|
|
|
|
#define GAMESTATE_HPP
|
|
|
|
|
|
|
|
#include <SFML/Graphics.hpp>
|
2024-08-02 19:45:07 -05:00
|
|
|
#include <memory>
|
2023-10-13 19:07:08 -05:00
|
|
|
#include "botinterface.hpp"
|
2024-08-14 03:35:04 -05:00
|
|
|
#include "common.hpp"
|
2023-04-06 19:27:10 -05:00
|
|
|
#include "snake.hpp"
|
|
|
|
#include "playerinterface.hpp"
|
|
|
|
|
2024-08-02 19:45:07 -05:00
|
|
|
const int kUnitSpeed = 1;
|
2023-08-19 23:32:53 -05:00
|
|
|
|
2024-08-21 02:59:30 -05:00
|
|
|
class GameEngine {
|
2024-08-02 19:45:07 -05:00
|
|
|
public:
|
2024-08-21 02:59:30 -05:00
|
|
|
GameEngine(void);
|
2024-08-02 19:45:07 -05:00
|
|
|
void Start(void);
|
|
|
|
void Reset(void);
|
|
|
|
sf::Vector2f GetGameBoundaries(void);
|
2024-08-02 21:23:49 -05:00
|
|
|
struct GameState {
|
|
|
|
unsigned char m_bIsGameOver : 1 = 0;
|
2024-08-03 18:34:14 -05:00
|
|
|
unsigned char m_bIsBotControlled : 1 = 0;
|
2024-08-02 21:23:49 -05:00
|
|
|
unsigned char m_bNoDisplay : 1 = 0;
|
2024-08-14 03:35:04 -05:00
|
|
|
unsigned char m_bSmart : 1 = 0;
|
|
|
|
unsigned char m_bSkipIterations : 1 = 0;
|
2024-08-02 21:23:49 -05:00
|
|
|
unsigned char _5 : 1 = 0;
|
|
|
|
unsigned char _6 : 1 = 0;
|
|
|
|
unsigned char _7 : 1 = 0;
|
|
|
|
} state;
|
|
|
|
std::vector< std::vector<GameSpace> > gameBoard;
|
2024-08-14 03:35:04 -05:00
|
|
|
PlayerDirection GetCurrentDirection(void);
|
2024-08-21 04:32:30 -05:00
|
|
|
sf::Vector2f GetCurrentDirectionRaw(void);
|
2024-08-14 03:35:04 -05:00
|
|
|
int GetPlayerSize(void);
|
|
|
|
sf::Vector2f GetHeadLocation(void);
|
|
|
|
sf::Vector2f GetFoodLocation(void);
|
2024-08-03 01:26:10 -05:00
|
|
|
private:
|
2024-08-02 19:45:07 -05:00
|
|
|
PlayerOutput graphics;
|
|
|
|
Snake player;
|
|
|
|
Food playerFood;
|
|
|
|
AISnake bot;
|
|
|
|
void Loop(void);
|
|
|
|
sf::Vector2f MovePlayer(void);
|
|
|
|
void PlaceNewSnakePart(sf::Vector2f location);
|
|
|
|
void RegenerateFood(void);
|
|
|
|
void PrepareGameBoard(void);
|
2024-08-21 02:59:30 -05:00
|
|
|
void UpdatePlayerSpeed(void);
|
2024-08-02 19:45:07 -05:00
|
|
|
};
|
2023-04-06 19:27:10 -05:00
|
|
|
|
2024-08-02 19:50:48 -05:00
|
|
|
inline std::unique_ptr<GameEngine> g_pEngine;
|
|
|
|
|
2023-04-06 19:27:10 -05:00
|
|
|
#endif
|