refactor: merge final cleanups before working on AI #6

Merged
Trianta merged 12 commits from refactor into master 2024-08-10 15:05:56 -05:00
5 changed files with 21 additions and 14 deletions
Showing only changes of commit 6e7ae19e8b - Show all commits

View File

@ -23,17 +23,19 @@ void GameEngine::Start()
void GameEngine::Reset() void GameEngine::Reset()
{ {
graphics.CheckContinue(state.m_bIsBotControlled); if (!state.m_bIsBotControlled)
bot.AddIteration(player.body.size()); graphics.CheckContinue();
player.Reset(); player.Reset();
if (state.m_bIsBotControlled) { while (!bot.path.empty()) { bot.path.pop(); } }
PrepareGameBoard(); PrepareGameBoard();
state.m_bIsGameOver = false; state.m_bIsGameOver = false;
if (state.m_bNoDisplay) if (state.m_bIsBotControlled) {
graphics.SetShowGame(false); while (!bot.path.empty())
else bot.path.pop();
if (state.m_bNoDisplay)
graphics.SetShowGame(false);
graphics.SetShowGame((bot.amountPlayed + 1) % 50 == 0); graphics.SetShowGame((bot.amountPlayed + 1) % 50 == 0);
return; bot.AddIteration(player.body.size());
}
} }
void GameEngine::Loop(void) void GameEngine::Loop(void)

View File

@ -19,7 +19,7 @@ public:
sf::Vector2f GetGameBoundaries(void); sf::Vector2f GetGameBoundaries(void);
struct GameState { struct GameState {
unsigned char m_bIsGameOver : 1 = 0; unsigned char m_bIsGameOver : 1 = 0;
unsigned char m_bIsBotControlled : 1 = 1; unsigned char m_bIsBotControlled : 1 = 0;
unsigned char m_bNoDisplay : 1 = 0; unsigned char m_bNoDisplay : 1 = 0;
unsigned char _3 : 1 = 0; unsigned char _3 : 1 = 0;
unsigned char _4 : 1 = 0; unsigned char _4 : 1 = 0;

View File

@ -11,6 +11,10 @@ int main(int argc, char* argv[])
if (it->compare("--no-gui") == 0) { if (it->compare("--no-gui") == 0) {
g_pEngine->state.m_bNoDisplay = true; g_pEngine->state.m_bNoDisplay = true;
std::cout << "[LOG - Main] Disabling display" << std::endl; std::cout << "[LOG - Main] Disabling display" << std::endl;
} else if (it->compare("--bot") == 0) {
g_pEngine->state.m_bIsBotControlled = true;
std::cout << "[LOG - Main] Bot control enabled" << std::endl;
} else { } else {
std::cerr << "[ERROR] Argument option not found, exiting..." << std::endl; std::cerr << "[ERROR] Argument option not found, exiting..." << std::endl;
return 1; return 1;

View File

@ -37,9 +37,8 @@ PlayerOutput::PlayerOutput(void)
return; return;
} }
void PlayerOutput::CheckContinue(bool isBotControlled) void PlayerOutput::CheckContinue()
{ {
if (isBotControlled) { return; }
DisplayEndScreen(); DisplayEndScreen();
while (true) while (true)
{ {
@ -115,7 +114,7 @@ void PlayerOutput::StartGameWindow(void)
} }
void PlayerOutput::SetShowGame(bool isShowing) { void PlayerOutput::SetShowGame(bool isShowing) {
if (isShowing) { delay = sf::milliseconds(2); } if (isShowing) { delay = sf::milliseconds(5); }
else { delay = sf::milliseconds(0); } else { delay = sf::milliseconds(0); }
return; return;
} }
@ -125,8 +124,10 @@ void PlayerOutput::CheckWindowEvents(void)
while (gameWindow.pollEvent(event)) while (gameWindow.pollEvent(event))
{ {
if ((event.type == sf::Event::Closed) if ((event.type == sf::Event::Closed)
|| (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))) {
gameWindow.close(); gameWindow.close();
isWindowAlive = false;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Equal)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Equal)) {
if (delay > sf::milliseconds(16)) { continue; } if (delay > sf::milliseconds(16)) { continue; }
delay += sf::milliseconds(1); delay += sf::milliseconds(1);

View File

@ -14,7 +14,7 @@ public:
sf::Vector2f gameBoundaries; sf::Vector2f gameBoundaries;
PlayerOutput(void); PlayerOutput(void);
bool IsOpen(void); bool IsOpen(void);
void CheckContinue(bool isBotControlled); void CheckContinue();
void DisplayGameState(std::vector< std::vector<GameSpace> >& gameBoard, int score); void DisplayGameState(std::vector< std::vector<GameSpace> >& gameBoard, int score);
void DisplayScore(int score); void DisplayScore(int score);
void StartGameWindow(void); void StartGameWindow(void);
@ -30,7 +30,7 @@ private:
sf::RectangleShape drawObject; sf::RectangleShape drawObject;
sf::Event event; sf::Event event;
bool isWindowAlive = false; bool isWindowAlive = false;
sf::Time delay = sf::milliseconds(1); sf::Time delay = sf::milliseconds(12);
}; };
#endif #endif