diff --git a/Makefile b/Makefile index 16244f8..ca5a19b 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,12 @@ fresh: dirs compile link compile: g++ $(INC) $(STD) -c -o build/main.o src/main.cpp - g++ $(INC) $(STD) -c -o build/Common.o src/Common.cpp - g++ $(INC) $(STD) -c -o build/GameState.o src/GameState.cpp - g++ $(INC) $(STD) -c -o build/Snake.o src/Snake.cpp - g++ $(INC) $(STD) -c -o build/SnakeFood.o src/SnakeFood.cpp + g++ $(INC) $(STD) -c -o build/common.o src/common.cpp + g++ $(INC) $(STD) -c -o build/display.o src/display.cpp + g++ $(INC) $(STD) -c -o build/game.o src/game.cpp + g++ $(INC) $(STD) -c -o build/gamestate.o src/gamestate.cpp + g++ $(INC) $(STD) -c -o build/snake.o src/snake.cpp + g++ $(INC) $(STD) -c -o build/snakefood.o src/snakefood.cpp dirs: mkdir bin build diff --git a/include/Common.h b/include/common.h similarity index 100% rename from include/Common.h rename to include/common.h diff --git a/include/display.h b/include/display.h new file mode 100644 index 0000000..ff43170 --- /dev/null +++ b/include/display.h @@ -0,0 +1,36 @@ +#ifndef DISPLAY_H +#define DISPLAY_H + +class DisplayInterface +{ +public: + DisplayInterface(void); +protected: + virtual void DisplayGameState(void) = 0; +private: + ; +}; + +class CommandLine : public DisplayInterface +{ +public: + CommandLine(void) = default; + void DisplayGameState(void); +protected: + ; +private: + ; +}; + +class GameWindow : public DisplayInterface +{ +public: + GameWindow(void) = default; + void DisplayGameState(void); +protected: + ; +private: + ; +}; + +#endif \ No newline at end of file diff --git a/include/game.h b/include/game.h new file mode 100644 index 0000000..e69de29 diff --git a/include/GameState.h b/include/gamestate.h similarity index 77% rename from include/GameState.h rename to include/gamestate.h index d6eb2a7..bf072c8 100644 --- a/include/GameState.h +++ b/include/gamestate.h @@ -2,12 +2,16 @@ #ifndef GAMESTATE_H #define GAMESTATE_H +#include #include -#include "Snake.h" +#include "snake.h" +#include "display.h" class GameState { public: + std::vector< std::vector > gameBoard; + bool useSFML = 1; GameState(); GameState(int newHorizontal, int newVertical); void StartGame(void); @@ -15,6 +19,7 @@ public: protected: ; private: + std::unique_ptr graphics; sf::RenderWindow gameWindow; sf::VideoMode gameVideoSettings; SnakeFood playerFood; diff --git a/include/Snake.h b/include/snake.h similarity index 94% rename from include/Snake.h rename to include/snake.h index b2c81bb..e510292 100644 --- a/include/Snake.h +++ b/include/snake.h @@ -4,7 +4,7 @@ #include #include -#include "SnakeFood.h" +#include "snakefood.h" class Snake @@ -17,7 +17,6 @@ public: sf::Vector2f GetSnakeHeadPosition(void); bool IsTouchingObject(sf::RectangleShape object); void MoveSnake(SnakeFood* playerFood); - void Reset(void); void UpdateDirection(int newDirection); protected: ; diff --git a/include/SnakeFood.h b/include/snakefood.h similarity index 100% rename from include/SnakeFood.h rename to include/snakefood.h diff --git a/src/Common.cpp b/src/common.cpp similarity index 93% rename from src/Common.cpp rename to src/common.cpp index e8887a6..e66adcf 100644 --- a/src/Common.cpp +++ b/src/common.cpp @@ -1,4 +1,4 @@ -#include "Common.h" +#include "common.h" // Test for collision between two object positions bool GlobalCollision(sf::Vector2f object1Position, sf::Vector2f object2Position) diff --git a/src/display.cpp b/src/display.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/game.cpp b/src/game.cpp new file mode 100644 index 0000000..b529604 --- /dev/null +++ b/src/game.cpp @@ -0,0 +1 @@ +#include "game.cpp" \ No newline at end of file diff --git a/src/GameState.cpp b/src/gamestate.cpp similarity index 93% rename from src/GameState.cpp rename to src/gamestate.cpp index 9a4350b..a9f1893 100644 --- a/src/GameState.cpp +++ b/src/gamestate.cpp @@ -1,15 +1,19 @@ // GameState.cpp #include #include -#include "Common.h" -#include "Snake.h" -#include "GameState.h" +#include "common.h" +#include "gamestate.h" GameState::GameState() { delay = sf::milliseconds(75); gameVideoSettings = sf::VideoMode(1025, 725); gameWindow.create(gameVideoSettings, "SnakePlusPlus"); + if (useSFML) + graphics.reset(new GameWindow()); + else + graphics.reset(new CommandLine()); + return; } @@ -42,7 +46,8 @@ void GameState::DisplayEndScreen(void) gameWindow.display(); if (!PlayerWantsToContinue()) return; - player.Reset(); + player = Snake(); + playerFood.GenerateNewFood(GetGameBoundaries()); gameWindow.clear(); return; } diff --git a/src/Snake.cpp b/src/snake.cpp similarity index 95% rename from src/Snake.cpp rename to src/snake.cpp index 3420fcc..4466d88 100644 --- a/src/Snake.cpp +++ b/src/snake.cpp @@ -2,9 +2,9 @@ #include #include #include -#include "Common.h" -#include "Snake.h" -#include "SnakeFood.h" +#include "common.h" +#include "snake.h" +#include "snakeFood.h" // General constructor for snake class Snake::Snake(void) @@ -79,14 +79,6 @@ void Snake::MoveSnake(SnakeFood* snakeFood) return; } -void Snake::Reset(void) -{ - snakeBody.clear(); - gameFinished = false; - CreateHead(); - snakeDirection = kRight; -} - void Snake::UpdateDirection(int newDirection) { snakeDirection = newDirection; diff --git a/src/SnakeFood.cpp b/src/snakefood.cpp similarity index 96% rename from src/SnakeFood.cpp rename to src/snakefood.cpp index b1989e4..1f71fb4 100644 --- a/src/SnakeFood.cpp +++ b/src/snakefood.cpp @@ -1,8 +1,8 @@ // SnakeFood.cpp #include #include -#include "Common.h" -#include "SnakeFood.h" +#include "common.h" +#include "snakeFood.h" SnakeFood::SnakeFood()