include <stdio.h>
#include <stdlib.h>
int main()
{
int shoot = 0,step = 0;//是否射中。操作次数
int Wide = 5,Long = 10;//初始位置
int x;
int y;
char m;//移动指令
int Rand;
int X = (Rand/15)%10+Rand%10;
int Y = (Rand/7)%10+Rand%10;//随机数,随机X,随机Y
printf("***************************************\n");
printf( "按任意方向键开始(W,A,S,D),空格键射击\n");
printf(" 十步杀一人,千里不留行\n");
printf(" 十步之内,射中靶子\n");
printf("***************************************\n");
for( ; ;){
m = getch();
step++;
if( 'w' == m || 'W' == m)
Wide--;
if( 's' == m || 'S' == m)
Wide++;
if( 'd' == m || 'D' == m)
Long++;
if( 'a' == m || 'A' == m)
Long--;
system("cls");
//发射激光
for( x = 0;x < Wide; x++){
printf("\n");
if( ' ' == m ){
if( Long == Y + 2)
shoot = 1;
for( y = 0;y <= Long; y++)
printf(" ");
printf("|");
}}
printf("\n");
for( y = 0;y < Long; y++)
printf(" ");
system("cls");
//发射激光END
//随机生成一个*
do{
Rand = rand();
if( shoot || step == 10)
X = (Rand/15)%10+Rand%10,
Y = (Rand/7)%10+Rand%10,
step = 0,
shoot = 0;
}while( X >= 15 && Y >= 13);
for( x = 0;x <= X; x++)
printf("\n");
for( y = 0;y <= Y; y++)
printf(" ");
printf("→O←");
//生成O END
//打造飞机
for( x = 0;x < Wide; x++)
printf("\n");
for( y = 0;y < Long; y++)
printf(" ");
printf("_|_\n");
for( y = 0;y+2 < Long; y++)
printf(" ");
printf("╱_n_╲");
//打造飞机END
}
return 0;
}
射击游戏
最新推荐文章于 2023-01-15 11:55:51 发布