-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
110 lines (109 loc) · 1.94 KB
/
main.cpp
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
#include "framework.h"
#include "getch.h"
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
int main()
{
game a;
double start(clock());
Init();
double end(clock());
system("clear");
a.print();
cout << "init used time : " << (end - start) / CLOCKS_PER_SEC << " s" << endl;
cout << "Game Start!" << endl;
char b;
int step=0;
while (1)
{
int point = 0;
int c;
c = getch();
if (c == 27 || c == 119 || c == 115 || c == 100 || c == 97 || c == 113)
{
if (c == 27)
{
c = getch();
if (c == 91)
{
c = getch();
if (c > 64 && c < 69)
{
system("clear");
switch (c)
{
case 65:
point = a.up();
break;
case 66:
point = a.down();
break;
case 67:
point = a.right();
break;
case 68:
point = a.left();
break;
}
if (point == -1)
{
a.print();
cout << "Use \'Q\' to Leave Game." << endl;
cout<<"Step: "<<step<<endl;
continue;
}
a.add_points(point);
a.new_block();
a.print();
cout << "Use \'Q\' to Leave Game." << endl;
cout<<"Step: "<<step++<<endl;
if (a.isdead())
break;
}
}
}
else
{
system("clear");
switch (c)
{
case 119:
point = a.up();
break;
case 115:
point = a.down();
break;
case 100:
point = a.right();
break;
case 97:
point = a.left();
break;
case 113:
a.print();
cout << "You quit this game. " << endl;
exit(0);
}
if (point == -1)
{
a.print();
cout << "Use \'Q\' to Leave Game. " << endl;
cout<<"Step: "<<step<<endl;
continue;
}
a.add_points(point);
a.new_block();
a.print();
cout << "Use \'Q\' to Leave Game." << endl;
cout<<"Step: "<<step++<<endl;
if (a.isdead())
break;
}
}
}
system("clear");
a.print();
cout << "Game Over!!" << endl;
return 0;
}