-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
86 lines (86 loc) · 3.65 KB
/
Main.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
namespace MineSweeper
{
public class Program
{
public static void Main(string[] args)
{
Game game;
Database database = new();
int PlayerId;
string PlayerName = "";
Console.Title = "MineSweeper by H1K0";
Console.WriteLine("(C) Masahiko AMANO a.k.a. H1K0, 2022\n\n" +
"Hey! Let's play the MineSweeper game!\nPress any button for help or Enter to log in.");
while (Console.ReadKey(true).Key != ConsoleKey.Enter)
Console.WriteLine("\nThe game follows the classic rules.\n" +
"Target cell coordinates are represented this way: A1, F5, I8. Case insensitive.\n" +
"Type coordinates of the cell to open it or use prefixes: \"M\" to mark or \"U\" to unmark the cell.\n" +
"For example: \"B9\", \"M D7\".\n" +
"Press any button to see help again or just press Enter to start the game.");
while (true)
{
Console.Write("\nYour name: ");
PlayerName = Console.ReadLine();
PlayerId = database.FindPlayer(PlayerName);
if (PlayerId == -1 || PlayerName == "")
{
Console.WriteLine("Could not find a player with the name \"" + PlayerName + "\". Press Enter to add new or any other button to re-enter.");
if (Console.ReadKey(true).Key == ConsoleKey.Enter)
{
database.AddPlayer(PlayerName);
PlayerId = database.PlayersCount() - 1;
break;
}
}
else
break;
}
Console.WriteLine("You logged in as \"" + PlayerName + "\".\nYour stats:");
Console.WriteLine($"Wins: {database.Stats(PlayerId)[0]}\nLoses: {database.Stats(PlayerId)[1]}");
while (true)
{
Console.Write("\nOkay, let's play!\nEnter field width, height and number of mines separated with a space: ");
while (true)
{
try
{
string[] input = Console.ReadLine().Split();
game = new Game(Convert.ToInt16(input[0]), Convert.ToInt16(input[1]), Convert.ToInt16(input[2]));
break;
}
catch (Exception ex)
{
Console.Write(ex.Message + "\nTry again.\n\n" +
"Enter field width, height and number of mines separated with a space: ");
}
}
bool result = game.Run();
if (result)
Console.WriteLine("You win! Congratulations!");
else
Console.WriteLine("You lose!");
database.AddGame(PlayerId, result);
database.Update();
Console.WriteLine("Press Enter to play again or Escape to exit.");
ConsoleKey key;
bool exit = false;
while (true)
{
key = Console.ReadKey(true).Key;
if (key == ConsoleKey.Enter)
{
Console.Clear();
break;
}
else if (key == ConsoleKey.Escape)
{
exit = true;
break;
}
}
if (exit)
break;
}
}
}
}