/** * 返回一个cell在world中的位置 * * @param row * @param col * @return */ public Rect getCellRectInWorld(int row, int col) { Cell cell = this.getCell(row, col); if (cell == null) { cell = new Cell(); cell.row = row; cell.col = col; } return this.getCellRectInWorld(cell); }
/** Method in JComponent overrided to draw this MazeGrid */ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; // draw each cell in the grid using drawCell() Cell a = new Cell(0, 0); for (; a.row < grid.getRows(); a.row++) { for (; a.col < grid.getCols(); a.col++) { drawCell(g2, a); } a.col = 0; } }
@Override public Cell decode(DataInputStream dis) throws IOException { Cell c = new Cell(); try { c.row = dis.readLong(); } catch (Exception e) { // EOF reached throw new IOException(e); } c.col = dis.readLong(); c.content = dis.readUTF(); return c; }
public static void main(String[] args) { Scanner scan = new Scanner(System.in); Cell cell = new Cell(); // 成员变量赋值 cell.row = 6; cell.col = 5; printCell(cell); boolean flags = true; while (flags) { System.out.println("1--下落,2--向左,3--向右,0--退出"); int num = scan.nextInt(); if (cell.row > 19) { cell.row = 0; } switch (num) { case 1: printCell(cell); // drop move cell.drop(); System.out.println("Cell的位置为:(" + cell.row + "," + cell.col + ")"); sleep(300000000l); printCell(cell); break; case 2: // left move cell.LeftMove(); System.out.println("Cell的位置为:(" + cell.row + "," + cell.col + ")"); sleep(300000000l); printCell(cell); break; case 3: // right move cell.RightMove(); System.out.println("Cell的位置为:(" + cell.row + "," + cell.col + ")"); sleep(300000000l); printCell(cell); break; case 0: flags = false; break; default: System.out.println("你输入错误!"); } } scan.close(); }