Doing too much at once. Need to fix branch

This commit is contained in:
2023-04-06 19:27:10 -05:00
parent 67e56bcb3c
commit c01f687ec7
15 changed files with 597 additions and 529 deletions
+3 -2
View File
@@ -1,8 +1,9 @@
#ifndef COMMON_H
#define COMMON_H
#ifndef COMMON_HPP
#define COMMON_HPP
enum PlayerDirection
{
kNone = 0,
kLeft = 1,
kUp = 2,
kDown = 3,
-60
View File
@@ -1,60 +0,0 @@
#ifndef DISPLAY_H
#define DISPLAY_H
#include <SFML/Graphics.hpp>
const int kGridSize = 25;
class DisplayInterface
{
public:
sf::Vector2f gameBoundaries;
DisplayInterface(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(75);
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 DrawEmpty(sf::Vector2f location);
void DrawFood(sf::Vector2f location);
void DrawSnake(sf::Vector2f location);
sf::RenderWindow gameWindow;
sf::VideoMode gameVideoSettings;
sf::RectangleShape drawObject;
};
#endif
-37
View File
@@ -1,37 +0,0 @@
// GameState.h
#ifndef GAMESTATE_H
#define GAMESTATE_H
#include <memory>
#include <SFML/Graphics.hpp>
#include "snake.h"
#include "snakefood.h"
#include "display.h"
class GameState
{
public:
GameState();
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;
Snake player;
SnakeFood playerFood;
bool useSFML = 1;
bool isGameOver = 0;
void ApplySettings(void);
void DisplayEndScreen(void);
void GetKeyboardInput(void);
void PlaceNewSnakePart(sf::Vector2f location);
void PlayerWantsToContinue(void);
void RegenerateFood(void);
void ResetGameBoard(void);
void RunGameLoop(void);
};
#endif
+40
View File
@@ -0,0 +1,40 @@
// GameState.h
#ifndef GAMESTATE_HPP
#define GAMESTATE_HPP
#include <memory>
#include <SFML/Graphics.hpp>
#include "snake.hpp"
#include "playerinterface.hpp"
namespace snakeplusplus
{
class GameEngine
{
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;
Snake player;
Food playerFood;
Input playerInput;
bool useSFML = 1;
bool isGameOver = 0;
void ApplySettings(void);
void DisplayEndScreen(void);
void GameLoop(void);
void PlaceNewSnakePart(sf::Vector2f location);
void PlayerWantsToContinue(void);
void RegenerateFood(void);
void ResetGameBoard(void);
void RestartGame(void);
};
}
#endif
+75
View File
@@ -0,0 +1,75 @@
#ifndef PLAYERINTERFACE_HPP
#define PLAYERINTERFACE_HPP
#include "common.hpp"
#include <SFML/Graphics.hpp>
const int kGridSize = 25;
namespace snakeplusplus
{
class Input
{
public:
Input(void);
PlayerDirection GetPlayerInput(void);
protected:
;
private:
PlayerDirection lastPlayerInput;
};
class DisplayInterface
{
public:
sf::Vector2f gameBoundaries;
DisplayInterface(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 DrawEmpty(sf::Vector2f location);
void DrawFood(sf::Vector2f location);
void DrawSnake(sf::Vector2f location);
sf::RenderWindow gameWindow;
sf::VideoMode gameVideoSettings;
sf::RectangleShape drawObject;
};
}
#endif
-26
View File
@@ -1,26 +0,0 @@
// Snake.h
#ifndef SNAKE_H
#define SNAKE_H
#include <queue>
#include <SFML/Graphics.hpp>
class Snake
{
public:
Snake(void);
sf::Vector2f MoveSnake(void);
sf::Vector2f Pop(void);
void UpdateDirection(int newDirection);
protected:
;
private:
std::queue<sf::Vector2f> snakeBody;
int snakeDirection = 0;
sf::Vector2f CalculateNewHead();
void CreateNewHead(sf::Vector2f);
};
#endif
+51
View File
@@ -0,0 +1,51 @@
// Snake.h
#ifndef SNAKE_HPP
#define SNAKE_HPP
#include <memory>
#include <queue>
#include <random>
#include <SFML/Graphics.hpp>
#include "common.hpp"
namespace snakeplusplus
{
class Snake
{
public:
Snake(void);
PlayerDirection GetDirection(void);
sf::Vector2f GetHeadLocation(void);
sf::Vector2f Move(void);
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
{
public:
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);
};
}
#endif
-22
View File
@@ -1,22 +0,0 @@
// SnakeFood.h
#ifndef SNAKEFOOD_H
#define SNAKEFOOD_H
#include <SFML/Graphics.hpp>
#include <random>
class SnakeFood
{
public:
SnakeFood();
void GenerateNewFood(sf::Vector2f boundaries);
sf::Vector2f GetFoodLocation(void);
protected:
;
private:
sf::Vector2f location;
std::default_random_engine generator;
int GenerateRandomNumber(int generationLimit);
};
#endif