void gameLoop() { while (game_state != GAME_DONE && quit != TRUE && player.is_dead == FALSE) { getPlayerInput(); if (quit == FALSE) { updatePlayer(); drawPlayArea(); drawStatsArea(); } } }
/* Contains Main game loop Parameters: player (Player*) - The player object that will be used to interact with the game */ void Game::startGame(Player* player) { bool playing = true; // Set the players start position to the start of the maze player->setRoom(gameMap.getStart()); string currentMove; while (playing) { cout << "\nYou are currently standing in: " << player->getRoomName() << endl; cout << player->getRoom()->getConnectionString() << endl; cout << "Where would you like to move?: "; currentMove = getPlayerInput(); if (currentMove == "q" || currentMove == "Q") { cout << "Quitting Game!" << endl; playing = false; } else { player->moveRoom(currentMove); // Checks if the player has finished the maze if (player->getRoom() == gameMap.getEnd()) { cout << "\nWell done " << player->getName() << " you reached the end of the maze!" << endl; cout << "Would you like to play again? "; string playAgain = getPlayerInput(); if (playAgain != "y") { playing = false; } else { player->setRoom(gameMap.getStart()); } } } } };
/* Displays the main menu and handles the users input Parameters: None */ void Game::displayMenu() { cout << "Welcome to the maze game!\n" << endl; string name; cout << "Enter your name: "; cin >> name; Player* player = new Player(name); cout << "\nMenu:" << endl; cout << "1. Play (default map)\n2. Load Map" << endl; string menuInput = getPlayerInput(); if (menuInput == "1") { setupMap(true); startGame(player); } else if (menuInput == "2") { setupMap(false); startGame(player); } };