《java俄罗斯方块.doc》由会员分享,可在线阅读,更多相关《java俄罗斯方块.doc(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Els extends JFrame implements KeyListener,Runnable public Els() setSize(240,320); setUndecorated(true); int H=(int) (this.getToolkit().getScreenSize().height); int W=(int) (this.getToolkit().getScreenSize().width); setLoc
2、ation(W/2-120,H/2-160); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); public void paint(Graphics g) super.paint(g); Graphics2D g2=(Graphics2D)g; g2.setColor(Color.darkGray.brighter().brighter(); /绘制小框格 for(int m=192;m=232;m+=10) g2.drawLine(m, 52, m,92); for(int m=52;m=92;m+=1
3、0) g2.drawLine(192, m, 232, m); /绘制大框格 for(int m=0;m=180;m+=15) g2.drawLine(m, 0, m, 300); for(int m=0;m=300;m+=15) g2.drawLine(0, m, 180, m); /将值不非0的格子涂黑 for(int i=1;i13;i+) for(int j=0;j20;j+) g2.setColor(Color.DARK_GRAY); if (oij!=0) g2.fillRect(15*i-13, 15*j+2, 13, 13); /在小框格中绘制下一个的模型 switch(nex
4、tMODE) case 0: g2.fillRect(204, 54, 8, 8); g2.fillRect(204, 64, 8, 8); g2.fillRect(204, 74, 8, 8); g2.fillRect(204, 84, 8, 8); break; case 1: g2.fillRect(194, 64, 8, 8); g2.fillRect(204, 64, 8, 8); g2.fillRect(214, 64, 8, 8); g2.fillRect(224, 64, 8, 8); break; case 2: g2.fillRect(214, 64, 8, 8); g2.
5、fillRect(214, 74, 8, 8); g2.fillRect(214, 84, 8, 8); g2.fillRect(204, 84, 8, 8); break; case 3: g2.fillRect(204, 64, 8, 8); g2.fillRect(204, 74, 8, 8); g2.fillRect(214, 74, 8, 8); g2.fillRect(224, 74, 8, 8); break; case 4: g2.fillRect(204, 64, 8, 8); g2.fillRect(214, 64, 8, 8); g2.fillRect(204, 74,
6、8, 8); g2.fillRect(204, 84, 8, 8); break; case 5: g2.fillRect(204, 64, 8, 8); g2.fillRect(214, 64, 8, 8); g2.fillRect(224, 64, 8, 8); g2.fillRect(224, 74, 8, 8); break; case 6: g2.fillRect(204, 54, 8, 8); g2.fillRect(204, 64, 8, 8); g2.fillRect(204, 74, 8, 8); g2.fillRect(214, 74, 8, 8); break; case
7、 7: g2.fillRect(204, 74, 8, 8); g2.fillRect(214, 74, 8, 8); g2.fillRect(224, 74, 8, 8); g2.fillRect(224, 64, 8, 8); break; case 8: g2.fillRect(204, 64, 8, 8); g2.fillRect(214, 64, 8, 8); g2.fillRect(214, 74, 8, 8); g2.fillRect(214, 84, 8, 8); break; case 9: g2.fillRect(204, 64, 8, 8); g2.fillRect(21
8、4, 64, 8, 8); g2.fillRect(224, 64, 8, 8); g2.fillRect(204, 74, 8, 8); break; case 10: g2.fillRect(204, 64, 8, 8); g2.fillRect(204, 74, 8, 8); g2.fillRect(214, 74, 8, 8); g2.fillRect(214, 84, 8, 8); break; case 11: g2.fillRect(204, 74, 8, 8); g2.fillRect(214, 74, 8, 8); g2.fillRect(214, 64, 8, 8); g2
9、.fillRect(224, 64, 8, 8); break; case 12: g2.fillRect(214, 64, 8, 8); g2.fillRect(214, 74, 8, 8); g2.fillRect(204, 74, 8, 8); g2.fillRect(204, 84, 8, 8); break; case 13: g2.fillRect(204, 64, 8, 8); g2.fillRect(214, 64, 8, 8); g2.fillRect(214, 74, 8, 8); g2.fillRect(224, 74, 8, 8); break; case 14: g2
10、.fillRect(204, 64, 8, 8); g2.fillRect(214, 64, 8, 8); g2.fillRect(204, 74, 8, 8); g2.fillRect(214, 74, 8, 8); break; g2.setColor(Color.black); g2.drawLine(180, 0, 180, 300); g2.setColor(Color.DARK_GRAY); g2.drawString(LEVEL, 194, 10); g2.drawString(+LEVEL, 210, 28); g2.drawString(NEXT, 196, 45); g2.
11、drawString(SCORE,193, 110); g2.drawString(+SCORE,205, 130); g2.drawString(Xiong, 205, 160); g2.drawString(Xuan, 205, 180); /方块下落的方法 public void down() Y+; switch(MODE) case 0: oX+2Y=1; oX+2Y+1=1; oX+2Y+2=1; oX+2Y+3+; oX+2Y-1=0; break; case 1: oXY+1+; oX+1Y+1+; oX+2Y+1+; oX+3Y+1+; oXY=0; oX+1Y=0; oX+
12、2Y=0; oX+3Y=0; break; case 2: oX+2Y=1; oX+2Y+1=1; oX+2Y+2+; oX+1Y+2+; oX+2Y-1=0; oX+1Y+1=0; break; case 3: oXY=1; oXY+1+; oX+1Y+1+; oX+2Y+1+; oXY-1=0; /oXY=0; oX+1Y=0; oX+2Y=0; break; case 4: oX+1Y=1; oX+2Y+; oX+1Y+1=1; oX+1Y+2+; oX+1Y-1=0; oX+2Y-1=0; break; case 5: oXY+; oX+1Y+; oX+2Y=1; oX+2Y+1+;
13、oXY-1=0; oX+1Y-1=0; oX+2Y-1=0; break; case 6: oX+1Y=1; oX+1Y+1=1; oX+1Y+2+; oX+2Y+2+; oX+1Y-1=0; /oX+1Y=0; /oX+1Y+1=0; oX+2Y+1=0; break; case 7: oXY+1+; oX+1Y+1+; oX+2Y+1+; oX+2Y=1; oXY=0; oX+1Y=0; /oX+2Y=0; oX+2Y-1=0; break; case 8: oX+1Y+; oX+2Y=1; oX+2Y+1=1; oX+2Y+2+; oX+1Y-1=0; oX+2Y-1=0; /oX+2Y
14、=0; /oX+2Y+1=0; break; case 9: oX+1Y=1; oX+2Y+; oX+3Y+; oX+1Y+1+; oX+1Y-1=0; oX+2Y-1=0; oX+3Y-1=0; /oX+1Y=0; break; case 10:oX+1Y=1; oX+1Y+1+; oX+2Y+1=1; oX+2Y+2+; oX+1Y-1=0; /oX+1Y=0; oX+2Y=0; /oX+2Y+1=0; break; case 11:oX+2Y=1; oX+3Y+; oX+1Y+1+; oX+2Y+1+; oX+2Y-1=0; oX+3Y-1=0; oX+1Y=0; /oX+2Y=0; b
15、reak; case 12:oX+1Y+1=1; oX+2Y+1+; oX+1Y+2+; oX+2Y=1; oX+1Y=0; /oX+2Y=0; /oX+1Y+1=0; oX+2Y-1=0; break; case 13:oX+1Y+; oX+2Y=1; oX+2Y+1+; oX+3Y+1+; oX+1Y-1=0; oX+2Y-1=0; /oX+2Y=0; oX+3Y=0; break; case 14:oX+1Y=1; oX+2Y=1; oX+1Y+1+; oX+2Y+1+; oX+1Y-1=0; oX+2Y-1=0; /oX+1Y=0; /oX+2Y=0; break; /如果碰撞,则自动上升一格 for(int i=0;i13;i+) for(int j=0;j21;j+) if (oij=2) up();