这样的要怎么改,是codeblocks改主题,想写一个贪吃蛇的游戏

查看: 3974|回复: 11
最近基于原子ministm32开发板写了一个贪吃蛇的游戏,基本功能实现了,但还不是很完美,那位哥们能帮忙修改一下呢?
主题帖子精华
初级会员, 积分 143, 距离下一级还需 57 积分
在线时间0 小时
附近如下:
21:22 上传
点击文件名下载附件
1.72 MB, 下载次数: 1765
追求卓越,超越自己!
主题帖子精华
金钱117144
在线时间899 小时
回复【楼主位】林中独步2:
---------------------------------
什么叫不完美?
我是开源电子网站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺:
微信公众平台:正点原子& &
主题帖子精华
初级会员, 积分 143, 距离下一级还需 57 积分
在线时间0 小时
下进去看看就知道哪儿不完美了,就是那个随机数有点问题?
追求卓越,超越自己!
主题帖子精华
初级会员, 积分 171, 距离下一级还需 29 积分
在线时间0 小时
回复【楼主位】林中独步2:
---------------------------------
牛牛牛~
原子哥,求交往~(*^__^*)&
主题帖子精华
金钱117144
在线时间899 小时
回复【3楼】林中独步2:
---------------------------------
随机数很好改进吧?
我是开源电子网站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺:
微信公众平台:正点原子& &
主题帖子精华
新手上路, 积分 27, 距离下一级还需 23 积分
在线时间0 小时
那游戏的用什么键控制蛇的运动方向的
主题帖子精华
初级会员, 积分 143, 距离下一级还需 57 积分
在线时间0 小时
自带的红外遥控器控制方向的
追求卓越,超越自己!
主题帖子精华
新手上路, 积分 38, 距离下一级还需 12 积分
在线时间0 小时
void changeskdir(void)&& //判断移动方向
&&& key=Remote_Process();
&& switch(key)
&&& case 168:
&&&& if (snake.dir != up) { while(!(key == 168));&& snake.dir =}&&
**********************省略*************************
说明:遥控(以前买的一个)用起来感觉比较的生硬,反应慢,家里的电视遥控也如此,这是不是红外传递的缺陷?
void setfoodcrd(void)&//设置食物坐标
&food.crd.x =20+ rand() % (240/20) *20;
&food.crd.y = 20+rand() % (320/20) *20;
&if(food.crd.x&220 )food.crd.x = 200;
&if(food.crd.y&300)food.crd.y = 300;
&GUI_SetColor(GUI_YELLOW);
&GUI_FillCircle(food.crd.x, food.crd.y,10);
&food.flag = 1;
说明:防止“食物”出界和只出现半圆的情况。
srand((unsigned)GUI_GetTime());
&&if (!food.flag)
&&&&setfoodcrd();
&//这里原来的两句放到画食物那个函数里了
&& snakemove();
&&delay_ms(500);
&&t0 = 30;
&&while( --t0 )
&&&changeskdir();
&&&judgesef();&
&&&gameover();
说明:如果只用rand的话,产生的是重复的假随机种子,增加srand((unsigned)GUI_GetTime());这句效果会更好一点
while循环是为了给遥控足够的操作时间(大致可以认为整个程序遥控模块要处于最高级),这能改善楼主运行出现"蛇身"
拐弯出现跳变(不连贯)的现象。
声明:程序完全基于楼主源程序,改动的只是小部分。
主题帖子精华
新手上路, 积分 38, 距离下一级还需 12 积分
在线时间0 小时
void gameover(void)
******************省略****************************
&& &for( i=2;i&snake.++i)& //咬尾
&&&&&&&& &if((snake.crd[0].x == snake.crd.x) &&(snake.crd[0].y == snake.crd.y))
&&&&& &&& &{
&&&&&&&&&&&& &GUI_Clear();
&&&&&&&& &&&& GUI_SetColor(GUI_WHITE);
&&&&&&&&&&&&& GUI_DispStringAt("GAME OVER",60,90);
&&&&&&&&&&&&& &while( 1 );
&&&&&&&& &}
说明:增加一段咬尾检测
主题帖子精华
金钱117144
在线时间899 小时
回复【9楼】joy321:
---------------------------------
顶...
我是开源电子网站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺:
微信公众平台:正点原子& &
主题帖子精华
金钱117144
在线时间899 小时
能上个效果图么?
我是开源电子网站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺:
微信公众平台:正点原子& &
主题帖子精华
高级会员, 积分 621, 距离下一级还需 379 积分
在线时间0 小时
对这种帖子表示无语。
水的比较多。
Powered by贪吃蛇游戏代码翻译
- 多媒体制作 - 蓝色理想
您的位置:  &
& 贪吃蛇游戏代码翻译
 贪吃蛇游戏代码翻译
