-
Notifications
You must be signed in to change notification settings - Fork 1
/
room.cpp
77 lines (66 loc) · 1.63 KB
/
room.cpp
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
#include <iostream>
#include "globals.h"
#include "exit.h"
#include "item.h"
#include "creature.h"
#include "room.h"
// ----------------------------------------------------
Room::Room(const char* title, const char* description) :
Entity(title, description, NULL)
{
type = ROOM;
}
// ----------------------------------------------------
Room::~Room()
{
}
// ----------------------------------------------------
void Room::Look() const
{
cout << "\n" << name << "\n";
cout << description;
// List exits --
for(list<Entity*>::const_iterator it = container.begin(); it != container.cend(); ++it)
{
if((*it)->type == EXIT)
{
Exit* ex = (Exit*)*it;
cout << "\nDirection (" << ex->GetNameFrom(this) << ") you see " << ex->GetDestinationFrom(this)->name;
}
}
// List items --
for(list<Entity*>::const_iterator it = container.begin(); it != container.cend(); ++it)
{
if((*it)->type == ITEM)
{
Item* item = (Item*)*it;
cout << "\nThere is an item here: " << item->name;
}
}
// List creatures --
for(list<Entity*>::const_iterator it = container.begin(); it != container.cend(); ++it)
{
if((*it)->type == CREATURE)
{
Creature* cr = (Creature*)*it;
cout << "\nThere is someone else here: " << cr->name;
if(cr->IsAlive() == false)
cout << " (dead)";
}
}
cout << "\n";
}
// ----------------------------------------------------
Exit* Room::GetExit(const string& direction) const
{
for(list<Entity*>::const_iterator it = container.begin(); it != container.cend(); ++it)
{
if((*it)->type == EXIT)
{
Exit* ex = (Exit*) *it;
if(Same(ex->GetNameFrom(this), direction))
return ex;
}
}
return NULL;
}