-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cs
245 lines (238 loc) · 8.96 KB
/
Game.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
namespace card_gameProtot
{
public class Game
{
Player player1{get;}
Player player2{get;}
public List<Character> CharactersInventary;
public List<Relics> CardsInventary;
public List<Relics> GraveYard;
int turn;
public Game(List<Character> CharactersInventary, List<Relics> CardsInventary)
{
this.CharactersInventary = CharactersInventary;
this.CardsInventary = CardsInventary;
GraveYard = new List<Relics>();
this.player1 = new Player(CharactersInventary[0], "Player1");
this.player2 = new Player(CharactersInventary[0], "Player2");
player1.SetAux(player2, this);
player2.SetAux(player1, this);
turn = 1;
}
public void game()
{
Console.Clear();
Console.WriteLine("Elige el personaje que seras");
player1.character = CharactersInventary[int.Parse(Console.ReadLine())];
Console.WriteLine("Elige el personaje que sera tu oponente");
player2.character = CharactersInventary[int.Parse(Console.ReadLine())];
player1.TakeFromDeck(5);
player2.TakeFromDeck(5);
Console.Clear();
while (player1.life > 0 && player2.life > 0)
{
if (turn % 2 != 0) //Impar
{
PlayGame(player1);
}
if (turn % 2 == 0) //Par
{
PlayGame(player2);
}
turn++;
}
}
public void PlayGame(Player player)
{
if(player.state == State.Poisoned)
{
player.life -= 10;
}
player.TakeFromDeck(1);
//All activity of player 1 goes here
int Option = 0;
while(Option != 3)
{
Console.Clear();
player.printInfo();
if(player.state == State.Freezed)
{
Console.WriteLine("Presione 1: Para atacar");
Console.WriteLine("Presione 3: Para Pasar turno");
try
{
Option = int.Parse(Console.ReadLine());
}
catch (System.Exception){}
switch (Option)
{
case 1: Attack(player);
break;
default:
break;
}
}
else if(player.state == State.Asleep)
{
Console.WriteLine("Presione 1: Para activar cartas");
Console.WriteLine("Presione 3: Para Pasar turno");
try
{
Option = int.Parse(Console.ReadLine());
}
catch (System.Exception){}
switch (Option)
{
case 1: ActivateCards(player);
break;
default:
break;
}
}
else
{
Console.WriteLine("Presione 1: Para activar cartas");
Console.WriteLine("Presione 2: Para atacar");
Console.WriteLine("Presione 3: Para Pasar turno");
try
{
Option = int.Parse(Console.ReadLine());
}
catch (System.Exception){}
switch (Option)
{
case 1: ActivateCards(player);
break;
case 2: Attack(player);
break;
default:
break;
}
}
}
UpdateBattleField(player);
Console.Clear();
}
public void UpdateBattleField(Player player)
{
for (int index = 0; index < player.userBattleField.Length; index++)
{
if(player.userBattleField[index] != null)
{
if (player.userBattleField[index].activeDuration == 1)
{
foreach (var Action in player.userBattleField[index].Actions)
{
if(Action.GetType().ToString() == "card_gameProtot.Attack")
{
Action.Effect();
}
else if(Action.GetType().ToString() == "card_gameProtot.ChangeState")
{
player.Enemy.state = State.Safe;
}
}
GraveYard.Add(player.userBattleField[index]);
player.userBattleField[index] = null; // Removing card from battelfield
}
else
{
if (player.userBattleField[index].passiveDuration != 0)
{
player.userBattleField[index].passiveDuration--;
}
else
{
int Defaultpassive = CardsInventary[player.userBattleField[index].id].passiveDuration;
player.userBattleField[index].passiveDuration = Defaultpassive;
player.userBattleField[index].activeDuration--;
}
}
}
}
}
public void ActivateCards(Player player)
{
do
{
Console.Clear();
player.printInfo();
Console.WriteLine("Elige la carta que quieres activar");
if(player.Enemy.HaveTrap())
{
}
AddtoBattleField(player.hand[int.Parse(Console.ReadLine())]);
player.hand[int.Parse(Console.ReadLine())].Effect();
Console.WriteLine("Si quiere activar otra carta presione: 1, si no presione 2");
} while (int.Parse(Console.ReadLine()) != 2);
}
public void AddtoBattleField(Relics relic)
{
for (int i = 0; i < relic.Owner.userBattleField.Length; i++)
{
if(relic.Owner.userBattleField[i] == null)
{
relic.Owner.userBattleField[i] = relic;
relic.Owner.hand.Remove(relic);
break;
}
}
}
public static void ActivateTrapCards(Player enemy, double attack)
{
do
{
Console.Clear();
enemy.printInfo();
Console.WriteLine("Elige la carta que quieres activar");
int HandPosition = int.Parse(Console.ReadLine());
Relics relic = enemy.hand.ElementAt(HandPosition);
relic.Effect();
if(relic.Actions.Count() != 0)
{
foreach (var Action in relic.Actions)
{
if(Action.GetType().ToString() == "card_gameProtot.StopAttack")
{
return;
}
if(Action.GetType().ToString() == "card_gameProtot.DamageReduction")
{
Action.Effect();
return;
}
}
}
Console.WriteLine("Si quiere activar otra carta presione: 1, si no presione 2");
} while (int.Parse(Console.ReadLine()) != 2);
enemy.life = enemy.life - enemy.Enemy.character.attack;
}
public static void Attack(Player player)
{
if(player.Enemy.character.defense!=0)
{
Console.WriteLine("Desea defenderse de este ataques? 1: Si, 2: No");
if(int.Parse(Console.ReadLine())==1)
{
player.Enemy.character.defense--;
}
else
{
player.Enemy.life = player.Enemy.life - player.character.attack;
}
}
else if(player.Enemy.HaveTrap())
{
Console.WriteLine("Desea activar una carta trampa? 1: Si, 2: No");
if(int.Parse(Console.ReadLine())==1)
{
ActivateTrapCards(player.Enemy, player.character.attack);
}
else
{
player.Enemy.life = player.Enemy.life - player.character.attack;
}
}
}
}
}