java动态小鸟代码 java动态图编程( 三 )


}
void CreatBird( )//建立小鸟的坐标(初始打印输出小鸟的位置)
{Bird-x = 41; Bird-y = 10;}
int CheckYN(Bg *q)//判断游戏结束与否(值为0是要结束 , 为1没有要结束)
{Bg *p = q; int i = 0;
while (++i = 5)
{if (Bird-y23)return 0;
if (Bird-x == p-xBird-y = p-y)return 0;
if ((Bird-x == p-x || Bird-x == p-x + 1 || Bird-x == p-x + 2)Bird-y == p-y)return 0;
if (Bird-x == p-xBird-yp-y + p-l_blank)return 0;
if ((Bird-x == p-x || Bird-x == p-x + 1 || Bird-x == p-x + 2)Bird-y == p-y + p-l_blank)
return 0;
p = p-next;
}
return 1;
}
void Check_Bg(Bg *q)//核查开头的障碍物坐标是否在游戏区内
{Bg *p = q; int i = 0, temp;
while (++i = 5)
{if (p-x-4)p = p-next;
else
{srand((int)time(0));temp = rand();
if (temp % 2 == 0)
{if ((temp % 4 + p-y + Max_blank - Grade)21)p-y = p-y + temp % 4;
else p-y = p-y; p-x = p-pri-x + Distance;
p-l_blank = Max_blank - Grade;
}
else
{if ((p-y - temp % 4)2)p-y = p-y - temp % 4;
else p-y = p-y; p-x = p-pri-x + Distance;
p-l_blank = Max_blank - Grade;
}
}
}
}
void Prt_Bg(Bg *q)//打印输出障碍物(依据其x、y坐标进行相应输出)
{Bg *p = q; int i = 0, k, j;
while (++i = 5)
{if (p-x0p-x = 78)
{for (k = 2; kp-y; k++){Position(p-x + 1, k); printf("■"); printf("■"); printf(" ");}
Position(p-x, p-y);
printf("■"); printf("■"); printf("■"); printf(" ");
Position(p-x, p-y + p-l_blank);
printf("■"); printf("■"); printf("■"); printf(" ");
k = k + p-l_blank + 1;
for (k; k = 23; k++){Position(p-x + 1, k); printf("■"); printf("■"); printf(" ");}
}
p = p-next;
if (p-x == 0)
{for (j = 2; jp-y; j++){Position(p-x + 1, j); printf(" "); printf(" ");}
Position(p-x + 1, p-y);
printf(" "); printf(" "); printf(" ");
Position(p-x + 1, p-y + Max_blank - Grade);
printf(" "); printf(" "); printf(" ");
j = j + Max_blank - Grade + 1;
for (j; j = 22; j++){Position(p-x + 1, j); printf(" "); printf(" ");}
}
}
}
void PrtBird( )//打印输出小鸟
{Position(Bird-x, Bird-y - 1); printf(" ");
Position(Bird-x, Bird-y); printf("Ю");
Position(38, 2); printf("Score:%d", Score);
}
void Loop_Bg(Bg *q)//障碍物x坐标左移,并记录成绩
{Bg *p = q; int i = 0;
while (++i = 5)
{p-x = p-x - 1; p = p-next;
if (Bird-x == p-x)
{Score += 1;
if (Score % 4 == 0Grade4)Grade++;
}
}
}
int main( )
{int i = 0; int t;
while (1)
{
Csh( );PrFK( );CreatBg( );
InsertBg(Bg1);InsertBg(Bg1);InsertBg(Bg1);
CreatBird( );
while (1)
{if (!CheckYN(Bg1))break;
Check_Bg(Bg1);Prt_Bg(Bg1);
PrtBird( );Loop_Bg(Bg1);
Bird-y = Bird-y + 1;
if (GetAsyncKeyState(VK_UP))//按下了向上方向键
{Position(Bird-x, Bird-y - 1);printf(" ");
Bird-y = Bird-y - 4;
}
Sleep(200);//程序延时200毫秒(数值大小决定游戏速度快慢)
i = 0;
}
Position(6, 25);
printf("游戏结束!请输入:0.退出1.重玩");
scanf("%d",t);
if (t==0)break;
system("cls"); Score = 0;
}
return 0;
}
java动态小鸟代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java动态图编程、java动态小鸟代码的信息别忘了在本站进行查找喔 。

推荐阅读