icfp-model/src/main/java/ru/bosony/model/game/Game.java
changeset 25 d6a75f29ba9b
parent 23 606bba9825c8
child 27 505c25412b16
equal deleted inserted replaced
24:46c2179854dc 25:d6a75f29ba9b
    28 	protected int				score					= 0;
    28 	protected int				score					= 0;
    29 	protected int				lastScoreChange			= 0;
    29 	protected int				lastScoreChange			= 0;
    30 	protected GameState			state					= GameState.Game;
    30 	protected GameState			state					= GameState.Game;
    31 	protected int				lambdaCollectedCount	= 0;
    31 	protected int				lambdaCollectedCount	= 0;
    32 	protected List<Movement>	route					= new ArrayList<Movement>();
    32 	protected List<Movement>	route					= new ArrayList<Movement>();
       
    33 	protected int				underwater				= 0;
    33 
    34 
    34 	public Game(Mine mine) {
    35 	public Game(Mine mine) {
    35 		this.mine = mine;
    36 		this.mine = mine;
    36 	}
    37 	}
    37 
    38 
   164 
   165 
   165 		// Other ending conditions
   166 		// Other ending conditions
   166 		robotCoord = mine.getRobotCell().getCoordinate();
   167 		robotCoord = mine.getRobotCell().getCoordinate();
   167 		if (getContent(mine.getCell(robotCoord.up())) != Rock && getContent(getCell(robotCoord.up(), newCells)) == Rock) {
   168 		if (getContent(mine.getCell(robotCoord.up())) != Rock && getContent(getCell(robotCoord.up(), newCells)) == Rock) {
   168 			mine.setCells(newCells);
   169 			mine.setCells(newCells);
       
   170 
   169 			lastScoreChange = score - prevScore;
   171 			lastScoreChange = score - prevScore;
   170 			state = GameState.Lose;
   172 			state = GameState.Lose;
   171 			return state;
   173 			return state;
   172 		}
   174 		}
   173 
   175 
   174 		mine.setCells(newCells);
   176 		mine.setCells(newCells);
       
   177 
       
   178 		// Water flooding
       
   179 		robotCoord = mine.getRobotCell().getCoordinate();
       
   180 		if (robotCoord.y <= mine.getWaterLevel()) {
       
   181 			underwater++;
       
   182 		} else {
       
   183 			underwater = 0;
       
   184 		}
       
   185 		if (underwater > mine.getRobotWaterproof()) {
       
   186 			lastScoreChange = score - prevScore;
       
   187 			state = GameState.Lose;
       
   188 			return state;
       
   189 		}
       
   190 		if (mine.getFlooding() > 0 && route.size() % mine.getFlooding() == 0) {
       
   191 			mine.setWaterLevel(mine.getWaterLevel() + 1);
       
   192 		}
   175 
   193 
   176 		lastScoreChange = score - prevScore;
   194 		lastScoreChange = score - prevScore;
   177 		state = GameState.Game;
   195 		state = GameState.Game;
   178 		return state;
   196 		return state;
   179 	}
   197 	}
   231 		for (Movement mov : route) {
   249 		for (Movement mov : route) {
   232 			movs += mov.toText();
   250 			movs += mov.toText();
   233 		}
   251 		}
   234 		return movs;
   252 		return movs;
   235 	}
   253 	}
       
   254 
       
   255 	public int getUnderwater() {
       
   256 		return underwater;
       
   257 	}
   236 }
   258 }