Esempio n. 1
0
        private void PutKingShip()
        {
            Ship ship = new Ship(m_Layer, 0, m_Data.Goal, 2, 2);
            ship.Initialize();
            m_Ships.Add(ship);

            //Put into board
            for (int x = m_Data.Goal; x < m_Data.Goal + ship.GetWidth(); x++) for (int y = 0; y < 0 + ship.GetHeight(); y++)
                    m_Board[x, y] = ship;
        }
Esempio n. 2
0
        private void PutShipToBoard()
        {
            Vector2 BoardPosition = CalculatePositionFromRay();

            //Calculate Tile Position
            int TileColumn      = (int)BoardPosition.X / (int)(Global.GAMETILE_WIDTH + (Global.GAMEGAP_WIDTH * 2));
            int TileRow         = (int)BoardPosition.Y / (int)(Global.GAMETILE_HEIGHT + (Global.GAMEGAP_HEIGHT * 2));

            //Check if cursor position are on board
            if ((TileRow >= 0) && (TileRow < BoardRow)) {
                if ((TileColumn >= 0) && (TileColumn < BoardColumn)) {
                    //Get variable
                    bool Available = false;
                    bool Empty = true;

                    //Quick check board and size
                    if ((TileRow + SelectedHeight <= BoardRow) && (TileColumn + SelectedWidth <= BoardColumn)) Available = true;

                    //Ensure ship's space is empty
                    if (Available) {
                        for (int x = TileColumn; x < TileColumn + SelectedWidth; x++) for (int y = TileRow; y < TileRow + SelectedHeight; y++)
                                if (m_Board[x, y] != null) Empty = false;
                    }

                    //Place the ship if empty
                    if (Available && Empty){
                        Ship ship = new Ship(m_Layer, TileRow, TileColumn, SelectedWidth, SelectedHeight);
                        m_Ships.Add(ship);
                        ship.Initialize();

                        //Put into board
                        for (int x = TileColumn; x < TileColumn + ship.GetWidth(); x++) for (int y = TileRow; y < TileRow + ship.GetHeight(); y++)
                                m_Board[x, y] = ship;
                    }
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Stores ship data.
 /// </summary>
 /// <param name="ship">The ship which data will be stored</param>
 public void AddShip(Ship ship)
 {
     //Add each data individually
     AddShip(ship.GetRow(), ship.GetColumn(), ship.GetWidth(), ship.GetHeight());
 }