自己編的 俄羅斯方塊

时间:2011-10-01 14:27:54
【文件属性】:

文件名称:自己編的 俄羅斯方塊

文件大小:3KB

文件格式:JAVA

更新时间:2011-10-01 14:27:54

俄羅斯方塊

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; class FrameClass extends Frame // implements ActionListener { MenuBar mb; Menu caozuo,shezhi,bangzhu; MenuItem star,close; TangGraphics p=new TangGraphics(); JButton star1,over; JPanel p1,p2; NextOne p3; Scors p4; Thread tankthread; Random makeobjet; int N,next; boolean isgo=false; Label string; FrameClass() { super("测试俄罗斯方块"); setSize(241,232); setLocation(400,200); setLayout(new BorderLayout(10,10)); makeobjet=new Random(); N=makeobjet.nextInt(19); setBackground(Color.yellow); mb=new MenuBar(); caozuo=new Menu("操作"); shezhi=new Menu("设置"); bangzhu=new Menu("帮助"); caozuo.add(star=new MenuItem("开始")); caozuo.add(close=new MenuItem("结束")); mb.add(caozuo); mb.add(shezhi); mb.add(bangzhu); setMenuBar(mb); string=new Label("制作人: 连泽荣 "); star1=new JButton("开始"); over=new JButton("结束"); p1=new JPanel(new GridLayout(3,1,10,10)); p2=new JPanel(); p3=new NextOne(N); p4=new Scors("0 point"); p4.setBackground(Color.green); p1.add(p3); p1.add(p4); p1.add(p2); p1.setBackground(Color.yellow); // p2.setLayout(new GridLayout(1,2,10,10)); p2.add(string); // p2.add(star1); // p2.add(over); p3.setBackground(Color.black); p3.setSize(100,60); add(p,"Center"); add(p1,"East"); setResizable(false); // star1.addActionListener(this); // over.addActionListener(this); addWindowListener(new windowlistener()); addKeyListener(new keymonitor()); setVisible(true); // tankthread=new Thread(new listenermonitor()); // tankthread.start(); } public void test() { // System.out.print(" ,x="+p3.getWidth()+" y="+p3.getHeight()); p.draw(next); } public void initp() { p.initmap(); while(!p.gameOver()) { p4.getScors(String.valueOf(p.count)+" ponit"); if(p.box.islive()==false) { next=N; N=makeobjet.nextInt(19); p3.getN(N); test(); } } } public static void main(String argc[]) { (new FrameClass()).initp(); } class windowlistener extends WindowAdapter{ public void windowClosing(WindowEvent e){System.exit(0);} } // private class keymonitor extends KeyAdapter { public void keyPressed(KeyEvent e) { p.keyPressed(e); } } } import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.Graphics; import java.util.*; class NextOne extends JPanel { int BOX[][][]= { { {2,2,2,2}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} }, { {2,0,0,0}, {2,0,0,0}, {2,0,0,0}, {2,0,0,0} }, { {3,3,3,0}, {3,0,0,0}, {0,0,0,0}, {0,0,0,0} }, { {3,3,0,0}, {0,3,0,0}, {0,3,0,0}, {0,0,0,0} }, { {0,0,3,0}, {3,3,3,0}, {0,0,0,0}, {0,0,0,0} }, { {3,0,0,0}, {3,0,0,0}, {3,3,0,0}, {0,0,0,0} }, { {4,4,4,0}, {0,0,4,0}, {0,0,0,0}, {0,0,0,0} }, { {0,4,0,0}, {0,4,0,0}, {4,4,0,0}, {0,0,0,0} }, { {4,0,0,0}, {4,4,4,0}, {0,0,0,0}, {0,0,0,0} }, { {4,4,0,0}, {4,0,0,0}, {4,0,0,0}, {0,0,0,0} }, { {5,5,5,0}, {0,5,0,0}, {0,0,0,0}, {0,0,0,0} }, { {0,5,0,0}, {5,5,0,0}, {0,5,0,0}, {0,0,0,0} }, { {0,5,0,0}, {5,5,5,0}, {0,0,0,0}, {0,0,0,0} }, { {5,0,0,0}, {5,5,0,0}, {5,0,0,0}, {0,0,0,0} }, { {6,6,0,0}, {0,6,6,0}, {0,0,0,0}, {0,0,0,0} }, { {0,6,0,0}, {6,6,0,0}, {6,0,0,0}, {0,0,0,0} }, { {0,7,7,0}, {7,7,0,0}, {0,0,0,0}, {0,0,0,0} }, { {7,0,0,0}, {7,7,0,0}, {0,7,0,0}, {0,0,0,0} }, { {8,8,0,0}, {8,8,0,0}, {0,0,0,0}, {0,0,0,0} } }; int N; Thread tankthread; Random makeobjet; public NextOne(int N) { setBorder(BorderFactory.createRaisedBevelBorder()); setBackground(Color.black); this.N=N; tankthread=new Thread(new listenermonitor()); tankthread.start(); } public void getN(int N){ this.N=N; } public void paint(Graphics g) { int i,j; super.paintComponent(g); Color c=g.getColor(); g.setColor(Color.red); for(i=0;i<4;i++) for(j=0;j<4;j++) { if(BOX[N][i][j]!=0) { g.fill3DRect(40+i*10,10+j*10,10,10,true); } } g.setColor(c); } private class listenermonitor implements Runnable { public void run() { while(true) { repaint(); try { Thread.sleep(350); } catch(Exception e){} } } } }


网友评论