c语言游戏编程,下落的小鸟 求代码

作者&投稿:穆于 (若有异议请与网页底部的电邮联系)
求一个用C语言编写的小游戏代码~

#include
#include
#include



/////////////////////////////////////////////
// 定义常量、枚举量、结构体、全局变量
/////////////////////////////////////////////

#defineWIDTH10// 游戏区宽度
#defineHEIGHT22// 游戏区高度
#defineSIZE20// 每个游戏区单位的实际像素

// 定义操作类型
enum CMD
{
CMD_ROTATE,// 方块旋转
CMD_LEFT, CMD_RIGHT, CMD_DOWN,// 方块左、右、下移动
CMD_SINK,// 方块沉底
CMD_QUIT// 退出游戏
};

// 定义绘制方块的方法
enum DRAW
{
SHOW,// 显示方块
HIDE,// 隐藏方块
FIX// 固定方块
};

// 定义七种俄罗斯方块
struct BLOCK
{
WORD dir[4];// 方块的四个旋转状态
COLORREF color;// 方块的颜色
}g_Blocks[7] = {{0x0F00, 0x4444, 0x0F00, 0x4444, RED},// I
{0x0660, 0x0660, 0x0660, 0x0660, BLUE},// 口
{0x4460, 0x02E0, 0x0622, 0x0740, MAGENTA},// L
{0x2260, 0x0E20, 0x0644, 0x0470, YELLOW},// 反L
{0x0C60, 0x2640, 0x0C60, 0x2640, CYAN},// Z
{0x0360, 0x4620, 0x0360, 0x4620, GREEN},// 反Z
{0x4E00, 0x4C40, 0x0E40, 0x4640, BROWN}};// T

// 定义当前方块、下一个方块的信息
struct BLOCKINFO
{
byte id;// 方块 ID
char x, y;// 方块在游戏区中的坐标
byte dir:2;// 方向
}g_CurBlock, g_NextBlock;

// 定义游戏区
BYTE g_World[WIDTH][HEIGHT] = {0};



/////////////////////////////////////////////
// 函数声明
/////////////////////////////////////////////

void Init();// 初始化游戏
void Quit();// 退出游戏
void NewGame();// 开始新游戏
void GameOver();// 结束游戏
CMD GetCmd();// 获取控制命令
void DispatchCmd(CMD _cmd);// 分发控制命令
void NewBlock();// 生成新的方块
bool CheckBlock(BLOCKINFO _block);// 检测指定方块是否可以放下
void DrawBlock(BLOCKINFO _block, DRAW _draw = SHOW);// 画方块
void OnRotate();// 旋转方块
void OnLeft();// 左移方块
void OnRight();// 右移方块
void OnDown();// 下移方块
void OnSink();// 沉底方块



/////////////////////////////////////////////
// 函数定义
/////////////////////////////////////////////

// 主函数
void main()
{
Init();

CMD c;
while(true)
{
c = GetCmd();
DispatchCmd(c);

// 按退出时,显示对话框咨询用户是否退出
if (c == CMD_QUIT)
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("您要退出游戏吗?"), _T("提醒"), MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
Quit();
}
}
}


// 初始化游戏
void Init()
{
initgraph(640, 480);
srand((unsigned)time(NULL));

// 显示操作说明
setfont(14, 0, _T("宋体"));
outtextxy(20, 330, _T("操作说明"));
outtextxy(20, 350, _T("上:旋转"));
outtextxy(20, 370, _T("左:左移"));
outtextxy(20, 390, _T("右:右移"));
outtextxy(20, 410, _T("下:下移"));
outtextxy(20, 430, _T("空格:沉底"));
outtextxy(20, 450, _T("ESC:退出"));

// 设置坐标原点
setorigin(220, 20);

// 绘制游戏区边界
rectangle(-1, -1, WIDTH * SIZE, HEIGHT * SIZE);
rectangle((WIDTH + 1) * SIZE - 1, -1, (WIDTH + 5) * SIZE, 4 * SIZE);

// 开始新游戏
NewGame();
}


// 退出游戏
void Quit()
{
closegraph();
exit(0);
}


