/// <summary> /// Updates the board and check next movement. /// </summary> private void UpdateBoard() { //Skip if board doesn't exist if (m_Board == null) return; //Checks winning condition if not editor if (m_Player != Player.Storm && m_Board[m_Data.Goal, 0] != null && m_Board[m_Data.Goal + 1, 0] != null) if (m_Board[m_Data.Goal, 0].IsKing() && m_Board[m_Data.Goal + 1, 0].IsKing()) { //Wins m_Victory = true; m_King = m_Board[m_Data.Goal, 0]; m_King.Wins(); //Set camera as birdview m_ActiveCamera = m_BirdsView; UpdateCamera(); //No need to check the rest return; } //For each ship foreach (Ship ship in m_Ships) { //Reset movement ship.ResetMovement(); //Check each direction #region Movement availability checking //Is ship on top row? bool Available = (ship.GetRow() + ship.GetHeight()) < m_Board.GetLength(1); //Check against other ship if not on top row if (Available) { for (int x = ship.GetColumn(); x < ship.GetColumn() + ship.GetWidth(); x++) if (m_Board[x, ship.GetRow() + ship.GetHeight()] != null) Available = false; if (Available) { ship.AddMovement(Direction.PositiveY); } } //Is ship on bottom row? Available = ship.GetRow() > 0; //Check against other ship if not on bottom row if (Available) { for (int x = ship.GetColumn(); x < ship.GetColumn() + ship.GetWidth(); x++) if (m_Board[x, ship.GetRow() - 1] != null) Available = false; if (Available) { ship.AddMovement(Direction.NegativeY); } } //Is ship on left most row? Available = (ship.GetColumn() + ship.GetWidth()) < m_Board.GetLength(0); //Check against other ship if not on bottom row if (Available) { for (int y = ship.GetRow(); y < ship.GetRow() + ship.GetHeight(); y++) if (m_Board[ship.GetColumn() + ship.GetWidth(), y] != null) Available = false; if (Available) { ship.AddMovement(Direction.PositiveX); } } //Is ship on right most row? Available = ship.GetColumn() > 0; //Check against other ship if not on bottom row if (Available) { for (int y = ship.GetRow(); y < ship.GetRow() + ship.GetHeight(); y++) if (m_Board[ship.GetColumn() - 1, y] != null) Available = false; if (Available) { ship.AddMovement(Direction.NegativeX); } } #endregion } }