示例#1
0
 private void SetBoatCells(Boat boat, Cell type)
 {
     var cells = boat.GetCellIndexes();
     for (int i = 0; i < boat.Length; i++)
     {
         m_myGrid[cells[i, 0], cells[i, 1]] = type;
     }
 }
示例#2
0
        private bool TrySink(Boat boat, int x, int y)
        {
            var cells = boat.GetCellIndexes();

            bool sunked = true;
            for (int i = 0; i < boat.Length; i++)
            {
                if (m_myGrid[cells[i, 0], cells[i, 1]] == Cell.Hit ||
                    m_myGrid[cells[i, 0], cells[i, 1]] == Cell.Sunked) continue;
                sunked = false;
                break;
            }

            if (sunked)
            {
                SetBoatCells(boat, Cell.Sunked);
                boat.IsSunk = true;
                CheckGameOver();
            }

            return sunked;
        }
示例#3
0
        private bool PositionLegal(Boat boat)
        {
            try
            {
                var cells = boat.GetCellIndexes();

                for(int i = 0; i < boat.Length; i++)
                {
                    if (m_myGrid[cells[i, 0], cells[i, 1]] != Cell.Empty)
                        return false;
                }
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }