-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
149 lines (124 loc) · 3.5 KB
/
Player.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System.Collections.Generic;
public class Player {
public string Name;
public int MaxHealth {
get;
protected set;
}
protected int m_CurrentHealth = 0;
public int CurrentHealth {
get {
return m_CurrentHealth;
}
set {
m_CurrentHealth = MathExtensions.Clamp(value, 0, MaxHealth);
}
}
public int MaxMana {
get;
protected set;
}
protected int m_ManaCrystals = 0;
public int ManaCrystals {
get {
return m_ManaCrystals;
}
set {
m_ManaCrystals = MathExtensions.Clamp(value, 0, MaxMana);
}
}
protected int m_ManaCount = 0;
public int ManaCount {
get {
return m_ManaCount;
}
set {
m_ManaCount = MathExtensions.Clamp(value, 0, m_ManaCrystals);
}
}
public LinkedList<Card> Hand {
get;
} = new LinkedList<Card>();
public Deck Deck {
get;
protected set;
}
public Player( int maxHealth, int maxMana, Deck newDeck )
{
MaxHealth = maxHealth;
CurrentHealth = maxHealth;
MaxMana = maxMana;
Deck = newDeck;
Hand.Clear();
}
public Card FindAt(int cardIndex)
{
if( cardIndex >= Hand.Count )
{
return null;
}
var currentNode = Hand.First;
for (int ix = 0; ix < cardIndex; ++ix)
{
currentNode = currentNode.Next;
}
System.Diagnostics.Debug.Assert(currentNode != null);
return currentNode.Value;
}
public bool PlayCard( int cardIndex, Player otherPlayer )
{
var currentCard = FindAt(cardIndex);
if( currentCard.Cost > ManaCount )
{
System.Console.WriteLine(string.Format("Not enough mana to play {0}", currentCard.Title));
System.Threading.Thread.Sleep(1000);
return false;
}
Hand.Remove(currentCard);
currentCard.Play(this, otherPlayer);
ManaCount -= currentCard.Cost;
return true;
}
public void DrawCards( int count )
{
for( int ix = 0; ix < count; ++ix )
{
if( Deck.IsEmpty )
{
CurrentHealth -= 1;
continue;
}
Hand.AddLast(Deck.DrawTop());
}
}
public void DiscardCards(int count)
{
for (int ix = 0; ix < count; ++ix)
{
if (Deck.IsEmpty)
{
CurrentHealth -= 1;
continue;
}
Deck.DrawTop();
}
}
public override string ToString()
{
using (var builderSlip = Neo.Utility.DataStructureLibrary<System.Text.StringBuilder>.Instance.CheckOut())
{
builderSlip.Value.Clear();
builderSlip.Value.AppendFormat("Name: {0}\n", Name);
builderSlip.Value.AppendFormat("Health: {0}/{1}\n", CurrentHealth, MaxHealth);
builderSlip.Value.AppendFormat("Mana: {0}/{1}\n", ManaCount, ManaCrystals);
builderSlip.Value.AppendFormat("Remaining Cards in Deck: {0}\n", Deck.Cards.Count);
builderSlip.Value.AppendLine("Hand:");
int cardIndex = 0;
foreach (var card in Hand)
{
builderSlip.Value.AppendFormat("{0}) {1}", ++cardIndex, card.ToString());
}
return builderSlip.Value.ToString();
}
}
}