-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartAndEndBase.cs
60 lines (56 loc) · 1.79 KB
/
StartAndEndBase.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
namespace Snake;
public abstract class StartAndEndBase: I_Update
{
int input=1;
protected string title="Snake";
protected string option1 = "开始游戏";
protected string option2 = "退出游戏";
public abstract void ChangeStage();
public void Update()
{
for (int i = 0; i < ObjectData.count+1; i++)
{
Console.SetCursorPosition(ObjectData.Snake[i].GetX(),ObjectData.Snake[i].GetY());
Console.Write(" ");
}
Console.SetCursorPosition(Console.BufferWidth/2, 5);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write(title);
Console.SetCursorPosition(Console.BufferWidth/2,8);
Console.ForegroundColor = (input==1) ? ConsoleColor.Green : ConsoleColor.White;
Console.Write(option1);
Console.SetCursorPosition(Console.BufferWidth/2,11);
Console.ForegroundColor = (input==2) ? ConsoleColor.Green : ConsoleColor.White;
Console.Write(option2);
ChangeOption();
}
public void ChangeOption()
{
ConsoleKey key = Console.ReadKey(true).Key;
switch (key)
{
case ConsoleKey.UpArrow:
{
if (input == 2)
input = 1;
break;
}
case ConsoleKey.DownArrow:
{
if (input == 1)
{
input = 2;
}
break;
}
case ConsoleKey.Spacebar:
{
if(input==1)
ChangeStage();//切换场景
else if(input==2)
Environment.Exit(0);//离开游戏
break;
}
}
}
}