今天来介绍飞机大战小游戏,首先我们要出现一个飞机并让它移动,如下所示:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h> //使用输入函数gwtch()不用回车就可以得到控制符
int main()
{
int i, j;
int x = 5, y = 10;
char input;
while (1)
{
system("cls"); //清屏函数
for (i = 0; i < x; i++)
printf("\n");
for (j = 0; j < y; j++)
printf(" ");
printf(" * \n"); //输入复杂的飞机图案
for (j = 0; j < y; j++)
printf(" ");
printf(" ***** \n");
for (j = 0; j < y; j++)
printf(" ");
printf(" * * \n");
if (_kbhit()) //判断是否有输入
{
input = _getch(); //根据用户的不同输入来移动不必输入回车
if (input == 'a')
x++; //下移
if (input == 'b')
x--; //上移
if (input == 'c') //右移
y++;
if (input == 'd