diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 35659a8..b246f6e 100755 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -23,17 +23,19 @@ void GameEngine::Start() void GameEngine::Reset() { - graphics.CheckContinue(state.m_bIsBotControlled); - bot.AddIteration(player.body.size()); + if (!state.m_bIsBotControlled) + graphics.CheckContinue(); player.Reset(); - if (state.m_bIsBotControlled) { while (!bot.path.empty()) { bot.path.pop(); } } PrepareGameBoard(); state.m_bIsGameOver = false; - if (state.m_bNoDisplay) - graphics.SetShowGame(false); - else + if (state.m_bIsBotControlled) { + while (!bot.path.empty()) + bot.path.pop(); + if (state.m_bNoDisplay) + graphics.SetShowGame(false); graphics.SetShowGame((bot.amountPlayed + 1) % 50 == 0); - return; + bot.AddIteration(player.body.size()); + } } void GameEngine::Loop(void) diff --git a/src/gamestate.hpp b/src/gamestate.hpp index e284b5d..8998dad 100755 --- a/src/gamestate.hpp +++ b/src/gamestate.hpp @@ -19,7 +19,7 @@ public: sf::Vector2f GetGameBoundaries(void); struct GameState { 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 _3 : 1 = 0; unsigned char _4 : 1 = 0; diff --git a/src/main.cpp b/src/main.cpp index 4b8b439..3e85364 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,10 @@ int main(int argc, char* argv[]) if (it->compare("--no-gui") == 0) { g_pEngine->state.m_bNoDisplay = true; 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 { std::cerr << "[ERROR] Argument option not found, exiting..." << std::endl; return 1; diff --git a/src/playerinterface.cpp b/src/playerinterface.cpp index d7d1723..6d6311a 100755 --- a/src/playerinterface.cpp +++ b/src/playerinterface.cpp @@ -37,9 +37,8 @@ PlayerOutput::PlayerOutput(void) return; } -void PlayerOutput::CheckContinue(bool isBotControlled) +void PlayerOutput::CheckContinue() { - if (isBotControlled) { return; } DisplayEndScreen(); while (true) { @@ -115,7 +114,7 @@ void PlayerOutput::StartGameWindow(void) } void PlayerOutput::SetShowGame(bool isShowing) { - if (isShowing) { delay = sf::milliseconds(2); } + if (isShowing) { delay = sf::milliseconds(5); } else { delay = sf::milliseconds(0); } return; } @@ -125,8 +124,10 @@ void PlayerOutput::CheckWindowEvents(void) while (gameWindow.pollEvent(event)) { if ((event.type == sf::Event::Closed) - || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))) + || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))) { gameWindow.close(); + isWindowAlive = false; + } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Equal)) { if (delay > sf::milliseconds(16)) { continue; } delay += sf::milliseconds(1); diff --git a/src/playerinterface.hpp b/src/playerinterface.hpp index fea4a70..55084e3 100755 --- a/src/playerinterface.hpp +++ b/src/playerinterface.hpp @@ -14,7 +14,7 @@ public: sf::Vector2f gameBoundaries; PlayerOutput(void); bool IsOpen(void); - void CheckContinue(bool isBotControlled); + void CheckContinue(); void DisplayGameState(std::vector< std::vector >& gameBoard, int score); void DisplayScore(int score); void StartGameWindow(void); @@ -30,7 +30,7 @@ private: sf::RectangleShape drawObject; sf::Event event; bool isWindowAlive = false; - sf::Time delay = sf::milliseconds(1); + sf::Time delay = sf::milliseconds(12); }; #endif