-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoor.cs
122 lines (110 loc) · 2.4 KB
/
Door.cs
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
using System;
using System.Xml;
namespace Game
{
/// <summary>
/// Door - has some message, description, symbol and name ok key, which opens it.
/// </summary>
public class Door: BasicObject
{
public string Description {get; private set;}
public bool Locked {get; private set;}
public Door (string description, bool locked=true)
{
Description = description;
Locked = locked;
if (locked) // set symbol based on state of doors (locked/open)
{
this.symbol = '/';
}
else
{
this.symbol = '-';
}
}
/// <summary>
/// Opens the door with given key.
/// </summary>
/// <returns>
/// The door.
/// </returns>
/// <param name='key'>
/// If set to <c>true</c> key.
/// </param>
public void OpenDoor()
{
ThisGame.messageLog.Enqueue("Door has been opened");
this.Locked = false;
this.UpdateSymbol();
}
public override bool CanMoveTo()
{
return !Locked;
}
public override bool CanDropItemOnto()
{
return false;
}
/// <summary>
/// Updates the symbol, depending on state.
/// </summary>
private void UpdateSymbol()
{
if (this.Locked)
{
this.symbol = '/';
}
else
{
this.symbol = '-';
}
}
/// <summary>
/// write the xml.
/// </summary>
/// <returns>
/// The xml.
/// </returns>
/// <param name='doc'>
/// Document.
/// </param>
/// <param name='slementName'>
/// Slement name.
/// </param>
public override XmlElement ToXml (XmlDocument doc, string slementName)
{
XmlElement door = doc.CreateElement("Door");
// append description
XmlElement msg = doc.CreateElement("Message");
msg.InnerXml = Description;
door.AppendChild(msg);
// append locked
door.SetAttribute("locked", Locked.ToString());
door.SetAttribute("symbol", symbol.ToString());
return door;
}
/// <summary>
/// Performs the action. If user has coorect key, opens the door, else - tells him he needs a key.
/// </summary>
/// <returns>
/// The action.
/// </returns>
/// <param name='p'>
/// If set to <c>true</c> p.
/// </param>
/// <param name='l'>
/// If set to <c>true</c> l.
/// </param>
/// <param name='msg'>
/// If set to <c>true</c> message.
/// </param>
/// <param name='l2'>
/// If set to <c>true</c> l2.
/// </param>
public override IPlace AutomaticAction(Player p)
{
// this wont happen, every door has a key
return this;
}
}
}