小游戲俄羅斯方塊代碼_第1頁(yè)
小游戲俄羅斯方塊代碼_第2頁(yè)
小游戲俄羅斯方塊代碼_第3頁(yè)
小游戲俄羅斯方塊代碼_第4頁(yè)
小游戲俄羅斯方塊代碼_第5頁(yè)
已閱讀5頁(yè),還剩22頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、東西絕對(duì)不多說(shuō),直接看!看了拷貝就懂了! !,直接可以拷貝下面的東西,然后記得 把那個(gè) BLOCK的名字改成你自己的類名,這個(gè)很關(guān)鍵哦,不然是錯(cuò)的可別怪我,呵呵 import import import import .*;import .*;implementspublic class Block extends JPanel ActionListener,KeyListenerddActionListener( this );but i.addKeyListener( this );but i.setBounds(360,(240 + 30 * i),160,25);add(scoreLa

2、badd(scoreTexadd(speedLabadd(speedTex););););add( infoLab ); add( infoTex ); add( scoreLab );(320,15,30,20) ;(360,15,160,20) ;(320,45,30,20) ;(360,45,160,20) ;but 1.setEnabled(false );but 4.setEnabled(false );(320,75,30,20) ;(360,75,160,20) ;(360,360,160,25);( this );( this );( this );( this );( thi

3、s );num_csh_game(); rand_block();actionPerformed(ActionEvent e)false ); ); );mi0 )etEnabled(false );false );/ 降低級(jí)數(shù)<= 1)!" ););/ 提高級(jí)數(shù)>= 9)!" );publicif () =but 1.setEnabled(but 4.setEnabled();true );if () = but 1|() = but 1.setEnabled( but 4.setEnabled( if () = but 2)( " 降低級(jí)數(shù) !&q

4、uot; ); speedMark -; if ( speedMarkvoidbut 0)etEnabled(truetruespeedMark = 1;( " 已經(jīng)是最低級(jí)數(shù)( speedMark +if () = but 3)( " 提高級(jí)數(shù) !" ); speedMark +; if ( speedMarkspeedMark = 9;( " 已經(jīng)是最高級(jí)數(shù)( speedMark +if () = but 4)( noStop );( but 4);( " 游戲暫停 !" );();if () =( noStop"&qu

5、ot; );/ 游戲暫停noStop ) / 取消暫停);( but 4);( " 繼續(xù)游戲 !" );();if () = but 5|() = mi1 ) / 退出游戲();if () = mi1_0 ) / 退出游戲dlg_1 = new JDialog( jf , " 關(guān) 于 " );"resource/" ); / 得到路徑try FileInputStream io =new FileInputStream(byte a =new byte ();(a);();String str = new String(a);(str

6、);catch (Exception g)( false );( dlg_1_text );();( false );(200, 120);(400, 240);();public void rand_block() / 隨機(jī)產(chǎn)生磚塊 int num;num = ( int )() * 6) + 1;/ 產(chǎn)生 06 之間的隨機(jī)數(shù)blockNumber = num;switch case( blockNumber)1:block1();blockNumber =1; breakcase2:block2();blockNumber =2; breakcase3:block3();blockNumb

7、er =3; breakcase4:block4();blockNumber =4; breakcase5:block5();blockNumber =5; breakcase6:block6();blockNumber =6; breakcase7:block7();blockNumber =7; breakpublic void change_body( int blockNumber) / 改變磚塊狀態(tài) dingwei();if (blockNumber = 1&& downSignfalse) / 變換長(zhǎng)條 2 種情況if ( game_sign_y 0 =game_s

8、ign_y1&& game_sign_y3長(zhǎng)條是橫著的if ( game_body game_sign_y 0- 1 game_sign_x02&& game_body game_sign_y 3 + 2game_sign_x3 - 2 !=2)num_csh_game();game_body game_sign_y0 - 1game_sign_x0 + 1 =1;game_body game_sign_y1 game_sign_x 1 =1;game_body game_sign_y2 + 1game_sign_x2 - 1 =1;game_body game

9、_sign_y3 + 2game_sign_x3 - 2 =1;( " 游戲進(jìn)行中 !" );repaint();<= 16)/1說(shuō)明!=if ( game_sign_x 01&& game_sign_x 3 <= 7)= game_sign_x 1&& game_sign_x 0 / 說(shuō)明長(zhǎng)條是豎著的>=game_sign_x 0-1!=2&& game_body game_sign_y num_csh_game();game_body game_sign_y3 - 2game_sign_x3 + 2 !=

