forked from hubojing/C-Language-Games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Easy Hit The Plane
109 lines (95 loc) · 1.31 KB
/
Easy Hit The Plane
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
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
int main()
{
int i, j;
int x = 5;
int y = 10;
char input;
int target_x = 5;
int target_y = 5;
int isFired = 0;
int isKilled = 0;
while (1)
{
system("cls");
//如果没击中靶子,就显示靶子
if (isKilled == 0)
{
for (i = 0; i < target_y; ++i)
{
printf("\n");
}
for (i = 0; i < target_x; ++i)
{
printf(" ");
}
printf("+\n");
}
if (isFired == 0)
{
for (i = 0; i < y; ++i)
{
printf("\n");
}
}
else//如果开火,有竖线
{
for (i = 0; i < y; ++i)
{
for (j = 0; j < x; ++j)
{
printf(" ");
}
printf(" |\n");
}
if (x + 2 == target_x)
{
isKilled = 1;
}
isFired = 0;
}
for (j = 0; j < x; ++j)
{
printf(" ");
}
printf(" *\n");
for (i = 0; i < x; ++i)
{
printf(" ");
}
printf("*****\n");
for (i = 0; i < x; ++i)
{
printf(" ");
}
printf(" * *\n");
// scanf("%c", &input);按回车*才会移动
input = getch();//实时移动
//飞机上下左右移动
if (input == 's')
{
y++;
}
if (input == 'w')
{
y--;
}
if (input == 'a')
{
x--;
}
if (input == 'd')
{
x++;
}
//按空格射击
if (input == ' ')
{
isFired = 1;
}
}
//system("pause");
}