📄 gameframe.java~1~
字号:
for(int i = 0; i < line.length; i++) { if(line[i] != 0) { block.delLine(line[i]); oneTime++; this.setLevel(); } } this.setScore(oneTime); } public void setHeight(int i){ int x,y; this.height = i; switch(i){ case 0: break; case 1: for(y = block.getbgHeight()-1; y > block.getbgHeight()-2 ; y--) for(x = 0; x < block.getbgWidth(); x++) block.bgInformation[x][y] = (byte)(Math.random()*2);repaint();break; case 2: for(y = block.getbgHeight()-1; y >= block.getbgHeight()-3 ; y--) for(x = 0; x < block.getbgWidth(); x++) block.bgInformation[x][y] = (byte)(Math.random()*2);repaint();break; case 3: for(y = block.getbgHeight()-1; y >= block.getbgHeight()-4 ; y--) for(x = 0; x < block.getbgWidth(); x++) block.bgInformation[x][y] = (byte)(Math.random()*2);repaint();break; case 4: for(y = block.getbgHeight()-1; y >= block.getbgHeight()-5 ; y--) for(x = 0; x < block.getbgWidth(); x++) block.bgInformation[x][y] = (byte)(Math.random()*2);repaint();break; case 5: for(y = block.getbgHeight()-1; y >= block.getbgHeight()-6 ; y--) for(x = 0; x < block.getbgWidth(); x++) block.bgInformation[x][y] = (byte)(Math.random()*2);repaint();break; case 6: for(y = block.getbgHeight()-1; y >= block.getbgHeight()-7 ; y--) for(x = 0; x < block.getbgWidth(); x++) block.bgInformation[x][y] = (byte)(Math.random()*2);repaint();break; case 7: for(y = block.getbgHeight()-1; y >= block.getbgHeight()-8 ; y--) for(x = 0; x < block.getbgWidth(); x++) block.bgInformation[x][y] = (byte)(Math.random()*2);repaint();break; case 8: for(y = block.getbgHeight()-1; y >= block.getbgHeight()-9 ; y--) for(x = 0; x < block.getbgWidth(); x++) block.bgInformation[x][y] = (byte)(Math.random()*2);repaint();break; case 9: for(y = block.getbgHeight()-1; y >= block.getbgHeight()-10 ; y--) for(x = 0; x < block.getbgWidth(); x++) block.bgInformation[x][y] = (byte)(Math.random()*2);repaint();break; } } public void paint(Graphics g ){ repaintBG(getGraphics()); if(isStart) paintCurrentBlock(getGraphics()); } public void update(Graphics g){ paint(g); } public boolean isStop(){ int x; for(x =0 ; x < block.getbgWidth(); x++){ if(block.bgInformation[x][0]==1) return true; } return false; } public void handleKeyEvent(KeyEvent e) { if(!this.isStart&&!this.isPause) return ; if(e.getKeyCode() == e.VK_LEFT){ if(block.goLeft()){ repaint(); } } else if(e.getKeyCode() == e.VK_UP){ if(block.goTurn()){ repaint(); } } else if(e.getKeyCode() == e.VK_RIGHT){ if(block.goRight()){ repaint(); } } else if(e.getKeyCode() == e.VK_DOWN){ if(block.goDown()){ repaint(); } } } public void repaintBG(Graphics g){ String nextBlock = "下一个方块"; String score = "得分 : ", level = "等级 : " , speed = "速度 : "; g.setColor(Color.red); g.drawString(score+this.blockScore,60,80); g.drawString(level+this.blockLevel,60,110); g.drawString(speed+this.blockSpeed,60,140); g.setColor(Color.blue); g.drawString(nextBlock,50,200); g.setColor(Color.red); g.draw3DRect(190,40,240,400,false); g.setColor(Color.blue); g.draw3DRect(195,45,230,390,true); this.paintBackGround(getGraphics()); } public void setScore(int delLine){ int s = delLine; switch(s){ case 0: this.blockScore += 5 ;break; case 1: this.blockScore += 20;break; case 2: this.blockScore += 50;break; case 3: this.blockScore += 80;break; case 4: this.blockScore += 100;break; } } public void setLevel(){ this.blockLevel++; this.setSpeed(); } public void setSpeed(){ if((this.blockLevel%5) == 0) this.blockSpeed++; this.setSleepTime(this.blockSpeed); } public void paintCurrentBlock(Graphics g){ int x,y; byte[][] currentBlockTemp; g.setColor(block.getCurrentBlockColor()); currentBlockTemp = block.getCurrentBlock(); for(x = 0; x < block.getCubeEach(); x++) for(y = 0; y < block.getCubeEach(); y++) if(currentBlockTemp[y][x] == 1) g.fill3DRect( block.getBGX()+(block.getCurrentX()+x)*block.getCubeWidth(), block.getBGY()+(block.getCurrentY()+y)*block.getCubeHeight(), block.getCubeWidth(),block.getCubeHeight(), false); } public void paintNextBlock(Graphics g){ int x,y; byte[][] nextBlockTemp; clearBlock(getGraphics()); g.setColor(block.getNextBlockColor()); nextBlockTemp = block.getNextBlock(); for(x = 0; x < block.getCubeEach(); x++) for(y = 0; y < block.getCubeEach(); y++) if(nextBlockTemp[y][x] == 1) g.fill3DRect( 60+x*block.getCubeWidth(), 240+y*block.getCubeHeight(), block.getCubeWidth(),block.getCubeHeight(), true); g.setColor(Color.white); g.fillRect(95,70,40,70); } public void clearBlock(Graphics g){ int x,y; g.setColor(Color.white); for(x = 0; x < block.getCubeEach(); x++) for(y = 0; y < block.getCubeEach(); y++) g.fillRect( 60+x*block.getCubeWidth(), 240+y*block.getCubeHeight(), block.getCubeWidth(),block.getCubeHeight()); } public void setBGInformation(){ int x,y; byte[][] currentBlockTemp; currentBlockTemp = block.getCurrentBlock(); for(x = 0; x < block.getCubeEach(); x++) for(y = 0; y < block.getCubeEach(); y++) if(currentBlockTemp[y][x] == 1) block.bgInformation[block.getCurrentX()+x][block.getCurrentY()+y]=1; } public void paintBackGround(Graphics g){ int x,y; byte[][] currentBlockTemp; currentBlockTemp = block.bgInformation; for(x = 0; x < block.getbgWidth(); x++) for(y = 0; y < block.getbgHeight(); y++) if(currentBlockTemp[x][y] == 1){ g.setColor(new Color(0,128,128)); g.fill3DRect( block.getBGX()+x*block.getCubeHeight(), block.getBGY()+y*block.getCubeWidth(), block.getCubeWidth(),block.getCubeHeight(), true); } else { g.setColor(this.getBGColor()); g.fillRect( block.getBGX()+x*block.getCubeHeight(), block.getBGY()+y*block.getCubeWidth(), block.getCubeWidth(),block.getCubeHeight() ); } } public void paintStop(){ int x,y; for(y = block.getbgHeight()-1; y >= 0 ; y--) for(x = 0; x<block.getbgWidth(); x++){ block.bgInformation[x][y]=1; this.paintBackGround(getGraphics());try{thread.sleep(10);}catch(InterruptedException e){ return; } } } public void reset(){ int x,y; block.setCurrentXY(4,0) ; for(y = block.getbgHeight()-1; y >= 0 ; y--) for(x = 0; x<block.getbgWidth(); x++) block.bgInformation[x][y]=0; this.isStart = true; this.setPause(true); this.sleep = 700; this.blockScore = this.blockLevel = this.blockSpeed = 0; this.setHeight(this.height); block.setNextBlock(); block.reset(); this.paintNextBlock(getGraphics()); repaint(); }}class SetDialog extends Dialog { private Panel panel1 = new Panel(); private Label labelUP = new Label(); private Label label2 = new Label(); private Label labelDOWN = new Label(); private Label labelLEFT = new Label(); private Label labelRIGHT = new Label(); private TextField textFieldUP = new TextField(); private TextField textFieldDOWN = new TextField(); private TextField textFieldRIGHT = new TextField(); private TextField textFieldLEFT = new TextField(); private Button bdefault = new Button(); private Button byes = new Button(); public SetDialog(Frame frame, String title, boolean modal) { super(frame, title, modal); enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); add(panel1); pack(); } catch(Exception ex) { ex.printStackTrace(); } } public SetDialog(Frame frame) { this(frame, "", false); } public SetDialog(Frame frame, boolean modal) { this(frame, "", modal); } public SetDialog(Frame frame, String title) { this(frame, title, false); } private void jbInit() throws Exception { byes.setLabel("确定"); byes.setBounds(new Rectangle(169, 133, 70, 27)); byes.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { byes_actionPerformed(e); } }); bdefault.setLabel("默认"); bdefault.setBounds(new Rectangle(61, 133, 70, 27)); labelUP.setFont(new java.awt.Font("Dialog", 0, 15)); labelUP.setForeground(Color.blue); labelUP.setText("上"); labelUP.setBounds(new Rectangle(26, 41, 24, 24)); panel1.setLayout(null); label2.setFont(new java.awt.Font("DialogInput", 0, 20)); label2.setForeground(Color.red); label2.setText("键盘设定"); label2.setBounds(new Rectangle(114, 9, 87, 22)); labelDOWN.setBounds(new Rectangle(27, 76, 24, 24)); labelDOWN.setText("下"); labelDOWN.setForeground(Color.blue); labelDOWN.setFont(new java.awt.Font("Dialog", 0, 15)); labelLEFT.setBounds(new Rectangle(166, 41, 24, 24)); labelLEFT.setText("左"); labelLEFT.setForeground(Color.blue); labelLEFT.setFont(new java.awt.Font("Dialog", 0, 15)); labelRIGHT.setBounds(new Rectangle(166, 78, 24, 24)); labelRIGHT.setText("右"); labelRIGHT.setForeground(Color.blue); labelRIGHT.setFont(new java.awt.Font("Dialog", 0, 15)); textFieldUP.setText("UP"); textFieldUP.setBounds(new Rectangle(65, 42, 47, 23)); textFieldDOWN.setBounds(new Rectangle(67, 77, 47, 23)); textFieldDOWN.setText("DOWN"); textFieldRIGHT.setBounds(new Rectangle(215, 79, 48, 23)); textFieldRIGHT.setText("RIGHT"); textFieldLEFT.setBounds(new Rectangle(215, 41, 48, 23)); textFieldLEFT.setText("LEFT"); panel1.add(textFieldLEFT, null); panel1.add(labelLEFT, null); panel1.add(textFieldRIGHT, null); panel1.add(labelRIGHT, null); panel1.add(textFieldUP, null); panel1.add(labelUP, null); panel1.add(textFieldDOWN, null); panel1.add(labelDOWN, null); panel1.add(byes, null); panel1.add(bdefault, null); panel1.add(label2, null); } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { cancel(); } super.processWindowEvent(e); } void cancel() { dispose(); } void byes_actionPerformed(ActionEvent e) { cancel(); }}class InputDialog extends Dialog { private Panel panel1 = new Panel(); private Label label1 = new Label(); private TextField textField1 = new TextField(); private Button button1 = new Button(); private Label label2 = new Label(); public InputDialog(Frame frame, String title, boolean modal) { super(frame, title, modal); enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); add(panel1); pack(); } catch(Exception ex) { ex.printStackTrace(); } } public InputDialog(Frame frame) { this(frame, "", false); } public InputDialog(Frame frame, boolean modal) { this(frame, "", modal); } public InputDialog(Frame frame, String title) { this(frame, title, false); } private void jbInit() throws Exception { label1.setFont(new java.awt.Font("DialogInput", 0, 15)); label1.setForeground(Color.red); label1.setText("请输入您的名字:"); label1.setBounds(new Rectangle(29, 51, 127, 21)); panel1.setLayout(null); textField1.setBackground(Color.lightGray); textField1.setForeground(Color.blue); textField1.setText("高人"); textField1.setBounds(new Rectangle(159, 47, 63, 25)); button1.setLabel("确定"); button1.setBounds(new Rectangle(109, 90, 74, 23)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); label2.setFont(new java.awt.Font("Dialog", 0, 20)); label2.setText("哇 ! 哇 ! 哇塞! 你好厉害!"); label2.setBounds(new Rectangle(25, 9, 252, 29)); panel1.add(button1, null); panel1.add(label1, null); panel1.add(label2, null); panel1.add(textField1, null); } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { cancel(); } super.processWindowEvent(e); } void cancel() { dispose(); } void button1_actionPerformed(ActionEvent e) { cancel(); }}class BlockDialog extends Dialog { private Panel panel1 = new Panel(); private Label labHero = new Label(); private Label label1 = new Label(); private Label label2 = new Label(); private Label label3 = new Label(); private Label label4 = new Label(); public BlockDialog(Frame frame, String title, boolean modal) { super(frame, title, modal); enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); add(panel1); pack(); } catch(Exception ex) { ex.printStackTrace(); } } public BlockDialog(Frame frame) { this(frame, "", false); } public BlockDialog(Frame frame, boolean modal) { this(frame, "", modal); } public BlockDialog(Frame frame, String title) { this(frame, title, false); } private void jbInit() throws Exception { labHero.setFont(new java.awt.Font("Monospaced", 0, 30)); labHero.setForeground(Color.red); labHero.setText("英雄榜"); labHero.setBounds(new Rectangle(110, 24, 95, 35)); panel1.setLayout(null); label1.setFont(new java.awt.Font("Dialog", 0, 15)); label1.setForeground(new Color(0, 203, 112)); label1.setText("高人 1 : 100 9 1000"); label1.setBounds(new Rectangle(36, 96, 243, 24)); label2.setBounds(new Rectangle(36, 71, 241, 24)); label2.setText("姓名 等级 速度 得分"); label2.setFont(new java.awt.Font("Dialog", 0, 15)); label2.setForeground(new Color(158, 151, 236)); label3.setBounds(new Rectangle(35, 124, 242, 24)); label3.setText("高人 2 : 80 7 800"); label3.setFont(new java.awt.Font("Dialog", 0, 15)); label3.setForeground(new Color(0, 203, 112)); label4.setBounds(new Rectangle(34, 151, 245, 24)); label4.setText("高人 3 : 60 5 500"); label4.setFont(new java.awt.Font("Dialog", 0, 15)); label4.setForeground(new Color(0, 203, 112)); panel1.add(label1, null); panel1.add(label2, null); panel1.add(labHero, null); panel1.add(label3, null); panel1.add(label4, null); } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { cancel(); } super.processWindowEvent(e); } void cancel() { dispose(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -