-
Notifications
You must be signed in to change notification settings - Fork 1
/
Game.cs
252 lines (238 loc) · 8.41 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
246
247
248
249
250
251
252
using System;
using System.Threading;
using System.Collections.Generic;
using System.Text;
namespace StonePaperScissor
{
class Game
{
public Player player;
public static int level = 1;
public static bool finished = false;
private static bool isNameset;
private int width;
private int height;
private static string failmsg = "La consola ha ganado, ¡intentalo de nuevo!";
private static string winmsg = "Le has ganado al bot, ¡felicidades!";
public int Run() //Reiniciar main menu en caso de opcion invalida.
{
do
{
switch (MainMenu())
{
case 0:
return 0;
default:
break;
}
} while (true);
}
public int MainMenu() //Devolver 0 para reiniciar, 2 para salir.
{
Console.Clear();
string neworcontinue = "1: Nuevo Juego";
if (isNameset) neworcontinue = "1: Continuar";
string[] menulist = {neworcontinue, "2: Creditos", "3: ???", "0: Salir", ""};
Graphics.DrawMargin(width,height,"Piedra, Papel, Tijeras", ConsoleColor.Green);
Graphics.DrawListCenterX(menulist,2);
switch (Input.Detect())
{
case ConsoleKey.D1: //Comenzar
if (!isNameset) Choosename();
else Comenzar();
break;
case ConsoleKey.D2:
Credits();
break;
case ConsoleKey.D3:
Keyroom();
break;
case ConsoleKey.D0: //Salir
return 0;
default: //No en lista
break;
}
return 1;
//ReturnConditions
}
#region Game
private void Choosename()
{
Console.Clear();
Graphics.DrawMargin(width, height, "Let me meet you", ConsoleColor.Yellow);
string[] list = { "Welcome to my land...", "I hope we can be friends, how are you named?", "C'mon, dont be shy hehehe", "Whats your name? :)"};
Graphics.DrawDelayedList(list, 5, 4,2500); //Delayed Text
Console.SetCursorPosition(2,6);
Thread.Sleep(3000);
Console.Write("Your answer: "); //Enter your name:
player = new Player(Console.ReadLine());
Console.Clear();
Graphics.DrawMargin(width, height, "I met you", ConsoleColor.DarkYellow);
Thread.Sleep(1000);
Console.SetCursorPosition(2, 2);
Console.Write("Hello then"); Anim.SusDots(3, 700);
Console.Write(" {0}.",player.name);
Thread.Sleep(2000);
isNameset = true;
while(true)
{
if(Comenzar() == 0) break;
}
}
public int Comenzar()
{
//Level Itself
Console.Clear();
Graphics.DrawMargin(width, height, "Coliseo Demano", ConsoleColor.Blue);
Graphics.DrawStatsOnScreen(player);
Console.SetCursorPosition(width-9, height-2);
Graphics.ColorText("X: Salir", ConsoleColor.Red);
//LevelConditions
Console.SetCursorPosition(2, 2);
Console.Write("Piedra, papel o tijera"); Anim.SusDots(3, 800);
Console.Write(" Elige alguno: ");
string playerguess = Console.ReadLine();
switch (StartRound(playerguess))
{
case 1: //WIN
Console.SetCursorPosition(2, 5);
Graphics.ColorText(winmsg, ConsoleColor.Green);
player.LevelSuccess();
break;
case 2: //FAIL
Console.SetCursorPosition(2, 5);
Graphics.ColorText(failmsg, ConsoleColor.Red);
player.LevelFail();
break;
case 3: //DRAW
Console.SetCursorPosition(2, 5);
Console.Write("Han empatado!");
break;
case 4:
Console.SetCursorPosition(2, 5);
Graphics.ColorText("Error. Intenta con piedra, papel o tijera.", ConsoleColor.Red);
break;
case 0:
return 0;
default:
break;
}
Console.ReadKey();
return 1;
}
#endregion
public int Credits()
{
//Level Itself
Console.Clear();
Graphics.DrawMargin(width, height, "Creditos", ConsoleColor.Yellow);
//LevelConditions
string[] list = { "Language: C#", "Piedra, Papel, Tijeras 1.0", "Created by @andrimator", "Hope you like it :)", "Made in 5 hours lol" };
Graphics.DrawList(list, 5, 4);
Console.ReadKey();
return 0;
}
public int Keyroom()
{
//Level Itself
Console.Clear();
Graphics.DrawMargin(width, height, "Keyroom", ConsoleColor.Magenta);
//LevelConditions
string[] list = { "Language: C#", "IDE: Visual Studio Community 2019", "Created by @andrimator", "Hope you like it :)", "Made in 5 hours lol" };
Graphics.DrawList(list, 5, 4);
Console.ReadKey();
return 0;
}
void GetGameResults()
{
}
public void SetResolution(int x, int y)
{
height = y;
width = x;
Graphics.SetGlobalResolution(x,y);
}
#region PiedraPapelTijeraLogics
private static int StartRound(string guess)
{
// 1: PLAYER 2: BOT 3: DRAW
//PLAYER
guess = guess.ToLower();
if (guess == "x") return 0;
if (guess == "tijeras") guess = "tijera";
//BOT GUESS
string botguess = RandomBotGuess();
Console.SetCursorPosition(2, 4);
Console.Write("Tu: {0}| El bot: {1}", guess, botguess);
return CompareMatchResults(guess,botguess);
}
private static string RandomBotGuess()
{
Random random = new Random();
int rnd = random.Next(1,3);
Console.Write(rnd);
string botguess = "N/A";
switch (rnd)
{
case 1:
botguess = "piedra";
break;
case 2:
botguess = "papel";
break;
case 3:
botguess = "tijera";
break;
}
return botguess;
}
public static int CompareMatchResults(string guess, string botguess)
{
//Final Comparation Between Answers
if (guess == botguess) return 3; // DRAW - Nobody wins, try again
else if (guess == "piedra")
{
switch (botguess)
{
case "papel":
return 2; //Bot Wins
case "tijera":
return 1; //Player Wins
}
}
else if (guess == "papel")
{
switch (botguess)
{
case "tijera":
return 2; //Bot Wins
case "piedra":
return 1; //Player Wins
}
}
else if (guess == "tijera")
{
switch (botguess)
{
case "papel":
return 1; //Player Wins
case "piedra":
return 2; //Bot Wins
}
}
return 4; //4 means no valid USER entry
}
private static int GetInput(int x, int y) { return Graphics.DrawGetInputInt(x,y); }
#endregion
private static void DelayMil(int miliseconds) { Thread.Sleep(miliseconds); }
/*public int Template()
{
//Level Itself
Console.Clear();
Graphics.DrawMargin(width, height, "Creditos", ConsoleColor.Yellow);
//LevelConditions
Console.Read();
return 0;
}*/
}
}