Add an additional option and supporting code in the player


Currently, there is a test program that calls a player's class. The program asks the player for a name and then gives options on what happens next. The only option available is to quit. Add an additional option and supporting code in the player header that will allow the player to input a preferred console type. After the player inputs a preferred console type, be sure to redisplay it. 

GameLoop.cpp

#include "GameLoop.h"

#include

using namespace std;

void Game::WelcomePlayer()

{

cout << "Welcome to Text Adventure!" << endl << endl;

cout << "What is your name?" << endl << endl;

string name;

cin >> name;

m_player.SetName(name);

cout << endl << "Hello " << m_player.GetName() << endl;

}

void Game::GivePlayerOptions() const

{

cout << "What would you like to do? (Enter a corresponding number)" << endl << endl;

cout << "1: Quit" << endl << endl;

}

void Game::GetPlayerInput(string& playerInput) const

{

cin >> playerInput;

}

PlayerOptions Game::EvaluateInput(string& playerInput) const

{

PlayerOptions chosenOption = PlayerOptions::None;

if (playerInput.compare("1") == 0)

{

cout << "You have chosen to Quit!" << endl << endl;

chosenOption = PlayerOptions::Quit;

}

else

{

cout << "I do not recognise that option, try again!" << endl << endl;

}

return chosenOption;

}

void Game::RunGame()

{

WelcomePlayer();

bool shouldEnd = false;

while (shouldEnd == false)

{

GivePlayerOptions();

string playerInput;

GetPlayerInput(playerInput);

shouldEnd = EvaluateInput(playerInput) == PlayerOptions::Quit;

}

}

Player header

#pragma once

#include

class Player

{

private:

std::string m_name;

public:

Player()

{

}

void SetName(const std::string& name)

{

m_name = name;

}

const std::string& GetName() const

{

return m_name;

}

};

Solution Preview :

Prepared by a verified Expert
Business Management: Add an additional option and supporting code in the player
Reference No:- TGS02657322

Now Priced at $20 (50% Discount)

Recommended (90%)

Rated (4.3/5)