Exemplo n.º 1
0
 public void DecreaseShipCount(Ship.EShip eShip)
 {
     if ((--ShipCounts[(int)eShip]) < 0)
     {
         throw new System.Exception("※ ShipCount is lower than 0");
     }
     UIManager.instance.UpdateShipCountTexts();
 }
Exemplo n.º 2
0
    void ClickUp()
    {
        if (Input.GetMouseButtonUp(0))
        {
            Hex hex = Hex.MouseToHex();

            // 타일에는 콜라이더가 있지만 함선에는 없음
            if (hex != null)
            {
                Ship.EShip eShip = MapManager.instance.IsValidTile(hex) ? MapManager.instance.Ships[hex.y, hex.x] : Ship.EShip.NONE;
                Debug.Log($"Clicked {hex}: {eShip}");

                switch (GameManager.instance.Mode)
                {
                case GameManager.EMode.NONE:
                    break;

                case GameManager.EMode.PLACE:
                    if (PlaceManager.instance.IsDragging)
                    {
                        break;
                    }
                    UIManager.instance.PlaceHighlight(hex);
                    if (eShip != Ship.EShip.NONE)
                    {
                        PlaceManager.instance.SelectShip(hex, eShip);
                    }
                    else if (PlaceManager.instance.ChosenEShip != Ship.EShip.NONE)
                    {
                        PlaceManager.instance.DeselectShip();
                    }
                    break;

                case GameManager.EMode.SELECT:
                    UIManager.instance.SelectHighlight(hex);
                    break;

                case GameManager.EMode.ATTACK:
                    UIManager.instance.AttackHighlight(hex);
                    break;

                default:
                    throw new System.ComponentModel.InvalidEnumArgumentException();
                }
            }
            else  // 타일이 없는 공간 클릭
            {
                UIManager.instance.UnhighlightAll();

                switch (GameManager.instance.Mode)
                {
                case GameManager.EMode.PLACE:
                    PlaceManager.instance.DeselectShip();
                    break;
                }
            }
        }
    }
Exemplo n.º 3
0
 public void ChooseShip(Ship.EShip eShip, GameObject ship)
 {
     Debug.Log($"Choose ship: {ship.name}");
     this.PlacingEShip = eShip;
     shipObj           = ship;
     hasPlaced         = false;
     IsDragging        = false;
     UIManager.instance.UpdateShipIcons(eShip);
 }
Exemplo n.º 4
0
    public void DeselectShip()
    {
        if (chosenHex == null)
        {
            return;
        }

        chosenHex   = null;
        ChosenEShip = Ship.EShip.NONE;
        UIManager.instance.DisplayPlacementButtons(false);
    }
Exemplo n.º 5
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);
    }
Exemplo n.º 6
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);
    }
Exemplo n.º 7
0
    public void UpdateShipIcons(Ship.EShip eShip)
    {
        Color newColor;

        foreach (Image shipIcon in shipIcons)
        {
            newColor       = shipIcon.color;
            newColor.a     = 0.5f;
            shipIcon.color = newColor;
        }

        if (eShip == Ship.EShip.NONE)
        {
            return;
        }

        Debug.Log(eShip);
        Image icon = shipIcons[(int)eShip - 1];

        newColor   = icon.color;
        newColor.a = 1f;
        icon.color = newColor;
    }
Exemplo n.º 8
0
 public void IncreaseShipCount(Ship.EShip eShip)
 {
     ShipCounts[(int)eShip]++;
     UIManager.instance.UpdateShipCountTexts();
 }
Exemplo n.º 9
0
 /// <summary>해당 타일의 함선을 선택합니다.</summary>
 public void SelectShip(Hex hex, Ship.EShip eShip)
 {
     chosenHex   = new Hex(hex);
     ChosenEShip = eShip;
     UIManager.instance.DisplayPlacementButtons(true);
 }