#include "Game.h" #include #include using namespace std; SnakeGame::SnakeGame() :gameName{"~Snake Game by VissaM~"},highScore{0}, bestPlayer{"None"} {} SnakeGame::~SnakeGame(){} void SnakeGame::addPlayer(string playerName){ players.emplace_back( Player{playerName} ); } unsigned int SnakeGame::getHighScore(void){ return highScore; } string SnakeGame::getBestPlayer(void){ return bestPlayer; } void SnakeGame::play(string playerName){ pair curBest{playerName, 0}; for(auto player : players){ if(player.getName() == playerName){ initializeGraphics((char *)gameName.c_str()); curBest = player.play(); endGraphics(); break; } } if(curBest.second > highScore){ highScore = curBest.second; bestPlayer = curBest.first; } cout << "Highscore: " << highScore << " by " << bestPlayer << "\n" <> playerName; cout << endl; list::iterator p; for(p=players.begin(); p!=players.end(); p++){ if(p->getName() == playerName) break; } if(p == players.end()){ //if the player isn't in the list, add him/her addPlayer(playerName); } play(playerName); //get the player to play the game cin.clear(); cin.ignore(numeric_limits::max(), '\n'); cout << "Do you want to play again? (yes or no): "; string ans; cin >> ans; if(ans != "yes"){ cout << "Exiting ..." << endl; break; } cout << "Perfect...\n" << endl; } }