/** * 创建一个方块 * * @return */ private Fangkuai createNewFangkuai() { int index = 0; Random random = new Random(); Fangkuai fangkuai = new Fangkuai(); Color color = new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255)); index = random.nextInt(4); fangkuai.setColor(color); curt_xingzhuang = Fangkuai.xingzhuangs[index]; return fangkuai; }
/** * @param d * @param xingzhuang */ void moveOther(int d, int xingzhuang[][]) { int dx = d == MOVE_LEFT ? 1 : -1; if (is_CanMoveOther(d, xingzhuang)) { fangkuai.run_x += dx; } }
/** * 画一个方块 * * @param g * @param curt_xing */ void drawFangkuai(Graphics g, int curt_xing[][]) { if (fangkuai == null) { fangkuai = createNewFangkuai(); } if (curt_xing != null) { int y = 0; boolean b = false; for (int i = 0; i < curt_xing.length; i++) { for (int j = 0; j < curt_xing[i].length; j++) { if (curt_xing[i][j] != 0) { g.setColor(fangkuai.getColor()); g.fillRect( (fangkuai.run_x + j) * Fangkuai.width, (fangkuai.run_y + y) * Fangkuai.height, Fangkuai.width - 1, Fangkuai.height - 1); b = true; } } if (b) y++; } } }