diff --git a/Tetris/bin/tetris/Cell.class b/Tetris/bin/tetris/Cell.class index 9b6b82a..3b8c42e 100644 Binary files a/Tetris/bin/tetris/Cell.class and b/Tetris/bin/tetris/Cell.class differ diff --git a/Tetris/bin/tetris/TetrisFrame.class b/Tetris/bin/tetris/TetrisFrame.class index 321f9f1..64739ae 100644 Binary files a/Tetris/bin/tetris/TetrisFrame.class and b/Tetris/bin/tetris/TetrisFrame.class differ diff --git a/Tetris/bin/tetris/TetrisPane$DropExecution.class b/Tetris/bin/tetris/TetrisPane$DropExecution.class index 377674d..df4fa63 100644 Binary files a/Tetris/bin/tetris/TetrisPane$DropExecution.class and b/Tetris/bin/tetris/TetrisPane$DropExecution.class differ diff --git a/Tetris/bin/tetris/TetrisPane$IShaped.class b/Tetris/bin/tetris/TetrisPane$IShaped.class index e5fa4bf..f860999 100644 Binary files a/Tetris/bin/tetris/TetrisPane$IShaped.class and b/Tetris/bin/tetris/TetrisPane$IShaped.class differ diff --git a/Tetris/bin/tetris/TetrisPane$JShaped.class b/Tetris/bin/tetris/TetrisPane$JShaped.class index 3ab86e2..aaf5b19 100644 Binary files a/Tetris/bin/tetris/TetrisPane$JShaped.class and b/Tetris/bin/tetris/TetrisPane$JShaped.class differ diff --git a/Tetris/bin/tetris/TetrisPane$KeyControl.class b/Tetris/bin/tetris/TetrisPane$KeyControl.class index a8c5be7..c7930fd 100644 Binary files a/Tetris/bin/tetris/TetrisPane$KeyControl.class and b/Tetris/bin/tetris/TetrisPane$KeyControl.class differ diff --git a/Tetris/bin/tetris/TetrisPane$LShaped.class b/Tetris/bin/tetris/TetrisPane$LShaped.class index b908e9f..0e81c03 100644 Binary files a/Tetris/bin/tetris/TetrisPane$LShaped.class and b/Tetris/bin/tetris/TetrisPane$LShaped.class differ diff --git a/Tetris/bin/tetris/TetrisPane$OShaped.class b/Tetris/bin/tetris/TetrisPane$OShaped.class index d69f0e7..a26797c 100644 Binary files a/Tetris/bin/tetris/TetrisPane$OShaped.class and b/Tetris/bin/tetris/TetrisPane$OShaped.class differ diff --git a/Tetris/bin/tetris/TetrisPane$SShaped.class b/Tetris/bin/tetris/TetrisPane$SShaped.class index 611b505..669892c 100644 Binary files a/Tetris/bin/tetris/TetrisPane$SShaped.class and b/Tetris/bin/tetris/TetrisPane$SShaped.class differ diff --git a/Tetris/bin/tetris/TetrisPane$TShaped.class b/Tetris/bin/tetris/TetrisPane$TShaped.class index e6d649a..c2d7985 100644 Binary files a/Tetris/bin/tetris/TetrisPane$TShaped.class and b/Tetris/bin/tetris/TetrisPane$TShaped.class differ diff --git a/Tetris/bin/tetris/TetrisPane$ZShaped.class b/Tetris/bin/tetris/TetrisPane$ZShaped.class index 15fe14c..e91225c 100644 Binary files a/Tetris/bin/tetris/TetrisPane$ZShaped.class and b/Tetris/bin/tetris/TetrisPane$ZShaped.class differ diff --git a/Tetris/bin/tetris/TetrisPane.class b/Tetris/bin/tetris/TetrisPane.class index 545d304..9f0f4d5 100644 Binary files a/Tetris/bin/tetris/TetrisPane.class and b/Tetris/bin/tetris/TetrisPane.class differ diff --git a/Tetris/bin/tetris/Tetromino.class b/Tetris/bin/tetris/Tetromino.class index 7238b44..07857cc 100644 Binary files a/Tetris/bin/tetris/Tetromino.class and b/Tetris/bin/tetris/Tetromino.class differ diff --git a/Tetris/src/tetris/Cell.java b/Tetris/src/tetris/Cell.java index da74660..e53e5aa 100644 --- a/Tetris/src/tetris/Cell.java +++ b/Tetris/src/tetris/Cell.java @@ -4,106 +4,83 @@ import java.awt.Graphics; /** - * 网格类 + * 呼摸 * @author Leslie Leung */ public class Cell { - public static final int CELL_SIZE = 25; //一个网格的大小 + //呼 + public static final int CELL_SIZE = 25; - /* 格子的所有颜色 */ - public static final int COLOR_CYAN = 0; - public static final int COLOR_BLUE = 1; - public static final int COLOR_GREEN = 2; - public static final int COLOR_YELLOW = 3; - public static final int COLOR_ORANGE = 4; - public static final int COLOR_RED = 5; - public static final int COLOR_PINK = 6; - - private int color; //格子的颜色 - private int x; //横坐标 - private int y; //纵坐标 + + private Color nowcolor;//肅︹ + private int x; //x畒夹 + private int y; //y畒夹 /** - * 构造方法 - * @param x 横坐标 - * @param y 纵坐标 - * @param style 格子的样式,通过颜色来指定 + * 篶 + * @param x x(绢)畒夹 + * @param y y(羇)畒夹 + * @param setcolor 稱璶砞Θ肅︹ */ - public Cell(int x, int y, int style) { - /* 根据传进来的样式决定格子的颜色 */ - switch(style) { - case 0: color = COLOR_CYAN; break; - case 1: color = COLOR_BLUE; break; - case 2: color = COLOR_GREEN; break; - case 3: color = COLOR_YELLOW; break; - case 4: color = COLOR_ORANGE; break; - case 5: color = COLOR_RED; break; - case 6: color = COLOR_PINK; break; - } - + public Cell(int x, int y, Color setcolor) { + setNowcolor(setcolor); this.x = x; this.y = y; } /** - * 设置该格子的横坐标 - * @param newX 新的横坐标 + * 砞﹚赣x畒夹 + * @param newX 穝x畒夹 */ public void setX(int newX) { x = newX; } /** - * 设置该格子的纵坐标 - * @param newY 新的纵坐标 + * 砞﹚赣y畒夹 + * @param newY 穝y畒夹 */ public void setY(int newY) { y = newY; } /** - * 获取该Cell的横坐标 - * @return 横坐标 + * 眔赣cellx畒夹 + * @return x畒夹 */ public int getX() { return x; } /** - * 获取该Cell的纵坐标 - * @return 纵坐标 + * 眔赣celly畒夹 + * @return y畒夹 */ public int getY() { return y; } /** - * 绘图方法 - * @param g Graphics引用 + * 酶瓜よ猭 + * @param g Graphicsまノ */ public void paintCell(Graphics g) { - switch(color) { - case COLOR_CYAN: g.setColor(Color.CYAN); - g.fillRect(x * CELL_SIZE + 1, y * CELL_SIZE + 1, CELL_SIZE - 2, CELL_SIZE - 2); - break; - case COLOR_BLUE: g.setColor(Color.BLUE); - g.fillRect(x * CELL_SIZE + 1, y * CELL_SIZE + 1, CELL_SIZE - 2, CELL_SIZE - 2); - break; - case COLOR_GREEN: g.setColor(Color.GREEN); - g.fillRect(x * CELL_SIZE + 1, y * CELL_SIZE + 1, CELL_SIZE - 2, CELL_SIZE - 2); - break; - case COLOR_YELLOW: g.setColor(Color.YELLOW); - g.fillRect(x * CELL_SIZE + 1, y * CELL_SIZE + 1, CELL_SIZE - 2, CELL_SIZE - 2); - break; - case COLOR_ORANGE: g.setColor(Color.ORANGE); - g.fillRect(x * CELL_SIZE + 1, y * CELL_SIZE + 1, CELL_SIZE - 2, CELL_SIZE - 2); - break; - case COLOR_RED: g.setColor(Color.RED); - g.fillRect(x * CELL_SIZE + 1, y * CELL_SIZE + 1, CELL_SIZE - 2, CELL_SIZE - 2); - break; - case COLOR_PINK: g.setColor(Color.PINK); - g.fillRect(x * CELL_SIZE + 1, y * CELL_SIZE + 1, CELL_SIZE - 2, CELL_SIZE - 2); - break; - } + g.setColor(nowcolor); + g.fillRect(x * CELL_SIZE + 1, y * CELL_SIZE + 1, CELL_SIZE - 2, CELL_SIZE - 2); + } + /** + * 眔赣cell肅︹ + * @return 肅︹ + */ + public Color getNowcolor() { + return nowcolor; + } + /** + * 砞﹚赣肅︹ + * @param newcolor 穝肅︹ + */ + public void setNowcolor(Color newcolor) { + this.nowcolor = newcolor; } + } diff --git a/Tetris/src/tetris/TetrisFrame.java b/Tetris/src/tetris/TetrisFrame.java index 38c1a6b..e458b92 100644 --- a/Tetris/src/tetris/TetrisFrame.java +++ b/Tetris/src/tetris/TetrisFrame.java @@ -5,31 +5,30 @@ import javax.swing.JLabel; /** - * 框架类 + * 琜摸 * @author Leslie Leung */ public class TetrisFrame extends JFrame { - private TetrisPane tp; //俄罗斯方块主游戏场景类 - private JLabel mention; //游戏的提示信息 + private TetrisPane tp; //玐霉吹よ遏笴栏初春 + private JLabel mention; //笴栏矗ボ癟 /** - * 构造方法 + * 篶 */ public TetrisFrame() { - setSize(550, 600); //设置窗体大小 + setSize(550, 600); //砞﹚跌怠 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setLocationRelativeTo(null); //设置窗体于屏幕中央 - setTitle("Tetris"); //设置标题为Tetris - setResizable(false); //不允许窗体缩放 - setLayout(new FlowLayout()); //设置布局管理器 + setLocationRelativeTo(null); //砞﹚跌怠棵辊い丁 + setTitle("Tetris"); //砞竚夹肈"Tetris" + setResizable(false); //ぃす砛跌怠罽 + setLayout(new FlowLayout()); //砞﹚皌竚 - tp = new TetrisPane(); //新建场景类对象 - mention = new JLabel("按A键逆时针转,按D顺时针转,按方向键控制向左、向右和向下的运动,按空格键硬下落"); + tp = new TetrisPane(); //穝初春ン + mention = new JLabel("A龄癴皐臂锣D抖皐臂锣よ龄北㎝笲笆龄钡辅┏"); + add(mention); //盢矗ボ癟睰琜 + add(tp); //盢笴栏初春狾睰琜い - add(mention); //把标签添加到主框架中 - add(tp); //把游戏主场景面板添加到主框架中 - - /* 注册键盘事件 */ + /*爹龄絃ㄆン*/ addKeyListener(tp.getInnerInstanceOfKeyControl()); tp.addKeyListener(tp.getInnerInstanceOfKeyControl()); diff --git a/Tetris/src/tetris/TetrisPane.java b/Tetris/src/tetris/TetrisPane.java index b13449e..d3290e3 100644 --- a/Tetris/src/tetris/TetrisPane.java +++ b/Tetris/src/tetris/TetrisPane.java @@ -13,14 +13,14 @@ import javax.swing.JPanel; /** - * 俄罗斯方块游戏场景类 + * 玐霉吹よ遏笴栏初春摸 * @author Leslie Leung */ public class TetrisPane extends JPanel { - public static final int ROWS = 20; //整个场景的行数 - public static final int COLUMNS = 16; //整个场景的列数 + public static final int ROWS = 20; //俱笴栏初春Τ碭︽ + public static final int COLUMNS = 16; //俱笴栏初春Τ碭 - /* 表示7种不同的四格方块 */ + /*ボ7贺ぃよ遏*/ public static final int I_SHAPED = 0; public static final int S_SHAPED = 1; public static final int T_SHAPED = 2; @@ -29,19 +29,19 @@ public class TetrisPane extends JPanel { public static final int O_SHAPED = 5; public static final int J_SHAPED = 6; - public static final int KIND = 7; //表示四格方块有7个种类 - public static final int INIT_SPEED = 1000; //表示下落的初始速度 + public static final int KIND = 7; //ボよ遏Τ7贺摸 + public static final int INIT_SPEED = 1000; //ボ﹍辅硉 - private static int randomNum = 0; //表示已生成的俄罗斯方块的数目 + private static int randomNum = 0; //ボネΘ玐霉吹よ遏计ヘ private Random random; - private Tetromino currentTetromino; //表示当前的四格方块 - private Cell[][] wall; //表示墙,null表示方块内没对象 - private Timer autoDrop; //实现自动下落的计时器 - private KeyControl keyListener; //表示键盘事件监控变量 + private Tetromino currentTetromino; //ボ讽玡よ遏 + private Cell[][] wall; //ボ鲤,nullボよ遏ず⊿Τン + private Timer autoDrop; //辅璸竟 + private KeyControl keyListener; //龄絃ㄆン菏钮竟 /** - * 构造方法 + * 篶 */ public TetrisPane() { setPreferredSize(new Dimension(COLUMNS * Cell.CELL_SIZE, ROWS * Cell.CELL_SIZE)); @@ -57,12 +57,12 @@ public TetrisPane() { } /** - * 随机生成一个四格方块 + * 繦诀ネΘよ遏 */ public void randomOne() { Tetromino tetromino = null; - /* 随机生成7种四格方块的其中一种 */ + /*繦诀ネΘ7贺よ遏ㄤい贺*/ switch(random.nextInt(KIND)) { case I_SHAPED: tetromino = new IShaped(); @@ -86,21 +86,21 @@ public void randomOne() { tetromino = new JShaped(); break; } - currentTetromino = tetromino; //当前的四格方块为生成的四格方块 - randomNum ++; + currentTetromino = tetromino; //ヘ玡よ遏=繦诀ネΘよ遏 + randomNum ++; //ネΘよ遏计+1 } /** - * 判断玩家是否输了 - * @return true,输了;false,没输 + * 耞產琌块 + * @return true:块 false:临⊿块 */ public boolean isGameOver() { - int x, y; //当前俄罗斯方块格子的横坐标和纵坐标 + int x, y; //眔讽玡玐霉吹よ遏x,y畒夹 for(int i = 0; i < getCurrentCells().length; i ++) { x = getCurrentCells()[i].getX(); y = getCurrentCells()[i].getY(); - if(isContain(x, y)) {//看其刚生成的位置是否已存在方块对象,存在的话,表示输了 + if(isContain(x, y)) {//ㄤネΘ竚琌よ遏ン.Τ杠玐霉吹よ遏礚猭=骸=块 return true; } } @@ -109,23 +109,23 @@ public boolean isGameOver() { } /** - * 每生成一个俄罗斯方块,通过改变TimerTask的时间间隔来加快下落速度 - * @return 时间间隔 + * –ネΘ玐霉吹よ遏,硄筁э跑TimerTask丁丁筳ㄓе辅硉 + * @return 丁丁筳 */ public double interval() { return INIT_SPEED * Math.pow((double)39 / 38, 0 - randomNum); } /** - * 返回KeyControl类的实例 - * @return KeyControl类实例 + * KeyControl classinstance + * @return KeyControl class instance */ public KeyControl getInnerInstanceOfKeyControl() { return keyListener; } /** - * 内部类,用于实现俄罗斯方块的自动下落 + * ず场盻摸 ノㄓ龟よ遏笆 * @author Leslie Leung */ private class DropExecution extends TimerTask { @@ -133,8 +133,8 @@ private class DropExecution extends TimerTask { public void run() { // TODO Auto-generated method stub - if(isGameOver()) {//如果输了 - JOptionPane.showMessageDialog(null, "你输了"); + if(isGameOver()) { //狦块 + JOptionPane.showMessageDialog(null, "块"); autoDrop.cancel(); removeKeyListener(keyListener); return; @@ -143,9 +143,9 @@ public void run() { if(!isReachBottomEdge()) { currentTetromino.softDrop(); } else { - landIntoWall(); //把俄罗斯方块添加到墙上 - removeRows(); //如满行,删除行 - randomOne(); //马上新建一个俄罗斯方块 + landIntoWall(); //р玐霉吹よ遏睰鲤 + removeRows(); //狦骸︽,埃︽ + randomOne(); //皑穝玐霉吹よ遏 autoDrop.cancel(); autoDrop = new Timer(); @@ -157,58 +157,59 @@ public void run() { } /** - * 把俄罗斯方块添加到墙上 + * 盢玐霉吹よ遏睰鲤 */ public void landIntoWall() { - int x, y; //定义俄罗斯方块不能移动后的横坐标和纵坐标 + int x, y; //﹚竡玐霉吹よ遏ぃ簿笆x,y畒夹 for(int i = 0; i < getCurrentCells().length; i ++) { x = getCurrentCells()[i].getX(); y = getCurrentCells()[i].getY(); - wall[y][x] = getCurrentCells()[i]; //添加到墙上 + wall[y][x] = getCurrentCells()[i]; //睰鲤 } } /** - * 内部类,用于实现键盘的事件控制 + * ず场盻摸,ノㄓ龟瞷龄絃ㄆン北 * @author Leslie Leung */ private class KeyControl extends KeyAdapter { @Override public void keyPressed(KeyEvent e) { switch(e.getKeyCode()) { - case KeyEvent.VK_LEFT: //往左移动 + case KeyEvent.VK_LEFT: //┕オ簿笆 - if(!isReachLeftEdge()) {//当俄罗斯方块没到达左边界时,往左移动 + if(!isReachLeftEdge()) {//讽よ遏临⊿窱オ娩,┕オ簿笆 currentTetromino.moveLeft(); repaint(); } break; - case KeyEvent.VK_RIGHT: //往右移动 + case KeyEvent.VK_RIGHT: //┕簿笆 - if(!isReachRightEdge()) {//当俄罗斯方块没到达右边界时,往右移动 + if(!isReachRightEdge()) {//讽よ遏临⊿窱娩,┕簿笆 currentTetromino.moveRight(); repaint(); } break; - case KeyEvent.VK_DOWN: //向下移动 + case KeyEvent.VK_DOWN: //┕簿笆 - if(!isReachBottomEdge()) {//当俄罗斯方块没到达下边界时,往下移动 + if(!isReachBottomEdge()) {//讽よ遏临⊿窱娩,┕簿笆 currentTetromino.softDrop(); repaint(); } break; - case KeyEvent.VK_SPACE: //硬下落 + case KeyEvent.VK_SPACE: //钡辅┏ - hardDrop(); //硬下落 - landIntoWall(); //添加到墙中 - removeRows(); //如满行,删除行 + hardDrop(); //祑辅 + landIntoWall(); //睰鲤 + removeRows(); //狦骸︽,埃︽ + //穝ネΘ穝よ遏 randomOne(); autoDrop.cancel(); autoDrop = new Timer(); @@ -217,18 +218,18 @@ public void keyPressed(KeyEvent e) { repaint(); break; - case KeyEvent.VK_D: //顺时针转 - - if(!clockwiseRotateIsOutOfBounds() && !(currentTetromino instanceof OShaped)) {//俄罗斯方块没越界且其不为O形时,旋转 + case KeyEvent.VK_D: //抖皐锣 + //讽よ遏臂锣ぃ穦禫ぃO,臂锣 + if(!clockwiseRotateIsOutOfBounds() && !(currentTetromino instanceof OShaped)) { currentTetromino.clockwiseRotate(getAxis(), getRotateCells()); repaint(); } break; - case KeyEvent.VK_A: //逆时针转 - - if(!anticlockwiseRotateIsOutOfBounds() && !(currentTetromino instanceof OShaped)) {//俄罗斯方块没越界且其不为O形时,旋转 - currentTetromino.anticlockwiseRotate(getAxis(), getRotateCells()); + case KeyEvent.VK_A: //癴皐锣 + //讽よ遏臂锣ぃ穦禫ぃO,臂锣 + if(!counterclockwiseRotateIsOutOfBounds() && !(currentTetromino instanceof OShaped)) { + currentTetromino.counterclockwiseRotate(getAxis(), getRotateCells()); repaint(); } break; @@ -237,22 +238,22 @@ public void keyPressed(KeyEvent e) { } /** - * 内部类,I形的四格方块,继承了Tetromino类 + * ず场盻摸,Iよ遏,膥┯Tetromino摸 * @author Leslie Leung */ private class IShaped extends Tetromino { /** - * 构造方法 + * 篶 */ public IShaped() { cells = new Cell[4]; - cells[1] = new Cell(3, 0, Cell.COLOR_CYAN); - cells[0] = new Cell(4, 0, Cell.COLOR_CYAN); - cells[2] = new Cell(5, 0, Cell.COLOR_CYAN); - cells[3] = new Cell(6, 0, Cell.COLOR_CYAN); + cells[1] = new Cell(3, 0, Color.cyan); + cells[0] = new Cell(4, 0, Color.cyan); + cells[2] = new Cell(5, 0, Color.cyan); + cells[3] = new Cell(6, 0, Color.cyan); - /* 设置旋转轴和要旋转的格子 */ + /*砞竚臂锣禸㎝璶臂锣*/ setAxis(); setRotateCells(); @@ -261,22 +262,22 @@ public IShaped() { } /** - * 内部类,S形的四格方块,继承了Tetromino类 + * ず场盻摸,Sよ遏,膥┯Tetromino摸 * @author Leslie Leung */ private class SShaped extends Tetromino { /** - * 构造方法 + * 篶 */ public SShaped() { cells = new Cell[4]; - cells[0] = new Cell(4, 0, Cell.COLOR_BLUE); - cells[1] = new Cell(5, 0, Cell.COLOR_BLUE); - cells[2] = new Cell(3, 1, Cell.COLOR_BLUE); - cells[3] = new Cell(4, 1, Cell.COLOR_BLUE); + cells[0] = new Cell(4, 0, Color.blue); + cells[1] = new Cell(5, 0, Color.blue); + cells[2] = new Cell(3, 1, Color.blue); + cells[3] = new Cell(4, 1, Color.blue); - /* 设置旋转轴和要旋转的格子 */ + /*砞竚臂锣禸㎝璶臂锣*/ setAxis(); setRotateCells(); @@ -285,22 +286,22 @@ public SShaped() { } /** - * 内部类,T形的四格方块,继承了Tetromino类 + * ず场盻摸,Tよ遏,膥┯Tetromino摸 * @author Leslie Leung */ private class TShaped extends Tetromino { /** - * 构造方法 + * 篶 */ public TShaped() { cells = new Cell[4]; - cells[1] = new Cell(3, 0, Cell.COLOR_GREEN); - cells[0] = new Cell(4, 0, Cell.COLOR_GREEN); - cells[2] = new Cell(5, 0, Cell.COLOR_GREEN); - cells[3] = new Cell(4, 1, Cell.COLOR_GREEN); + cells[1] = new Cell(3, 0, Color.green); + cells[0] = new Cell(4, 0, Color.green); + cells[2] = new Cell(5, 0, Color.green); + cells[3] = new Cell(4, 1, Color.green); - /* 设置旋转轴和要旋转的格子 */ + /*砞竚臂锣禸㎝璶臂锣*/ setAxis(); setRotateCells(); @@ -309,22 +310,22 @@ public TShaped() { } /** - * 内部类,Z形的四格方块,继承了Tetromino类 + * ず场盻摸,Zよ遏,膥┯Tetromino摸 * @author Leslie Leung */ private class ZShaped extends Tetromino { /** - * 构造方法 + * 篶 */ public ZShaped() { cells = new Cell[4]; - cells[1] = new Cell(3, 0, Cell.COLOR_ORANGE); - cells[2] = new Cell(4, 0, Cell.COLOR_ORANGE); - cells[0] = new Cell(4, 1, Cell.COLOR_ORANGE); - cells[3] = new Cell(5, 1, Cell.COLOR_ORANGE); + cells[1] = new Cell(3, 0, Color.orange); + cells[2] = new Cell(4, 0, Color.orange); + cells[0] = new Cell(4, 1, Color.orange); + cells[3] = new Cell(5, 1, Color.orange); - /* 设置旋转轴和要旋转的格子 */ + /*砞竚臂锣禸㎝璶臂锣*/ setAxis(); setRotateCells(); @@ -333,22 +334,22 @@ public ZShaped() { } /** - * 内部类,L形的四格方块,继承了Tetromino类 + * ず场盻摸,Lよ遏,膥┯Tetromino摸 * @author Leslie Leung */ private class LShaped extends Tetromino { /** - * 构造方法 + * 篶 */ public LShaped() { cells = new Cell[4]; - cells[1] = new Cell(3, 0, Cell.COLOR_PINK); - cells[0] = new Cell(4, 0, Cell.COLOR_PINK); - cells[2] = new Cell(5, 0, Cell.COLOR_PINK); - cells[3] = new Cell(3, 1, Cell.COLOR_PINK); + cells[1] = new Cell(3, 0, Color.pink); + cells[0] = new Cell(4, 0, Color.pink); + cells[2] = new Cell(5, 0, Color.pink); + cells[3] = new Cell(3, 1, Color.pink); - /* 设置旋转轴和要旋转的格子 */ + /*砞竚臂锣禸㎝璶臂锣*/ setAxis(); setRotateCells(); @@ -357,22 +358,22 @@ public LShaped() { } /** - * 内部类,O形的四格方块,继承了Tetromino类 + * ず场盻摸,Oよ遏,膥┯Tetromino摸 * @author Leslie Leung */ private class OShaped extends Tetromino { /** - * 构造方法 + * 篶 */ public OShaped() { cells = new Cell[4]; - cells[0] = new Cell(4, 0, Cell.COLOR_RED); - cells[1] = new Cell(5, 0, Cell.COLOR_RED); - cells[2] = new Cell(4, 1, Cell.COLOR_RED); - cells[3] = new Cell(5, 1, Cell.COLOR_RED); + cells[0] = new Cell(4, 0, Color.red); + cells[1] = new Cell(5, 0, Color.red); + cells[2] = new Cell(4, 1, Color.red); + cells[3] = new Cell(5, 1, Color.red); - /* 设置旋转轴和要旋转的格子 */ + /*砞竚臂锣禸㎝璶臂锣*/ setAxis(); setRotateCells(); @@ -381,22 +382,22 @@ public OShaped() { } /** - * 内部类,J形的四格方块,继承了Tetromino类 + * ず场盻摸,Jよ遏,膥┯Tetromino摸 * @author Leslie Leung */ private class JShaped extends Tetromino { /** - * 构造方法 + * 篶 */ public JShaped() { cells = new Cell[4]; - cells[1] = new Cell(3, 0, Cell.COLOR_YELLOW); - cells[0] = new Cell(4, 0, Cell.COLOR_YELLOW); - cells[2] = new Cell(5, 0, Cell.COLOR_YELLOW); - cells[3] = new Cell(5, 1, Cell.COLOR_YELLOW); + cells[1] = new Cell(3, 0, Color.yellow); + cells[0] = new Cell(4, 0, Color.yellow); + cells[2] = new Cell(5, 0, Color.yellow); + cells[3] = new Cell(5, 1, Color.yellow); - /* 设置旋转轴和要旋转的格子 */ + /*砞竚臂锣禸㎝璶臂锣*/ setAxis(); setRotateCells(); @@ -405,7 +406,7 @@ public JShaped() { } /** - * 删除若干行 + * 埃璝︽ */ public void removeRows() { for(int i = 0; i < getCurrentCells().length; i ++) { @@ -414,46 +415,46 @@ public void removeRows() { } /** - * 获取旋转轴 - * @return 旋转轴 + * 莉臂锣禸 + * @return 臂锣禸 */ public Cell getAxis() { return currentTetromino.getAxis(); } /** - * 获取需要旋转的格子 - * @return 需要旋转的格子 + * 莉惠璶臂锣 + * @return 惠璶臂锣 */ public Cell[] getRotateCells() { return currentTetromino.getRotateCells(); } /** - * 获取当前俄罗斯方块的所有格子 - * @return 当前俄罗斯方块的所有格子 + * 莉讽玡玐霉吹よ遏┮Τ + * @return 讽玡玐霉吹よ遏┮Τ */ public Cell[] getCurrentCells() { return currentTetromino.getCells(); } /** - * 判断俄罗斯方块是否到达底部(包括是否到达面板底部和下一位置是否有方块) - * @return true,到达;false,没到达 + * 耞玐霉吹よ遏琌笷┏场 + * @return true:笷 false:⊿笷 */ public boolean isReachBottomEdge() { - int oldY, newY, oldX; //定义格子旧的纵坐标、新的纵坐标和旧的横坐标 + int oldY, newY, oldX; //﹚竡侣/穝Y(羇Г夹)㎝侣X(绢)Г夹 绢Г夹┏场碞ぃ穦跑 for(int i = 0; i < getCurrentCells().length; i ++) { oldY = getCurrentCells()[i].getY(); newY = oldY + 1; oldX = getCurrentCells()[i].getX(); - if(oldY == ROWS - 1) {//到达面板底部 + if(oldY == ROWS - 1) { //笷狾┏场 return true; } - if(isContain(oldX, newY)) {//下一位置有方块 + if(isContain(oldX, newY)) { //竚Τよ遏 return true; } } @@ -461,22 +462,22 @@ public boolean isReachBottomEdge() { } /** - * 判断俄罗斯方块是否到达左边界(包括是否超出面板左边界和下一位置是否出现与其他方块碰撞) - * @return true,已到达;false,没到达 + * 耞玐霉吹よ遏琌笷オ娩(珹琌禬狾オ娩㎝竚琌瞷籔ㄤよ遏窱疾) + * @return true:笷 false:⊿笷 */ public boolean isReachLeftEdge() { - int oldX, newX, oldY; //定义格子旧的横坐标、新的横坐标和旧的纵坐标 + int oldX, newX, oldY; //﹚竡侣/穝绢Г夹,侣羇Г夹 for(int i = 0; i < getCurrentCells().length; i ++) { oldX = getCurrentCells()[i].getX(); newX = oldX - 1; oldY = getCurrentCells()[i].getY(); - if(oldX == 0 || isContain(newX, oldY)) {//到达左边界 + if(oldX == 0 || isContain(newX, oldY)) {//笷オ娩 return true; } - if(isContain(newX, oldY)) {//下一位置有方块 + if(isContain(newX, oldY)) {//オ娩Τよ遏 return true; } } @@ -484,22 +485,22 @@ public boolean isReachLeftEdge() { } /** - * 判断俄罗斯方块是否到达右边界(包括是否超出面板右边界和下一位置是否出现与其他方块碰撞) - * @return true,已到达;false,没到达 + * 耞玐霉吹よ遏琌笷娩(珹琌禬狾娩㎝竚琌瞷籔ㄤよ遏窱疾) + * @return true:笷 false:⊿笷 */ public boolean isReachRightEdge() { - int oldX, newX, oldY; //定义格子旧的横坐标、新的横坐标和旧的纵坐标 + int oldX, newX, oldY; //﹚竡侣/穝绢Г夹,侣羇Г夹 for(int i = 0; i < getCurrentCells().length; i ++) { oldX = getCurrentCells()[i].getX(); newX = oldX + 1; oldY = getCurrentCells()[i].getY(); - if(oldX == COLUMNS - 1 || isContain(newX, oldY)) {//到达右边界 + if(oldX == COLUMNS - 1 || isContain(newX, oldY)) {//笷娩 return true; } - if(isContain(newX, oldY)) {//下一位置有方块 + if(isContain(newX, oldY)) {//娩Τよ遏 return true; } } @@ -507,27 +508,27 @@ public boolean isReachRightEdge() { } /** - * 判断俄罗斯方块顺时针转后是否超出边界(包括是否超出面板边界和下一位置是否有方块) - * @return true,超出边界;false,没超边界 + * 耞よ遏抖皐臂锣琌穦禬娩(珹琌禬狾娩㎝竚琌瞷籔ㄤよ遏窱疾) + * @return true:禬娩 false:⊿禬 */ public boolean clockwiseRotateIsOutOfBounds() { - int oldX; //rotateCell的横坐标 - int oldY; //rotateCell的纵坐标 - int newX; //rotateCell旋转后的横坐标 - int newY; //rotateCell旋转后的纵坐标 + int oldX; //rotateCell绢Г夹 + int oldY; //rotateCell羇Г夹 + int newX; //rotateCell臂锣绢Г夹 + int newY; //rotateCell臂锣羇Г夹 for(int i = 0; i < 3; i ++) { oldX = getRotateCells()[i].getX(); oldY = getRotateCells()[i].getY(); - newX = getAxis().getX() - oldY + getAxis().getY(); //新横坐标计算算法 - newY = getAxis().getY() + oldX - getAxis().getX(); //新纵坐标计算算法 + newX = getAxis().getX() - oldY + getAxis().getY(); //穝绢Г夹璸衡衡猭 + newY = getAxis().getY() + oldX - getAxis().getX(); //穝羇Г夹璸衡衡猭 - if(newX < 0 || newY < 0 || newX > COLUMNS - 1 || newY > ROWS - 1) {//如果越界,返回true + if(newX < 0 || newY < 0 || newX > COLUMNS - 1 || newY > ROWS - 1) {//狦禫,return true return true; } - if(isContain(newX, newY)) {//如果越界,返回true + if(isContain(newX, newY)) {//狦禫,return true return true; } } @@ -536,27 +537,27 @@ public boolean clockwiseRotateIsOutOfBounds() { } /** - * 判断俄罗斯方块逆时针转后是否超出边界(包括是否超出面板边界和下一位置是否有方块) - * @return true,超出边界;false,没超边界 + * 耞よ遏癴皐臂锣琌穦禬娩(珹琌禬狾娩㎝竚琌瞷籔ㄤよ遏窱疾) + * @return true:禬娩 false:⊿禬 */ - public boolean anticlockwiseRotateIsOutOfBounds() { - int oldX; //rotateCell的横坐标 - int oldY; //rotateCell的纵坐标 - int newX; //rotateCell旋转后的横坐标 - int newY; //rotateCell旋转后的纵坐标 + public boolean counterclockwiseRotateIsOutOfBounds() { + int oldX; //rotateCell绢Г夹 + int oldY; //rotateCell羇Г夹 + int newX; //rotateCell臂锣绢Г夹 + int newY; //rotateCell臂锣羇Г夹 for(int i = 0; i < 3; i ++) { oldX = getRotateCells()[i].getX(); oldY = getRotateCells()[i].getY(); - newX = getAxis().getX() - getAxis().getY() + oldY; //新横坐标计算算法 - newY = getAxis().getY() + getAxis().getX() - oldX; //新纵坐标计算算法 + newX = getAxis().getX() - getAxis().getY() + oldY; //穝绢Г夹璸衡衡猭 + newY = getAxis().getY() + getAxis().getX() - oldX; //穝羇Г夹璸衡衡猭 - if(newX < 0 || newY < 0 || newX > COLUMNS - 1 || newY > ROWS - 1) {//如果越界,返回true + if(newX < 0 || newY < 0 || newX > COLUMNS - 1 || newY > ROWS - 1) {//狦禫,return true return true; } - if(isContain(newX, newY)) {//如果越界,返回true + if(isContain(newX, newY)) {//狦禫,return true return true; } } @@ -565,10 +566,10 @@ public boolean anticlockwiseRotateIsOutOfBounds() { } /** - * 判断某个格子是否存在方块对象 - * @param x 横坐标 - * @param y 纵坐标 - * @return true,存在对象;false,不存在对象 + * 耞琘琌Τよ遏 + * @param x 绢Г夹 + * @param y 羇Г夹 + * @return true:癸禜 false:ぃ癸钩 */ public boolean isContain(int x, int y) { if(wall[y][x] == null) { @@ -579,7 +580,7 @@ public boolean isContain(int x, int y) { } /** - * 实现俄罗斯方块的硬下落 + * 龟瞷玐霉吹よ遏祑辅 */ public void hardDrop() { while(!isReachBottomEdge()) { @@ -588,24 +589,24 @@ public void hardDrop() { } /** - * 消除单行 - * @param i 行的下标 + * 埃虫︽ + * @param i︽index */ public void removeRow(int i) { int oldY, newY; - + //狦ㄤいよ遏⊿Τ恶骸,return for(int j = 0; j < COLUMNS; j ++) { - if(wall[i][j] == null) {//如果其中一个方块没有填满,return + if(wall[i][j] == null) { return; } } - /* 消除行并把该行上面的方块往下移 */ + //埃︽р赣︽よ遏┕簿 for(int k = i; k >= 1; k --){ System.arraycopy(wall[k - 1], 0, wall[k], 0, COLUMNS); for(int m = 0; m < COLUMNS; m ++) { - if(wall[k][m] != null) {//对于不是空的对象,要重设其纵坐标 + if(wall[k][m] != null) {//癸ぃ琌癸禜,璶砞ㄤ羇畒夹 oldY = wall[k][m].getY(); newY = oldY + 1; wall[k][m].setY(newY); @@ -621,19 +622,19 @@ public void paint(Graphics g) { g.setColor(Color.BLACK); g.fillRect(0, 0, getBounds().width, getBounds().height); - /* 画墙 */ + /*礶鲤*/ for(int i = 0; i < ROWS; i ++) { for(int j = 0; j < COLUMNS; j ++) { - if(wall[i][j] == null) {//某点的方块为空时 + if(wall[i][j] == null) {//讽琘翴よ遏 g.setColor(Color.WHITE); g.fillRect(j * Cell.CELL_SIZE + 1, i * Cell.CELL_SIZE + 1, Cell.CELL_SIZE - 2, Cell.CELL_SIZE - 2); - } else {//当方块不为空时 + } else {//讽よ遏ぃ wall[i][j].paintCell(g); } } } - /* 画当前俄罗斯方块 */ + /*礶讽玡玐霉吹よ遏*/ for(int i = 0; i < getCurrentCells().length; i ++) { getCurrentCells()[i].paintCell(g); } diff --git a/Tetris/src/tetris/Tetromino.java b/Tetris/src/tetris/Tetromino.java index 422a5fd..a99eeac 100644 --- a/Tetris/src/tetris/Tetromino.java +++ b/Tetris/src/tetris/Tetromino.java @@ -1,68 +1,68 @@ package tetris; /** - * 四格方块类 + * よ遏摸 * @author Leslie Leung */ public class Tetromino { - protected Cell[] cells; //用对象数组cells存储四格方块 - protected Cell axis; //旋转轴 - protected Cell[] rotateCells; //需要旋转的格子集合 + protected Cell[] cells; //ノン皚纗よ遏 + protected Cell axis; //臂锣禸 + protected Cell[] rotateCells; //惠璶臂锣ぇ栋 /** - * 实现四格方块逆时针转的算法 - * @param axis 旋转轴,以cells中下标为0的Cell为旋转轴 - * @param rotateCells 要旋转的格子的集合 + * 龟瞷よ遏癴皐臂锣簍衡猭 + * @param axis臂锣禸,cellsい夹0cell臂锣禸 + * @param rotateCells 惠璶臂锣栋 */ - protected void anticlockwiseRotate(Cell axis, Cell[] rotateCells) { - int oldX; //用以表示传进来的rotateCell的横坐标 - int oldY; //用以表示传进来的rotateCell的纵坐标 - int newX; //用以表示传进来的rotateCell旋转后的横坐标 - int newY; //用以表示传进来的rotateCell旋转后的纵坐标 + protected void counterclockwiseRotate(Cell axis, Cell[] rotateCells) { + int oldX; //ノㄓボ肚秈ㄓrotatecell绢Г夹 + int oldY; //ノㄓボ肚秈ㄓrotatecell羇Г夹 + int newX; //ノㄓボ肚秈ㄓrotatecell"臂锣"绢Г夹 + int newY; //ノㄓボ肚秈ㄓrotatecell"臂锣"绢Г夹 for(int i = 0; i < 3; i ++) { oldX = rotateCells[i].getX(); oldY = rotateCells[i].getY(); - newX = axis.getX() - axis.getY() + oldY; //新横坐标计算算法 - newY = axis.getY() + axis.getX() - oldX; //新纵坐标计算算法 + newX = axis.getX() - axis.getY() + oldY; //穝绢Г夹璸衡衡猭 + newY = axis.getY() + axis.getX() - oldX; //穝羇Г夹璸衡衡猭 - rotateCells[i].setX(newX); //重新设置目标格子的横坐标 - rotateCells[i].setY(newY); //重新设置目标格子的纵坐标 + rotateCells[i].setX(newX); //穝砞竚ヘ夹绢Г夹 + rotateCells[i].setY(newY); //穝砞竚ヘ夹羇Г夹 } } /** - * 实现四格方块顺时针转的算法 - * @param axis 旋转轴,以cells中下标为0的Cell为旋转轴 - * @param rotateCells 要旋转的格子的集合 + * 龟瞷よ遏抖皐臂锣簍衡猭 + * @param axis臂锣禸,cellsい夹0cell臂锣禸 + * @param rotateCells 惠璶臂锣栋 */ protected void clockwiseRotate(Cell axis, Cell[] rotateCells) { - int oldX; //用以表示传进来的rotateCell的横坐标 - int oldY; //用以表示传进来的rotateCell的纵坐标 - int newX; //用以表示传进来的rotateCell旋转后的横坐标 - int newY; //用以表示传进来的rotateCell旋转后的纵坐标 + int oldX; //ノㄓボ肚秈ㄓrotatecell绢Г夹 + int oldY; //ノㄓボ肚秈ㄓrotatecell羇Г夹 + int newX; //ノㄓボ肚秈ㄓrotatecell"臂锣"绢Г夹 + int newY; //ノㄓボ肚秈ㄓrotatecell"臂锣"绢Г夹 for(int i = 0; i < 3; i ++) { oldX = rotateCells[i].getX(); oldY = rotateCells[i].getY(); - newX = axis.getX() - oldY + axis.getY(); //新横坐标计算算法 - newY = axis.getY() + oldX - axis.getX(); //新纵坐标计算算法 + newX = axis.getX() - oldY + axis.getY(); //穝绢Г夹璸衡衡猭 + newY = axis.getY() + oldX - axis.getX(); //穝羇Г夹璸衡衡猭 - rotateCells[i].setX(newX); //重新设置目标格子的横坐标 - rotateCells[i].setY(newY); //重新设置目标格子的纵坐标 + rotateCells[i].setX(newX); //穝砞竚ヘ夹绢Г夹 + rotateCells[i].setY(newY); //穝砞竚ヘ夹羇Г夹 } } /** - * 实现四格方块的自动下落 + * 龟瞷よ遏硁辅(笆辅) */ protected void softDrop() { - int oldY; //某个格子下落前的纵坐标 - int newY; //某个格子下落后的纵坐标 + int oldY; //琘辅玡羇畒夹 + int newY; //琘辅羇畒夹 - /* 所有格子下移 */ + //赣よ遏┮Τ簿 for(int i = 0; i < cells.length; i ++) { oldY = cells[i].getY(); newY = oldY + 1; @@ -72,13 +72,13 @@ protected void softDrop() { } /** - * 实现四格方块左移的算法 + * 龟瞷よ遏オ簿簍衡猭 */ protected void moveLeft() { - int oldX; //某个格子左移前的横坐标 - int newX; //某个格子左移后的横坐标 + int oldX; //琘オ簿玡绢畒夹 + int newX; //琘オ簿绢畒夹 - /* 所有格子左移 */ + //赣よ遏┮Τオ簿 for(int i = 0; i < cells.length; i ++) { oldX = cells[i].getX(); newX = oldX - 1; @@ -88,13 +88,13 @@ protected void moveLeft() { } /** - * 实现四格方块右移的算法 + * 龟瞷よ遏簿簍衡猭 */ protected void moveRight() { - int oldX; //某个格子右移前的横坐标 - int newX; //某个格子右移后的横坐标 + int oldX; //琘簿玡绢畒夹 + int newX; //琘簿绢畒夹 - /* 所有格子右移 */ + //赣よ遏┮Τ簿 for(int i = 0; i < cells.length; i ++) { oldX = cells[i].getX(); newX = oldX + 1; @@ -104,38 +104,38 @@ protected void moveRight() { } /** - * 返回四格方块的格子的集合 - * @return Cell的集合 + * よ遏栋 + * @return Cell栋 */ protected Cell[] getCells() { return cells; } /** - * 获取旋转轴 - * @return 旋转轴 + * 莉眔臂锣禸 + * @return 臂锣禸 */ protected Cell getAxis() { return axis; } /** - * 获取需要旋转的目标格子的集合 - * @return 目标格子的集合 + * 莉惠璶臂锣ヘ夹栋 + * @return ヘ夹栋 */ protected Cell[] getRotateCells() { return rotateCells; } /** - * 把cells[0]设置为旋转轴 + * рcells[0]砞臂锣禸 */ protected void setAxis() { axis = cells[0]; } /** - * 新建长度为3的数组并把cells[1]、cells[2]、cells[3]添加到rotateCells中 + * 穝3皚рcells[1]~cells[3]rotateCellsい */ protected void setRotateCells() { rotateCells = new Cell[]{cells[1], cells[2], cells[3]};