// 开始新游戏
void NewGame()
{
// 清空游戏区
setfillstyle(BLACK);
bar(0, 0, WIDTH * SIZE - 1, HEIGHT * SIZE - 1);
ZeroMemory(g_World, WIDTH * HEIGHT);

// 生成下一个方块
g_NextBlock.id = rand() % 7;
g_NextBlock.dir = rand() % 4;
g_NextBlock.x = WIDTH + 1;
g_NextBlock.y = HEIGHT - 1;

// 获取新方块
NewBlock();
}


// 结束游戏
void GameOver()
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("游戏结束。
您想重新来一局吗?"), _T("游戏结束"), MB_YESNO | MB_ICONQUESTION) == IDYES)
NewGame();
else
Quit();
}


// 获取控制命令
DWORD m_oldtime;
CMD GetCmd()
{
// 获取控制值
while(true)
{
// 如果超时,自动下落一格
DWORD newtime = GetTickCount();
if (newtime - m_oldtime >= 500)
{
m_oldtime = newtime;
return CMD_DOWN;
}

// 如果有按键,返回按键对应的功能
if (kbhit())
{
switch(getch())
{
case 'w':
case 'W':return CMD_ROTATE;
case 'a':
case 'A':return CMD_LEFT;
case 'd':
case 'D':return CMD_RIGHT;
case 's':
case 'S':return CMD_DOWN;
case 27:return CMD_QUIT;
case ' ':return CMD_SINK;
case 0:
case 0xE0:
switch(getch())
{
case 72:return CMD_ROTATE;
case 75:return CMD_LEFT;
case 77:return CMD_RIGHT;
case 80:return CMD_DOWN;
}
}
}

// 延时 (降低 CPU 占用率)
Sleep(20);
}
}


// 分发控制命令
void DispatchCmd(CMD _cmd)
{
switch(_cmd)
{
case CMD_ROTATE:OnRotate();break;
case CMD_LEFT:OnLeft();break;
case CMD_RIGHT:OnRight();break;
case CMD_DOWN:OnDown();break;
case CMD_SINK:OnSink();break;
case CMD_QUIT:break;
}
}


// 生成新的方块
void NewBlock()
{
g_CurBlock.id = g_NextBlock.id,g_NextBlock.id = rand() % 7;
g_CurBlock.dir = g_NextBlock.dir,g_NextBlock.dir = rand() % 4;
g_CurBlock.x = (WIDTH - 4) / 2;
g_CurBlock.y = HEIGHT + 2;

// 下移新方块直到有局部显示
WORD c = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
while((c & 0xF) == 0)
{
g_CurBlock.y--;
c >>= 4;
}

// 绘制新方块
DrawBlock(g_CurBlock);

// 绘制下一个方块
setfillstyle(BLACK);
bar((WIDTH + 1) * SIZE, 0, (WIDTH + 5) * SIZE - 1, 4 * SIZE - 1);
DrawBlock(g_NextBlock);

// 设置计时器,用于判断自动下落
m_oldtime = GetTickCount();
}


// 画方块
void DrawBlock(BLOCKINFO _block, DRAW _draw)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;

int color = BLACK;
switch(_draw)
{
case SHOW: color = g_Blocks[_block.id].color; break;
case HIDE: color = BLACK;break;
case FIX: color = g_Blocks[_block.id].color / 3; break;
}
setfillstyle(color);

for(int i=0; i<16; i++)
{
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if (y < HEIGHT)
{
if (_draw != HIDE)
bar3d(x * SIZE + 2, (HEIGHT - y - 1) * SIZE + 2, (x + 1) * SIZE - 4, (HEIGHT - y) * SIZE - 4, 3, true);
else
bar(x * SIZE, (HEIGHT - y - 1) * SIZE, (x + 1) * SIZE - 1, (HEIGHT - y) * SIZE - 1);
}
}
b <<= 1;
}
}


// 检测指定方块是否可以放下
bool CheckBlock(BLOCKINFO _block)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;

for(int i=0; i<16; i++)
{
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if ((x = WIDTH) || (y < 0))
return false;

if ((y < HEIGHT) && (g_World[x][y]))
return false;
}
b <<= 1;
}

return true;
}


