public void Play(int mapSize) { var map = PrepareMap(mapSize); while (true) { WriteBattleScore(); WriteMap(map); var input = Console.ReadLine(); if (ValidateFormat(mapSize, input)) { Console.WriteLine("Incorrect format"); continue; } var coordinates = new FieldCoordinates(input); var result = battleService.Shoot(coordinates.Row, coordinates.Column); WriteBattleStatusMessage(result); if (result.Score.Sinks == 3) { Console.WriteLine("Game is over! You won!"); break; } } Console.ReadKey(); }
public GameResult Execute(BattleScenario scenario) { var plain = new Plain(scenario.Plain.Xsize, scenario.Plain.Ysize); try { foreach (var battleship in scenario.Battleships) { _battleService.AddBattleship(plain, new Battleship(battleship.Start, battleship.End)); } var shotResults = scenario.ShotPoints?.Select(shotPoint => _battleService.Shoot(plain, shotPoint)).ToList(); var hasLost = plain.IsDestroyed(); return(new GameResult { AttackResults = shotResults, HasLost = hasLost }); } catch (Exception e) { return(new GameResult { IsError = true, Error = e.Message }); } }