俄罗斯方块英文JAVA版下载_俄罗斯方块java源代码完美版
package russia;
/www.quzhuanpan.com 转载请告知/
/*
控制面板类
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class ControlPanel extends JPanel
{
private TipBlockPanel tipBlockPanel;
private JPanel tipPanel,InfoPanel,buttonPanel;
private final JTextField levelField,scoreField;
private JButton playButton,pauseButton,stopButton,
turnHarderButton,turnEasilyButton;
private EtchedBorder border=new EtchedBorder(EtchedBorder.RAISED,Color.WHITE, new Color(148, 145, 140)) ;
private RussiaBlocksGame game;
private Timer timer;
/www.quzhuanpan.com 转载请告知/
public ControlPanel(final RussiaBlocksGame game)
{
this.game = game;
/*
*图形界面部分
*/
setLayout(new GridLayout(3,1,0,4));
tipBlockPanel = new TipBlockPanel();
tipPanel = new JPanel( new BorderLayout() );
tipPanel.add( new JLabel("Next Block:") , BorderLayout.NORTH );
tipPanel.add( tipBlockPanel , BorderLayout.CENTER );
tipPanel.setBorder(border);
InfoPanel = new JPanel( new GridLayout(4,1,0,0) );
levelField = new JTextField(""+RussiaBlocksGame.DEFAULT_LEVEL);
levelField.setEditable(false);
scoreField = new JTextField("0");
scoreField.setEditable(false);
InfoPanel.add(new JLabel("Level:"));
InfoPanel.add(levelField);
InfoPanel.add(new JLabel("Score:"));
InfoPanel.add(scoreField);
InfoPanel.setBorder(border);
/www.quzhuanpan.com 转载请告知/
buttonPanel = new JPanel(new GridLayout(5,1,0,0));
playButton = new JButton("Play");
pauseButton = new JButton("Pause");
stopButton = new JButton("Stop");
turnHarderButton = new JButton("Turn harder");
turnEasilyButton = new JButton("Turn easily");
buttonPanel.add(playButton);
buttonPanel.add(pauseButton);
buttonPanel.add(stopButton);
buttonPanel.add(turnHarderButton);
buttonPanel.add(turnEasilyButton);
buttonPanel.setBorder(border);
addKeyListener(new ControlKeyListener());//添加
add(tipPanel);
add(InfoPanel);
add(buttonPanel);
/*
*添加事件监听器
*/
playButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
game.playGame();
requestFocus();//让ControlPanel重新获得焦点以响应键盘事件
}
});
/*www.quzhuanpan.com 转载请告知*/
pauseButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(pauseButton.getText().equals("Pause"))
game.pauseGame();
else
game.resumeGame();
requestFocus();//让ControlPanel重新获得焦点以响应键盘事件
}
}
);
stopButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
game.stopGame();
requestFocus();//让ControlPanel重新获得焦点以响应键盘事件
}
});
turnHarderButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
int level = 0;
try{
level = Integer.parseInt(levelField.getText());
setLevel(level + 1);
}catch(NumberFormatException e)
{
e.printStackTrace();
}
requestFocus();//让ControlPanel重新获得焦点以响应键盘事件
}
});
turnEasilyButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
int level = 0;
try{
level = Integer.parseInt(levelField.getText());
setLevel(level - 1);
}catch(NumberFormatException e)
{
e.printStackTrace();
}
requestFocus();//让ControlPanel重新获得焦点以响应键盘事件
}
});
/*
* 时间驱动程序,每格500毫秒对level,score值进行更新
*/
timer = new Timer(500,
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
scoreField.setText(""+game.getScore());
game.levelUpdate();
}
}
);
timer.start();
}
/*
设置预显方块的样式
*/
public void setBlockStyle(int style)
{
tipBlockPanel.setStyle(style);
tipBlockPanel.repaint();
}
/*
重置,将所有数据恢复到最初值
*/
public void reset()
{
levelField.setText(""+RussiaBlocksGame.DEFAULT_LEVEL);
scoreField.setText("0");
setPlayButtonEnabled(true);
setPauseButtonLabel(true);
tipBlockPanel.setStyle(0);
}
/*
*设置playButton是否可用
*/
public void setPlayButtonEnabled(boolean enable)
{
playButton.setEnabled(enable);
}
/*
*设置pauseButton的文本
*/
public void setPauseButtonLabel(boolean pause)
{
pauseButton.setText( pause ? "Pause" : "Rusume" );
}
/*
*设置方块的大小,改变窗体大小时调用可自动调整方块到合适的尺寸
*/
public void fanning()
{
tipBlockPanel.fanning();
}
/*
*根据level文本域的值返回当前的级别
*/
public int getLevel()
{
int level = 0;
try
{
level=Integer.parseInt(levelField.getText());
}catch(NumberFormatException e)
{
e.printStackTrace();
}
return level;
}
/*
设置level文本域的值
*/
public void setLevel(int level)
{
if(level > 0 && level <= RussiaBlocksGame.MAX_LEVEL)
levelField.setText("" + level);
}
/*
内部类 为预显方块的显示区域
*/
private class TipBlockPanel extends JPanel
{
private Color bgColor = Color.darkGray,
blockColor = Color.lightGray;
private RussiaBox [][]boxes = new RussiaBox[RussiaBlock.ROWS][RussiaBlock.COLS];
private int boxWidth, boxHeight,style;
private boolean isTiled = false;
/*
* 构造函数
*/
public TipBlockPanel()
{
for(int i = 0; i < boxes.length; i ++)
for(int j = 0; j < boxes[i].length; j ++)
{
boxes[i][j]=new RussiaBox(false);
}
style = 0x0000;
}
/*
* 构造函数
*/
public TipBlockPanel(Color bgColor, Color blockColor)
{
this();
this.bgColor = bgColor;
this.blockColor = blockColor;
}
/*
* 设置方块的风格
*/
public void setStyle(int style)
{
this.style = style;
repaint();
}
/*
* 绘制预显方块
*/
public void paintComponent(Graphics g)
{
super.paintComponent(g);
int key = 0x8000;
if(!isTiled)
fanning();
for(int i = 0; i < boxes.length; i ++)
for(int j = 0; j
{
Color color = (style & key) != 0 ? blockColor : bgColor;
g.setColor(color);
g.fill3DRect(j * boxWidth, i * boxHeight, boxWidth, boxHeight, true);
key >>=1;
}
}
/*
*设置方块的大小,改变窗体大小时调用可自动调整方块到合适的尺寸
*/
public void fanning()
{
boxWidth = getSize().width / RussiaBlock.COLS;
boxHeight = getSize().height /RussiaBlock.ROWS;
isTiled=true;
}
}
/*
*内部类 键盘键听器,响应键盘事件
*/
class ControlKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent ke)
{
if (!game.isPlaying()) return;
RussiaBlock block = game.getCurBlock();
switch (ke.getKeyCode()) {
case KeyEvent.VK_DOWN:
block.moveDown();
break;
case KeyEvent.VK_LEFT:
block.moveLeft();
break;
case KeyEvent.VK_RIGHT:
block.moveRight();
break;
case KeyEvent.VK_UP:
block.turnNext();
break;
case KeyEvent.VK_SPACE://一键到底
while(block.moveDown())
{
}
break;
default:
break;
}
}
}
}
package russia;
/www.tengxunyun.me 转载请告知/
/*
游戏中方块显示的画布类
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class GameCanvas extends JPanel
{
private RussiaBox [][]boxes;
private int rows = 20 , cols = 12;
private static GameCanvas canvas=null;
private int boxWidth, boxHeight;//默认为零需要调用fanning函数设置
private Color blockColor = Color.RED, bgColor = new Color(0,204,204);
private EtchedBorder border=new EtchedBorder(EtchedBorder.RAISED,Color.WHITE, new Color(148, 145, 140)) ;
/*
*采用单件模式,构造函数私有
*/
private GameCanvas()
{
boxes = new RussiaBoxrows;
for(int i = 0; i < boxes.length; i ++)
for(int j = 0; j
boxes[i][j] = new RussiaBox(false);
setBorder(border);
}
/*
*获得GameCanvas实例
*/
public static GameCanvas getCanvasInstance()
{
if(canvas == null)
canvas = new GameCanvas();
return canvas;
}
/*
*设置画布的背景色
*/
public void setBgColor(Color bgColor)
{
this.bgColor = bgColor;
}
/*
获得画布的背景色
*/
public Color getBgColor()
{
return bgColor;
}
/*
*设置方块的颜色
*/
public void setBlockColor(Color blockColor)
{
this.blockColor = blockColor;
}
/*
*方块的颜色
*/
public Color getBlockColor()
{
return blockColor;
}
/*
*设置画布中方块的行数
*/
public void setRows(int rows)
{
this.rows = rows;
}
/*
*得到画布中方块的行数
*/
public int getRows()
{
return rows;
}
/*
*设置画布中方块的列数
*/
public void setCols(int cols)
{
this.cols = cols;
}
/*
*得到画布中方块的列数
*/
public int getCols()
{
return cols;
}
/*
*得到row行,col列的方格
*/
public RussiaBox getBox(int row, int col)
{
if(row >= 0 && row < rows && col >= 0 && col < cols)
return boxes[row][col];
else
return null;
}
/*
*在画布中绘制方块
*/
public void paintComponent(Graphics g)
{
super.paintComponent(g);
fanning();
for(int i = 0; i < boxes.length; i ++)
for(int j = 0; j < boxes[i].length; j ++)
{
Color color = boxes[i][j].isColorBox() ? blockColor : bgColor;
g.setColor(color);
g.fill3DRect(j * boxWidth, i * boxHeight , boxWidth , boxHeight , true);
}
}
/*
*清除第row行
*/
public void removeLine(int row)
{
for(int i = row; i > 0; i --)
for(int j = 0; j < cols; j ++)
{
boxes[i][j] = (RussiaBox)boxes[i-1][j].clone();
}
}
/*
*重置 为初始时的状态
*/
public void reset()
{
for(int i = 0; i < boxes.length; i++)
for(int j = 0 ;j < boxes[i].length; j++)
{
boxes[i][j].setColor(false);
}
repaint();
}
/*
根据窗体的大小自动调整方格的大小
*/
public void fanning()
{
boxWidth = getSize().width / cols;
boxHeight = getSize().height / rows;
}
}
package russia;
/*
方块类
*/
public class RussiaBlock extends Thread
{
private int style,y,x,level;
private boolean moving,pausing;
private RussiaBox boxes[][];
private GameCanvas canvas;
public final static int ROWS = 4;
public final static int COLS = 4;
public final static int BLOCK_KIND_NUMBER = 7;
public final static int BLOCK_STATUS_NUMBER = 4;
public final static int BETWEEN_LEVELS_TIME = 50;
public final static int LEVEL_FLATNESS_GENE = 3;
/*
*方块的所有风格及其不同的状态
*/
public final static int[][] STYLES = {// 共28种状态
{0x0f00, 0x4444, 0x0f00, 0x4444}, // 长条型的四种状态
{0x04e0, 0x0464, 0x00e4, 0x04c4}, // 'T'型的四种状态
{0x4620, 0x6c00, 0x4620, 0x6c00}, // 反'Z'型的四种状态
{0x2640, 0xc600, 0x2640, 0xc600}, // 'Z'型的四种状态
{0x6220, 0x1700, 0x2230, 0x0740}, // '7'型的四种状态
{0x6440, 0x0e20, 0x44c0, 0x8e00}, // 反'7'型的四种状态
{0x0660, 0x0660, 0x0660, 0x0660}, // 方块的四种状态
};
/*
*构造函数
*/
/www.tengxunyun.me 转载请告知/
public RussiaBlock(int y,int x,int level,int style)
{
this.y = y;
this.x = x;
this.level = level;
moving = true;
pausing = false;
this.style = style;
canvas = GameCanvas.getCanvasInstance();
boxes = new RussiaBoxROWS;
int key = 0x8000;
for(int i = 0; i < boxes.length; i++)
for(int j = 0; j < boxes[i].length; j++)
{
boolean isColor = ( (style & key) != 0 );
boxes[i][j] = new RussiaBox(isColor);
key >>= 1;
}
display();
}
/*
*线程的 run方法控制放块的下落及下落速度
*/
public void run()
{
while(moving)
{
try
{
sleep( BETWEEN_LEVELS_TIME * (RussiaBlocksGame.MAX_LEVEL - level + LEVEL_FLATNESS_GENE) );
if(!pausing)
moving = ( moveTo(y + 1,x) && moving );
}catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
/*
*暂停移动
*/
public void pauseMove()
{
pausing = true;
}
/*
*从暂停状态恢复
*/
public void resumeMove()
{
pausing = false;
}
/*
*停止移动
*/
public void stopMove()
{
moving = false;
}
/*
*向左移一格
*/
public void moveLeft()
{
moveTo(y , x - 1);
}
/*
*向右移一格
*/
public void moveRight()
{
moveTo(y , x + 1);
}
/*
*向下移一格,返回与其他几个不同,为了一键到底
*/
public boolean moveDown()
{
if(moveTo(y + 1, x))
return true;
else
return false;
}
/*
*移到newRow,newCol位置
*/
public synchronized boolean moveTo(int newRow, int newCol)
{
//erase();//必须在判断前进行擦除,否则isMoveable将产生错误行为
if(!moving || !isMoveable(newRow,newCol))
{
display();
return false;
}
y = newRow;
x = newCol;
display();
canvas.repaint();
return true;
}
/*
*判断能否移到newRow,newCol位置
*/
private boolean isMoveable(int newRow, int newCol)
{
erase();
for(int i = 0; i < boxes.length; i ++)
for(int j = 0; j< boxes[i].length; j ++ )
{
if( boxes[i][j].isColorBox() )
{
RussiaBox box = canvas.getBox(newRow + i, newCol + j);
if(box == null || box.isColorBox())
return false;
}
}
return true;
}
/*
*通过旋转变为下一种状态
*/
public void turnNext()
{
int newStyle = 0;
for(int i = 0; i < STYLES.length; i ++)
for(int j = 0 ;j < STYLES[i].length; j++)
{
if(style == STYLES[i][j])
{
newStyle = STYLES[i][(j + 1)%BLOCK_STATUS_NUMBER];
break;
}
}
turnTo(newStyle);
}
/*
*通过旋转变能否变为newStyle状态
*/
private synchronized boolean turnTo(int newStyle)
{
//erase();//擦除之后在判断isTurnNextAble
if(!moving || !isTurnable(newStyle))
{
display();
return false;
}
style=newStyle;
int key = 0x8000;
for(int i = 0; i < boxes.length; i ++)
for(int j = 0 ;j < boxes[i].length; j++)
{
boolean isColor = ((key & style) != 0 );
boxes[i][j].setColor(isColor);
key >>=1;
}
display();
canvas.repaint();
return true;
}
/*
*判断通过旋转能否变为下一种状态
*/
private boolean isTurnable(int newStyle)
{
erase();
int key = 0x8000;
for(int i = 0; i< boxes.length; i++)
for(int j=0; j
{
if((key & newStyle) != 0)
{
RussiaBox box = canvas.getBox(y + i, x + j);
if(box == null || box.isColorBox())
return false;
}
key >>= 1;
}
return true;
}
/*
*擦除当前方块(只是设置isColor属性,颜色并没有清除,为了判断能否移动之用)
*/
/www.tengxunyun.me 转载请告知/
private void erase()
{
for(int i = 0; i < boxes.length; i ++)
for(int j = 0; j< boxes[i].length; j ++ )
{
if( boxes[i][j].isColorBox() )
{
RussiaBox box = canvas.getBox( y + i, x + j);
if(box != null)
box.setColor(false);
}
}
}
/*
*显示当前方块(其实只是设置Color属性,在调用repaint方法时才真正显示)
*/
private void display()
{
for(int i = 0; i < boxes.length; i ++)
for(int j = 0;j< boxes[i].length ; j ++)
{
if(boxes[i][j].isColorBox())
{
RussiaBox box = canvas.getBox( y + i, x + j);
if(box != null)
box.setColor( true );
}
}
}
}
package russia;
/*
主游戏类
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RussiaBlocksGame extends JFrame
{
public final static int PER_LINE_SCORE = 100;//消去一行得分
public final static int PER_LEVEL_SCORE = PER_LINE_SCORE*20;//升一级需要的分数
public final static int DEFAULT_LEVEL = 5;//默认级别
public final static int MAX_LEVEL = 10;//最高级别
private int score=0,curLevelScore = 0;//总分和本级得分
private GameCanvas canvas;
private ControlPanel controlPanel;
private RussiaBlock block;
private int style = 0;
boolean playing = false;
private JMenuBar bar;
private JMenu gameMenu,controlMenu,windowStyleMenu,informationMenu;
private JMenuItem newGameItem,setBlockColorItem,setBgColorItem,
turnHardItem,turnEasyItem,exitItem;
private JMenuItem playItem,pauseItem,resumeItem,stopItem;
private JRadioButtonMenuItem windowsRadioItem,motifRadioItem,metalRadioItem;
private JMenuItem authorItem,helpItem;
private ButtonGroup buttonGroup;
/*
构造函数
*/
public RussiaBlocksGame(String title)
{
super(title);
setSize(300,400);
Dimension scrSize=Toolkit.getDefaultToolkit().getScreenSize();
setLocation((scrSize.width-getSize().width)/2,(scrSize.height-getSize().height)/2);
createMenu();
Container container=getContentPane();
container.setLayout(new BorderLayout());
canvas = GameCanvas.getCanvasInstance();
controlPanel = new ControlPanel(this);
container.add(canvas,BorderLayout.CENTER);
container.add(controlPanel,BorderLayout.EAST);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
stopGame();
System.exit(0);
}
}
);
addComponentListener(
new ComponentAdapter()
{
public void componentResized(ComponentEvent event)
{
canvas.fanning();
}
}
);
canvas.fanning();
setVisible(true);
}
/*
判断游戏是否正在进行
*/
public boolean isPlaying()
{
return playing;
}
/*
* 开始游戏并设置按钮和菜单项的可用性
*/
public void playGame()
{
play();
controlPanel.setPlayButtonEnabled(false);
playItem.setEnabled(false);
}
/*
* 暂停游戏
*/
public void pauseGame()
{
if(block != null) block.pauseMove();
controlPanel.setPauseButtonLabel(false);
pauseItem.setEnabled(false);
resumeItem.setEnabled(true);
}
/*
* 从暂停中恢复游戏
*/
public void resumeGame()
{
if(block != null) block.resumeMove();
controlPanel.setPauseButtonLabel(true);
pauseItem.setEnabled(true);
resumeItem.setEnabled(false);
}
/*
* 停止游戏
*/
public void stopGame()
{
if(block != null) block.stopMove();
playing = false;
controlPanel.setPlayButtonEnabled(true);
controlPanel.setPauseButtonLabel(true);
playItem.setEnabled(true);
}
/*
* 得到当前级别
*/
public int getLevel()
{
return controlPanel.getLevel();
}
/*
* 设置当前级别,并更新控制面板的显示
*/
public void setLevel(int level)
{
if(level>0&&level<11)
controlPanel.setLevel(level);
}
/*
* 得到当前总分数
*/
public int getScore()
{
if(canvas != null)
return score;
return 0;
}
/*
* 得到本级得分
*/
public int getCurLevelScore()
{
if(canvas != null)
return curLevelScore;
return 0;
}
/*
* 更新等级
*/
public void levelUpdate()
{
int curLevel = getLevel();
if(curLevel < MAX_LEVEL && curLevelScore >= PER_LEVEL_SCORE)
{
setLevel(curLevel + 1);
curLevelScore -= PER_LEVEL_SCORE;
}
}
/*
* 获得当前得方块
*/
public RussiaBlock getCurBlock() {
return block;
}
/*
* 开始游戏
*/
private void play()
{
playing=true;
Thread thread = new Thread(new Game());
thread.start();
reset();
}
/*
* 重置
*/
private void reset()
{
controlPanel.reset();
canvas.reset();
score = 0;
curLevelScore = 0;
}
/*
* 宣告游戏结束
*/
private void reportGameOver()
{
JOptionPane.showMessageDialog(this,"Game over!");
}
/*
* 创建菜单
*/
private void createMenu()
{
gameMenu = new JMenu("Game");
newGameItem = new JMenuItem("New Game");
setBlockColorItem = new JMenuItem("Set Block Color...");
setBgColorItem = new JMenuItem("Set BackGround Color...");
turnHardItem = new JMenuItem("Turn Harder");
turnEasyItem = new JMenuItem("Turn Easily");
exitItem = new JMenuItem("Exit");
gameMenu.add(newGameItem);
gameMenu.add(setBlockColorItem);
gameMenu.add(setBgColorItem);
gameMenu.add(turnHardItem);
gameMenu.add(turnEasyItem);
gameMenu.add(exitItem);
/*www.panmum.com 转载请告知*/
controlMenu = new JMenu("Control");
playItem = new JMenuItem("Play");
pauseItem = new JMenuItem("Pause");
resumeItem = new JMenuItem("Resume");
stopItem = new JMenuItem("Stop");
controlMenu.add(playItem);
controlMenu.add(pauseItem);
controlMenu.add(resumeItem);
controlMenu.add(stopItem);
windowStyleMenu = new JMenu("WindowStyle");
buttonGroup = new ButtonGroup();
windowsRadioItem = new JRadioButtonMenuItem("Windows");
motifRadioItem = new JRadioButtonMenuItem("Motif");
metalRadioItem = new JRadioButtonMenuItem("Mentel",true);
windowStyleMenu.add(windowsRadioItem);
buttonGroup.add(windowsRadioItem);
windowStyleMenu.add(motifRadioItem);
buttonGroup.add(motifRadioItem);
windowStyleMenu.add(metalRadioItem);
buttonGroup.add(metalRadioItem);
informationMenu = new JMenu("Information");
authorItem = new JMenuItem("Author:Fuliang");
helpItem = new JMenuItem("Help");
informationMenu.add(authorItem);
informationMenu.add(helpItem);
bar = new JMenuBar();
bar.add(gameMenu);
bar.add(controlMenu);
bar.add(windowStyleMenu);
bar.add(informationMenu);
addActionListenerToMenu();
setJMenuBar(bar);
}
/*
添加菜单响应
*/
private void addActionListenerToMenu()
{
newGameItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
stopGame();
reset();
setLevel(DEFAULT_LEVEL);
}
});
setBlockColorItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Color newBlockColor =
JColorChooser.showDialog(RussiaBlocksGame.this,
"Set color for block", canvas.getBlockColor());
if (newBlockColor != null)
canvas.setBlockColor(newBlockColor);
}
});
setBgColorItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Color newBgColor =
JColorChooser.showDialog(RussiaBlocksGame.this,"Set color for block",
canvas.getBgColor());
if (newBgColor != null)
canvas.setBgColor(newBgColor);
}
});
/www.oksousou.com 转载请告知/
turnHardItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int curLevel = getLevel();
if (curLevel < MAX_LEVEL) setLevel(curLevel + 1);
}
});
turnEasyItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int curLevel = getLevel();
if (curLevel > 1) setLevel(curLevel - 1);
}
});
exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
});
playItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
playGame();
}
});
pauseItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
pauseGame();
}
});
resumeItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
resumeGame();
}
});
stopItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
stopGame();
}
});
windowsRadioItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
setWindowStyle(plaf);
canvas.fanning();
controlPanel.fanning();
}
});
motifRadioItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
setWindowStyle(plaf);
canvas.fanning();
controlPanel.fanning();;
}
});
metalRadioItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "javax.swing.plaf.metal.MetalLookAndFeel";
setWindowStyle(plaf);
canvas.fanning();
controlPanel.fanning();
}
});
}
/*
* 设定窗口风格
*/
private void setWindowStyle(String plaf)
{
try {
UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
e.printStackTrace();
}
}
/www.quzhuanpan.com 转载请告知/
private class Game implements Runnable
{
/*
(non-Javadoc)
@see java.lang.Runnable#run()
游戏线程的run函数
*/
public void run()
{
int col=(int)(Math.random()*(canvas.getCols()-3));
style=RussiaBlock.STYLES(int)(Math.random()*RussiaBlock.BLOCK_KIND_NUMBER);
while (playing) {
if (block != null) { //第一次循环时,block为空
if (block.isAlive()) {
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
continue;
}
}
checkFullLine();
if (isGameOver()) { //检查游戏是否应该结束了
playItem.setEnabled(true);
pauseItem.setEnabled(true);
resumeItem.setEnabled(false);
controlPanel.setPlayButtonEnabled(true);
controlPanel.setPauseButtonLabel(true);
reportGameOver();
return;
}
block = new RussiaBlock(-1, col, getLevel(),style);
block.start();
col=(int)(Math.random()*(canvas.getCols()-3));
style=RussiaBlock.STYLES(int)(Math.random()*RussiaBlock.BLOCK_KIND_NUMBER);
controlPanel.setBlockStyle(style);
}
}
/*
判断是否能消去整行
*/
public void checkFullLine()
{
for (int i = 0; i < canvas.getRows(); i++) {
int row = -1;
boolean fullLineColorBox = true;
for (int j = 0; j < canvas.getCols(); j++) {
if (!canvas.getBox(i, j).isColorBox()) {
fullLineColorBox = false;
break;
}
}
if (fullLineColorBox) {
curLevelScore += PER_LINE_SCORE;
score += PER_LINE_SCORE;
row = i--;
canvas.removeLine(row);
}
}
}
/*
判断游戏是否结束
*/
private boolean isGameOver() {
for (int i = 0; i < canvas.getCols(); i++) {
RussiaBox box = canvas.getBox(0, i);
if (box.isColorBox()) return true;
}
return false;
}
}
public static void main(String[] args)
{
new RussiaBlocksGame("Russia Blocks Game");
}
}
package russia;
/*
*虚拟的单个方格类,控制方格的颜色
*/
public class RussiaBox implements Cloneable
{
private boolean isColor;
public RussiaBox(boolean isColor)
{
this.isColor = isColor;
}
/*
*设置颜色
*/
public void setColor(boolean isColor)
{
this.isColor=isColor;
}
/*
*返回颜色
*/
/www.oksousou.com 转载请告知/
public boolean isColorBox()
{
return isColor;
}
/*
@see java.lang.Object#clone()
*/
public Object clone()
{
Object o = null;
try
{
o=super.clone();
}catch(CloneNotSupportedException e)
{
e.printStackTrace();
}
return o;
}
}
俄罗斯方块英文JAVA版下载_俄罗斯方块java源代码完美版相关推荐
- 我的世界java测试版下载_我的世界中国版PC不删档测试版_网易我的世界JAVA版测试版单机游戏下载...
游戏介绍 配置要求 操作系统 Windows XP,Windows Vista,Windows 7,Windows 8 运行环境 无特殊需求 CPU Intel Core2 Duo E4600 @ 2 ...
- 我的世界精灵java怎么下载_我的世界精灵版官网
我的世界精灵版是玩家根据口袋妖怪系列制作的一个整合包.在游戏中玩家可以自己捕捉精灵,训练和对战,游戏的模式基本仿照的口袋妖怪,尤其是对战模式,很有意思哦,推荐喜欢我的世界和口袋妖怪的玩家下载来试试. ...
- 微软java虚拟机下载_微软Java虚拟机下载-Microsoft VM(Java虚拟机)5.0.3805最新版 - 维维软件园...
你在找最新版本的Java虚拟机吗,快来维维下载Microsoft VM(Microsoft Java Virtual Machine)官方版进行安装吧,它是一款专业便捷的微软Java虚拟机软件,它的功 ...
- java 多线程下载_使用java实现http多线程下载
Feedback # re: 使用java实现http多线程下载 2008-07-27 22:46 xzqttt 看了您的文章,收到了很大的启发,谢谢分享,好文! 回复 更多评论 # re: 使用j ...
- java 柱状图下载_(JFreeChart)Java图表制作
(JFreeChart)Java图表制作软件时一个灵活的设计,很容易扩展,和目标服务器端和客户端应用程序;,支持多种图表类型. 输出类型也是多样化.包括Swing组件.图像文件(包括PNG和JPEG) ...
- 我的世界基岩版json_我的世界基岩版下载_我的世界基岩版app下载_我的世界基岩版官网最新版下载-新手游网...
在这一版本号中可以充足体会到随意探寻的挑战性,提高本人的战斗能力跟损害整体实力:为自己造就存活的机遇,角逐最终的总体目标,展现娴熟的实际操作技术性,抢掠大量的資源应用.迷你世界岩层版被称作是全世界第一 ...
- 官方版下载_药店大学app官方版下载
阅读本文前,请您先点击上面的蓝色字体,再点击"关注",这样您就可以继续免费收到最新文章了.每天都有分享.完全是免费订阅,请放心关注.注:本文转载自网络,不代表本平台立场,仅供读者参 ...
- 民科微服务电脑版下载_天翼云桌面通用版电脑版下载|天翼云桌面通用版PC客户端 V1.23.0 官方最新版 下载_当下软件园...
天翼云桌面通用版电脑版是一款由中国电信股份有限公司云计算分公司所推出的云终端桌面平台.该版本是通过在电脑上安装安卓模拟器来实现运行的,以此达到PC端的使用效果,基于特有的通信协议,通过云终端将桌面或应 ...
- linux下的p图软件,美图秀秀Linux版官方版下载_美图秀秀Linux版 v1.0.0.0免费版[db:版本号] - Win7旗舰版...
美图秀秀linux版是一款图片处理软件,可以帮助用户对图片进行美化处理,支持批量处理图片,能够方便用户直接在Linux系统上修改图像,有需要可以下载. 功能介绍 1.美图秀秀是国内非常著名的图片处理软 ...
- 本草纲目pdf彩图版下载_本草纲目彩图版(全二册)
内容概要 <本草纲目>为明代著名本草学家.医学家.博物学家李时珍所撰,被誉为"东方药学巨典".它集中体现了中国古代医学所取得的最高成就,是取之不尽的中华医药学知识宝库, ...
最新文章
- YARN中的失败分析
- kafka记录及面试题
- 程序员必备 Git 分支开发规范指南
- 用集合实现二分(折半)查找
- IOError: encoder jpeg not available
- 淘宝店铺类目怎么删除
- SSH 命令的11种用法
- imagecopyresampled要生成彩色却生成了灰色图片
- python控制蓝牙pybluez_Python之蓝牙通讯模块pybluez学习笔记
- 设置电脑 保护视力 还有桌面默认颜色
- arcgis html图像标记,图片标记
- bestCoder 百度之星程序设计资格赛 1005下棋
- 打破校史!「双非」高校,首发 Science
- 快速排序深度优化详解
- 《协整理论与波动模型-金融时间序列分析及应用(第二版)》
- Windows电脑桌面透明云便签怎么自定义设置便签快捷键?
- 前端框架:jQuery
- ​人和人之间的差距在哪里?
- web自动化测试理论之selenium八大定位 -(2)
- 一对一直播系统源码——如何只需三步搭建
热门文章
- 免费分享一套详细的Hadoop学习视频
- VUE项目中引入135编辑器
- 图书馆预约占座系统 (SSM JAVA)
- C语言视频教程-谭浩强版-小甲鱼主讲—P19
- 清华大学计算机专业在职博士吧,清华大学在职博士含金量高吗?
- 如何用vb制作“简单”的表白软件
- 在MyEclipse中安装SVN插件subclipse
- win7mysql卸载数据库_win7系统彻底卸载Mysql数据库的操作方法
- 20220911- LC第310场周赛
- ad19pcb所有元件都在报错_AD09如何放置过孔阵列?Allegro PCB,元器件高度限制区域设置?...