-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
57 lines (50 loc) · 1.81 KB
/
Program.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
public static class Program
{
static void Main(string[] args)
{
#if DEBUG
Battleships.RunTests();
#endif
Console.WriteLine("==============================");
Console.WriteLine("=--------BATTLESHIPS---------=");
Console.WriteLine("==============================");
Console.WriteLine();
Console.WriteLine("Welcome to the Battleships game!\n");
Console.WriteLine("To shoot missiles, please specify coordinates like this: \"B6\", \"G10\", etc.");
Console.WriteLine("Both the player and the enemy have one ship with length of 5 and two with length of 5.");
Console.WriteLine("The game ends when there are no ships left.\n");
Console.WriteLine("If you want to exit, type \"exit\", if you want to start again, type \"new\".\n");
Console.WriteLine("Good luck!");
Console.ReadKey();
Battleships game = new Battleships();
game.StartNewGame();
game.RenderGameState();
while (true)
{
string? target = Console.ReadLine();
if (target != null)
{
if (target.ToLower() == "exit")
{
break;
}
if (target.ToLower() == "new")
{
game.StartNewGame();
game.RenderGameState();
continue;
}
Input input = Input.ParseInput(target);
if (input.IsValid())
{
if (false == game.Turn(input))
{
Console.ReadKey();
game.StartNewGame();
}
game.RenderGameState();
}
}
}
}
}