@Override public void updateSpeed() { final MapEwin map = game.getMap(); switch (type) { case MapManager.EARTH: if (broken) { type = MapManager.GRAVA; } break; case MapManager.GAZ: break; case MapManager.GRAVA: final Cell underCell = map.get(getRow() + 1, getCol()); if (underCell == null) { return; } if (!MapManager.stopPlayer(underCell.getType())) { type = underCell.type; underCell.setType(MapManager.GRAVA); map.addToUpdate(underCell); map.remoteToUpdate(this); System.out.println( "fall from " + getRow() + "," + getCol() + " to " + underCell.getRow()); } else { // we try to fall randomly on a side // We load data here Cell overCell = map.get(getRow() - 1, getCol()); if (overCell == null) { overCell = new Cell(game, MapManager.METAL, getRow(), getCol() - 1); } final Cell downLeftCell = map.get(getRow(), getCol() - 1); final Cell downRightCell = map.get(getRow(), getCol() + 1); final Random r = new Random(); final Cell[] c = new Cell[2]; if (r.nextFloat() < 0.5) { c[0] = downLeftCell; c[1] = downRightCell; } else { c[1] = downLeftCell; c[0] = downRightCell; } // and we try to fall if (overCell.getType() == MapManager.GRAVA) { for (final Cell cell : c) { if (cell == null) { continue; } if (!MapManager.stopPlayer(cell.getType())) { type = cell.getType(); cell.setType(MapManager.GRAVA); map.addToUpdate(cell); map.remoteToUpdate(this); System.out.println( "SIDE from " + getRow() + "," + getCol() + " to " + cell.getRow() + "," + cell.getCol()); break; } } } } // we still update those cells break; case MapManager.HERO: break; case MapManager.METAL: // nothing to do break; case MapManager.VOID: break; case MapManager.WATER: final Cell underCell2 = map.get(getRow() + 1, getCol()); if (underCell2 == null) { return; } // fall if you can if (!MapManager.stopPlayer(underCell2.getType()) && (underCell2.getType() != MapManager.WATER)) { type = underCell2.type; underCell2.setType(MapManager.WATER); map.addToUpdate(underCell2); map.remoteToUpdate(this); pingPongLastDir = 0; // we don't play ping pong right/left } else { // if the is water on one side, try to go the other side ! // We load data here Cell overCell = map.get(getRow() - 1, getCol()); if (overCell == null) { overCell = new Cell(game, MapManager.METAL, getRow(), getCol() - 1); } Cell leftCell = map.get(getRow(), getCol() - 1); if (leftCell == null) { leftCell = new Cell(game, MapManager.METAL, getRow(), getCol() - 1); } Cell rightCell = map.get(getRow(), getCol() + 1); if (rightCell == null) { rightCell = new Cell(game, MapManager.METAL, getRow(), getCol() + 1); } final Random r = new Random(); final Cell[] c = new Cell[2]; c[0] = leftCell; c[1] = rightCell; int i; if (r.nextFloat() < 0.5) { i = 0; } else { i = 1; } // and we try to fall for (int j = 0; j <= 1; j++) { final int k = (i + 1) % 2; // if the cell on one side is water and that we can go to // the other side (which is not water), go ! // if the cell on one side is not water but that there is // water above us, we try to go ! if (((c[i].getType() == MapManager.WATER) || (!MapManager.stopPlayer(overCell.getType()) && (overCell.getType() == MapManager.WATER))) && !MapManager.stopPlayer(c[k].getType()) && (c[k].getType() != MapManager.WATER)) { // if we don't play ping pong // if (getCol() - c[k].getCol() != pingPongLastDir % 2) // { pingPongLastDir = getCol() - c[k].getCol(); type = c[k].getType(); c[k].setType(MapManager.WATER); map.addToUpdate(c[k]); map.remoteToUpdate(this); break; // } } i = (i + 1) % 2; } } break; } }
public void breakCell() { broken = true; final MapEwin map = game.getMap(); map.addToUpdate(this); }