1.飞机可以通过键盘移动,发射子弹.
2.显示得分.
3.靶子随机
4.打到靶子加分并换位
#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>
#include<stdlib.h>
#include <conio.h>//_getch()函数
#include<time.h>#define HIGH 20
#define WIDE 50int main()
{srand(time(NULL));//种子int x = 10,y = 20;//飞机的坐标int target;//靶子的横坐标char input;//键盘的输入target = 2 + rand() % 50;//随机值int score=0;//得分while(1)//死循环{input = _getch();//控制边框while (x > HIGH)x--;while (x < 0)x++;while (y > WIDE)y--;while (y < 2)y++;while (target > WIDE)target--;system("cls");//清屏for (int j = 0; j < target; j++)printf(" ");printf("---");//靶子if(input==' ')//射击{printf("\n");for (int i = 1; i < x; i++){for (int j = 0; j < y; j++)printf(" ");printf("|\n");}for (int j = 0; j < y; j++)printf(" ");if (y == target||y==target+2||y==target+1){target = 2 + rand() % 50;score++;}}else//移动{for (int i = 0; i < x; i++)printf("\n");for (int j = 0; j < y; j++)printf(" ");}//打印飞机printf("*\n");for (int j = 0; j < y-2; j++)printf(" ");printf("*****\n");for (int j = 0; j < y - 1; j++)printf(" ");printf("* *\n");//键盘控制飞机if (input == 'w')x--;if (input == 's')x++;if (input == 'a')y--;if (input == 'd')y++;printf("\n");printf("score=%d", score);//显示分数}return 0;
}