版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、 . 東西絕對不多說,直接看!看了拷貝就懂了!,直接可以拷貝下面的東西,然后記得把那個(gè)BLOCK的名字改成你自己的類名,這個(gè)很關(guān)鍵哦,不然是錯(cuò)的可別怪我,呵呵 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.applet.*; import java.lang.String.*; import java.lang.*; import java.io.*; public class Block extends JPanel implements ActionListener,KeyList
2、ener/應(yīng)該是 繼承JPanel but = new Button Button6; staticnoStop = new Button(取 消 static Button 暫 停); scoreLab = new Label(分?jǐn)?shù)尺static Label ); infoLab = new Label(提示static Label 尺); speedLab = new Label( Label 級數(shù)尺); staticscoreTex = new Label( Label ); staticinfoTex = new Label(?static Label ); speedTex = ne
3、w Label(?static Label ); 專業(yè)資料 . jf = new JFrame(); static JFrame timer; MyTimer staticicon=new ImageIcon(static ImageIcon 牜獥畯捲履?潬正樮杰); mb = new JMenuBar(); static JMenuBar menu0 = new JMenu(游戲 static JMenu ); menu1 = new JMenu(幫助 static JMenu ); mi0 = new JMenuItem(新 JMenuItem 游 戲); staticmi1 = new
4、JMenuItem(退出static JMenuItem ); mi1_0 = new JMenuItem(關(guān)于static JMenuItem ); dlg_1; JDialog staticdlg_1_text = newstatic JTextArea JTextArea(); startSign = 0;/游戲開始標(biāo)志 0 未開始 1 開始static int 2 暫停 butLab = 開 始 游 戲,重 新 開 始,降 低 級 數(shù),提 String static高 級 數(shù),游 戲 暫 停,退 出 游 戲; game_body = new intstatic int 1910; ga
5、me_sign_x = new int4;/用于記錄 static int4個(gè)方格的水平位置 game_sign_y = new int4;/int 用于記錄4個(gè)方格的垂直位置 static downSign = false;/boolean 是否落下 staticblockNumber = 1;/ 磚塊的編號 intstatic gameScore = 0;/游戲分?jǐn)?shù) staticint speedMark = 1; intstatic 專業(yè)資料 . public static void main(String args) Block myBlock = new Block(); mbmen
6、u0); .add(mbmenu1); .add(menu0mi0); .add(menu0mi1); .add(menu1mi1_0); .add(jfmb); .setJMenuBar( myBlock.init(); jf.add(myBlock); jf.setSize(565,501); jf.setResizable(false); jf.setTitle(俄羅斯方塊); jficon.getImage(); .setIconImage(jf.setLocation(200,100); jf.show(); timer = new MyTimer(myBlock); /啟動(dòng)線程 t
7、imer.setDaemon(true); timer.start(); timer.suspend(); 專業(yè)資料 . public void init() setLayout(null); for(int i = 0;i 6;i+) butbutLabi); Button(i = newbuti); add( buti.addActionListener(this); buti.addKeyListener(this); buti.setBounds(360,(240 + 30 * i),160,25); scoreLab); add( scoreTex); add( speedLab);
8、 add( speedTex); add( infoLab); add( infoTex); add( scoreLab); add( scoreLab.setBounds(320,15,30,20); scoreTex.setBounds(360,15,160,20); 專業(yè)資料 . scoreTexwhite); .setBackground(Color.speedLab.setBounds(320,45,30,20); speedTex.setBounds(360,45,160,20); speedTexwhite); .setBackground(Color. but1.setEnab
9、led(false); but4.setEnabled(false); infoLab.setBounds(320,75,30,20); infoTex.setBounds(360,75,160,20); infoTexwhite); .setBackground(Color.noStop.setBounds(360,360,160,25); noStop.addActionListener(this); noStop.addKeyListener(this); mi0.addActionListener(this); mi1.addActionListener(this); mi1_0.ad
10、dActionListener(this); num_csh_game(); rand_block(); public void actionPerformed(ActionEvent e) 專業(yè)資料 . but0)/開始游戲if(e.getSource() = startSign = 1; infoTex.setText(游戲已經(jīng)開始尡); but0.setEnabled(false ); but1.setEnabled(true ); but4.setEnabled(true ); timer.resume(); butmi0)/(e.getSource() = 重新開始游戲1|e.get
11、Source() = if startSign = 0; gameScore = 0; timer.suspend(); num_csh_restart(); repaint(); rand_block(); scoreTex.setText(); infoTex.setText(新游戲?qū)?); but0.setEnabled(true ); but1.setEnabled(false ); 專業(yè)資料 . but4.setEnabled(false); but2)/降低級數(shù)if(e.getSource() = infoTex.setText(降低級數(shù)尡); speedMark-; speedM
12、ark = 9) if( speedMark = 9; infoTex.setText(已經(jīng)是最高級數(shù)尡); 專業(yè)資料 . speedTexspeedMark + ); .setText( but4)/游戲暫停if(e.getSource() = noStop); .add( thisbut4); .remove( thisinfoTex.setText(游戲暫停尡); timer.suspend(); noStop)/取消暫停 if(e.getSource() = noStop); this.remove( but4); this.add( infoTex.setText(繼續(xù)游戲?qū)?; t
13、imer.resume(); butmi1)/退出游戲5|e.getSource() = if (e.getSource() = jf.dispose(); mi1_0)/退出游戲 if (e.getSource() = 專業(yè)資料 . dlg_1jf,關(guān) new JDialog(于 ); = try FileInputStream io = new FileInputStream(牜獥畯捲履術(shù)慵祮?硴屴);/得到路徑 byte a = new byteio.available(); io.read(a); io.close(); String str = new String(a); dlg_
14、1_text.setText(str); catch(Exception g) dlg_1_text.setEditable(false ); dlg_1dlg_1_text); .add( dlg_1.pack(); dlg_1.setResizable(false); dlg_1.setSize(200, 120); dlg_1.setLocation(400, 240); dlg_1.show(); public void rand_block()/隨機(jī)產(chǎn)生磚塊 專業(yè)資料 . int num; random() * 6) + 1;/產(chǎn)生)(Math.06之間的隨機(jī)數(shù) num = (int
15、blockNumber = num; blockNumber) switch( blockNumber = 1; break; case 1: block1(); blockNumber = 2; breakcase 2: block2(); ; blockNumber = 3; breakcase 3: block3(); ; blockNumber = 4; break 4: block4(); ; case blockNumber = 5; break 5: block5(); ; caseblockNumber = 6; break 6: block6(); ; caseblockNu
16、mber = 7; break; case 7: block7(); public void change_body(int blockNumber)/改變磚塊狀態(tài) dingwei(); downSign = false)/變換長條2if (blockNumber = 1&種情況 game_sign_ygame_sign_ygame_sign_y3 = 1&1&if (= 1) 2 = 3&2& game_bodygame_sign_ygame_sign_x0 - 1 != 0 + ( if1game_bodygame_sign_ygame_sign_xgame_body 2 + 1 != 2
17、&2 - 12& game_sign_ygame_sign_x3 != 2) 3 - 2 num_csh_game(); game_bodygame_sign_ygame_sign_x0 - 1 = 1; 0 + 1game_bodygame_sign_ygame_sign_x1 = 1; 1 game_bodygame_sign_ygame_sign_x2 + 1 = 1; 2 - 1 game_bodygame_sign_ygame_sign_x3 = 1; 3 - 2 專業(yè)資料 . infoTex.setText(游戲進(jìn)行中尡 ); repaint(); game_sign_ygame_
18、sign_ygame_sign_y2 2&1 = = if(game_sign_ygame_sign_xgame_sign_xgame_sign_y1 = 17) 3&3&0 = game_bodygame_sign_ygame_sign_x0 - 02 if(!= game_sign_xgame_bodygame_sign_y1 11 + + 1 2&!= game_sign_ygame_body 2& game_sign_x3 - 1 != 2) 3 - 1 num_csh_game(); game_sign_xgame_bodygame_sign_y 00 - 2 = 1; game_s
19、ign_xgame_sign_ygame_body1 + 1 = 1; 1 + 1 game_sign_xgame_sign_ygame_body2 = 1; 2 game_sign_xgame_sign_ygame_body3 - 1 = 1; 3 - 1 infoTex); 游戲進(jìn)行中尡 .setText(repaint(); 專業(yè)資料 . game_sign_xgame_sign_xgame_sign_x1 = if (2&1 = game_sign_xgame_sign_ygame_sign_ygame_sign_x3 = 8) 0 = 3&1& game_bodygame_sign_
20、ygame_sign_x0 != + 20 if(game_sign_xgame_bodygame_sign_y!= - + 12&1 1 1 game_sign_ygame_body 2& game_sign_x3 + 1 != 2) 3 - 1 num_csh_game(); game_sign_xgame_bodygame_sign_y 0 + 20 = 1; game_sign_xgame_bodygame_sign_y1 - 1 = 1; 1 + 1game_sign_xgame_bodygame_sign_y2 = 1; 2 game_sign_xgame_bodygame_sig
21、n_y3 + 1 = 1; 3 - 1 infoTex); 尡.setText(游戲進(jìn)行中 repaint(); game_sign_ygame_sign_ygame_sign_y= 0 = 1&1 if(game_sign_xgame_sign_ygame_sign_x3) 0 = 2& game_sign_xgame_bodygame_sign_y!= 1( if0 + 0 + 1 專業(yè)資料 . game_bodygame_sign_ygame_sign_xgame_body 2&2 - 12 - 1 != 2& game_sign_ygame_sign_x3 + 2 != 2) 3 nu
22、m_csh_game(); game_bodygame_sign_ygame_sign_x0 + 1 = 1; 0 + 1game_bodygame_sign_ygame_sign_x1 = 1; 1 game_bodygame_sign_ygame_sign_x2 - 1 = 1; 2 - 1 game_bodygame_sign_ygame_sign_x3 + 2 = 1; 3 infoTex.setText(游戲進(jìn)行中尡); repaint(); downSign = false)/變換轉(zhuǎn)彎2有4 if(blockNumber = 4&種情況 game_sign_xgame_sign_x
23、game_sign_x0 = 0 = if(1&game_sign_xgame_sign_ygame_sign_ygame_sign_x3 = 2) 1 = 2&3& game_bodygame_sign_ygame_sign_x0 - (2 != 0 ifgame_sign_xgame_sign_ygame_body2 1- 2&- 1 2 != game_sign_ygame_body 2& game_sign_x3 != 2) 3 - 2 num_csh_game(); game_sign_xgame_bodygame_sign_y0 - 2 = 1; 0 game_sign_xgame
24、_bodygame_sign_y1 = 1; 1game_sign_xgame_bodygame_sign_y2 - 1 = 1; 2 - 1game_sign_xgame_bodygame_sign_y3 = 1; 3 - 2 專業(yè)資料 . infoTex.setText(游戲進(jìn)行中尡 ); repaint(); game_sign_ygame_sign_ygame_sign_y0 1&0 = = if(game_sign_ygame_sign_xgame_sign_xgame_sign_y0 = 2) 3&1&0 = game_bodygame_sign_ygame_sign_x0 - 1
25、 + if(1!= 0 game_bodygame_sign_ygame_sign_x1 - 2 1!= 2&game_bodygame_sign_y 2& game_sign_x3 + 1 != 2) 3 - 1 num_csh_game(); game_bodygame_sign_ygame_sign_x0 - 1 = 1; 0 + 1game_bodygame_sign_ygame_sign_x1 - 2 = 1; 1 game_bodygame_sign_ygame_sign_x2 = 1; 2 game_bodygame_sign_ygame_sign_x3 + 1 = 1; 3 -
26、 1infoTex.setText(游戲進(jìn)行中 尡); repaint(); game_sign_ygame_sign_ygame_sign_y2 = ( if1 = 2& 專業(yè)資料 . game_sign_ygame_sign_xgame_sign_xgame_sign_y0 = 2) 0 = if(2& game_bodygame_sign_ygame_sign_x0 - 2 0!= if(game_sign_xgame_sign_ygame_body!= 2 2&-1 2 - 1game_sign_ygame_body 2& game_sign_x3 + 1 != 2) 3 - 1 nu
27、m_csh_game(); game_sign_xgame_sign_ygame_body0 - 2 = 1; 0 game_sign_xgame_sign_ygame_body1 = 1; 1 專業(yè)資料 . game_bodygame_sign_ygame_sign_x2 - 1 = 1; 2 - 1game_bodygame_sign_ygame_sign_x3 + 1 = 1; 3 - 1infoTex.setText(游戲進(jìn)行中尡 ); repaint(); game_sign_ygame_sign_ygame_sign_y3 = 17) (1&0 = if game_bodygame
28、_sign_ygame_sign_x0 + 0 if(2 != game_sign_xgame_sign_ygame_body!= 1 1 + 1 12&+ game_sign_ygame_body 2& game_sign_x3 - 1 != 2) 3 + 1 num_csh_game(); game_sign_xgame_bodygame_sign_y0 + 2 = 1; 0game_sign_xgame_bodygame_sign_y1 + 1 = 1; 1 + 1 game_sign_xgame_sign_ygame_body2 = 1; 2 game_sign_xgame_bodyg
29、ame_sign_y3 - 1 = 1; 3 + 1infoTex); .setText(游戲進(jìn)行中尡 repaint(); 專業(yè)資料 . downSign = false)/變換兩層磚塊2的2 if(blockNumber = 7&種情況 game_sign_xgame_sign_xgame_sign_x0 = 16) if(1&0 = game_bodygame_sign_ygame_sign_x0 + 2 0 if(!= game_sign_xgame_sign_ygame_body!= 1 1 2&+ 1 - 1game_sign_ygame_body 2& game_sign_x3
30、- 1 != 2) 3 - 1 num_csh_game(); game_sign_xgame_sign_ygame_body0 + 2 = 1; 0 game_sign_xgame_bodygame_sign_y1 + 1 = 1; 1 - 1game_sign_xgame_bodygame_sign_y2 = 1; 2game_sign_xgame_sign_ygame_body3 - 1 = 1; 3 - 1 infoTex); .setText(游戲進(jìn)行中 尡repaint(); game_sign_ygame_sign_ygame_sign_y2 = 17) 1&(if0 = 專業(yè)資
31、料 . game_bodygame_sign_ygame_sign_x0 - 1 0 + if(1!= game_bodygame_sign_ygame_sign_x1 - 2&2 1!= game_bodygame_sign_y 2& game_sign_x2 + 1 != 2) 2 + 1 num_csh_game(); game_bodygame_sign_ygame_sign_x0 - 1 = 1; 0 + 1game_bodygame_sign_ygame_sign_x1 - 2 = 1; 1game_bodygame_sign_ygame_sign_x2 + 1 = 1; 2 +
32、1 game_bodygame_sign_ygame_sign_x3 = 1; 3 infoTex.setText(游戲進(jìn)行中尡); repaint(); public void num_csh_game()/數(shù)組清零 for(int i = 0;i 19;i+) 專業(yè)資料 . for(int j = 0;j 10;j+) game_bodyij = 2) if( game_bodyij = 2; else game_bodyij = 0; public void num_csh_restart()/重新開始時(shí)數(shù)組清零 for(int i = 0;i 19;i+) for(int j = 0;
33、j 10;j+) game_bodyij = 0; 專業(yè)資料 . public void keyTyped(KeyEvent e) public void keyPressed(KeyEvent e) VK_DOWNstartSign = 1)/處理下鍵if(e.getKeyCode() = KeyEvent.& this.down(); VK_LEFTstartSign = 1)/&處理左鍵if (e.getKeyCode() = KeyEvent. this.left(); VK_RIGHTstartSign = 1)/(e.getKeyCode() = KeyEvent.處理右鍵& if this.right(); VK_UPstartSign = 1)/處理上鍵轉(zhuǎn)換
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《巨匠童心》課件
- 《童年回憶的》課件
- 《客戶梳理技巧》課件
- 2024年黑龍江農(nóng)業(yè)工程職業(yè)學(xué)院單招職業(yè)技能測試題庫標(biāo)準(zhǔn)卷
- 四川省南充市2025屆高三上學(xué)期高考適應(yīng)性考試(一診)英語試卷含答案
- 單位管理制度匯編大全職員管理
- 單位管理制度合并選集人力資源管理
- 單位管理制度分享合集【人力資源管理篇】
- 單位管理制度分享大合集【人力資源管理篇】
- 單位管理制度范例匯編職員管理篇十篇
- 廚政管理說課市公開課一等獎(jiǎng)省賽課微課金獎(jiǎng)?wù)n件
- 遵守道德規(guī)范錘煉道德品格專題第3講 投身崇德向善的道德實(shí)踐1課件
- 《高等數(shù)學(xué)教程》全套教學(xué)課件
- 2024年天津市中考英語試題卷(含答案)
- 2024-2034年中國皮帶輸送機(jī)托輥行業(yè)發(fā)展趨勢及投資前景預(yù)測報(bào)告
- FZ∕T 73037-2019 針織運(yùn)動(dòng)襪行業(yè)標(biāo)準(zhǔn)
- (圖文并茂)綠化工程施工組織設(shè)計(jì)
- MOOC 生物醫(yī)學(xué)傳感器與測量-山東大學(xué) 中國大學(xué)慕課答案
- 上海市民辦華育中學(xué)2022-2023學(xué)年六年級上學(xué)期期末科學(xué)試卷
- 導(dǎo)診服務(wù)意識課件培訓(xùn)總結(jié)
- 成人用品行業(yè)分析
評論
0/150
提交評論