俄羅斯方塊程序_第1頁
俄羅斯方塊程序_第2頁
俄羅斯方塊程序_第3頁
俄羅斯方塊程序_第4頁
俄羅斯方塊程序_第5頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

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,0x

2、00,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,0x

3、ff,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,0x

4、ff,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)外面為游戲邊界區(qū):第0列,第41列,第31行里面為游戲區(qū):第0列,第41列,第31行

5、之間的區(qū)域4 /zook0k/*/* * 功能: 方塊的圖形代碼,每四個字節(jié)表示一個圖形* 每行表示一個內容,只表示了第一個狀態(tài)的樣子* 其它按順時針轉圖形可得 */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,0

6、x00,0x04,0x04,0x0C,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*/0

7、x0C,0x0C,0x00,0x00;/* * 功能: 圖形指針數組* 指示了各種方塊在圖形代碼里的最初指針*/char code TtrsBlckPoint = 0, /Middle 16, /Left 32, /Right 48, /Z 56, /Z-twist 64, /Line 72 /Stone ;/* * 名稱: INT8U code TtrsBlckStsNum* 功能: 方塊狀態(tài)個數* 表示每種方塊的狀態(tài)的個數 */char code TtrsBlckStsNum = 4, /Middle 4, /Left 4, /Right 2, /Z 2, /Z-twist 2, /Lin

8、e 1 /Stone ; typedef struct unsigned char BlckIndex :4; /對象序號06 unsigned char Status :4; /每個對象當前形狀03 unsigned char code * pPIC; /對應于圖形區(qū)的指針 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,/0 0x00,0x20,0x20,0x3

9、F,0x20,0x20,0x00,0x00,0x00,0x10,0x10,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,0x0

10、0,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,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,0x0

11、8,0x08,0x88,0x70,0x00,0x00,0x00,0x31,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)檢測按鍵并移動方塊如果方塊不能移動則判斷有無重復行并消除程序跳出循環(huán)*/#include #include/液晶引腳初始化sbitRs_Lcd=P35;sbitRw_Lcd=P36;sbitEn_Lcd=P37;sbitC

12、s1_Lcd=P10;sbitCs2_Lcd=P11;sfr DataBuss=0xa0;/P0作為Lcd的數據線unsigned char dat=0;/按鍵引腳及其狀態(tài)機初始值#define key_state_00#define key_state_11#define key_state_22unsigned 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

13、=0;unsigned char crack_state=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 SetYAdd

14、r(char y);void ClrScreen(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(unsig

15、ned char x,unsigned char 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-):state void DisChar(unsigned char *p,unsigned char page,unsigned char y,char state);/消除地圖的全1

16、行void check_ditu(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 boxunsign

17、ed char Check_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,0

18、x00,0x00,0x00,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,0x0

19、0,0x00,0x00,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,/21

20、0x00,0x00,0x00,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=0x

21、ff;P3=0xff;delay_ms(20);do SonState=SysInit( ); while(SonState!=0);ClrScreen(); game_line();show_ditu(); /mode:line(01 23 45 67):colum(08-):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; /cra

22、ck game overwhile(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:columvoi

23、d onepoint(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;i(x+2);i+)for(j=y;j(y+2);j+)Dispoint(i,j);/x:line y:columvoid clr_onepoint(unsigned char x,unsigned char y)/clear one point(2*2) unsigned char i=0,j=0;x=2*x;y=2*y;for(i=x;i(x+2);i+)for(j=y;j(y+2

24、);j+)Clrpoint(i,j);void show_ditu()/show ditu:line(0-30)colum(1-40) ,line31 colun0&41 game linefor(j=0;j31;j+)for(i=0;i0;j-)/form down to upif(tiduj0=0xff)&(tiduj1=0xff)&(tiduj2=0xff)&(tiduj3=0xff)&(tiduj4=0xff)/full aaa=1; score+;for(i=j;i0;i-)tidui0=tidui-10;tidui1=tidui-11;tidui2=tidui-12;tidui3=

25、tidui-13;tidui4=tidui-14;/show_one_Line(i);tidu00=0;tidu01=0;tidu02=0;tidu03=0;/add ampty one line/if there are many full lines togetherif(tiduj0=0xff)&(tiduj1=0xff)&(tiduj2=0xff)&(tiduj3=0xff)&(tiduj4=0xff)j+;/for(j=30;j0;j-)/updata ditu beacuse there have full lineif(aaa=1)ClrScreen(); game_line()

26、;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_wei=0,shi_wei=0,bai_wei=0;if(score10) ge_wei=score;else if(score100) shi_wei=score/10;ge_wei=score%10;else bai_wei=score/100;shi_wei=score%100/10;ge_w

27、ei=score%10;DisChar(figbai_wei,6,104,0);DisChar(figshi_wei,6,112,0);DisChar(figge_wei,6,120,0);/寫進地圖x:line y:colum z=1寫1 z=0寫0 updata is fastvoid write_ditu(unsigned char x,unsigned char y,unsigned char z)char i=0,j=0;/ditu0 form 1 not from 0/ditu0=y-1y-;i=y/8;j=y%8;if(z=1) tiduxi|=1j; onepoint(x,y+

28、1);else if(z=0) tiduxi&=(1j); clr_onepoint(x,y+1);/讀出地圖x:line y:colum unsigned char read_ditu(unsigned char x,unsigned char y)char i=0,j=0,k=0;/ditu0 form 1 not from 0/ditu0=y-1y-;i=y/8;j=y%8;k|=1j;if(tiduxi&k) return 1;/have point else return 0;/no point /generate a boxvoid Box_Generate() static un

29、signed char box_no=5;this.x=0;this.y=20; this.BlckIndex = (box_no+)%7; this.Status = 0; this.pPIC = TtrsBlck + TtrsBlckPointthis.BlckIndex + (this.Status) * 4;/if there is the game lineunsigned char Check_Box_gameline()for(i=0;i30)|(this.y+1)40)|(this.y+1)30)|(this.y+2)40)|(this.y+2)30)|(this.y+3)40

30、)|(this.y+3)30)|(this.y+4)40)|(this.y+4)30)|(this.y+1)40) return 1;/have pointif(this.pPICi&0x04)if(this.x+i30)|(this.y+2)40) return 1;/have pointif(this.pPICi&0x02)if(this.x+i30)|(this.y+3)40) return 1;/have pointif(this.pPICi&0x01)if(this.x+i30)|(this.y+4)40) return 1;/have pointreturn 0;/no point

31、/if there hava boxunsigned char Check_Box_ditu()for(i=0;i4;i+)if(this.pPICi&0x08)if(read_ditu(this.x+i,this.y+1) return 1;/have pointif(this.pPICi&0x04)if(read_ditu(this.x+i,this.y+2)return 1;/have pointif(this.pPICi&0x02)if(read_ditu(this.x+i,this.y+3)return 1;/have pointif(this.pPICi&0x01)if(read_

32、ditu(this.x+i,this.y+4)return 1;/have pointreturn 0;/no point/if it can ratation/unsigned char Check_Box_ditu_ratation()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;i4;i+)if(this.pPICi&0x08) onepoint(this.x+i,this.y+1); w

33、rite_ditu(this.x+i,this.y+1,1);if(this.pPICi&0x04) onepoint(this.x+i,this.y+2); write_ditu(this.x+i,this.y+2,1);if(this.pPICi&0x02) onepoint(this.x+i,this.y+3); write_ditu(this.x+i,this.y+3,1);if(this.pPICi&0x01) onepoint(this.x+i,this.y+4); write_ditu(this.x+i,this.y+4,1);/clear a boxvoid Clr_Box_d

34、itu()for(i=0;i4;i+)if(this.pPICi&0x08) clr_onepoint(this.x+i,this.y+1); write_ditu(this.x+i,this.y+1,0);if(this.pPICi&0x04) clr_onepoint(this.x+i,this.y+2); write_ditu(this.x+i,this.y+2,0);if(this.pPICi&0x02) clr_onepoint(this.x+i,this.y+3); write_ditu(this.x+i,this.y+3,0);if(this.pPICi&0x01) clr_on

35、epoint(this.x+i,this.y+4); write_ditu(this.x+i,this.y+4,0);void game_line()for(i=0;i32;i+)onepoint(i,0); onepoint(i,41);for(i=0;i= TtrsBlckStsNumthis.BlckIndex) this.Status = 0; this.pPIC = TtrsBlck + TtrsBlckPointthis.BlckIndex + (this.Status) * 4;Write_Box_ditu();/crack_state=0;can move down/crack_state=1;can not move down check is h

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論