日期:2014-05-20  浏览次数:20734 次

帮忙调个程序,俄罗斯方块,希望它能一直往下落,跪求
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
//import javax.swing.Timer;


public class Tetris extends JFrame 
{
public static final int GAME_HEIGHT = 600, GAME_WIDTH = 400; 
public NewBlock myBlock = new NewBlock();
//Timer timer = new Timer(1000, new TimerListener());
public void paint(Graphics g) {
  super.paint(g);
myBlock.draw(g);
System.out.println("调用");
}

public void launch()
{
this.setLocation(200,300);
this.setSize(GAME_WIDTH,GAME_HEIGHT);
this.setResizable(false);
JMenuBar menu = new JMenuBar();
this.setJMenuBar(menu);
JMenu game = new JMenu("游戏");
JMenuItem newgame = game.add("新游戏");
JMenuItem pause = game.add("暂停");
JMenuItem goon = game.add("继续");
JMenuItem exit = game.add("退出");
JMenu help = new JMenu("帮助");
JMenuItem about = help.add("关于");
menu.add(game);
menu.add(help);
this.setVisible(true);
new Thread(new PaintThread()).start();
}

public static void main(String[] args) 
{
Tetris Frame = new Tetris();
Frame.launch();
}
private class PaintThread implements Runnable {

public void run() {
while(true) {
repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
/*class TimerListener implements ActionListener 
{

public void actionPerformed(ActionEvent e)
{
repaint();
}

}*/



import java.awt.Color;
import java.awt.Graphics;

public class NewBlock
{
int blockType = 6;
int speed = 0;
int state = 0;
int y = 1;
private final int shapes[][][]= new int[][][] 
{
// i
{ { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
{ 1, 0, 0, 1, 0, 0, 1, 0, 0},
{ 1, 1, 1, 0, 0, 0, 0, 0, 0 },
{ 1, 0, 0, 1, 0, 0, 1, 0, 0 } },
// s
{ { 1, 0, 0, 1, 1, 0, 1, 0, 0},
{1, 1, 1, 0, 1, 0, 0, 0, 0},
{ 0, 0, 1, 0, 1, 1, 0, 0, 1 },
{ 0, 1, 0, 1, 1, 1, 0, 0, 0} },
// z
{ { 1, 0, 0, 1, 1, 0, 0, 1, 0 },
{ 0, 1, 1, 0, 1, 0, 1, 1, 0 },
{ 1, 0, 0, 1, 1, 0, 0, 1, 0 },
{ 0, 1, 1, 0, 1, 0, 1, 1, 0 } },
// j
{ { 0, 1, 0, 1, 1, 0, 1, 0, 0 },
{ 1, 1, 0, 0, 1, 0, 0, 1, 1 },
{ 0, 1, 0, 1, 1, 0, 1, 0, 0 },
{ 1, 1, 0, 0, 1, 0, 0, 1, 1 } },
// o
{ { 1, 1, 0, 1, 1, 0, 0, 0, 0 },
{ 1, 1, 0, 1, 1, 0, 0, 0, 0 },