-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsefullMethods.cs
More file actions
235 lines (215 loc) · 7.81 KB
/
Copy pathUsefullMethods.cs
File metadata and controls
235 lines (215 loc) · 7.81 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Spectre.Console;
namespace MazeRunners
{
public class UsefullMethods
{
public int ancho;
public int altura;
public (int,int) winner;
public Casilla[,] maze;
public List<Jugador> tokens;
public List<Jugador> jugadores;
public Random rand = new Random();
public int current = 0;
public UsefullMethods(List<Jugador> Jugadores)
{
jugadores = Jugadores;
ancho = 31;
altura = 31;
maze = new Casilla[ancho,altura];
winner = (ancho/2,altura/2);
tokens = new List<Jugador>
{
new Jugador((0,0), 3, "Man1", new EliminarTrampa()),
new Jugador((0,0), 3, "Man2", new Teleport()),
new Jugador((0,0), 3, "Man3", new AturdirTodos()),
new Jugador((0,0), 3, "Man4", new DuplicarVelocidad()),
new Jugador((0,0), 3, "Man5", new BreakWalls())
};
MazeGenerator generator = new MazeGenerator(ancho, altura);
maze = generator.GenerateMaze();
}
public void ElegirJugadores()
{
while (jugadores.Count < 2)
{
for (int i = 0; i < tokens.Count; i++)
{
Console.WriteLine($"{i + 1}: {tokens[i].Name} Skill: {tokens[i].Habilidad.Name}\n");
}
int key = int.Parse(Console.ReadLine());
switch(key)
{
case 1:
jugadores.Add(tokens[0]);
break;
case 2:
jugadores.Add(tokens[1]);
break;
case 3:
jugadores.Add(tokens[2]);
break;
case 4:
jugadores.Add(tokens[3]);
break;
case 5:
jugadores.Add(tokens[4]);
break;
default:
throw new ArgumentException("Por favor presiona los numeros dados para elegir el jugador");
}
tokens.RemoveAt(key - 1);
List<(int,int)> Dir = new List<(int,int)> {(1,1), (ancho - 2,1), (1,altura - 2), (ancho - 2, altura -2)};
for (int i = 0; i < jugadores.Count; i++)
{
bool assign = false;
(int,int)? position = null;
while (!assign)
{
int Pos = rand.Next(Dir.Count);
position = Dir[Pos];
if (position.HasValue)
{
assign = true;
}
else
{
Dir[Pos] = Dir.Last();
Dir.RemoveAt(Dir.Count - 1);
}
}
jugadores[i].Posicion = position.Value;
}
}
}
public void ShowPlayer()
{
Console.WriteLine($"Jugador actual: {jugadores[current].Name}");
Console.WriteLine($"Posición actual: {jugadores[current].Posicion}");
Console.WriteLine($"Velocidad: {jugadores[current].Speed}");
Console.WriteLine();
}
public void HandleInput(int velocidad)
{
Console.WriteLine("Pulse Enter si desea iniciar su turno");
Console.ReadLine();
int count = 0;
int pcount = 0;
int maxUses = 1;
var tempSpeed = jugadores[current].Speed;
while (count < velocidad)
{
var temp = jugadores[current].Posicion;
var key = Console.ReadKey(true).Key;
if (jugadores[current].Status == "Stunned")
{
break;
}
switch (key)
{
case ConsoleKey.W:
jugadores[current].Mover((-1,0), maze);
Console.Clear();
DisplayMaze();
break;
case ConsoleKey.S:
jugadores[current].Mover((1,0), maze);
Console.Clear();
DisplayMaze();
break;
case ConsoleKey.A:
jugadores[current].Mover((0,-1), maze);
Console.Clear();
DisplayMaze();
break;
case ConsoleKey.D:
jugadores[current].Mover((0,1), maze);
Console.Clear();
DisplayMaze();
break;
case ConsoleKey.P:
if (pcount < maxUses && jugadores[current].Cooldown == 0)
{
jugadores[current].Habilidad.UseSkill(jugadores[current], jugadores, maze);
if (jugadores[current].Speed != 3)
{
velocidad = jugadores[current].Speed;
}
jugadores[current].Cooldown = 3;
Console.Clear();
DisplayMaze();
pcount++;
}
else if (jugadores[current].Cooldown > 0)
{
Console.WriteLine("Esta habilidad tiene cooldown");
}
else
{
Console.WriteLine("Esta habilidad ya fue usadad");
}
break;
default:
Console.WriteLine("Por favor presiona WASD para moverte o P para activar el poder");
break;
}
if (jugadores[current].Cooldown > 0)
{
jugadores[current].Cooldown--;
}
if (jugadores[current].Posicion != temp)
{
count++;
}
if (key == ConsoleKey.P && jugadores[current].Posicion != temp)
{
count--;
}
if (CheckWin())
{
break;
}
}
jugadores[current].Speed = tempSpeed;
}
public void DisplayMaze()
{
Console.Clear();
for (int i = 0; i < maze.GetLength(0); i++)
{
for (int j = 0; j < maze.GetLength(1); j++)
{
if ((i,j) == jugadores[0].Posicion)
{
maze[i,j].DisplayPlayer();
}
else if ((i,j) == jugadores[1].Posicion)
{
maze[i,j].DisplayPlayer();
}
else
{
maze[i,j].Display();
}
}
Console.WriteLine();
}
}
public void SwitchTurn()
{
current = (current + 1) % jugadores.Count;
}
public bool CheckWin()
{
if (jugadores[current].Posicion == winner)
{
return true;
}
return false;
}
}
}