Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ I added images of all of the code in their respective cpp and headers. I want to add a dice roll to it. I

C++ I added images of all of the code in their respective cpp and headers. I want to add a dice roll to it. I added some extra lines of code but dont know if they were necessary. how do I make it so that when you choose option 2. A number appears?

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.

// TextAdventure.cpp : Defines the entry point for the console application. //

#include "stdafx.h" #include #include "Player.h" #include "GameLoop.h" #include "PlayerOptions.h" #include // for including tchar

using namespace std;

int _tmain(int argc, _TCHAR* argv[]) { Game game; game.RunGame();

return 0; }

// GameLoop.cpp

#include "GameLoop.h" #include

using namespace std;

void Game::WelcomePlayer() { cout

string name; cin >> name; m_player.SetName(name);

cout

void Game::GivePlayerOptions() const { cout

void Game::GetPlayerInput(string& playerInput) const { cin >> playerInput; }

PlayerOptions Game::EvaluateInput(string& playerInput) const { PlayerOptions chosenOption = PlayerOptions::None;

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

return chosenOption; }

void Game::RunGame() { WelcomePlayer();

bool shouldEnd = false; while (shouldEnd == false) { GivePlayerOptions();

string playerInput; GetPlayerInput(playerInput);

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

// GameLoop Header

#pragma once #include "Player.h" #include "PlayerOptions.h"

class Game { //for accessing member 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 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; } };

// Player Options Header

#pragma once

enum class PlayerOptions { Quit, None };

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Gameleop.h Gameloop cpp (Global Scepel 1 Chapter7-TextAdventure.cpp Defines the entry point for the console application Seanch Solution Explorer (Ctrl-3 inclade "Player.h 7inclade "Ganeloop.h Etemal Dependencies #include .Player0ptions.h" #include tchar.h> // for including tchar Gemelcop.h using nanespoce std Source F Gemelcop.cpp stolatk.cpp return 0 R ReadMe bt olution Explcrer Propertin Gamelooph Gameloop.cpp. Chapter7. TetAdventure.cpp. GetPleyerirput string&playerinput) const aainclude Loop, h Searrh Solution Explorer (Ctrl+ solution 'Chapter? TotAdventure' (1 project) 4sing naespace std; Chapter7-TextAdventure References Hesde Files cout "Welcome to Text Adventure!" Gameloop.h 10 PlayerOptions.h Resource Files 15 N:eference additionsl headers your prceran requires her t+stdas.cpp ReadMett

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

Step: 3

blur-text-image

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

1. If your script has a villain, are his motivations clear?

Answered: 1 week ago