This was overengineered, lots of trimming to do
This commit is contained in:
@@ -13,27 +13,25 @@ namespace snakeplusplus
|
||||
{
|
||||
public:
|
||||
GameEngine();
|
||||
void SetGameSettings(int argc, char* argv[]);
|
||||
void StartGame(void);
|
||||
sf::Vector2f GetGameBoundaries(void);
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
std::vector< std::vector<char> > gameBoard;
|
||||
std::unique_ptr<DisplayInterface> graphics;
|
||||
PlayerInput controls;
|
||||
PlayerOutput graphics;
|
||||
Snake player;
|
||||
Food playerFood;
|
||||
Input playerInput;
|
||||
bool useSFML = 1;
|
||||
bool isGameOver = 0;
|
||||
void ApplySettings(void);
|
||||
void DisplayEndScreen(void);
|
||||
void GameLoop(void);
|
||||
sf::Vector2f MovePlayer(void);
|
||||
void PlaceNewSnakePart(sf::Vector2f location);
|
||||
void PlayerWantsToContinue(void);
|
||||
void RegenerateFood(void);
|
||||
void ResetGameBoard(void);
|
||||
void RestartGame(void);
|
||||
void PrepareGameBoard(void);
|
||||
void UpdatePlayerSpeed();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ const int kGridSize = 25;
|
||||
|
||||
namespace snakeplusplus
|
||||
{
|
||||
class Input
|
||||
class PlayerInput
|
||||
{
|
||||
public:
|
||||
Input(void);
|
||||
PlayerInput(void);
|
||||
PlayerDirection GetPlayerInput(void);
|
||||
protected:
|
||||
;
|
||||
@@ -19,56 +19,28 @@ namespace snakeplusplus
|
||||
PlayerDirection lastPlayerInput;
|
||||
};
|
||||
|
||||
class DisplayInterface
|
||||
class PlayerOutput
|
||||
{
|
||||
public:
|
||||
sf::Vector2f gameBoundaries;
|
||||
DisplayInterface(void);
|
||||
PlayerOutput(void);
|
||||
bool IsOpen(void);
|
||||
virtual void CheckContinue(void) = 0;
|
||||
virtual void DisplayGameState(std::vector< std::vector<char> >* gameBoard) = 0;
|
||||
virtual void DisplayEndScreen(void) = 0;
|
||||
virtual void StartGameWindow(void) = 0;
|
||||
protected:
|
||||
bool isWindowAlive;
|
||||
sf::Time delay = sf::milliseconds(120);
|
||||
private:
|
||||
;
|
||||
};
|
||||
|
||||
class CommandLine : public DisplayInterface
|
||||
{
|
||||
public:
|
||||
CommandLine(void);
|
||||
void CheckContinue(void);
|
||||
void DisplayGameState(std::vector< std::vector<char> >* gameBoard);
|
||||
void DisplayEndScreen(void);
|
||||
void StartGameWindow(void);
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
void Clear(void);
|
||||
};
|
||||
|
||||
class SFML : public DisplayInterface
|
||||
{
|
||||
public:
|
||||
SFML(void);
|
||||
void CheckContinue(void);
|
||||
void DisplayGameState(std::vector< std::vector<char> >* gameBoard);
|
||||
void DisplayEndScreen(void);
|
||||
void StartGameWindow(void);
|
||||
void UpdateResolution(sf::Vector2i newResolution);
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
void CheckWindowEvents(void);
|
||||
void DisplayEndScreen(void);
|
||||
void DrawEmpty(sf::Vector2f location);
|
||||
void DrawFood(sf::Vector2f location);
|
||||
void DrawSnake(sf::Vector2f location);
|
||||
sf::RenderWindow gameWindow;
|
||||
sf::VideoMode gameVideoSettings;
|
||||
sf::RectangleShape drawObject;
|
||||
bool isWindowAlive;
|
||||
sf::Time delay = sf::milliseconds(120);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+10
-19
@@ -2,47 +2,38 @@
|
||||
#ifndef SNAKE_HPP
|
||||
#define SNAKE_HPP
|
||||
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <random>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "common.hpp"
|
||||
|
||||
namespace snakeplusplus
|
||||
{
|
||||
class Snake
|
||||
struct Snake
|
||||
{
|
||||
public:
|
||||
Snake(void);
|
||||
PlayerDirection GetDirection(void);
|
||||
sf::Vector2f GetHeadLocation(void);
|
||||
sf::Vector2f Move(void);
|
||||
sf::Vector2f headLocation;
|
||||
sf::Vector2f speed;
|
||||
std::queue< std::shared_ptr<char> > body;
|
||||
void Pop(void);
|
||||
sf::Vector2f Reset(void);
|
||||
void UpdateDirection(PlayerDirection newDirection);
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
std::queue< std::shared_ptr<char> > snakeBody;
|
||||
PlayerDirection direction = kNone;
|
||||
sf::Vector2f headLocation;
|
||||
void MoveLeft(void);
|
||||
void MoveUp(void);
|
||||
void MoveDown(void);
|
||||
void MoveRight(void);
|
||||
;
|
||||
};
|
||||
|
||||
class Food
|
||||
struct Food
|
||||
{
|
||||
public:
|
||||
Food();
|
||||
Food(void);
|
||||
sf::Vector2f location;
|
||||
std::shared_ptr<char> food;
|
||||
void GenerateNewFood(sf::Vector2f boundaries);
|
||||
sf::Vector2f GetFoodLocation(void);
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
std::shared_ptr<char> food;
|
||||
sf::Vector2f location;
|
||||
std::default_random_engine generator;
|
||||
int GenerateRandomNumber(int generationLimit);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user