public Board(int boardLength, BattleshipConfig battleshipConfig) { _boardLength = boardLength; _cells = new Cell[_boardLength, _boardLength]; for (int i = 0; i < _boardLength; ++i) { for (int j = 0; j < _boardLength; ++j) { _cells[i, j] = new Cell(i, j); } } _battleshipConfig = battleshipConfig; _owner = 0; }
public void Initialize() { /// <summary> /// Consider connect to DB in the future /// </summary> if (File.Exists(_settingPath)) { var text = File.ReadAllText(_settingPath); this._battleshipConfig = JsonConvert.DeserializeObject <BattleshipConfig>(text, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, Error = (sender, args) => { args.ErrorContext.Handled = true; } }); if (_battleshipConfig == null) { _battleshipConfig = new BattleshipConfig(); Log.Logger.Write(LogLevel.Warn, "Config: BattleshipSetting.json is crashed."); } } else { _battleshipConfig = new BattleshipConfig(); Log.Logger.Write(LogLevel.Warn, "Config: BattleshipSetting.json does not exist."); } // TODO: we can make this configurable if needed var shipSizeByType = new Dictionary <ShipType, Size>(); shipSizeByType[ShipType.Carrier] = new Size(1, 5); shipSizeByType[ShipType.Battleship] = new Size(1, 4); shipSizeByType[ShipType.Submarine] = new Size(1, 3); shipSizeByType[ShipType.Cruiser] = new Size(1, 2); shipSizeByType[ShipType.Patrol] = new Size(1, 1); _battleshipConfig.ShipSizeByType = shipSizeByType; _boardOfPlayer1 = new Board(_battleshipConfig.BoardSquare.Value, _battleshipConfig); _boardOfPlayer1.Owner = Player1.ID; _boardOfPlayer2 = new Board(_battleshipConfig.BoardSquare.Value, _battleshipConfig); _boardByPlayer[Player1] = _boardOfPlayer1; _boardByPlayer[Player2] = _boardOfPlayer2; }