-
Notifications
You must be signed in to change notification settings - Fork 0
/
Characteristics.cs
102 lines (94 loc) · 2.51 KB
/
Characteristics.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
/* Basic class to store attributes of item/being, is a Dictionary
* hitpoints, attack, defence, speed, mana, and manareg
* mana and manareg are invisible (not printed in ToString() method)
*/
using System;
using System.Collections.Generic;
using System.Xml;
namespace Game
{
public class Characteristics :IXml
{
public int hitpoints;
public int attack;
public int defence;
public int speed;
/// <summary>
/// Initializes a new instance of the <see cref="Game.Characteristics"/> class.
/// </summary>
/// <param name='hitpoints'>
/// Hitpoints.
/// </param>
/// <param name='attack'>
/// Attack.
/// </param>
/// <param name='defence'>
/// Defence.
/// </param>
/// <param name='speed'>
/// Speed.
/// </param>
/// <param name='mana'>
/// Mana.
/// </param>
/// <param name='manareg'>
/// Manareg.
/// </param>
public Characteristics (int hitpoints, int attack, int defence, int speed)
{
this.hitpoints = hitpoints;
this.attack = attack;
this.defence = defence;
this.speed = speed;
}
/// <summary>
/// Update the specified hp, attack, def, speed, mana and manareg - adds specified values.
/// </summary>
/// <param name='hp'>
/// Hp.
/// </param>
/// <param name='attack'>
/// Attack.
/// </param>
/// <param name='def'>
/// Def.
/// </param>
/// <param name='speed'>
/// Speed.
/// </param>
/// <param name='mana'>
/// Mana.
/// </param>
/// <param name='manareg'>
/// Manareg.
/// </param>
public void Update(int hp, int attack, int def, int speed)
{
this.hitpoints += hp;
this.attack += attack;
this.defence += def;
this.speed += speed;
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current <see cref="Game.Characteristics"/>.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents the current <see cref="Game.Characteristics"/>.
/// </returns>
public override string ToString ()
{
return string.Format ("[Characteristics:]\nHitpoints: {0}\nAttack: {1}\nDefence: {2}\n" +
"Speed: {3}", this.hitpoints, this.attack, this.defence, this.speed);
}
public XmlElement ToXml(XmlDocument doc, string elementName)
{
XmlElement ch = doc.CreateElement(elementName);
// append hitpoints
ch.SetAttribute("hitpoints", this.hitpoints.ToString());
ch.SetAttribute("attack", this.attack.ToString());
ch.SetAttribute("defence", this.defence.ToString());
ch.SetAttribute("speed", this.speed.ToString());
return ch;
}
}
}