refactor: remove all code from being in namespace
This commit is contained in:
parent
d5c797d460
commit
0ff3ef3f62
@ -7,8 +7,6 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
namespace snakeplusplus
|
|
||||||
{
|
|
||||||
PlayerDirection lastKnownDirection = kNone;
|
PlayerDirection lastKnownDirection = kNone;
|
||||||
|
|
||||||
AISnake::AISnake() {
|
AISnake::AISnake() {
|
||||||
@ -175,4 +173,3 @@ namespace snakeplusplus
|
|||||||
visited.at(currentLocation.y).at(currentLocation.x) = true;
|
visited.at(currentLocation.y).at(currentLocation.x) = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
namespace snakeplusplus
|
|
||||||
{
|
|
||||||
class AISnake {
|
class AISnake {
|
||||||
public:
|
public:
|
||||||
std::stack<sf::Vector2f> path;
|
std::stack<sf::Vector2f> path;
|
||||||
@ -22,6 +20,5 @@ namespace snakeplusplus
|
|||||||
void BFS(const std::vector< std::vector<char> >& gameBoard, const sf::Vector2f& source, const sf::Vector2f& boundaries);
|
void BFS(const std::vector< std::vector<char> >& gameBoard, const sf::Vector2f& source, const sf::Vector2f& boundaries);
|
||||||
void DFS(const std::vector< std::vector<char> >& gameBoard, const sf::Vector2f& source, const sf::Vector2f& boundaries);
|
void DFS(const std::vector< std::vector<char> >& gameBoard, const sf::Vector2f& source, const sf::Vector2f& boundaries);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
|
|
||||||
namespace snakeplusplus
|
|
||||||
{
|
|
||||||
std::default_random_engine generator;
|
std::default_random_engine generator;
|
||||||
void InitializeGenerator(void)
|
void InitializeGenerator(void)
|
||||||
{
|
{
|
||||||
@ -15,7 +13,6 @@ namespace snakeplusplus
|
|||||||
{
|
{
|
||||||
int generatedNumber;
|
int generatedNumber;
|
||||||
std::uniform_int_distribution<> distribution(0, generationLimit - 1);
|
std::uniform_int_distribution<> distribution(0, generationLimit - 1);
|
||||||
generatedNumber = distribution(snakeplusplus::generator);
|
generatedNumber = distribution(generator);
|
||||||
return generatedNumber;
|
return generatedNumber;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef COMMON_HPP
|
#ifndef COMMON_HPP
|
||||||
#define COMMON_HPP
|
#define COMMON_HPP
|
||||||
|
|
||||||
namespace snakeplusplus
|
|
||||||
{
|
|
||||||
void InitializeGenerator(void);
|
void InitializeGenerator(void);
|
||||||
int GenerateRandomNumber(int generationLimit);
|
int GenerateRandomNumber(int generationLimit);
|
||||||
|
|
||||||
@ -15,6 +13,4 @@ namespace snakeplusplus
|
|||||||
kRight = 4
|
kRight = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
#include "playerinterface.hpp"
|
#include "playerinterface.hpp"
|
||||||
#include "gamestate.hpp"
|
#include "gamestate.hpp"
|
||||||
|
|
||||||
namespace snakeplusplus
|
|
||||||
{
|
|
||||||
GameEngine::GameEngine()
|
GameEngine::GameEngine()
|
||||||
{
|
{
|
||||||
InitializeGenerator();
|
InitializeGenerator();
|
||||||
@ -163,9 +161,9 @@ namespace snakeplusplus
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEngine::UpdateAverage() {
|
void GameEngine::UpdateAverage() {
|
||||||
totalLength += player.body.size();
|
totalLength += player.body.size();
|
||||||
amountPlayed += 1;
|
amountPlayed += 1;
|
||||||
average = (double)totalLength / amountPlayed;
|
average = (double)totalLength / amountPlayed;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -3,12 +3,11 @@
|
|||||||
#define GAMESTATE_HPP
|
#define GAMESTATE_HPP
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
#include <memory>
|
||||||
#include "botinterface.hpp"
|
#include "botinterface.hpp"
|
||||||
#include "snake.hpp"
|
#include "snake.hpp"
|
||||||
#include "playerinterface.hpp"
|
#include "playerinterface.hpp"
|
||||||
|
|
||||||
namespace snakeplusplus
|
|
||||||
{
|
|
||||||
const int kUnitSpeed = 1;
|
const int kUnitSpeed = 1;
|
||||||
|
|
||||||
class GameEngine
|
class GameEngine
|
||||||
@ -39,6 +38,5 @@ namespace snakeplusplus
|
|||||||
int amountPlayed = 0;
|
int amountPlayed = 0;
|
||||||
double average = 0;
|
double average = 0;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
snakeplusplus::GameEngine game;
|
GameEngine game;
|
||||||
game.Start();
|
game.Start();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <SFML/Window/Keyboard.hpp>
|
#include <SFML/Window/Keyboard.hpp>
|
||||||
|
|
||||||
namespace snakeplusplus
|
|
||||||
{
|
|
||||||
PlayerDirection GetPlayerInput(void)
|
PlayerDirection GetPlayerInput(void)
|
||||||
{
|
{
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)
|
||||||
@ -171,4 +169,3 @@ namespace snakeplusplus
|
|||||||
gameWindow.draw(drawObject);
|
gameWindow.draw(drawObject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
const int kGridSize = 25;
|
const int kGridSize = 25;
|
||||||
|
|
||||||
namespace snakeplusplus
|
|
||||||
{
|
|
||||||
PlayerDirection GetPlayerInput(void);
|
PlayerDirection GetPlayerInput(void);
|
||||||
|
|
||||||
class PlayerOutput
|
class PlayerOutput
|
||||||
@ -34,6 +32,5 @@ namespace snakeplusplus
|
|||||||
bool isWindowAlive;
|
bool isWindowAlive;
|
||||||
sf::Time delay = sf::milliseconds(1);
|
sf::Time delay = sf::milliseconds(1);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "snake.hpp"
|
#include "snake.hpp"
|
||||||
|
|
||||||
namespace snakeplusplus
|
|
||||||
{
|
|
||||||
void Snake::Pop(void)
|
void Snake::Pop(void)
|
||||||
{
|
{
|
||||||
*(body.front()) = ' ';
|
*(body.front()) = ' ';
|
||||||
@ -28,4 +26,3 @@ namespace snakeplusplus
|
|||||||
location.y = GenerateRandomNumber(boundaries.y);
|
location.y = GenerateRandomNumber(boundaries.y);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
namespace snakeplusplus
|
|
||||||
{
|
|
||||||
struct Snake
|
struct Snake
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -24,6 +22,5 @@ namespace snakeplusplus
|
|||||||
char* food;
|
char* food;
|
||||||
void GenerateNewFood(sf::Vector2f boundaries);
|
void GenerateNewFood(sf::Vector2f boundaries);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user