You will create a class that could be used to create a Text Adventure game. The class will be called "Player" that will represent a user-controlled character in the game.  The Player Class The Player class will have the following 5 properties: A property to represent the player's name A property to represent the player's current x location. A property to represent the player's current y location. An array property that represents the list of items that the player is currently carrying. The length of the array should be 3, so the player will only be able to hold a maximum of 3 items at a time. A property that represents the number of items that the player is currently carrying. (This value should never be greater than 3.) (Note: Your Player class MUST have all of the properties listed above. You are allowed to create additional properties if needed, but please be judicious about it. In other words, you should only create additional properties if you have a legitimate reason for doing so.) The Player class will have exactly 5 methods: There will be a constructor that takes the player's name as a parameter. The player's initial location should be (0,0). The player should initially not be carrying any items. There will be a method called "move" that will take a Direction value as a parameter. You will create an enumeration called "Direction" with the values NORTH, SOUTH, EAST, and WEST. The "move" method will take one of these enumerated values as a parameter. If the player moves NORTH, its y location will be incremented. If it moves SOUTH, its y location will be decremented. If it moves EAST, its x location will be incremented. If it moves WEST, its x location will be decremented. There will be a method called "pickUpItem" that takes an Item as a parameter. The specified item should be added to the Player's array of items. (Note that the player will only be able to hold a maximum of 3 items, because of the capacity of the array. If a player tries to pick up an item while the array is full, then the item should NOT be picked up and an error message should be printed.) There will be a method called "putDownItem" that takes no parameters. The last item that was picked up by the player should be removed from the player's list of items. There will be a method called "print" that will print the Player's information to standard output. First, the name should be printed. Then, the player's current (x,y) location should be printed. Finally, the player's list of items should be printed.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

You will create a class that could be used to create a Text Adventure game.

The class will be called "Player" that will represent a user-controlled character in the game. 

The Player Class

The Player class will have the following 5 properties:

  1. A property to represent the player's name
  2. A property to represent the player's current x location.
  3. A property to represent the player's current y location.
  4. An array property that represents the list of items that the player is currently carrying. The length of the array should be 3, so the player will only be able to hold a maximum of 3 items at a time.
  5. A property that represents the number of items that the player is currently carrying. (This value should never be greater than 3.)

(Note: Your Player class MUST have all of the properties listed above. You are allowed to create additional properties if needed, but please be judicious about it. In other words, you should only create additional properties if you have a legitimate reason for doing so.)

The Player class will have exactly 5 methods:

  1. There will be a constructor that takes the player's name as a parameter. The player's initial location should be (0,0). The player should initially not be carrying any items.
  2. There will be a method called "move" that will take a Direction value as a parameter. You will create an enumeration called "Direction" with the values NORTH, SOUTH, EAST, and WEST. The "move" method will take one of these enumerated values as a parameter. If the player moves NORTH, its y location will be incremented. If it moves SOUTH, its y location will be decremented. If it moves EAST, its x location will be incremented. If it moves WEST, its x location will be decremented.
  3. There will be a method called "pickUpItem" that takes an Item as a parameter. The specified item should be added to the Player's array of items. (Note that the player will only be able to hold a maximum of 3 items, because of the capacity of the array. If a player tries to pick up an item while the array is full, then the item should NOT be picked up and an error message should be printed.)
  4. There will be a method called "putDownItem" that takes no parameters. The last item that was picked up by the player should be removed from the player's list of items.
  5. There will be a method called "print" that will print the Player's information to standard output. First, the name should be printed. Then, the player's current (x,y) location should be printed. Finally, the player's list of items should be printed.

PLEASE MAKE SURE ITS POSSIBLE TO COMPILE WITH THIS CODE. THANKS.

#include "Player.h"

#include <iostream>

#include <string> using namespace std;

int main()

{

Item sword("Sword of Destiny");

Item potion("Healing Potion");

Item key("Key of Wisdom");

string name;

cout << "Enter your name: ";

getline(cin, name);

Player user(name);

user.print();

cout << "USER PICKS UP SWORD:" << endl;

user.pickUpItem(sword);

user.print();

cout << "USER MOVES NORTH:" << endl;

user.move(NORTH);

user.print();

cout << "USER PICKS UP POTION:" << endl;

user.pickUpItem(potion);

user.print();

cout << "USER PUTS DOWN ITEM:" << endl;

user.putDownItem();

user.print();

cout << "USER MOVES WEST:" << endl;

user.move(WEST);

user.print();

cout << "USER PICKS UP KEY:" << endl;

user.pickUpItem(key);

user.print();

}

 

Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education