-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartinterface.cpp
More file actions
78 lines (70 loc) · 1.39 KB
/
Copy pathStartinterface.cpp
File metadata and controls
78 lines (70 loc) · 1.39 KB
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
#include "startinterface.h"
#include "controller.h"
#include <windows.h>
// 蛇从左边出现到完全出现的过程
void StartInterface::PrintFirst()
{
for (auto& point : startsnake)
{
point.Print();
Sleep(speed);
}
}
// 蛇从左向右移动的过程
void StartInterface::PrintSecond()
{
// 蛇头需要从10移动到40
for (int i = 10; i != 40; ++i)
{
// 计算蛇头的下一个位置,并将其压入startsnake中,绘制出来,将蛇尾去掉
int j = (((i - 2) % 8) < 4) ? (15 + (i - 2) % 8) : (21 - (i - 2) % 8);
startsnake.emplace_back(Point(i, j));
startsnake.back().Print();
startsnake.front().Clear();
startsnake.pop_front();
Sleep(speed);
}
}
// 蛇从接触右边到消失的过程
void StartInterface::PrintThird()
{
// 当蛇还没消失或文字没移动到指定位置
while (!startsnake.empty() || textsnake.back().GetX() < 33)
{
// 如果蛇还没消失,继续移动
if (!startsnake.empty())
{
startsnake.front().Clear();
startsnake.pop_front();
}
ClearText();
PrintText();
Sleep(speed);
}
}
// 绘制更新位置后的文字
void StartInterface::PrintText()
{
for (auto& point : textsnake)
{
if (point.GetX() >= 0)
point.Print();
}
}
// 清除已有文字
void StartInterface::ClearText()
{
// 清除的同时将文字整体向右移动一格
for (auto& point : textsnake)
{
if (point.GetX() >= 0)
point.Clear();
point.ChangePosition(point.GetX() + 1, point.GetY());
}
}
void StartInterface::Action()
{
PrintFirst();
PrintSecond();
PrintThird();
}