Fixed class organization
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
enum PlayerDirection
|
||||
{
|
||||
kLeft = 1,
|
||||
@@ -11,6 +9,4 @@ enum PlayerDirection
|
||||
kRight = 4
|
||||
};
|
||||
|
||||
bool GlobalCollision(sf::Vector2f object1Position, sf::Vector2f object2Position);
|
||||
|
||||
#endif
|
||||
|
||||
+15
-8
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
const int kGridSize = 25;
|
||||
|
||||
class DisplayInterface
|
||||
{
|
||||
public:
|
||||
@@ -10,10 +12,10 @@ public:
|
||||
DisplayInterface(void);
|
||||
bool IsOpen(void);
|
||||
protected:
|
||||
bool isGameStillRunning;
|
||||
virtual void DisplayGameState(void) = 0;
|
||||
bool isWindowAlive;
|
||||
virtual void DisplayGameState(std::vector< std::vector<char> >* gameBoard) = 0;
|
||||
virtual void DisplayEndScreen(void) = 0;
|
||||
virtual void StartGame(void) = 0;
|
||||
virtual void StartGameWindow(void) = 0;
|
||||
private:
|
||||
;
|
||||
};
|
||||
@@ -22,29 +24,34 @@ class CommandLine : public DisplayInterface
|
||||
{
|
||||
public:
|
||||
CommandLine(void);
|
||||
void DisplayGameState(void);
|
||||
void DisplayGameState(std::vector< std::vector<char> >* gameBoard);
|
||||
void DisplayEndScreen(void);
|
||||
void StartGame(void);
|
||||
void StartGameWindow(void);
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
const int kGridSize = 25;
|
||||
;
|
||||
};
|
||||
|
||||
class SFML : public DisplayInterface
|
||||
{
|
||||
public:
|
||||
SFML(void);
|
||||
void DisplayGameState(void);
|
||||
void DisplayGameState(std::vector< std::vector<char> >* gameBoard);
|
||||
void DisplayEndScreen(void);
|
||||
void StartGame(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::Time delay;
|
||||
sf::RenderWindow gameWindow;
|
||||
sf::VideoMode gameVideoSettings;
|
||||
sf::RectangleShape drawObject;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
class Game
|
||||
{
|
||||
public:
|
||||
;
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
;
|
||||
};
|
||||
|
||||
#endif
|
||||
+6
-3
@@ -5,22 +5,25 @@
|
||||
#include <memory>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "snake.h"
|
||||
#include "snakefood.h"
|
||||
#include "display.h"
|
||||
|
||||
class GameState
|
||||
{
|
||||
public:
|
||||
std::vector< std::vector<char> > gameBoard;
|
||||
bool useSFML = 1;
|
||||
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;
|
||||
SnakeFood playerFood;
|
||||
Snake player;
|
||||
SnakeFood playerFood;
|
||||
bool useSFML = 1;
|
||||
void ApplySettings(void);
|
||||
void DisplayEndScreen(void);
|
||||
void GetKeyboardInput(void);
|
||||
bool PlayerWantsToContinue(void);
|
||||
|
||||
+6
-15
@@ -2,33 +2,24 @@
|
||||
#ifndef SNAKE_H
|
||||
#define SNAKE_H
|
||||
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "snakefood.h"
|
||||
|
||||
|
||||
class Snake
|
||||
{
|
||||
public:
|
||||
bool gameFinished = false;
|
||||
Snake(void);
|
||||
void DisplaySnake(sf::RenderWindow& window);
|
||||
sf::RectangleShape GetSnakeHead(void);
|
||||
sf::Vector2f GetSnakeHeadPosition(void);
|
||||
bool IsTouchingObject(sf::RectangleShape object);
|
||||
void MoveSnake(SnakeFood* playerFood);
|
||||
sf::Vector2f MoveSnake(void);
|
||||
sf::Vector2f Pop(void);
|
||||
void UpdateDirection(int newDirection);
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
std::deque<sf::RectangleShape> snakeBody;
|
||||
sf::Vector2f bodyPartSize;
|
||||
std::queue<sf::Vector2f> snakeBody;
|
||||
int snakeDirection = 0;
|
||||
void AddBodyPart(sf::RectangleShape newBodyPart);
|
||||
sf::Vector2f CalculateNewPosition(sf::Vector2f position);
|
||||
bool CheckBoundaries(void);
|
||||
void CreateHead(void);
|
||||
bool IsSelfCollision(sf::RectangleShape testRectangle);
|
||||
sf::Vector2f CalculateNewHead();
|
||||
void CreateNewHead(sf::Vector2f);
|
||||
};
|
||||
|
||||
|
||||
|
||||
+2
-5
@@ -9,14 +9,11 @@ class SnakeFood
|
||||
{
|
||||
public:
|
||||
SnakeFood();
|
||||
SnakeFood(sf::Vector2f snakeFoodSize);
|
||||
void GenerateNewFood(sf::Vector2f windowSize);
|
||||
sf::RectangleShape GetFoodObject(void);
|
||||
sf::Vector2f GetFoodObjectPosition(void);
|
||||
sf::Vector2f GenerateNewFood(sf::Vector2f boundaries);
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
sf::RectangleShape snakeFoodObject;
|
||||
sf::Vector2f location;
|
||||
std::default_random_engine generator;
|
||||
int GenerateRandomNumber(int generationLimit);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user