游戏总集!!!
1.推方块
include [HTML_REMOVED]
include [HTML_REMOVED]
include[HTML_REMOVED]
int map[9][11] = {
{0,1,1,1,1,1,1,1,1,1,0}, //0代表空地
{0,1,0,0,0,1,0,0,0,1,0}, //1代表墙
{0,1,0,4,4,4,4,4,0,1,0}, //3代表目的地
{0,1,0,4,0,4,0,4,0,1,1}, //4代表箱子
{0,1,0,0,0,0,0,0,4,0,1}, //5代表人
{1,1,0,1,1,1,1,0,4,0,1},
{1,0,8,3,3,3,3,1,0,0,1}, //2 3 4 5 6 7 8 9 1 0
{1,0,3,3,3,3,3,0,0,1,1},
{1,1,1,1,1,1,1,1,1,1,0} };
//绘制地图 //二维数组+switch()
void DrawMap()
{
//遍历二维数组 //0 打印空格 //1 墙 //3 目的地 //什么结构?
for (int i = 0; i < 9; i)
{
for (int j = 0; j < 11; j)
{
//if else switch
switch (map[i][j])
{
case 0:
printf(” “);
break;
case 1:
printf(“■”);
break;
case 3:
printf(“☆”);
break;
case 4:
printf(“□”);
break;
case 5:
printf(“♀”); //5人
break;
case 7: //4 + 3 箱子在目的地中
printf(“★”);
break;
case 8: // 5 + 3 人在目的地当中 人?
printf(“♀”);
break;
}
}
printf(“\n”);
}
}
void PlayGame()
{
int r, c; //人的下标 //
for (int i = 0; i < 9; i)
{
for (int j = 0; j < 11; j)
{
if (map[i][j] == 5||map[i][j]==8) //i j 人的下标?
{
r = i;
c = j;
}
}
}
char ch; //字符变量
ch = getch(); //键盘的输入保存到字符中
// getch() getchar() 接收键盘字符
// getch()直接接收 不显示回文 getchar()显示回文可以修改 enter键结束
//根据不同的按键 改变不同的值. 分支.
switch (ch)
{
case 'W': //W A S D方向 72 80 75 77 虚拟键值 ascii windowVK_UP VK_TAB VK_RETUNE
case 'w':
case 72:
if (map[r - 1][c] == 0|| map[r - 1][c] == 3)
{
map[r - 1][c] += 5;
map[r][c] -= 5;
}
else if (map[r - 1][c] == 4 || map[r - 1][c] == 7)
{
if (map[r - 2][c] == 0 || map[r - 2][c] == 3)
{
map[r - 2][c] += 4;
map[r - 1][c] += 1;
map[r][c] -= 5;
}
}
break;
case 'S': //enter按键的作用 确认 返回
case 's':
case 80:
if (map[r + 1][c] == 0 || map[r + 1][c] == 3)
{
map[r + 1][c] += 5;
map[r][c] -= 5;
}
else if (map[r + 1][c] == 4 || map[r+ 1][c] == 7)
{
if (map[r + 2][c] == 0 || map[r + 2][c] == 3)
{
map[r + 2][c] += 4;
map[r + 1][c] += 1;
map[r][c] -= 5;
}
}
break;
case 'A':
case 'a':
case 75:
if (map[r ][c - 1] == 0 || map[r ][c - 1] == 3)
{
map[r ][c - 1] += 5;
map[r][c] -= 5;
}
else if (map[r][c - 1] == 4 || map[r][c - 1] == 7)
{
if (map[r ][c - 2] == 0 || map[r ][c - 2] == 3)
{
map[r ][c - 2] += 4;
map[r ][c - 1] += 1;
map[r][c] -= 5;
}
}
break;
case 'D':
case 'd':
case 77:
if (map[r][c + 1] == 0 || map[r][c + 1] == 3)
{
map[r][c + 1] += 5;
map[r][c] -= 5;
}
else if (map[r][c + 1] == 4 || map[r][c + 1] == 7)
{
if (map[r][c + 2] == 0 || map[r][c + 2] == 3)
{
map[r][c + 2] += 4;
map[r][c + 1] += 1;
map[r][c] -= 5;
}
}
break;
}
}
//
int main() //主函数
{
while (1)
{
system(“cls”);
DrawMap();
PlayGame();
}
return 0;
}
2.贪吃蛇
include[HTML_REMOVED]
include[HTML_REMOVED]//该函数主要可以提供一些函数与符号常量
include[HTML_REMOVED]//提供大量基于迭代器的非成员模版函数
include[HTML_REMOVED]//其中定义了通过控制台进行数据输入和数据输出的函数
include[HTML_REMOVED]//日期和时间头文件
include[HTML_REMOVED]
define ML 100
using namespace std;
class Snake //声明一个类Snake
{
public:
int head,tail,body[200],length;
};
Snake T; //定义一个对象T
int map[100][100]; //定义一个整形的二维数组做标记用
char maze[100][100]; //根据map数组的不同数值显示不同符号,以此绘图
void init() //初始化函数
{
T.head=3;
T.tail=0;
// T.length=0;
memset(T.body,0,sizeof(T.body));
}
int card[800];
char order; //接收指令
int getnum()
{
static int n=0;
n++;
n=n%800;
return card[n];
}
void up()
{
int sum,i;
sum=T.body[(T.head-1+ML)%ML]-100;
if(map[sum/100][sum%100]==1)
{
T.length;
T.body[T.head]=sum;
T.head%=ML;
map[sum/100][sum%100]=0;
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
map[sum/100][sum%100]=-1;
i;
i%=ML;
}
while(1)
{
sum=getnum();
if(map[sum/100][sum%100]==0)
{
map[sum/100][sum%100]=1;
break;
}
}
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
map[sum/100][sum%100]=0;
i;
i%=ML;
}
}
else
{
T.body[T.head]=sum;
T.head%=ML;
T.tail=(T.tail)%ML;
}
}
void down()
{
int sum,i;
sum=T.body[(T.head-1+ML)%ML]+100;
if(map[sum/100][sum%100]==1)
{
T.length;
T.body[T.head]=sum;
T.head%=ML;
map[sum/100][sum%100]=0;
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
map[sum/100][sum%100]=-1;
i;
i%=ML;
}
while(1)
{
sum=getnum();
if(map[sum/100][sum%100]==0)
{
map[sum/100][sum%100]=1;
break;
}
}
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
map[sum/100][sum%100]=0;
i;
i%=ML;
}
}
else
{
T.body[T.head]=sum;
T.head%=ML;
T.tail=(T.tail)%ML;
}
}
void right()
{
int sum,i;
sum=T.body[(T.head-1+ML)%ML]+1;
if(map[sum/100][sum%100]==1)
{
T.length;
T.body[T.head]=sum;
T.head%=ML;
map[sum/100][sum%100]=0;
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
map[sum/100][sum%100]=-1;
i;
i%=ML;
}
while(1)
{
sum=getnum();
if(map[sum/100][sum%100]==0)
{
map[sum/100][sum%100]=1;
break;
}
}
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
map[sum/100][sum%100]=0;
i;
i%=ML;
}
}
else
{
T.body[T.head]=sum;
T.head%=ML;
T.tail=(T.tail)%ML;
}
}
void left()
{
int sum,i;
sum=T.body[(T.head-1+ML)%ML]-1;
if(map[sum/100][sum%100]==1)
{
T.length;
T.body[T.head]=sum;
T.head%=ML;
map[sum/100][sum%100]=0;
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
map[sum/100][sum%100]=-1;
i;
i%=ML;
}
while(1)
{
sum=getnum();
if(map[sum/100][sum%100]==0)
{
map[sum/100][sum%100]=1;
break;
}
}
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
map[sum/100][sum%100]=0;
i;
i%=ML;
}
}
else
{
T.body[T.head]=sum;
T.head%=ML;
T.tail=(T.tail)%ML;
}
}
int main()
{
memset(map,0,sizeof(map));
memset(maze,’ ‘,sizeof(maze));
int i,j,sum=0,k=0,temp;
for(i=1;i<20;i)
for(j=1;j<40;j)
{
card[k]=i100+j;
}
srand(time(0));
temp=rand()%10+1;
while(temp–)
random_shuffle(card,card+1939);
for(i=0;i<=40;i)
map[i][0]=map[20][i]=map[i][40]=map[0][i]=-1;
init();
T.length=1;
T.body[T.head++]=101;
T.head%=ML;
sum=getnum();
map[sum/100][sum%100]=1;
char jud='d';
int TM=300,start;
while(1)
{
(TM>100)?(TM=300-T.length*60):(TM=50);
start=clock();
//利用临时无穷循环制作刷屏时间
while(clock()-start<=TM && !kbhit()) //kbhit() 检查当前是否有键盘输入,若有则返回一个非0值,否则返回0
{
;
}
if(kbhit()&&(order=getch(),order=='w'||order=='s'||order=='a'||order=='d'))
{
sum=T.body[(T.head-1+ML)%ML];
system("CLS");
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
map[temp/100][temp%100]=-1;
i++;
i%=ML;
}
if(order=='w')
{
jud=order;
//cout<<"-->w\n";
if(map[sum/100-1][sum%100]!=-1)
{
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
up();
}
else
{
system("CLS");
cout<<"============================================"<<endl;
cout<<" 很遗憾,你输了!!!最后得分为:"<<T.length*10-10<<endl;
cout<<"============================================"<<endl;
break;
}
}
else if(order=='a')
{
jud=order;
//cout<<"-->a\n";
if(map[sum/100][sum%100-1]!=-1)
{
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
left();
}
else
{
system("CLS");
cout<<"============================================"<<endl;
cout<<" 很遗憾,你输了!!!最后得分为:"<<T.length*10-10<<endl;
cout<<"============================================"<<endl;
break;
}
}
else if (order=='s')
{
jud=order;
//cout<<"-->s\n";
if(map[sum/100+1][sum%100]!=-1)
{
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
down();
}
else
{
system("CLS");
cout<<"============================================"<<endl;
cout<<" 很遗憾,你输了!!!最后得分为:"<<T.length*10-10<<endl;
cout<<"============================================"<<endl;
break;
}
}
else if(order=='d')
{
jud=order;
//cout<<"-->d\n";
if(map[sum/100][sum%100+1]!=-1)
{
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
right();
}
else
{
system("CLS");
cout<<"============================================"<<endl;
cout<<" 很遗憾,你输了!!!最后得分为:"<<T.length*10-10<<endl;
cout<<"============================================"<<endl;
break;
}
}
memset(maze,' ',sizeof(maze));
for(i=0;i<=20;i++)
for(j=0;j<=40;j++)
{
if(map[i][j]==-1)
maze[i][j]='#';
else if(map[i][j]==1)
maze[i][j]='o';
}
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
maze[sum/100][sum%100]='*';
++i;
i%=ML;
}
sum=T.body[(i-1+ML)%ML];
maze[sum/100][sum%100]='@';
cout<<"游戏操作: ↑:w ↓:s ←:a →:d"<<endl;
cout<<"score: "<<T.length*10-10<<endl;
for(i=0;i<=20;i++)
{
for(j=0;j<=40;j++)
{
cout<<maze[i][j];
}
cout<<endl;
}
}
else
{
sum=T.body[(T.head-1+ML)%ML];
system("CLS");
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
map[temp/100][temp%100]=-1;
i++;
i%=ML;
}
if(jud=='w')
{
//cout<<"-->w\n";
if(map[sum/100-1][sum%100]!=-1)
{
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
up();
}
else
{
system("CLS");
cout<<"============================================"<<endl;
cout<<" 很遗憾,你输了!!!最后得分为:"<<T.length*10-10<<endl;
cout<<"============================================"<<endl;
break;
}
}
else if(jud=='a')
{
//cout<<"-->a\n";
if(map[sum/100][sum%100-1]!=-1)
{
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
left();
}
else
{
system("CLS");
cout<<"============================================"<<endl;
cout<<" 很遗憾,你输了!!!最后得分为:"<<T.length*10-10<<endl;
cout<<"============================================"<<endl;
break;
}
}
else if (jud=='s')
{
//cout<<"-->s\n";
if(map[sum/100+1][sum%100]!=-1)
{
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
down();
}
else
{
system("CLS");
cout<<"============================================"<<endl;
cout<<" 很遗憾,你输了!!!最后得分为:"<<T.length*10-10<<endl;
cout<<"============================================"<<endl;
break;
}
}
else if(jud=='d')
{
//cout<<"-->d\n";
if(map[sum/100][sum%100+1]!=-1)
{
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
right();
}
else
{
system("CLS");
cout<<"============================================"<<endl;
cout<<" 很遗憾,你输了!!!最后得分为:"<<T.length*10-10<<endl;
cout<<"============================================"<<endl;
break;
}
}
if(T.length>=20){
system("CLS");
cout<<"============================================"<<endl;
cout<<" 恭喜,过关!!! "<<endl;
cout<<"============================================"<<endl;
break;
}
memset(maze,' ',sizeof(maze));
for(i=0;i<=20;i++)
for(j=0;j<=40;j++)
{
if(map[i][j]==-1)
maze[i][j]='#';
else if(map[i][j]==1)
maze[i][j]='o';
}
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
maze[sum/100][sum%100]='*';
++i;
i%=ML;
}
sum=T.body[(i-1+ML)%ML];
maze[sum/100][sum%100]='@';
cout<<"游戏操作: ↑:w ↓:s ←:a →:d"<<endl;
cout<<"score: "<<T.length*10-10<<endl;
for(i=0;i<=20;i++)
{
for(j=0;j<=40;j++)
{
cout<<maze[i][j];
}
cout<<endl;
}
}
}
system("pause");
return 0;
}
3.五子棋
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
define MAXIMUS 15 //定义棋盘大小
int p[MAXIMUS][MAXIMUS];//存储对局信息
char buff[MAXIMUS2+1][MAXIMUS4+3];//输出缓冲器
int Cx,Cy;//当前光标位置
int Now;//当前走子的玩家,1代表黑,2代表白
int wl,wp;//当前写入缓冲器的列数和行数位置
char* showText;//在棋盘中央显示的文字信息
int count;//回合数
char Copy(char strDest,const char strSrc) { //修改过的字符串复制函数,会忽略末端的\0
char strDestCopy = strDest;
while (strSrc!=’\0’) {
strDest=*strSrc;
}
return strDestCopy;
}
void Initialize() { //初始化一个对局函数
int i,j;//循环变量
showText=”“;//重置显示信息
count=0;//回合数归零
for(i=0; i[HTML_REMOVED]0&&p[Cx][Cy-i]==Now)w;
else break;//向上检查
if(w>=5)return Now;//若果达到5个则判断当前走子玩家为赢家
for(i=1; i<5; i)if(Cx+i[HTML_REMOVED]0&&p[Cx-i][Cy]==Now)x;
else break;//向左检查
if(x>=5)return Now;//若果达到5个则判断当前走子玩家为赢家
for(i=1; i<5; i)if(Cx+i[HTML_REMOVED]0&&Cy-i>0&&p[Cx-i][Cy-i]==Now)y;
else break;//向左上检查
if(y>=5)return Now;//若果达到5个则判断当前走子玩家为赢家
for(i=1; i<5; i)if(Cx+i[HTML_REMOVED]0&&p[Cx+i][Cy-i]==Now)z;
else break;//向右上检查
for(i=1; i<5; i)if(Cx-i>0&&Cy+i[HTML_REMOVED]=5)return Now;//若果达到5个则判断当前走子玩家为赢家
return 0;//若没有检查到五连珠,则返回0表示还没有玩家达成胜利
}
int RunGame() { //进行整个对局,返回赢家信息(虽然有用上)
int input;//输入变量
int victor;//赢家信息
Initialize();//初始化对局
while(1) { //开始无限回合的死循环,直到出现胜利跳出
Print();//打印棋盘
input=getch();//等待键盘按下一个字符
if(input==27) { //如果是ESC则退出程序
exit(0);
} else if(input==0x20) { //如果是空格则开始走子
if(Put()) { //如果走子成功则判断胜负
victor=Check();
Now=3-Now;//轮换当前走子玩家
count;
if(victor==1) { //如果黑方达到胜利,显示提示文字并等待一次按键,返回胜利信息
showText=”黑方获得了胜利!”;
Print();
if(getch()==0xE0) {
getch();
}
return Now;
} else if(victor==2) { //如果白方达到胜利,显示提示文字并等待一次按键,返回胜利信息
showText=”白方获得了胜利!”;
Display();
if(getch()==0xE0) {
getch();
}
return Now;
} else if(count==MAXIMUS*MAXIMUS) { //如果回合数达到了棋盘总量,即棋盘充满,即为平局
showText=”平局!”;
Display();
if(getch()==0xE0) {
getch();
}
return 0;
}
}
} else if(input==0xE0) { //如果按下的是方向键,会填充两次输入,第一次为0xE0表示按下的是控制键
input=getch();//获得第二次输入信息
switch(input) { //判断方向键方向并移动光标位置
case 0x4B://
Cx–;
break;
case 0x48:
Cy–;
break;
case 0x4D:
Cx;
break;
case 0x50:
Cy++;
break;
}
if(Cx<0)Cx=MAXIMUS-1;//如果光标位置越界则移动到对侧
if(Cy<0)Cy=MAXIMUS-1;
if(Cx>MAXIMUS-1)Cx=0;
if(Cy>MAXIMUS-1)Cy=0;
}
}
}
int main() { //主函数
system(“title 简易五子棋 ——Etsnarl制作”);//设置标题
system(“mode con cols=63 lines=32”);//设置窗口大小
system(“color A1”);//设置颜色
while(1) { //循环执行游戏
RunGame();
}
}
4.小鸟
include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
/*函数变量声明*/
define PR_Box printf(“■”)
define PR_Gold printf(“★”)
define PR_Ag printf(“☆”)
define PR_FBird printf(“Ю”)
define PR_DBird printf(“Ф”)
define PR_Land printf(“┳┳┯”)
define PR_Bg_TL printf(“╔”)
define PR_Bg_TR printf(“╗”)
define PR_Bg_DL printf(“╚”)
define PR_Bg_DR printf(“╝”)
define PR_Bg_X printf(“═”)
define PR_Bg_Y printf(“║”)
define PR_Blank printf(” “);
int Grade = 1, C_Gold = 0, C_Ag = 0, Score = 0, Delay_time = 1000, Max_blank = 9, Distance = 18;
struct Birds
{
int x, y;
int condition;
};
Birds Bird = (Birds)malloc(sizeof(Birds));
struct Bg
{
int x, y;
int l_blank;
int reward[9];
Bg pri;
Bg next;
};
Bg Bg1 = new Bg[sizeof(Bg)];
void Position(int x, int y)
{
COORD pos = { x - 1, y - 1 };
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
void CreatBird()
{
Bird->x = 41;
Bird->y = 10;
Bird->condition = 0;
}
void CreatBg()
{
Bg Bg2 = (Bg)malloc(sizeof(Bg));
Bg1->x = 90; Bg1->y = 8;
Bg2->x = Bg1->x + Distance; Bg2->y = 9;
Bg1->l_blank = Max_blank - Grade;
Bg2->l_blank = Max_blank - Grade;
Bg1->next = Bg2;
Bg1->pri = Bg2;
Bg2->next = Bg1;
Bg2->pri = Bg1;
}
void InsertBg(Bg p)
{
int temp;
Bg Bgs = (Bg)malloc(sizeof(Bg));
Bgs->x = p->pri->x + Distance;
Bgs->l_blank = Max_blank - Grade;
srand((int)time(0));
temp = rand();
if (temp % 2 == 0)//
{
if ((temp % 4 + p->pri->y + Max_blank - Grade)<21)
Bgs->y = p->pri->y + temp % 4;
else
Bgs->y = p->pri->y;
}
else
{
if ((p->pri->y - temp % 4)>2)
Bgs->y = p->pri->y - temp % 4;
else
Bgs->y = p->pri->y;
}
Bgs->pri = p->pri;
Bgs->next = p;
p->pri->next = Bgs;
p->pri = Bgs;
}
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 Loop_Bg(Bg q)
{
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 == 0 && Grade<4)
Grade;
}
}
}
void Prt_Bg(Bg q)
{
Bg p = q; int i = 0, k, j;
while (i <= 5)
{
if (p->x>0 && p->x <= 78)
{
for (k = 2; k[HTML_REMOVED]y; k)
{
Position(p->x + 1, k);
PR_Box; PR_Box; PR_Blank
}
Position(p->x, p->y);
PR_Box; PR_Box; PR_Box; PR_Blank;
Position(p->x, p->y + p->l_blank);
PR_Box; PR_Box; PR_Box; PR_Blank;
k = k + p->l_blank + 1;
for (k; k <= 22; k)
{
Position(p->x + 1, k);
PR_Box; PR_Box; PR_Blank;
}
Position(p->x, 23);
for (k = 1; k[HTML_REMOVED]next;
if (p->x == 0)
{
for (j = 2; j[HTML_REMOVED]y; j)
{
Position(p->x + 1, j);
PR_Blank; PR_Blank;
}
Position(p->x + 1, p->y);
PR_Blank; PR_Blank; PR_Blank;
Position(p->x + 1, p->y + Max_blank - Grade);
PR_Blank; PR_Blank; PR_Blank;
j = j + Max_blank - Grade + 1;
for (j; j <= 22; j)
{
Position(p->x + 1, j);
PR_Blank; PR_Blank;
}
}
}
}
void PrtBg()
{
int i;
Position(1, 1); PR_Bg_TL;
Position(79, 1); PR_Bg_TR;
Position(1, 24); PR_Bg_DL;
Position(79, 24); PR_Bg_DR;
for (i = 3; i <= 78; i += 2)
{
Position(i, 1); PR_Bg_X;
Position(i, 24); PR_Bg_X;
}
/*for(i=2;i<=23;i)
{ Position(1,i);PR_Bg_Y;printf(“%d”,i-1);
Position(79,i);PR_Bg_Y;
}/
}
void PrtBird()
{
Position(Bird->x, Bird->y - 1);
PR_Blank;
Position(Bird->x, Bird->y);
PR_FBird;
Position(38, 2);
printf(“Score:%d”, Score);
}
int CheckYN(Bg q)
{
Bg *p = q; int i = 0;
while (i <= 5)
{
if (Bird->y>23)
return 0;
if (Bird->x == p->x&&Bird->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->x&&Bird->y>p->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 Prtfirst()
{
printf(“══════════════════════════════════════\n”);
printf(” ■■ ■■\n”);
printf(” ■■ ■■\n”);
printf(” ■■ ■■ C语言版 Flappy Bird\n”);
printf(” ■■ ■■ 瞎搞人:yyposs\n”);
printf(” ■■ ■■ 瞎搞日期:2014.2\n”);
printf(” ■■ ■■ 耗时:4小时\n”);
printf(” ■■■ ■■ 游戏说明:\n”);
printf(” ■■ 1-按上箭头使鸟起飞\n”);
printf(” ■■ 2-等级越高,难度越大!\n”);
printf(” Ю123 ■■■\n”);
printf(“\n”);
printf(” ■■■ 欢迎各路大神与我探讨C、\nC、VB、PHP、C#\n”);
printf(” ■■\n”);
printf(” ■■\n”);
printf(” ■■ ■■■ \n”);
printf(” ■■ ■■\n”);
printf(” ■■ Ф ■■\n”);
printf(” ■■ ■■\n”);
printf(” ■■ ■■\n”);
printf(” ■■ ■■\n”);
printf(” ■■ ■■\n”);
printf(” ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳\n”);
system(“pause”);
Position(1, 1);
int i = 0;
while (i<40 * 25)
PR_Blank;
}
int main()
{
int i = 0; char ch;
Prtfirst();
PrtBg();
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);
PR_Blank;
Bird->y = Bird->y - 4;
}
while (i++<500);
{
Sleep(100);
}
i = 0;
}
Position(38, 10);
printf(“You Lost!”);
Position(1, 25);
system(“pause”);
return 0;
}
关注我,下期更精彩