Cleaned up code for readability

This commit is contained in:
2023-03-12 08:50:50 -05:00
parent 153b4e1367
commit de189301d4
8 changed files with 133 additions and 78 deletions
+15 -5
View File
@@ -1,22 +1,32 @@
// GameState.h
#ifndef GAMESTATE_H
#define GAMESTATE_H
#include <SFML\Graphics.hpp>
#include "Snake.h"
class GameState
{
private:
public:
sf::VideoMode gameVideoMode;
sf::RenderWindow gameWindow;
GameState();
GameState(int newHorizontal, int newVertical);
void startNewGame();
void StartGame(void);
sf::Vector2f GetGameBoundaries(void);
/*
gameGridHorizontal = (videoSizeHorizontal // 25) * 25;
gameGridVertical = (videoSizeVertical // 25) * 25;
*/
// sf::Vector2f GetGameBoundaries();
protected:
;
private:
sf::RenderWindow gameWindow;
sf::VideoMode gameVideoSettings;
SnakeFood playerFood;
Snake player;
sf::Time delay;
void RegenerateFood(void);
void RunGameLoop(void);
void RenderWindow(void);
};
#endif
+6 -4
View File
@@ -11,9 +11,6 @@ bool GlobalCollision(sf::Vector2f object1Position, sf::Vector2f object2Position)
class Snake
{
private:
std::deque<sf::RectangleShape> snakeBody;
int snakeDirection = 0;
public:
Snake();
Snake(sf::Vector2f head);
@@ -21,10 +18,15 @@ public:
sf::RectangleShape GetSnakeHead();
void DisplaySnake(sf::RenderWindow& window);
void MoveSnake(SnakeFood& playerFood, sf::VideoMode gameVideoMode);
void SnakeFoodCollision(SnakeFood& snakeFood, sf::VideoMode gameVideoMode);
void CheckDirection();
bool CheckBoundaries();
bool IsSelfCollision(sf::RectangleShape testRectangle);
bool IsTouchingObject(sf::RectangleShape object);
protected:
;
private:
std::deque<sf::RectangleShape> snakeBody;
int snakeDirection = 0;
};
+10 -4
View File
@@ -1,18 +1,24 @@
// SnakeFood.h
#ifndef SNAKEFOOD_H
#define SNAKEFOOD_H
#include <random>
#include <SFML\Graphics.hpp>
extern const int kGridSize;
class SnakeFood
{
private:
public:
sf::RectangleShape snakeFoodObject;
std::default_random_engine generator;
SnakeFood();
SnakeFood(sf::Vector2f snakeFoodSize);
void GenerateNewLocation(int horizontalLocation, int verticalLocation);
void GenerateNewFood(sf::Vector2f windowSize);
sf::RectangleShape GetFoodObject(void);
protected:
;
private:
sf::RectangleShape snakeFoodObject;
std::default_random_engine generator;
int GenerateRandomNumber(int generationLimit);
};