-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interface.cs
120 lines (111 loc) · 3.99 KB
/
Interface.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
using ConsoleExtender;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace consoleSnake
{
class Interface
{
const int width = 80;
const int height = 25;
static void Main(string[] args)
{
int lvl = 0;
ConsoleHelper.SetConsoleFont(3);
Console.SetWindowSize(width, height + 5);
Console.SetBufferSize(width, height + 5);
Console.Title = "Snake";
Console.CursorVisible = false;
bool CanClose;
do
{
int speed = 0;
Console.Clear();
StartGameHint();
while (speed == 0)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey();
if (key.KeyChar == '1')
speed = 1;
else if (key.KeyChar == '2')
speed = 2;
else if (key.KeyChar == '3')
speed = 3;
else if (key.KeyChar == '4')
speed = 4;
else if (key.KeyChar == '5')
speed = 5;
}
}
Console.Clear();
Game game = new Game(width, height, speed);
if (lvl == 0)
EndGameInfo(game.Start());
else
{
int a = game.Start(lvl);
EndGameInfo(a);
lvl = 0;
}
while (true)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey();
if (key.Key == ConsoleKey.Spacebar)
{
CanClose = false;
break;
}
else if (key.Key == ConsoleKey.Escape)
{
CanClose = true;
break;
}
else if ("123456789".Contains(key.KeyChar))
{
lvl = Convert.ToInt32(key.KeyChar) - 48;
CanClose = false;
break;
}
}
}
} while (!CanClose);
}
static void EndGameInfo(int score)
{
Console.Clear();
Console.SetCursorPosition(34, 10);
Console.Write("Игра окончена");
Console.SetCursorPosition(30, 11);
Console.Write("Вы набрали " + score.ToString() + " очков");
Console.SetCursorPosition(25, 12);
Console.Write("Нажмите Space чтобы играть заново,");
Console.SetCursorPosition(34, 13);
Console.Write("Esc для выхода,");
Console.SetCursorPosition(28, 14);
Console.Write("или выберите уровень (1-9)");
line_horizontal l1 = new line_horizontal(23, 59, 8, 4);
line_horizontal l2 = new line_horizontal(23, 59, 16, 4);
Console.ForegroundColor = ConsoleColor.Green;
l1.Draw();
l2.Draw();
Console.ForegroundColor = ConsoleColor.Gray;
Console.Beep();
}
static void StartGameHint()
{
Console.ForegroundColor = ConsoleColor.Green;
line_horizontal l1 = new line_horizontal(23, 59, 8, 4);
l1.Draw();
Console.ForegroundColor = ConsoleColor.Gray;
Console.SetCursorPosition(30, 10);
Console.Write("Выберите скорость (1-5)");
}
}
}