public BattleMap(BaseMapInfo mapInfo) { _currentId = 1; _width = mapInfo.Width; _height = mapInfo.Height; _map = new int[_height, _width]; }
public void InitShips(BaseMapInfo mapInfo) { var shipInfos = mapInfo.ShipInfos.Where(si => si.ShipType == ShipType.BattleCruiser); if (shipInfos != null && shipInfos.Count() == mapInfo.NumberOfBattleCruisers) { foreach (var shipInfo in shipInfos) { shipInfo.Id = _currentId; PlaceShip(shipInfo); _currentId++; } } else throw new Exception("Invalid map."); shipInfos = mapInfo.ShipInfos.Where(si => si.ShipType == ShipType.Cruiser); if (shipInfos != null && shipInfos.Count() == mapInfo.NumberOfCruisers) { foreach (var shipInfo in shipInfos) { shipInfo.Id = _currentId; PlaceShip(shipInfo); _currentId++; } } else throw new Exception("Invalid map."); shipInfos = mapInfo.ShipInfos.Where(si => si.ShipType == ShipType.Frigate); if (shipInfos != null && shipInfos.Count() == mapInfo.NumberOfFrigates) { foreach (var shipInfo in shipInfos) { shipInfo.Id = _currentId; PlaceShip(shipInfo); _currentId++; } } else throw new Exception("Invalid map."); shipInfos = mapInfo.ShipInfos.Where(si => si.ShipType == ShipType.Destroyer); if (shipInfos != null && shipInfos.Count() == mapInfo.NumberOfDestroyers) { foreach (var shipInfo in shipInfos) { shipInfo.Id = _currentId; PlaceShip(shipInfo); _currentId++; } } else throw new Exception("Invalid map."); }
public PlayerController(IPlayer player, BaseMapInfo mapInfo) { _player = player; _map = new BattleMap(mapInfo); _map.InitShips(mapInfo); }