c语言小游戏 精简_C语言简易版小游戏【flappy bird】

这篇博客介绍了如何使用C语言编写一个简易版的Flappy Bird小游戏,包括游戏界面的初始化、柱子更新、小鸟移动、计分系统等功能,并提供了关键代码示例。
摘要由CSDN通过智能技术生成

C语言简易版小游戏【flappy bird】

#include

#include

#include

#include "interface.h"

char interf[M][N] = {{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32 },

{ 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32 },

{ 38,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32 },

{ 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 },

{ 32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35 }, };

//初始界面矩阵,ASCII码中“ ”是32,“&”是38表示小鸟,“#”是35用来画柱子

int num = 0;//用于计数输出并排两列黑柱子同一位置

int black;//黑方块位置

int p= M/2 ;//小鸟初始位置

int score = 0;//分数

/*初始化界面*/

void InitialInterface(void)

{

printf("\n          作者:xhyang,博客地址:http://blog.csdn.net/weixin_39449570\n");

printf("            按\"w\"使小鸟跳起来,别落地,顺利穿过尽可能多的柱子!\n");

for (int i = 0; i < M; i++)

{

printf("            ");

for (int j = 0; j < N; j++)

{

printf("%c", interf[i][j]);

}

printf("\n");

}

}

/*更新界面各个柱子*/

void newinterface(void)

{

if (interf[0][1] == 35 && num==0)//当矩阵第二列为黑色方块时,计算出下一次黑柱子上半部分的位置

{

black = 5 + rand() % 5;

num = 2;//黑柱子是两列#组成,第二列与第一列位置一样,用num保证两列位置一致

}

for (int i = 0; i < M; i++)

{

for (int j = 0; j < N - 1; j++)

{

interf[i][j] = interf[i][j + 1];

}

if (interf[0][0] == 35 && (i < black || i>(black + 5)))//此时上面的第二列变成了第一列,更新下一个黑柱子,有了黑柱子上半部分位置+5即是下半部分的起始位置

{

interf[i][N-1] = 35;

}

else

{

interf[i][N-1] = 32;

}

}

if (num > 0)

num--;

}

/*更新小鸟位置*/

void birdmove(void)

{

for (int a = 0; a < 3; a++)

{

if (a  == 2 && p > 0)//减缓鸟的速度,使按键上跳速度是下落的4倍

{

p = p + 1;

}

if (_kbhit())

{

if (_getch() == 'w' || _getch() == 'W')

{

p = p - 3;

}

}

}

}

/*计分*/

void scoring(void)

{

if (p > 20 || interf[p][0] == 35)

{

system("cls");

printf("\n\n            游戏结束!\n\n");

printf("            最终得分:%d\n\n\n", score);

system("pause");

}

if (interf[0][0] == 35 && interf[0][1] == 32 )

score++;

}

/*重画界面*/

void draw(void)

{

system("cls");

printf("\n          作者:xhyang,博客地址:http://blog.csdn.net/weixin_39449570\n");

printf("            按\"w\"使小鸟跳起来,别落地,顺利穿过尽可能多的柱子!\n");

for (int i = 0; i < M; i++)

{

printf("            ");

for (int j = 0; j < N; j++)

{

if (i == p && j == 0 && interf[p][0] != 35)

printf("%c", 38);

else

printf("%c", interf[i][j]);

}

printf("\n");

}

printf("            得分:%d \n", score);

}

本文由IT教学网整理发布,转载请注明出处:http://www.itjx.com/ziyuan/yuanma/553.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值