10、 2)0 + 1game_sign_x0 - 1 = 1;game_body game_sign_y1 game_sign_x 1=1;game_body game_sign_y2 - 1game_sign_x2 + 1 = 1;game_body game_sign_y3 - 2game_sign_x3 + 2 = 1;1+if ( game_body game_sign_y 0( " 游戲進(jìn)行中 !" );repaint();if (blockNumber = 3&&if ( game_sign_x 0 game_sign_x 2&& g

11、ame_sign_y 2 1)downSignfalse ) / 變換轉(zhuǎn)彎 1有 4種情況game_sign_x 1&& game_sign_x 0 = game_sign_y 3&& game_sign_x0>=if ( game_body game_sign_y 02&& game_body game_sign_y 2 - 1+ 1 game_sign_x 0 - 1 != game_sign_x 2 + 1 != 2&& game_body game_sign_y 3 - 2 num_csh_game();game_s

12、ign_x3 != 2)game_body game_sign_y0 + 1game_sign_x0 - 1game_body game_sign_y1 game_sign_x 1 =1;game_body game_sign_y2 - 1game_sign_x2 + 1game_body game_sign_y3 - 2game_sign_x3 = 1);= 1;= 1;( " 游戲進(jìn)行中 !"repaint();if ( game_sign_y game_sign_y 3&& 17)if ( game_body game_sign_y 2&&am

13、p; game_body game_sign_y 1 2&& game_body game_sign_y1 = game_sign_x0game_sign_y 2&& game_sign_y 2 = game_sign_x 3&& game_sign_y0game_sign_x 0+ 1 game_sign_x 1211<=!=!=3 - 1num_csh_game();game_bodygame_bodygame_bodygame_bodygame_sign_x 3 - 1 != 2) game_sign_y game_sign_y ga

14、me_sign_y game_sign_y);01 + 123 - 1game_sign_x 0 - 2 = 1; game_sign_x 1 + 1 = 1;game_sign_x 2 = 1; game_sign_x 3 - 1 = 1;( " 游戲進(jìn)行中 !"repaint();if ( game_sign_xgame_sign_x 3&&8)if ( game_body game_sign_y2&& game_body game_sign_y 12&& game_body game_sign_y1 = game_sig

15、n_y10game_sign_x 2&& game_sign_x= game_sign_y 1&& game_sign_x3<=2 game_sign_x 01 game_sign_x 1 -!=3 - 1 game_sign_x 3 + 1 != 2) num_csh_game();01!= 1;game_body game_sign_y0 + 2game_sign_x0 =1game_body game_sign_y1 +1game_sign_x1 -1game_body game_sign_y2game_sign_x 2 =1;game_body g

16、ame_sign_y3 -1game_sign_x3 +1);= 1;( " 游戲進(jìn)行中 !"repaint();if ( game_sign_y game_sign_y 2&&0 = game_sign_xgame_sign_y 1&& game_sign_y 1 0 =game_sign_x 3)if ( game_body game_sign_y2&& game_body game_sign_y 20- 1+ 1 game_sign_x 0 + 1 != game_sign_x 2 - 1 != 2&&

17、game_body game_sign_y 3 game_sign_x 3 + 2 != 2) num_csh_game();game_body game_sign_y 0 + game_body game_sign_y 1 game_body game_sign_y 2 - game_body game_sign_y 31 game_sign_x 0 + 1 = 1; game_sign_x 1 = 1;1 game_sign_x 2 - 1 = 1; game_sign_x 3 + 2 = 1;( " 游戲進(jìn)行中 !" ); repaint();if (blockNum

18、ber = 4&& downSign= false ) / 變換轉(zhuǎn)彎 2有 4種情況if ( game_sign_x 0 = game_sign_x 3&& game_sign_y 7)if ( game_body game_sign_ygame_sign_x 1&& game_sign_x 01 = game_sign_y 2&& game_sign_x0 + 2 game_sign_x 03 <=!=+ 1 game_sign_x 1+ 1 !=2&& game_body game_sign_y 12&a

19、mp;& game_body game_sign_y3 game_sign_x 3 + 2 != 2) num_csh_game();game_body game_sign_y0 +2 game_sign_x0 = 1game_body game_sign_y1 +1 game_sign_x1 + 1game_body game_sign_y2game_sign_x 2 =1;game_body game_sign_y3game_sign_x 3 +2 = 1;( " 游戲進(jìn)行中 !" );repaint();if ( game_sign_y 1 =game_sig

20、n_y 2&& game_sign_y1 =game_sign_y 3&& game_sign_x if ( game_body game_sign_y0 = game_sign_x2)1game_sign_x 1+2!=2&& game_body game_sign_y 22&& game_body game_sign_y- 1 game_sign_x 2 +1!=3 - 2 game_sign_x 3 != 2)num_csh_game();game_body game_sign_y0game_sign_x 0 =1;game

21、_body game_sign_y1game_sign_x 1 +2 = 1;game_body game_sign_y2 - 1game_sign_x2 + 1game_body game_sign_y3 - 2game_sign_x3 = 1);= 1;( " 游戲進(jìn)行中 !"repaint();if ( game_sign_x game_sign_x 3&& 2) if ( game_body game_sign_y2&& game_body game_sign_y 22&& game_body game_sign_y0

22、 = game_sign_y01game_sign_x 2&& game_sign_x= game_sign_y 2&& game_sign_x0 game_sign_x 0- 1 game_sign_x 2210>=!=!=3 - 2 game_sign_x 3 != 2)num_csh_game();game_body game_sign_y0game_sign_x 0 -2 = 1;game_body game_sign_y1game_sign_x 1= 1;game_body game_sign_y2 - 1game_sign_x2 - 1game

23、_body game_sign_y3 - 2game_sign_x3 = 1);= 1;( " 游戲進(jìn)行中 !" repaint();if ( game_sign_y game_sign_y 2&& 16)0 = game_sign_x 1game_sign_y 1&& game_sign_y 0 = game_sign_x 3&& game_sign_y0<=1if ( game_body game_sign_y 0+ 2 game_sign_x 02&& game_body game_sign_y 1

24、2&& game_body game_sign_y+ 1 game_sign_x 1!=!=2 game_sign_x 2 - 2 != 2) num_csh_game();game_body game_sign_y0 + 2 game_sign_x0 = 1game_body game_sign_y1 + 1 game_sign_x1 - 1game_body game_sign_y2 game_sign_x 2 -2 = 1;game_body game_sign_y3 game_sign_x 3= 1;= 1;( " 游戲進(jìn)行中 !" );repain

25、t();if (blockNumber = 5&&if ( game_sign_x 0 game_sign_x 3&& game_sign_y 2)if ( game_body game_sign_y2&& game_body game_sign_y 12&& game_body game_sign_ydownSignfalse) / 變換轉(zhuǎn)彎 3有 4種情況00game_sign_x= game_sign_y 1&& game_sign_x2&& game_sign_x 2+ 1 game_sig

26、n_x 0 game_sign_x 1 -211>=!=!=3 - 1 game_sign_x 3 + 1 != 2)num_csh_game();game_body game_sign_y0 +1 game_sign_x0 - 1game_body game_sign_y1game_sign_x 1 -2 = 1;game_body game_sign_y2game_sign_x 2= 1;game_body game_sign_y3 -1 game_sign_x3 + 1);= 1;= 1;( " 游戲進(jìn)行中 !"repaint();if ( game_sign_

27、y game_sign_y 3&& 16) if ( game_body game_sign_y2&& game_body game_sign_y 11 = game_sign_x002&& game_body game_sign_ygame_sign_y 2&& game_sign_y 2 = game_sign_x 1&& game_sign_y02 game_sign_x 01 game_sign_x 1 +<=!=!=1game_sign_x 0 = 1; game_sign_x 1 + 1 = 1;

28、game_body game_sign_y2 game_sign_x 2 = 1;game_body game_sign_y 3 - 1game_sign_x 3 - 1 = 1;( " 游戲進(jìn)行中 !" );repaint(); if ( game_sign_x 0 = game_sign_x 1&& game_sign_x 1 = game_sign_x 3&& game_sign_y 2 = game_sign_y 3)if ( game_body game_sign_y 0 + 1 game_sign_x 0 - 1 != 2&

29、;& game_body game_sign_y 2 game_sign_x 2 + 2 != 2&& game_body game_sign_y3 - 1 game_sign_x 3 + 1 != 2)num_csh_game();game_body game_sign_y0 +1 game_sign_x0 - 1game_body game_sign_y1game_sign_x 1 =1;game_body game_sign_y2game_sign_x 2 +2 = 1;game_body game_sign_y3 -1 game_sign_x3 + 1);= 1

30、;= 1;( " 游戲進(jìn)行中 !"repaint();if ( game_sign_y game_sign_y 2&&0 = game_sign_xgame_sign_y 1&& game_sign_y 2 =game_sign_x 3)1if ( game_body game_sign_y2&& game_body game_sign_y 20- 1+ 1 game_sign_x 0 game_sign_x 2 - 1 != 2&& game_body1!= game_sign_y 3 - 2 game_si

31、gn_x 3 != 2) num_csh_game();game_body game_sign_y0 + 1game_sign_x0 + 1game_body game_sign_y1 game_sign_x 1 =1;game_body game_sign_y2 - 1game_sign_x2 - 1game_body game_sign_y3 - 2game_sign_x3 = 1= 1;( " 游戲進(jìn)行中 !" );3 - 1game_sign_x 3 - 1 != 2)num_csh_game();game_body game_sign_y 0 + 2 game_b

32、ody game_sign_y 1 + 1= 1;repaint();if (blockNumber = 6&&downSign = false ) / 變換兩層磚塊 1 的2種情況if ( game_sign_x 0 =game_sign_x 2&& game_sign_x 0 >= 2)if ( game_body game_sign_y 0 game_sign_x 0 - 2 2&& game_body game_sign_y 2 - 1 game_sign_x 2 -1 2&& game_body game_sign

33、_y!=!=3 - 1 game_sign_x 3 + 1 != 2)num_csh_game();game_body game_sign_y0game_sign_x 0 - 2 = 1;game_body game_sign_y1game_sign_x 1 = 1;game_body game_sign_y2 - 1game_sign_x 2 - 1game_body game_sign_y3 - 1game_sign_x 3 + 1);= 1;= 1;( " 游戲進(jìn)行中 !" repaint();if ( game_sign_y0 =game_sign_y1&&

34、amp; game_sign_y3<=17)if ( game_body game_sign_y 0game_sign_x 0+ 22&& game_body game_sign_y 1+ 1 game_sign_x 1+ 1!=!=2&& game_body game_sign_y3 + 1 game_sign_x 3 - 1 != 2) num_csh_game();game_body game_sign_y0game_sign_x 0 + 2 = 1;game_body game_sign_y1 +1 game_sign_x1+ 1game_body

35、 game_sign_y2game_sign_x 2 =1;game_body game_sign_y3 +1 game_sign_x3- 1= 1;= 1;( " 游戲進(jìn)行中 !" ); repaint();downSignfalse ) / 變換兩層磚塊 2 的2種情況if (blockNumber = 7&& if ( game_sign_x 0 = game_sign_x 1&& game_sign_x 0 <= 16)if ( game_body game_sign_y 0 game_sign_x 0 + 22&&am

36、p; game_body game_sign_y 1 - 1 game_sign_x 1 + 1!=!=game_sign_x 3 - 1 != 2)num_csh_game();game_body game_sign_y0game_sign_x 0 +2 =1;game_body game_sign_y1 - 1game_sign_x1+ 1game_body game_sign_y2game_sign_x 2 =1;game_body game_sign_y3 - 1game_sign_x3- 1);= 1;= 1;3 - 1 ( " 游戲進(jìn)行中 !"repaint()

37、;if ( game_sign_y if ( game_body0 =game_sign_y game_sign_y 01&&+ 12&& game_body game_sign_y 1 game_sign_xgame_sign_y 2 <= 17)game_sign_x 01 -21!=!=2&& game_body game_sign_y2&& game_body game_sign_y 2 + 1 game_sign_x 2 + 1 != 2)num_csh_game();game_body game_sign_y0

38、+1 game_sign_x0 - 1game_body game_sign_y1game_sign_x 1 -2 = 1;game_body game_sign_y2 +1 game_sign_x2 + 1game_body game_sign_y3game_sign_x 3= 1;= 1;= 1;( " 游戲進(jìn)行中 !" );repaint();public void num_csh_game() / 數(shù)組清零 for ( int i = 0;i < 19;i+)for ( int j = 0;j < 10;j+) if ( game_body ij = 2

39、)game_body ij = 2;elsegame_body ij = 0;public void num_csh_restart() / 重新開(kāi)始時(shí)數(shù)組清零 for ( int i = 0;i < 19;i+)for ( int j = 0;j < 10;j+)game_body ij = 0;public void keyTyped(KeyEvent e)public void keyPressed(KeyEvent e) if ();() = &&startSign= 1)/處理下鍵();if() = &&startSign= 1)/處理左鍵

40、();();if() = &&startSign= 1)/處理右鍵();if() = &&startSign= 1)/處理上鍵轉(zhuǎn)換( blockNumber );if ( startSign = 0)( " 游戲未開(kāi)始或已結(jié)束 !" );publicvoid keyReleased(KeyEvent e)publicvoid paint(Graphics g)(0,0,300,450, true );for ( int i = 0;i < 19;i+)for ( int j = 0;j < 10;j+)if ( game_body

41、 ij = 1)(30*j,30*(i-4),30,30, true );if ( game_body ij = 2)(30*j,30*(i-4),30,30, true );public void left() / 向左移動(dòng)int sign = 0;dingwei();for ( int k = 0;k < 4;k+)if ( game_sign_x k = 0| game_body game_sign_y k game_sign_x k - 1 = 2)sign = 1;if (sign = 0&& downSign = false )num_csh_game();f

42、or ( int k = 0;k < 4;k+)game_body game_sign_y k game_sign_x k - 1 = 1;( " 向左移動(dòng) !" ); repaint();public void right() / 向右移動(dòng)int sign = 0;dingwei();for ( int k = 0;k < 4;k+)if ( game_sign_x k = 9| game_body game_sign_y k game_sign_x k 1 = 2)sign = 1;if (sign = 0&& downSign = fals

43、e )num_csh_game();for ( int k = 0;k < 4;k+)game_body game_sign_y k game_sign_x k + 1 = 1;( " 向右移動(dòng) !" );repaint();public void down() / 下落int sign = 0;dingwei();for ( int k = 0;k < 4;k+)if ( game_sign_y k = 18| game_body game_sign_y k1 game_sign_x k = 2)sign = 1;downSign = true ;change

44、Color(); cancelDW();getScore();if (game_over() = false ) rand_block(); repaint();if (sign = 0) num_csh_game();for ( int k = 0;k < 4;k+) game_body game_sign_y k + 1 ( " 游戲進(jìn)行中 !" ); repaint();game_sign_k = 1;public boolean game_over() int sign=0;for ( int i = 0;i < 10;i+)if ( game_body 4i = 2)sign = 1;if (sign = 1)( " 游戲結(jié)束 !" ); changeColor();repaint();startSign = 0;();return true ;elsereturn false ;/ 判斷游戲是否結(jié)束public void getScore()/ 滿行消除方法for ( int i= 0;i < 19;i

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論