作者: 时间:  文档类型:翻译 来自:
今天翻译了一段经典的贪吃蛇代码,译后感觉还有很多地方不太妥当,很多不妥的地方希望大家多指教
//--- Flash MX Snake Game 1Kb by Strille. Version 2.2, 746 bytes//--- Paste this code on frame 1 and set scene size to 512x280 and Frame Rate to 16//--- The code is not written with speed in mind, only small file size. Not that it is slow :-)createTextField("t", 1, 1, 255, 511, 32); // create a text field to write score and instructionst.text = "Snake Game\t-\tPress SPACE"; // show start textbeginFill(0xeeeeee); lineStyle(1); lineTo(511, 0); lineTo(511, 256); lineTo(0, 256); endFill(); // draw background with borderKey.addListener(t); // use an existing object as key listener (we don't waste bytes by creating a new object)t.onKeyDown = function() { // define an anonymous method to execute when a key is pressed&&& c = Key.getCode()-37; // get key code (c is a variable used "locally" several times)&&& if (!(c&&2)) { // arrow keys pressed (c = 0, 1, 2 or 3)&&&&&&& if (c != q[0]) // only add to the queue if it is a new direction&&&&&&&&&&& q.unshift(c);&&&&&&& // save the turn in the queue and exit method&&& }&&& // SPACE or another key other than an arrow key has been pressed&&& x = 32*8 + 32*520; // snake start pos (left and right side of + can be viewed as x and y coord&&& q = []; // a queue to store key presses (so that x number of key presses during one frame are spread over x number of frames)&&& m = []; // create an array to store food pos and snake&&& createEmptyMovieClip("s", w=0); // create MC to store the snake and the food MC and reset snake counter(w)&&& e = 2*(m[x-520] = 2*(r=1)); // set erase counter (e) to 4, set current direction (r) to up (1) and set food on the position the snake will be over the first time to place food&&& onEnterFrame = function () { // MAIN function&&&&&&& c = q.pop(); // pick the next turn in the queue (may be undefined if queue is empty)&&&&&&& if (c%2 != r%2) // and check that it is not undefined and not a 180 degree turn (annoying to be able to turn into the snake with one key press)&&&&&&&&&&& if (c != undefined)&&&&&&&&&&&&&&& r = // change current direction to the new value&&&&&&& x += [-1, -65, 1, 65][r]*8; // move the snake to a new x position (-1 = left, -65 = up, 1 = right, 65 = down)&&&&&&& if (m[x] == 1 or !(x%520) or !(int(x/520) % 33)) { // GAME OVER if it is a snake block or outside the map on the next position&&&&&&&&&&& delete onEnterF // quit looping main function&&&&&&&&&&& t.text += "\tGAME OVER!"; // type game over text and exit main&&&&&&& }&&&&&&& with(s.createEmptyMovieClip(w, w)) { // place a snake block (or food block the first loop)&&&&&&&&&&& beginFill(255&&16); // red food color first time&&&&&&&&&&& if (w++) // blue snake color the other times&&&&&&&&&&&&&&& beginFill(0x555588);&&&&&&&&&&& _x = x%520; _y = int(x/520)*8; // set snake block position&&&&&&&&&&& lineTo(-7, 0); lineTo(-7, -7); lineTo(0, -7); endFill(); // draw a square&&&&&&& }&&&&&&& m[x] += 1; // set current pos as "occupied" by a snake block&&&&&&& if (m[x] == 3) { // check if there is a food block on the new pos&&&&&&&&&&& t.text = "Score: " +(w-(e-=5)-2)*2; // delay erase counter with 5 (the snake will grow 5 blocks each time), calculate and type score (+10p for a food block)&&&&&&&&&&& do {} while (m[c = (s[0]._x = 8+random(64)*8)+(s[0]._y = 8+random(32)*8)*65]); // pick a free spot to place the food, save that number, place the food MC&&&&&&&&&&& m[c] = 2; // set the position picked on the line above to 2&&&&&&& }&&&&&&& if (e) { // if not food MC (s[0]) then erase last snake MC and entry in array m&&&&&&&&&&& c = s[e]; // get last MC&&&&&&&&&&& delete m[c._x+65*c._y]; removeMovieClip(c); // delete the value in the array m and delete the MC&&&&&&& }&&&&&&& e++; // increase erase snake counter&&& }}
//--- Flash MX 贪吃蛇游戏(1Kb) 制作Strille. 版本 2.2, 共计 746 字节//--- 复制以下代码在主场景的第一帧场景大小为 512x280 , FPS 16createTextField("t", 1, 1, 255, 511, 32); // create a text field to write score and instructions// 创建一个文本框用于输出成绩和指示t.text = "Snake Game\t-\tPress SPACE";// 显示开始信息beginFill(0xeeeeee); lineStyle(1); lineTo(511, 0); lineTo(511, 256); lineTo(0, 256); endFill();// 沿边框绘制背景Key.addListener(t); // 使用一个已存在的Object 作键盘帧听 (就样就不用再创建新Obejct,从而节约了空间)t.onKeyDown = function() {// 当键盘按下后,去执行自定义的这个方法&&& c = Key.getCode()-37; // 获得按键的ASCII码 (变量 c 每次获取相对的ASCII码)&&& if (!(c&&2)) { // 方向键的表示 (c = 0, 1, 2 or 3)&&&&&&& if (c != q[0]) // 只将新的方向键存入队列 q&&&&&&&&&&& q.unshift(c);&&&&&&& // 在队列中保存,并结束该方法(函数)&&& }&&& // 空格或其它键不同于按下的方向键&&& x = 32*8 + 32*520;&&& // 蛇的起点坐标( 左边 + 右边:可被视为 x、y 坐标)&&& q = [];&&& // 用于存储按键的队列(因此改变在一帧中的X坐标对于所有帧中的X坐标都起作用)&&& m = [];&&& // 创建一个数组用于存储食物的坐标和蛇&&& createEmptyMovieClip("s", w=0);&&& // 创建一个空影片用于存储蛇和食物的影片剪辑,并重置蛇的计数器(w)&&& e = 2*(m[x-520] = 2*(r=1)); &&& // 设置擦除计数器(e) to 4, 设置当前方向(r)为向上(1),当蛇经过食物后立即设置食物位置为当前设置的位置&&& onEnterFrame = function () { &&& // 主函数&&&&&&& c = q.pop(); &&&&& // 在队列中提取出下一轮变换(当队列为空时,提取数是undefined的)&&&&&&& if (c%2 != r%2) &&&&&&& // 检查其不属于undefined和180度旋转(避免任意按下一个键后就改变蛇的方向)&&&&&&&&&&& if (c != undefined)&&&&&&&&&&&&&&& r = &&&&&&&&&&& // 改变当前方向为新的方向&&&&&&& x += [-1, -65, 1, 65][r]*8; &&&&&& // 移动蛇到一个新的X位置 (-1 = left, -65 = up, 1 = right, 65 = down)&&&&&&& if (m[x] == 1 or !(x%520) or !(int(x/520) % 33)) { &&&&&& // 如果新的位置在蛇身上或出了边界则 GAME OVER &&&&&&&&&&& delete onEnterF &&&&&&&&& // 退出主循环函数&&&&&&&&&&& t.text += "\tGAME OVER!"; &&&&&&&& // 输出 GAME OVER! 并退出主程序&&&&&&& }&&&&&&& with(s.createEmptyMovieClip(w, w)) { &&&&&& // 放置蛇身 (第一次循环时用于放置食物)&&&&&&&&&&& beginFill(255&&16); &&&&&&&&& // 首先将食物设为红色&&&&&&&&&&& if (w++) // blue snake color the other times&&&&&&&&&&&&&&& beginFill(0x555588);&&&&&&&&&&& _x = x%520; _y = int(x/520)*8; &&&&&&&&&& // 设置蛇身的位置&&&&&&&&&&& lineTo(-7, 0); lineTo(-7, -7); lineTo(0, -7); endFill(); &&&&&&&&& // 绘制一个方形&&&&&&& }&&&&&&& m[x] += 1; &&&&& // 设置当前位置为"已占用"区作为蛇身&&&&&&& if (m[x] == 3) { &&&&& // 检查是否有食物在新的位置上&&&&&&&&&&& t.text = "Score: " +(w-(e-=5)-2)*2; &&&&&&&& // 延迟擦除计数器5(蛇身每次增长5), 计算并输出分数 (一个食物加10分)&&&&&&&&&&& do {} while (m[c = (s[0]._x = 8+random(64)*8)+(s[0]._y = 8+random(32)*8)*65]); &&&&&&&& // 寻找一个空位置放置点, 并存储该数值, 并设置食物的影片剪辑&&&&&&&&&&& m[c] = 2;&&&&&&&& //设置选出的位置为为大于2的线路上&&&&&&& }&&&&&&& if (e) { &&&&&& // if not food MC (s[0]) then erase last snake MC and entry in array m&&&&&&&&&&& c = s[e]; &&&&&&&&&& // 获得最后一个影片剪辑&&&&&&&&&&& delete m[c._x+65*c._y]; removeMovieClip(c); &&&&&&&&& // 删除数组 m 中该元素的值并删除影片剪辑&&&&&&& }&&&&&&& e++; &&&&&& // 将蛇的擦除计数器加一&&& }}
经典论坛讨论:
本文链接: 
责任编辑:
◎进入论坛版块参加讨论
蓝色理想版权申明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有。
转载要求:转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。
特别注意:本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有,文章若有侵犯作者版权,请与我们,我们将立即删除修改。
说明:输入正确的用户名和密码才能参与评论。如果您不是本站会员,你可以 为本站会员。
注意:文章中的链接、内容等需要修改的错误,请用,以利文档及时修改。
注意:请不要在评论中含与内容无关的广告链接,违者封ID
请您注意:?不良评论请用,以利管理员及时删除。?尊重网上道德,遵守中华人民共和国的各项有关法律法规?承担一切因您的行为而直接或间接导致的民事或刑事法律责任?本站评论管理人员有权保留或删除其管辖评论中的任意内容
?您在本站发表的作品,本站有权在网站内转载或引用 ?参与本评论即表明您已经阅读并接受上述条款
专业书推荐
&1999-. 版权所有想用c语言编一个贪吃蛇的游戏 求大神帮忙【codeblocks吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:14,103贴子:
想用c语言编一个贪吃蛇的游戏 求大神帮忙收藏
想用c编一个贪吃蛇 百度上搜到的都是需要用到graphics的 有没有大神能用最普通的codeblocks编一个贪吃蛇
象山艺坊-美在象山,艺在人为!
求大神帮忙啊 或者怎么让codeblocks能引用graphics.h这个头文件
求大神帮忙啊
求大神帮忙啊
求大神帮忙啊
我也想知道/(ㄒoㄒ)/~~楼主成功了吗?
安装一个easyx就可以用了
楼主,有人回答的话记得艾特一下我,大恩大德!!
网上找的到的
工业提升门平移门-别说没用的,质量说话!
#include&iostream&#include&windows.h&#include&time.h&#include&conio.h&// 刷新当前屏幕inline void Refresh(char q[][22], int grade, int gamespeed){
system(&cls&);
for(i=0;i&22;i++)
cout && &\t&;
for(j=0;j&22;j++)
cout&&q[i][j]&&' ';
输出贪吃蛇棋盘
if(i==0) cout && &\t等级为:& &&
if(i==4) cout && &\t自动前进时间&;
if(i==6) cout && &\t间隔为:& && gamespeed && &ms&;
}}int main(){
char tcsQipan[22][22];
贪吃蛇棋盘是一个二维数组(如22*22,包括墙壁)
for(i=1;i&=20;i++)
for(j=1;j&=20;j++)
tcsQipan[i][j]=' ';
初始化贪吃蛇棋盘中间空白部分
for(i=0;i&=21;i++)
tcsQipan[0][i] = tcsQipan[21][i] = '-';
//初始化贪吃蛇棋盘上下墙壁
for(i=1;i&=20;i++)
tcsQipan[i][0] = tcsQipan[i][21] = '|';
//初始化贪吃蛇棋盘左右墙壁
int tcsZuobiao[2][100];
//蛇的坐标数组
for(i=0; i&4; i++) {
tcsZuobiao[0][i] = 1;
tcsZuobiao[1][i] = i + 1;
int head = 3,tail = 0;
for(i=1;i&=3;i++)
tcsQipan[1][i]='*';
tcsQipan[1][4]='#';
int x1, y1;
// 随机出米
srand(time(0));
x1=rand()%20+1;
y1=rand()%20+1;
}while(tcsQipan[x1][y1]!=' ');
tcsQipan[x1][y1]='*';
cout&&&\n\n\t\t贪吃蛇游戏即将开始 !&&&//准备开始;;
int grade = 1, length = 4;
int gamespeed = 500;
//前进时间间隔
for(i=3;i&=0;i--)
start=clock();
while(clock()-start&=1000)
system(&cls&);
cout && &\n\n\t\t进入倒计时:& && i &&
Refresh(tcsQipan,grade,gamespeed);
char direction = 77;
// 初始情况下,向右运动
while(1) {
timeover = 1;
start = clock();
while((timeover=(clock()-start&=gamespeed))&&!kbhit())
//如果有键按下或时间超过自动前进时间间隔则终止循环
if(timeover)
getch();direction = getch();
switch(direction)
case 72: x= tcsZuobiao[0][head]-1; y= tcsZuobiao[1][head];
case 80: x= tcsZuobiao[0][head]+1; y= tcsZuobiao[1][head];
case 75: x= tcsZuobiao[0][head]; y= tcsZuobiao[1][head]-1;
case 77: x= tcsZuobiao[0][head]; y= tcsZuobiao[1][head]+1;
if(!(direction==72||direction==80||direction==75 ||direction==77))
按键非方向键
cout && &\tGame over!& && system(&pause&);return 0;
if(x==0 || x==21 ||y==0 || y==21) // 碰到墙壁
cout && &\tGame over!& &&system(&pause&);return 0;
if(tcsQipan[x][y]!=' '&&!(x==x1&&y==y1))//
蛇头碰到蛇身
cout && &\tGame over!& &&system(&pause&);return 0;
if(x==x1 && y==y1)
吃米,长度加1
length ++;
if(length&=8)
length -= 8;
if(gamespeed&=200)
gamespeed = 550 - grade * 50; // 改变自动前进时间间隔
tcsQipan[x][y]= '#';
tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]] = '*';
head = (head+1)%100;
tcsZuobiao[0][head] =
tcsZuobiao[1][head] =
x1=rand()%20+1;
y1=rand()%20+1;
}while(tcsQipan[x1][y1]!=' ');
tcsQipan[x1][y1]='*';
Refresh(tcsQipan,grade,gamespeed);
tcsQipan [tcsZuobiao[0][tail]][tcsZuobiao[1][tail]]=' ';
tail=(tail+1)%100;
tcsQipan [tcsZuobiao[0][head]][tcsZuobiao[1][head]]='*';
head=(head+1)%100;
tcsZuobiao[0][head]=x;
tcsZuobiao[1][head]=y;
tcsQipan[tcsZuobiao[0][head]][tcsZuobiao[1][head]]='#';
Refresh(tcsQipan,grade,gamespeed);
return 0;}
登录百度帐号推荐应用

我要回帖

更多关于 codeblocks更改字体 的文章

 

随机推荐