51单片机+8-8点阵实现的贪食蛇源代码

51 单片机+8*8 点阵实现的贪食蛇源代码

电路图和单片机仿真文件下载:51hei/bbs/dpj-20604-1.html 下面是源代码: #include #define uchar unsigned char#define SNAKE 20 //最大长度#define TIME 50 //显示延时时间#define SPEED 71 //速度控制//#define keyenable 1sbit keyenable=P3 ;//方向使能/*sbit

keyx=P0 ;//左右 sbit

keyy=P0 ;//上下*///sbit

up=P0;sbit up=P3 ; //downsbit down=P3 ;sbit right=P3 ;sbit left=P3 ;uch ar x[SNAKE+1];uchar y[SNAKE+1];uchar time,n,i,e; //延时时间,当前蛇长,通用 循环变量,当前速度 char addx,addy; //位移偏移量/********************延时 程序*********************/void delay(char MS){char us,usn;while(MS!=0){usn =

0;while(usn!=0){us=0xff;while

(us!=0){us--;};usn--;}MS--

;}}/*******************************************判断碰撞 *******************************************/bit k;k=0;if(x[1]>7||y[1]>7)k=1; k=1;

//撞自己 return

knock(){bit

//撞墙 for(i=2;i

k;}/*****************上下左右键位处理

interrupt

0

using

else addx=- addy=-

*****************/void turnkey()//

2{//up=1;if(keyenable){if(left){addy=0;if(addx!=1)addx=-1; addx=1;}if(right){addy=0;if(addx!=-1)addx=1; 1;}if(up){addx=0;if(addy!=-1)addy=1;

else else

1;}if(down){addx=0;if(addy!=1)addy=-1; else addy=1;}/*if(keyy){addy=0; //左右 if(keyx)if(addx==-1)addx=-1; else addx=1; //左 elseif(addx==1)addx=1; else addx=- 1; //右}else{addx=0; //上下 if(keyx)if(addy==1)addy=1; else addy=-1; //下 elseif(addy==-1)addy=-1; else addy=1; //上} */}}tips:感谢大家的阅读,本文由我 司收集整编。仅供参阅!

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4