Question
Instructions For this assignment, you will be modifying code within a program. Extract the Chapter7-TextAdventure.zip folder (in the zip file in Start Here). To open
Instructions For this assignment, you will be modifying code within a program.
Extract the Chapter7-TextAdventure.zip folder (in the zip file in Start Here). To open the project, double-click on the .sln (or solution) file. As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code.
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 (PS4, XBOX 1, Wii, Computer) , 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;
cout << "2: Choose Console" << 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;
}
}
PlayerOption.h
#pragma once
enum class PlayerOptions
{
Quit,
None
};
Gameloop.h
#pragma once
#include "Player.h"
#include "PlayerOptions.h"
class Game
{
private:
Player m_player;
void WelcomePlayer();
void GivePlayerOptions() const;
void GetPlayerInput(std::string& playerInput) const;
PlayerOptions EvaluateInput(std::string& playerInput) const;
public:
void RunGame();
};
Player.h
#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;
}
};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started