Turned Makefile into CMake

This commit is contained in:
2023-08-10 18:34:43 -05:00
parent fb672c7ddb
commit a8cc2d1174
7 changed files with 28 additions and 22 deletions
+13
View File
@@ -0,0 +1,13 @@
find_package(SFML COMPONENTS graphics window system REQUIRED)
add_executable(snakeplusplus
./main.cpp
./gamestate.cpp
./snake.cpp
./playerinterface.cpp
)
target_include_directories(snakeplusplus PUBLIC ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(snakeplusplus sfml-graphics)
Executable
+13
View File
@@ -0,0 +1,13 @@
#ifndef COMMON_HPP
#define COMMON_HPP
enum PlayerDirection
{
kNone = 0,
kLeft = 1,
kUp = 2,
kDown = 3,
kRight = 4
};
#endif
+36
View File
@@ -0,0 +1,36 @@
// 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 StartGame(void);
sf::Vector2f GetGameBoundaries(void);
private:
std::vector< std::vector<char> > gameBoard;
PlayerInput controls;
PlayerOutput graphics;
Snake player;
Food playerFood;
bool useSFML = 1;
bool isGameOver = 0;
void DisplayEndScreen(void);
void GameLoop(void);
sf::Vector2f MovePlayer(void);
void PlaceNewSnakePart(sf::Vector2f location);
void RegenerateFood(void);
void PrepareGameBoard(void);
void UpdatePlayerSpeed();
};
}
#endif
+43
View File
@@ -0,0 +1,43 @@
#ifndef PLAYERINTERFACE_HPP
#define PLAYERINTERFACE_HPP
#include "common.hpp"
#include <SFML/Graphics.hpp>
const int kGridSize = 25;
namespace snakeplusplus
{
class PlayerInput
{
public:
PlayerInput(void);
PlayerDirection GetPlayerInput(void);
private:
PlayerDirection lastPlayerInput;
};
class PlayerOutput
{
public:
sf::Vector2f gameBoundaries;
PlayerOutput(void);
bool IsOpen(void);
void CheckContinue(void);
void DisplayGameState(std::vector< std::vector<char> >& gameBoard);
void StartGameWindow(void);
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(60);
};
}
#endif
Executable
+35
View File
@@ -0,0 +1,35 @@
// Snake.h
#ifndef SNAKE_HPP
#define SNAKE_HPP
#include <SFML/System/Vector2.hpp>
#include <memory>
#include <queue>
#include <random>
#include <SFML/Graphics.hpp>
namespace snakeplusplus
{
struct Snake
{
public:
sf::Vector2f headLocation;
sf::Vector2f speed;
std::queue<char*> body;
void Pop(void);
};
struct Food
{
public:
Food(void);
sf::Vector2f location;
char* food;
void GenerateNewFood(sf::Vector2f boundaries);
private:
std::default_random_engine generator;
int GenerateRandomNumber(int generationLimit);
};
}
#endif