qq_36691241 2017-02-16 01:33 采纳率: 29.2%
浏览 787

关于一个Java小项目的问题

package Tetris;

public class TandJProject {

public static void main(String[] args) {
    //创建T对象
    T t = new T(0,1);
    //原始坐标
    System.out.println("t的原始坐标是:");
    t.print();
    //测试T下落
    t.drop();
    System.out.println("下落后的位置是:");
    t.print();
    //测试T左移
    t.leftMove();
    System.out.println("左移后的位置是:");
    t.print();
    //测试T右移
    t.rightMove();
    System.out.println("右移后的位置是:");
    t.print();
    //创建J对象
    J j = new J(0,1);
    System.out.println("原始坐标是:");
    j.print();
    //测试J下落
    j.drop();
    System.out.println("下落后的位置是:");
    j.print();
    //测试J左移
    j.leftMove();
    System.out.println("左移后的位置是:");
    j.print();
    //测试J右移
    j.rightMove();
    System.out.println("右移后的位置是:");

    j.print();
    //创建O对象


}

}
//构建T类
class T {
Cell[] cells;
//无参的构造方法
public T() {
this(0,0);
}
//有参的构造方法
public T(int row,int col) {
cells = new Cell[4];
cells[0] = new Cell(row,col);
cells[1] = new Cell(row,col + 1);
cells[2] = new Cell(row,col + 2);
cells[3] = new Cell(row + 1,col + 1);
}
//打印的方法
public void print() {
String str = "";
for(int i=0;i<=cells.length-1;i++) {
str += "(" + cells[i].getCellInfo() + ")";
}
System.out.println(str);
}
//左移的方法
public void leftMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].leftMove();
}
}
//右移的方法
public void rightMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].rightMove();
}
}
//下落的方法
public void drop() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].drop();
}
}

}
//构建J类
class J {
Cell[] cells;
//无参的构造方法
public J() {
this(0,0);
}
//有参的构造方法
public J(int row,int col) {
cells = new Cell[4];
cells[0] = new Cell(row,col);
cells[1] = new Cell(row,col + 1);
cells[2] = new Cell(row,col + 2);
cells[3] = new Cell(row + 1,col + 2);
}
//打印的方法
public void print() {
String str = "";
for(int i=0;i<=cells.length-1;i++) {
str += "(" + cells[i].getCellInfo() + ")";
}
System.out.println(str);
}
//左移的方法
public void leftMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].leftMove();
}
}
//右移的方法
public void rightMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].rightMove();
}
}
//下降的方法
public void drop() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].drop();
}
}
//创建O类
class O {
Cell[] cells;
//定义构造方法
public O() {
this(0,0);
}
//有参的构造方法
public O(int row,int col) {
cells = new Cell[4];
cells[0] = new Cell(row,col);
cells[1] = new Cell(row,col + 1);
cells[2] = new Cell(row + 1,col);
cells[3] = new Cell(row + 1,col + 1);
}
//打印的方法
public void print() {
String str = "";
for(int i=0;i<=cells.length-1;i++) {
str += "(" + cells[i].getCellInfo() + ")";
}
System.out.println(str);
}
//定义下落
public void drop() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].drop();
}
}
//定义左移
public void leftMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].leftMove();
}
}
//定义右移
public void rightMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].rightMove();
}
}

}
//构建方格
class Cell {
int row;
int col;

public Cell() {
    this(0,0);
}

public Cell(int row,int col) {
    this.row = row;
    this.col = col;
}

public void leftMove() {
    col--;
}

public void rightMove() {
    col++;
}

public void drop() {
    row++;
}

public String getCellInfo() {
    return row + "," + col;
}

}
图片说明
这是错误信息、
错在哪里?错了那又该怎样改正呢?

  • 写回答

5条回答 默认 最新

  • viewgroup 2017-02-16 01:48
    关注

    你把你完整代码贴出来,我手打的没有错误啊。。

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作