本文中的代码只是部分代码,全部代码及用到的图片下载地址:链接:/s/1Ryvr0uxPVX22Ag3aVzGQKQ 密码: tm48
1、我们来分析一下游戏界面,从中能抽象出来:小方块类型,组合方块类型
先来创建 Cell() 小方块类型,此类代表的时游戏中的最小单位(自身的属性有:row--行号 , col--列号 , image--图片)(行为方法有:left()--左移 , right()--右移 , drop()--下移),下面是具体代码:package com.tetris2;
import java.awt.image.BufferedImage;
public class Cell {
/*
* 俄罗斯方块中最小单位
*/
private int row; //行号
private int col; //列号
private BufferedImage image;
public Cell() {
}
//有参构造器,用来接收小方块的行列坐标和图片
public Cell(int row, int col, BufferedImage image) {
super();
this.row = row;
this.col = col;
this.image = image;
}
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
public int getCol() {
return col;
}
public void setCol(int col) {
this.col =