// 旋转方块
void OnRotate()
{
// 获取可以旋转的 x 偏移量
int dx;
BLOCKINFO tmp = g_CurBlock;
tmp.dir++;if (CheckBlock(tmp)){dx = 0;goto rotate;}
tmp.x = g_CurBlock.x - 1;if (CheckBlock(tmp)){dx = -1;goto rotate;}
tmp.x = g_CurBlock.x + 1;if (CheckBlock(tmp)){dx = 1;goto rotate;}
tmp.x = g_CurBlock.x - 2;if (CheckBlock(tmp)){dx = -2;goto rotate;}
tmp.x = g_CurBlock.x + 2;if (CheckBlock(tmp)){dx = 2;goto rotate;}
return;

rotate:
// 旋转
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.dir++;
g_CurBlock.x += dx;
DrawBlock(g_CurBlock);
}


// 左移方块
void OnLeft()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x--;
DrawBlock(g_CurBlock);
}
}


// 右移方块
void OnRight()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x++;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x++;
DrawBlock(g_CurBlock);
}
}


// 下移方块
void OnDown()
{
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.y--;
DrawBlock(g_CurBlock);
}
else
OnSink();// 不可下移时,执行“沉底方块”操作
}


// 沉底方块
void OnSink()
{
int i, x, y;

// 连续下移方块
DrawBlock(g_CurBlock, HIDE);
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
while (CheckBlock(tmp))
{
g_CurBlock.y--;
tmp.y--;
}
DrawBlock(g_CurBlock, FIX);

// 固定方块在游戏区
WORD b = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
for(i = 0; i < 16; i++)
{
if (b & 0x8000)
{
if (g_CurBlock.y - i / 4 >= HEIGHT)
{// 如果方块的固定位置超出高度,结束游戏
GameOver();
return;
}
else
g_World[g_CurBlock.x + i % 4][g_CurBlock.y - i / 4] = 1;
}

b <<= 1;
}

// 检查是否需要消掉行,并标记
int row[4] = {0};
bool bRow = false;
for(y = g_CurBlock.y; y >= max(g_CurBlock.y - 3, 0); y--)
{
i = 0;
for(x = 0; x < WIDTH; x++)
if (g_World[x][y] == 1)
i++;
if (i == WIDTH)
{
bRow = true;
row[g_CurBlock.y - y] = 1;
setfillstyle(WHITE, DIAGCROSS2_FILL);
bar(0, (HEIGHT - y - 1) * SIZE + SIZE / 2 - 2, WIDTH * SIZE - 1, (HEIGHT - y - 1) * SIZE + SIZE / 2 + 2);
}
}

if (bRow)
{
// 延时 200 毫秒
Sleep(200);

// 擦掉刚才标记的行
IMAGE img;
for(i = 0; i < 4; i++)
{
if (row[i])
{
for(y = g_CurBlock.y - i + 1; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
{
g_World[x][y - 1] = g_World[x][y];
g_World[x][y] = 0;
}

getimage(&img, 0, 0, WIDTH * SIZE, (HEIGHT - (g_CurBlock.y - i + 1)) * SIZE);
putimage(0, SIZE, &img);
}
}
}

// 产生新方块
NewBlock();
}

#include
#include
#include

char str[10][10]={0};
int n,i=0,j=0,k=1;

main()
{
for(i=0;i<10;i++){
for(j=0;j<10;j++)
str[i][j]='.';
}
srand((unsigned) time(NULL));
i=0,j=0;
char c='A';
str[0][0]=c;
do{
top:
n=rand()%4;
switch(n){
case 0:
if(i!=0){
i--;
break;
}else
goto top;
case 1:
if(i!=9){
i++;
break;
}else
goto top;
case 2:
if(j!=0){
j--;
break;
}else
goto top;
case 3:
if(j!=9){
j++;
break;
}else
goto top;
}
if(str[i][j]!='.'){
if(n==0){
i++;
goto top;
}
else if(n==1){
i--;
goto top;
}
else if(n==2){
j++;
goto top;
}
else{
j--;
goto top;
}
}else{
str[i][j]=++c;
k++;
}
if((str[i-1>0?i-1:1-i][j]!='.')
&&(str[i+1>9?i-1:1+i][j]!='.')
&&(str[i][j-1>0?j-1:1-j]!='.')
&&(str[i][j+1>9?j-1:1+j]!='.'))
goto end;
}while(k<26);
end:
for(i=0;i<10;i++){
for(j=0;j<10;j++)
printf("%c ",str[i][j]);
printf("
");
}
}

下落的小鸟

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<Windows.h>
int Grade = 1, Score = 0, Max_blank = 9, Distance = 18;
struct Birds{int x; int y;};  //定义一种Birds数据类型(含3个成员)
Birds *Bird = (Birds*)malloc(sizeof(Birds));  //定义Birds类型 指针变量Bird并赋初值
struct Bg{int x, y; int l_blank; Bg *pri; Bg *next;};  //定义一种Bg数据类型(含5个成员)
Bg *Bg1 = (Bg*)malloc(sizeof(Bg));  //定义Bg类型 指针变量Bg1并赋初值

void Position(int x, int y)  //光标定位函数(用于指定位置输出)
{COORD pos = { x - 1, y - 1 };
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}

void Csh( )  //初始化界面

{

printf("══════════════════════════════════════
");

printf(" ■■ ■■ C语言版 Flappy Bird
");

printf(" ■■ ■■
");

printf(" ■■ ■■
");

printf(" ■■ ■■ 瞎搞人:yyposs原创
");

printf(" ■■ ■■ 瞎搞日期:2014.2
");

printf(" ■■ ■■
");

printf(" ■■ ■■ 改编:鸣蝉百2021.7
");

printf(" ■■ ■■ 操作:按向上方向键让小鸟起飞
");

printf(" ■■
");

printf(" ■■
");

printf(" ■■ ■■
");

printf(" ■■ ■■
");

printf(" ■■ ■■
");

printf(" ■■ ■■
");

printf(" ■■ ■■ DEVc++运行通过
");

printf("══════════════════════════════════════
");

printf("  按键继续…");

getch( );

system("cls");

}

 

void PrFK( )  //输出方框(游戏范围区)

{int i;

Position(1, 1); printf("╔");  Position(79, 1); printf("╗");

Position(1, 24); printf("╚");  Position(79, 24); printf("╝");

for (i = 3; i <= 78; i += 2){Position(i, 1); printf("═"); Position(i, 24); printf("═");}

for(i=2;i<=23;i++)

  { Position(1,i); printf("║");if(i<11)printf("0%d",i-1);else printf("%d",i-1);

   Position(79,i); printf("║");

  }

Position(4, 25); printf("小鸟即将出现,请准备按键起飞… ");

getch( );

Position(4, 25); printf("                                  ");

}

void CreatBg( )  //创建障碍物坐标(便于打印输出)
{Bg *Bg2 = (Bg*)malloc(sizeof(Bg));
Bg1->x = 90; Bg1->y = 8;  //确定障碍物的一对基本坐标(此时值是在游戏框之外)
Bg2->x = Bg1->x + Distance; Bg2->y = 9;  //下一障碍物的基本坐标x、y
Bg1->l_blank = Max_blank - Grade;  //障碍物上下两部分之间的空白距离l_blank
Bg2->l_blank = Max_blank - Grade;
Bg1->next = Bg2; Bg1->pri = Bg2;
Bg2->next = Bg1; Bg2->pri = Bg1;
}


void InsertBg(Bg *p)  //随机改变障碍物的y坐标,让空白通道有上下变化
{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( );  //产生一个随机数并赋值给temp
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 CreatBird( )  //建立小鸟的坐标(初始打印输出小鸟的位置)
{Bird->x = 41; Bird->y = 10;}

int CheckYN(Bg *q)  //判断游戏结束与否(值为0是要结束,为1没有要结束)
{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 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->x>0 && p->x <= 78)
{for (k = 2; k<p->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; j<p->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 == 0 && Grade<4)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;
}



//没玩过,你看这个是吗
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<Windows.h>
/********函数变量声明********/
#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<p->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<Distance / 3 - 2; k++)
PR_Land;
}
p = p->next;
if (p->x == 0)
{
for (j = 2; j<p->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;
}