1
1.Hello please I need a help with the following in adventure.cpp game.Please advise.Thanks
Create constructors and destructors for each class you make from a converted “struct”
Create overloaded constructor functions
Create overloaded constructor functions for the one or more classes you converted from “structs”
Class public/private members
Make sure you have public/private members of your classes (data members or member functions)
Use “setters/getters” for private data members
Use functions to get/set the values of your private data members in your classes (“setters/getters”)
Use a static data member to limit number of objects
Consider using a static data member that limits the maximum number of objects that may be created for your converted class (word, room, noun)
Use constructors to create the objects
Use a constructor to initialize your data, instead of a function that initializes the data in the structs (Note - you may still call a function that in turn will call your constructors)
50
Change rooms array into vectors
Change the rooms[ROOMS] array into a vector, use the STL (sort, shuffle, etc.) where appropriate
Change directions array into vectors
Change the directions[DIRS] array into a vector, use the STL (sort, shuffle, etc.) where appropriate
Change verbs array into vectors
Change the verbs(VERBS] array into a vector, use the STL (sort, shuffle, etc.) where appropriate
Change nouns array into vectors
Change the nouns[NOUNS] array into a vector, use the STL (sort, shuffle, etc.) where appropriate
25
Re-theme the game
Make it your own. Instead of rooms at a casino, make it a “dungeon”, or a “cave”, or a “forest”. This means the nouns and verbs should also follow the theme.
I have cut the code to make it fit.So I will be posting the source code in 3 steps.
Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
Put the code you need help with here.
#include <iostream>
#include < string>
#include < vector>
#include <cctype >
using namespace std ;
enum en_DIRS {NORTH, EAST,SOUTH, WEST };
enum en_ROOMS {SPORTSHOP,CASINO,CARPARK,LOBBY,RESTAURANT,CORRIDOR,STOREROOM,POOL,GARDEN,POND,PUMPROOM};
enum en_VERBS {GET,DROP, USE, OPEN,CLOSE,EXAMINE,INVENTORY,LOOK};
enum en_NOUNS {STORE_DOOR, MAGNET,METER,ROULETTE, MONEY,FISHROD};
const int NONE = -1 ;
const int DIRS = 4 ;
const int ROOMS = 11 ;
const int VERBS = 8 ;
const int NOUNS = 6 ;
class Words
{
public :
string word;
int code ;
Words (); // This a constructor declaration
~Words (); // This is a destructor declaration
};
Words::Words():
{
}
class Room
{
public:
string description;
int exits_to_Room[DIRS];
Room ();// This a constructor declaration
~Room ();// This is a destructor declaration
};
Room::Room(int exiits_to_Room);
class Noun
{
public:
string word ;
string description;
int code ;
int location;
bool can_carry ;
Noun (); // This a constructor declaration
~Noun (); // This is a destructor declaration
};
Noun::Noun()
{
}
//------------------------------------------------------------------------------------------------------------------------------------------------
void set_rooms(vector<Room> &rms)
{
rms.push_back(Room(SPORTSHOP,"sports shop",NONE,NONE,CARPARK,NONE));
rms[CASINO].description.assign("bustling casino");
rms[CASINO].exits_to_Room[NORTH] = NONE ;
rms[CASINO].exits_to_Room[EAST] = NONE ;
rms[CASINO].exits_to_Room[SOUTH] = LOBBY ;
rms[CASINO].exits_to_Room[WEST] = NONE ;
rms[CARPARK].description.assign(" car park");
rms[CARPARK].exits_to_Room[NORTH] = SPORTSHOP;
rms[CARPARK].exits_to_Room[EAST] = LOBBY ;
rms[CARPARK].exits_to_Room[SOUTH] = NONE ;
rms[CARPARK].exits_to_Room[WEST] = NONE ;
rms[LOBBY].description.assign(" hotel lobby");
rms[LOBBY].exits_to_Room[NORTH] = CASINO;
rms[LOBBY].exits_to_Room[EAST] = RESTAURANT;
rms[LOBBY].exits_to_Room[SOUTH] = CORRIDOR;
rms[LOBBY].exits_to_Room[NORTH] = CARPARK;
rms[RESTAURANT].description.assign(" restaurant");
rms[RESTAURANT].exits_to_Room[NORTH] = NONE;
rms[RESTAURANT].exits_to_Room[EAST] = NONE;
rms[RESTAURANT].exits_to_Room[SOUTH] = NONE;
rms[RESTAURANT].exits_to_Room[NORTH] = LOBBY;
rms[CORRIDOR].description.assign(" corridor");
rms[CORRIDOR].exits_to_Room[NORTH] = LOBBY;
rms[CORRIDOR].exits_to_Room[EAST] = NONE;
rms[CORRIDOR].exits_to_Room[SOUTH] = GARDEN;
rms[CORRIDOR].exits_to_Room[NORTH] = NONE;
rms[STOREROOM].description.assign("store room");
rms[STOREROOM].exits_to_Room[NORTH] = NONE;
rms[STOREROOM].exits_to_Room[EAST] = NONE;
rms[STOREROOM].exits_to_Room[SOUTH] = NONE;
rms[STOREROOM].exits_to_Room[NORTH] = NONE;
rms[POOL].description.assign(" swimming pool area");
rms[POOL].exits_to_Room[NORTH] = NONE;
rms[POOL].exits_to_Room[EAST] = GARDEN;
rms[POOL].exits_to_Room[SOUTH] = PUMPROOM;
rms[POOL].exits_to_Room[NORTH] = NONE;
rms[GARDEN].description.assign(" tranquil garden");
rms[GARDEN].exits_to_Room[NORTH] = CORRIDOR;
rms[GARDEN].exits_to_Room[EAST] = POND;
rms[GARDEN].exits_to_Room[SOUTH] = NONE;
rms[GARDEN].exits_to_Room[NORTH] = POOL;
rms[PUMPROOM].description.assign(" damp pump room");
rms[PUMPROOM].exits_to_Room[NORTH] = POOL;
rms[PUMPROOM].exits_to_Room[EAST] = NONE;
rms[PUMPROOM].exits_to_Room[SOUTH] = NONE;
rms[PUMPROOM].exits_to_Room[NORTH] = NONE;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|