-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardState.cs
executable file
·195 lines (146 loc) · 4.92 KB
/
CardState.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
namespace TheCardGame;
public abstract class CardState {
protected Card card;
public CardState(Card card) {
this.card = card;
}
public Card Card
{
get { return card; }
set { card = value; }
}
public virtual bool onIsTaken() {return false;}
public virtual bool onDraw() { return false;}
public virtual void onEndTurn() {}
public virtual bool isNotYetInTheGame() {return false;}
public virtual bool isInTheHand() {return false;}
public virtual bool canBePlayed() {return false;}
public virtual int givesEnergyLevel() {return 0;}
public virtual void tapEnergy() {}
public virtual void goDefending() {}
public virtual void goAttacking() {}
public virtual bool peformAttack() { return false;}
public virtual (bool, int) absorbAttack(int iAttackValue) { return (false, 0); }
public virtual bool dispose() {return false;}
}
public class InTheDeck : CardState {
public InTheDeck(CardState state) : base(state.Card) {
}
public InTheDeck(Card card) : base(card) {
}
public override int givesEnergyLevel() {
return 0;
}
public override bool isNotYetInTheGame()
{
return true;
}
public override bool onIsTaken()
{
this.card.State = new InTheHand(this);
return true;
}
}
public class InTheHand : CardState {
public InTheHand(CardState state) : base(state.Card) {
}
public override int givesEnergyLevel() {
return 0;
}
public override bool isInTheHand() {
return true;
}
public override bool dispose() {
this.card.State = new OnTheDisposedPile(this);
return true;
}
public override bool onDraw() {
this.card.State = new OnTheBoard(this);
return true;
}
}
public class OnTheBoard : CardState {
public OnTheBoard(CardState state) : base(state.Card) {
}
public override void tapEnergy() {
this.card.State = new IsTapped(this);
}
public override void goDefending() {
this.card.State = new IsDefending(this);
}
public override void goAttacking() {
this.card.State = new IsAttacking(this);
}
public override int givesEnergyLevel() {
return 0;
}
public override bool canBePlayed() {return true;}
}
public class OnTheDisposedPile : CardState {
public OnTheDisposedPile(CardState state) : base(state.Card) {
}
public override int givesEnergyLevel() {
return 0;
}
}
public class IsAttacking : CardState {
public IsAttacking(CardState state) : base(state.Card) {
}
public override int givesEnergyLevel() {
return 0;
}
public override bool peformAttack() {
System.Console.WriteLine($"{this.card.getId()} Peforms attack.");
CreatureCard? ccard = this.card as CreatureCard;
if (ccard is not null) {
bool defended = false;
int attackValue = this.card.getInitialAttackValue();
GameBoard gb = new GameBoard();
foreach(Card card in gb.getOpponentPlayer().getCards()) {
(bool cardDefended, int attackValueLeft) = card.State.absorbAttack(attackValue);
if (cardDefended) {
defended = true;
attackValue = attackValueLeft;
}
}
if (!defended) {
gb.getOpponentPlayer().decreaseHealthValue(attackValue);
}
return true;
}
return false;
}
public override void onEndTurn() {
this.card.State = new OnTheBoard(this);
}
}
public class IsDefending : CardState {
public IsDefending(CardState state) : base(state.Card) {
}
public override int givesEnergyLevel() {
return 0;
}
public override void onEndTurn() {
this.card.State = new OnTheBoard(this);
}
public override (bool, int) absorbAttack(int iAttackValue) {
int defenseValue = this.card.getDefenseValue();
int attackValueLeft = iAttackValue - defenseValue;
int defenseValueLeft = this.card.subtractDefenseValue(iAttackValue);
System.Console.WriteLine($"Card '{this.card.getId()}' with defense-value {defenseValue} absorbed attack-value {iAttackValue}. Attack value left: {attackValueLeft}");
if (defenseValueLeft <= 0) {
this.card.State = new OnTheDisposedPile(this);
}
return (true, attackValueLeft);
}
}
public class IsTapped : CardState {
public IsTapped(CardState state) : base(state.Card) {
}
public override int givesEnergyLevel() {
return this.card.getEnergyLevel();
}
public override void onEndTurn() {
this.card.State = new OnTheBoard(this);
}
}