Cleaned up naming of files; setup more structure

This commit is contained in:
TriantaTV 2023-03-13 21:10:52 -05:00
parent 3ee01d936b
commit a76d9ccfb5
13 changed files with 65 additions and 25 deletions

View File

@ -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

36
include/display.h Normal file
View File

@ -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

0
include/game.h Normal file
View File

View File

@ -2,12 +2,16 @@
#ifndef GAMESTATE_H
#define GAMESTATE_H
#include <memory>
#include <SFML\Graphics.hpp>
#include "Snake.h"
#include "snake.h"
#include "display.h"
class GameState
{
public:
std::vector< std::vector<char> > gameBoard;
bool useSFML = 1;
GameState();
GameState(int newHorizontal, int newVertical);
void StartGame(void);
@ -15,6 +19,7 @@ public:
protected:
;
private:
std::unique_ptr<DisplayInterface> graphics;
sf::RenderWindow gameWindow;
sf::VideoMode gameVideoSettings;
SnakeFood playerFood;

View File

@ -4,7 +4,7 @@
#include <deque>
#include <SFML\Graphics.hpp>
#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:
;

View File

@ -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)

0
src/display.cpp Normal file
View File

1
src/game.cpp Normal file
View File

@ -0,0 +1 @@
#include "game.cpp"

View File

@ -1,15 +1,19 @@
// GameState.cpp
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#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;
}

View File

@ -2,9 +2,9 @@
#include <iostream>
#include <queue>
#include <SFML\Graphics.hpp>
#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;

View File

@ -1,8 +1,8 @@
// SnakeFood.cpp
#include <iostream>
#include <SFML\Graphics.hpp>
#include "Common.h"
#include "SnakeFood.h"
#include "common.h"
#include "snakeFood.h"
SnakeFood::SnakeFood()