基于Round1的游戏,在其中加入了更多的元素。
欢迎试玩以及提出意见。
#include
#include
#include
#include
#define High 15 //游戏画面尺寸
#define Width 25
#define EnemyNum 5 //敌机个数
int position_x,position_y; //飞机位置
int enemy_x[EnemyNum],enemy_y[EnemyNum]; // 敌机位置
int canvas[High][Width] = {0}; //定义一个二维数组存储游戏界面中的对应元素(0为空格,1为飞机 *,2为子弹|,3为敌机@)
int score; //得分
int BulletWidth; //子弹宽度
int EnemyMoveSpeed; //敌机移动速度
void gotoxy (int x,int y)
{
HANDLE handle = GetStdHandle (STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition (handle,pos);
}
void startup ()
{
int k;
position_x = High-1;
position_y = Width/2;
canvas[position_x][position_y] = 1;
for (k = 0;k < EnemyNum;k++)
{
enemy_x[k] = rand()%2;
enemy_y[k] = rand()%Width;
canvas[enemy_x[k]][enemy_y[k]] = 3;
}
score = 0;
BulletWidth = 0;
EnemyMoveSpeed = 20;
}
void show ()
{
int i,j;
gotoxy (0,0);
for (i = 0;i < High;i++)
{
for (j = 0;j < Width;j++)
{
if (canvas[i][j] == 0)
printf (" ");
else if (canvas[i][j] == 1)
printf ("*");
else if (canvas[i][j] == 2)
printf ("|");
else if (canvas[i][j] == 3)
printf ("@");
}
printf ("\n");
}
printf ("SCORE:%d\n",score);
Sleep (20);
}
void updateWithoutInput ()
{
int i,j,k;
static int speed = 0;
for (i = 0;i < High;i++)
{
for (j = 0;j < Width;j++)
{
if (canvas[i][j] == 2)
{
for (k = 0;k < EnemyNum;k++)
{
if ((i == enemy_x[k]) && (j == enemy_y[k]))
{
score ++;
if ((score % 5 == 0) && (EnemyMoveSpeed > 3))
EnemyMoveSpeed --;
for (BulletWidth = 0;BulletWidth < 2;BulletWidth++)
{
if (score == 10)
BulletWidth ++;
}
canvas[enemy_x[k]][enemy_y[k]] = 0;}
void updateWithInput ()}