Esempio n. 1
0
    /// <summary>
    /// 위치 hex에 방향 eDirec으로 함선 eShip을 배치할 수 있는지 확인합니다.
    /// </summary>
    public bool CanPlace(Ship.EShip eShip, Hex _hex, Hex.EDirec eDirec)
    {
        Hex hex = new Hex(_hex);  // Clone

        int shipSize = Ship.GetSizeOf(eShip);

        for (int i = 0; i < shipSize; i++)
        {
            if (!IsValidTile(hex))
            {
                Debug.Log("Tile out of bound");
                return(false);
            }

            Tile.ETile eTile = Tiles[hex.y, hex.x];
            Debug.Log($"{i}: {hex}, {eTile}");

            if (Ships[hex.y, hex.x] != Ship.EShip.NONE)
            {
                Debug.Log("There is already another ship in the place");
                return(false);
            }

            switch (eShip)
            {
            case Ship.EShip.BATTLESHIP:
            case Ship.EShip.CRUISER:
                if (eTile != Tile.ETile.OCEAN)
                {
                    return(false);
                }
                break;

            case Ship.EShip.DESTROYER:
                if (eTile != Tile.ETile.OCEAN && eTile != Tile.ETile.SHORE)
                {
                    return(false);
                }
                break;

            default:
                throw new System.ComponentModel.InvalidEnumArgumentException();
            }

            hex.Move(eDirec);  // 방향에 따른 hex 값 조정
        }

        return(true);
    }
Esempio n. 2
0
    /// <summary>
    /// 함선을 Ships 배열에 저장합니다. 유효성 검사를 하지 않으므로 CanPlace를 먼저 수행하세요.
    /// 같은 함종을 더 배치할 수 있으면 참을, 그렇지 않으면 거짓을 반환합니다.
    /// </summary>
    public bool Place(Ship.EShip eShip, Hex _hex, Hex.EDirec eDirec)
    {
        DecreaseShipCount(eShip);

        Hex hex      = new Hex(_hex); // Clone
        int shipSize = Ship.GetSizeOf(eShip);

        for (int i = 0; i < shipSize; i++)
        {
            Ships[hex.y, hex.x] = eShip;
            hex.Move(eDirec);
        }

        return(ShipCounts[(int)eShip] > 0);
    }