Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions