收藏 分享(赏)

俄罗斯方块程序.doc

上传人:ysd1539 文档编号:7255200 上传时间:2019-05-10 格式:DOC 页数:23 大小:124KB
下载 相关 举报
俄罗斯方块程序.doc_第1页
第1页 / 共23页
俄罗斯方块程序.doc_第2页
第2页 / 共23页
俄罗斯方块程序.doc_第3页
第3页 / 共23页
俄罗斯方块程序.doc_第4页
第4页 / 共23页
俄罗斯方块程序.doc_第5页
第5页 / 共23页
点击查看更多>>
资源描述

1、/* 1.方块图标坐标举例:7 高位 4 3 低位 0 对于上幅方块图像,所示处为(0,0)点,2.RAM 坐标举例 31X40(x,y):| (0, 1) (0,1) . (0, 40) | | (1, 1) | . | . | . | (30,1) . (30,40) |_| 第 0 列第 41 列第 31 行为游戏的边界线/line:31 colum:5*8unsigned char idata tidu315=0x01,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x08,0x00,0x00

2、,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff

3、,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff

4、,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x02,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,;3.(x,y)x:line.y:colum(0,0) |(0,1)-(0,40)| (0,41)(1,0) |(1,1)-(1,40)| (1,41)(2,0) |(2,1)-(2,40)| (2,41)- |-|-(30,0)|(30,1)-(30,40)| (30,41)_-(31,0)|(31,1)-(31,40)|(31,41)外面为游戏边界区:第 0 列,第 41 列,第 31 行里面为游戏区:第 0 列,第 4

5、1 列,第 31 行之间的区域4 http:/ * 功能: 方块的图形代码,每四个字节表示一个图形* 每行表示一个内容,只表示了第一个状态的样子* 其它按顺时针转图形可得 */unsigned char code TtrsBlck= /* Middle 0 0*/0x04,0x0E,0x00,0x00,0x08,0x0C,0x08,0x00,0x0E,0x04,0x00,0x00,0x04,0x0C,0x04,0x00,/* Left 16 1*/0x08,0x0E,0x00,0x00,0x0C,0x08,0x08,0x00,0x0E,0x02,0x00,0x00,0x04,0x04,0x0C

6、,0x00,/* Right 32 2*/0x02,0x0E,0x00,0x00,0x08,0x08,0x0C,0x00,0x0E,0x08,0x00,0x00,0x0C,0x04,0x04,0x00,/* Z 48 3*/0x0C,0x06,0x00,0x00,0x04,0x0C,0x08,0x00,/* Z_Reversal 56 4*/0x06,0x0C,0x00,0x00,0x08,0x0C,0x04,0x00,/* Line 64 5*/0x0F,0x00,0x00,0x00,0x08,0x08,0x08,0x08,/* Stone 72 6*/0x0C,0x0C,0x00,0x00

7、;/* * 功能: 图形指针数组* 指示了各种方块在图形代码里的最初指针*/char code TtrsBlckPoint = 0, /Middle16, /Left32, /Right48, /Z56, /Z-twist64, /Line72 /Stone;/* * 名称: INT8U code TtrsBlckStsNum* 功能: 方块状态个数* 表示每种方块的状态的个数 */char code TtrsBlckStsNum = 4, /Middle4, /Left4, /Right 2, /Z2, /Z-twist2, /Line1 /Stone;typedef structunsig

8、ned char BlckIndex :4; /对象序号 06unsigned char Status :4; /每个对象当前形状 03unsigned char code * pPIC; /对应于图形区的指针unsigned char x,y; /位置TETRIS;TETRIS this;char code fig1017= 0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,/00x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x10,0x1

9、0,0xF8,0x00,0x00,0x00,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0

10、E,0x00,0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x3

11、1,0x22,0x22,0x11,0x0F,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00;/9void Box_Generate(void);void Write_Box_ditu(void);/*初始化while(1)生成一个方块,如失败结束while(1)检测按键并移动方块如果方块不能移动则判断有无重复行并消除程序跳出循环*/#include #include/液晶引脚初始化sbit Rs_Lcd=P35;sbit Rw_Lcd=P36;sbit En_Lcd=P37;sbit Cs1_Lcd=P10;sbit Cs2_Lcd=P11;sfr D

12、ataBuss=0xa0; /P0 作为 Lcd 的数据线unsigned char dat=0;/按键引脚及其状态机初始值#define key_state_0 0#define key_state_1 1#define key_state_2 2unsigned char key_state4=0,0,0,0;sbit key_up=P14;sbit key_down=P33;sbit key_left=P13;sbit key_right=P32;unsigned char i=0,j=0; unsigned char down_time=0;unsigned char crack_st

13、ate=0;unsigned char score=1;/液晶函数初始化char RdStateLcd();char WrCommandIc(unsigned char Command);char WrCommandLcd(unsigned char Command);char WrDataLcd(unsigned char dat);char SetStarLine(char line);void InitDis(void);char SysInit(void);char SetPageAddr(char page);char SetYAddr(char y);void ClrScreen(

14、void); /一个像素点的显示清除void Dispoint(unsigned char page,unsigned char y);void Clrpoint(unsigned char page,unsigned char y);/延时和读取按键void delay_us(unsigned int a);void delay_ms(unsigned int a);unsigned char read_key(unsigned char a,unsigned char key);/四个个像素点的显示清除void onepoint(unsigned char x,unsigned char

15、y);void clr_onepoint(unsigned char x,unsigned char y);/显示地图void show_ditu(void);/show game linevoid game_line(void);/show scorevoid show_score(void);/mode:line(01 23 45 67):colum(08-120128):state void DisChar(unsigned char *p,unsigned char page,unsigned char y,char state);/消除地图的全 1 行void check_ditu(

16、void);/写进地图 0 或 1void write_ditu(unsigned char x,unsigned char y,unsigned char z);/读出地图unsigned char read_ditu(unsigned char x,unsigned char y);/产生一个方块void Box_Generate(void);/写一个方块 to 地图void Write_Box_ditu(void);/from titu erase a fangkuaivoid Clr_Box_ditu(void);/if there hava boxunsigned char Chec

17、k_Box_ditu();/if there is the game lineunsigned char Check_Box_gameline();/check if the box can ratateunsigned char Check_Box_ditu_ratation(void);/movevoid mov_left(void);void mov_right(void);void mov_ratation(void);void mov_down(void);/line:31 colum:5*8unsigned char idata tidu315=0x00,0x00,0x00,0x0

18、0,0x00,/00x00,0x00,0x00,0x00,0x00,/10x00,0x00,0x00,0x00,0x00,/20x00,0x00,0x00,0x00,0x00,/30x00,0x00,0x00,0x00,0x00,/40x00,0x00,0x00,0x00,0x00,/50x00,0x00,0x00,0x00,0x00,/60x00,0x00,0x00,0x00,0x00,/70x00,0x00,0x00,0x00,0x00,/80x00,0x00,0x00,0x00,0x00,/90x00,0x00,0x00,0x00,0x00,/100x00,0x00,0x00,0x00,

19、0x00,/110x00,0x00,0x00,0x00,0x00,/120x00,0x00,0x00,0x00,0x00,/130x00,0x00,0x00,0x00,0x00,/140x00,0x00,0x00,0x00,0x00,/150x00,0x00,0x00,0x00,0x00,/160x00,0x00,0x00,0x00,0x00,/170x00,0x00,0x00,0x00,0x00,/180x00,0x00,0x00,0x00,0x00,/190x00,0x00,0x00,0x00,0x00,/200x00,0x00,0x00,0x00,0x00,/210x00,0x00,0x

20、00,0x00,0x00,/220x00,0x00,0x00,0x00,0x00,/230x00,0x00,0x00,0x00,0x00,/240x00,0x00,0x00,0x00,0x00,/250x00,0x00,0x00,0x00,0x00,/260xff,0xff,0xff,0xff,0xef,/300xff,0xff,0xff,0xff,0xef,/300xff,0xff,0xff,0xff,0xef,/300x00,0xff,0xff,0xff,0xef,/30;void main()char SonState; P0=0xff;P1=0xff;P2=0xff;P3=0xff;d

21、elay_ms(20);doSonState=SysInit( );while(SonState!=0);ClrScreen(); game_line();show_ditu();/mode:line(01 23 45 67):colum(08-120128):state DisChar(fig0,6,104,0);DisChar(fig0,6,112,0);DisChar(fig0,6,120,0);while(1)Box_Generate();if(Check_Box_ditu()=0) Write_Box_ditu();/no crackelse break; /crack game o

22、verwhile(1)if(read_key(0,key_left)mov_left();if(read_key(1,key_right)mov_right();if(read_key(2,key_up)mov_ratation();if(read_key(3,key_down)mov_down();if(down_time250)mov_down();delay_us(200);down_time+;if(crack_state=1)crack_state=0;break;/while(1)/while(1)/basic function/x:line y:columvoid onepoin

23、t(unsigned char x,unsigned char y)/show one point(2*2) unsigned char i=0,j=0;x=2*x;y=2*y;for(i=x;i0;j-)/form down to upif(tiduj0=0xff) score+;for(i=j;i0;i-)tidui0=tidui-10;tidui1=tidui-11;tidui2=tidui-12;tidui3=tidui-13;tidui4=tidui-14;/show_one_Line(i);tidu00=0;tidu01=0;tidu02=0;tidu03=0;/add ampty

24、 one line/if there are many full lines togetherif(tiduj0=0xff)/for(j=30;j0;j-)/updata ditu beacuse there have full lineif(aaa=1)ClrScreen(); game_line();show_ditu();show_score();/the better is show the change lines ,the no change not clear /void check_ditu()/显示分数void show_score(void)unsigned char ge

25、_wei=0,shi_wei=0,bai_wei=0;if(score30)|(this.y+1)40)|(this.y+1)30)|(this.y+2)40)|(this.y+2)30)|(this.y+3)40)|(this.y+3)30)|(this.y+4)40)|(this.y+4)30)|(this.y+1)40) return 1;/have pointif(this.pPICi/have pointif(this.pPICi/have pointif(this.pPICi/have pointreturn 0;/no point/if there hava boxunsigne

26、d char Check_Box_ditu()for(i=0;i27)return 1;/bottom lineif(this.y37)return 1;/right linereturn 0;/no point/write a boxvoid Write_Box_ditu()for(i=0;i= TtrsBlckStsNumthis.BlckIndex) this.Status = 0;this.pPIC = TtrsBlck+ TtrsBlckPointthis.BlckIndex + (this.Status) * 4;Write_Box_ditu();/crack_state=0;ca

27、n move down/crack_state=1;can not move down check is have full lines then delete it/void mov_down()down_time=0;Clr_Box_ditu();this.x+;if(Check_Box_ditu()|(Check_Box_gameline()/crackthis.x-; crack_state=1;else crack_state=0;Write_Box_ditu();if(crack_state=1)check_ditu();/延时void delay_us(unsigned int

28、a)while(a0)a-;void delay_ms(unsigned int a)while(a0)a-;delay_us(250);/液晶基本函数char RdStateLcd( )unsigned char state;Rs_Lcd=0;Rw_Lcd=1;En_Lcd=1;state=DataBuss;En_Lcd=0;return(state);char WrCommandIc(unsigned char Command) unsigned char state,tmp;state=0;for(tmp=0xFF;(RdStateLcd( )tmp-) ; if(tmp=0) stat

29、e=0xFF; elseRs_Lcd=0;Rw_Lcd=0; DataBuss=Command;En_Lcd=1;En_Lcd=0;return(state); char WrCommandLcd(unsigned char Command)unsigned char state;Cs1_Lcd=1;Cs2_Lcd=0;state=WrCommandIc(Command);if(state=0)Cs1_Lcd=0;Cs2_Lcd=1;state=WrCommandIc(Command);return(state);char WrDataLcd(unsigned char dat)unsigne

30、d char state,tmp;state=0;for(tmp=0xFF;(RdStateLcd( )tmp-)/ban mang ? ; if(tmp=0) state=0xFF; elseRw_Lcd=0;Rs_Lcd=1;DataBuss=dat;En_Lcd=1;En_Lcd=0;return(state); /*/* Name: SetStarLine/* Function: 设置显示开始行/*/char SetStarLine(char line) char state;line=(linestate=WrCommandLcd(line);return(state);void I

31、nitDis(void)SetStarLine(0x00);WrCommandLcd(0x3F);/kai xian shi char SysInit(void)unsigned char i, state;/ Rst_Lcd=0; /复位 lcdfor(i=0xFF;i0;i-) /延时 1ms ; /Rst_Lcd=1;SetStarLine(0x00);InitDis( );return(state);/*/* Name: SetStarLine/* Function: 设置当前页地址 /* Input: page=页地址 /*/char SetPageAddr(char page)ch

32、ar state;page=(pagestate=WrCommandLcd(page);return(state);/*/* Name: SetStarLine/* Function: 设置当 Y 地址 /* Input: line=开始显示的行数 ? / */char SetYAddr(char y)char state;y=(ystate=WrCommandLcd(y);return(state); /显示某点void Dispoint(unsigned char page,unsigned char y)unsigned char tmp=0;unsigned char state=0;

33、SetPageAddr(page/8);SetYAddr(y);if(y0x00);tmp-) ; if(tmp=0) state=0xFF; elseRs_Lcd=1;Rw_Lcd=1; En_Lcd=1; delay_us(2);dat=DataBuss;En_Lcd=0; delay_us(2);En_Lcd=1; delay_us(2);dat=DataBuss;En_Lcd=0; delay_us(2);dat|=(10x00);tmp-)/ban mang ? ; if(tmp=0) state=0xFF; elseRw_Lcd=0;Rs_Lcd=1;DataBuss=dat;En

34、_Lcd=1;En_Lcd=0;/清除某点void Clrpoint(unsigned char page,unsigned char y)unsigned char tmp=0;unsigned char state=0;SetPageAddr(page/8);SetYAddr(y);if(y0x00);tmp-) ; if(tmp=0) state=0xFF; elseRs_Lcd=1;Rw_Lcd=1; En_Lcd=1; delay_us(10);dat=DataBuss;En_Lcd=0; delay_us(10);En_Lcd=1; delay_us(10);dat=DataBus

35、s;En_Lcd=0; delay_us(10);dattmp-)/ban mang ? ; if(tmp=0) state=0xFF; elseRw_Lcd=0;Rs_Lcd=1;DataBuss=dat;En_Lcd=1;En_Lcd=0;/请屏幕void ClrScreen(void)char i,j,state;for(j=0;j8;j+)state=SetPageAddr(j);state=SetYAddr(0x00);Cs1_Lcd=1;Cs2_Lcd=0;for(i=0;i64;i+)/清state=WrDataLcd(0);Cs1_Lcd=0;Cs2_Lcd=1;for(i=0

36、;i64;i+)/清state=WrDataLcd(0);void DisChar(unsigned char *p,unsigned char page,unsigned char y,char state)unsigned char i,j,tmp;for(j=0;j2;j+)SetPageAddr(page+j);if(y64) i=y; else i=y-64; SetYAddr(i);/SetStarLine(i);if(y64)Cs1_Lcd=1;Cs2_Lcd=0;elseCs1_Lcd=0;Cs2_Lcd=1;for(i=8;i16;i+)tmp=pi-8*j; if(state=0x01) tmp=tmp; WrDataLcd(tmp);/

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报