예제 #1
0
    // Place an initial city
    public bool placeInitialCity(Vertex v, List <GamePiece> pieces, bool server)
    {
        if (!ma.canPlaceInitialTownPiece(v))
        {
            return(false);
        }

        assignAuthority(server);
        RpcPlaceInitialCity(v.transform.position, GameManager.instance.getCurrentPlayer().getColor());

        Player current = GameManager.instance.getCurrentPlayer();

        // Give starting resources to current player
        foreach (Hex h in BoardState.instance.hexPosition.Values)
        {
            if (h.adjacentToVertex(v))
            {
                Enums.ResourceType res = GameManager.instance.getResourceFromHex(h.getHexType());
                if (res != Enums.ResourceType.NONE)
                {
                    current.changeResource(res, 1);
                    Bank.instance.withdrawResource(res, 1, current.isServer);
                }
            }
        }

        // Update the victory points and add a port
        current.changeVictoryPoints(2);

        removeAuthority(server);

        return(true);
    }
예제 #2
0
    /// <summary>
    /// Sets the ToResource attribute of this instance of UI manager that the Player wants to get from a trade
    /// This is Private, because it is only called when the actual trade with bank is called as well
    /// </summary>
    /// <param name="p_ResourceType">P resource type.</param>
    private void setToResource(string p_ResourceType)
    {
        switch (p_ResourceType)
        {
        case "Brick":
            _ToResource = Enums.ResourceType.BRICK;
            break;

        case "Wool":
            _ToResource = Enums.ResourceType.WOOL;
            break;

        case "Grain":
            _ToResource = Enums.ResourceType.GRAIN;
            break;

        case "Lumber":
            _ToResource = Enums.ResourceType.LUMBER;
            break;

        case "Ore":
            _ToResource = Enums.ResourceType.ORE;
            break;
        }
    }
예제 #3
0
파일: Hex.cs 프로젝트: sorinmuchi/Settlers
 public Hex(Enums.TerrainType terrain, Enums.HexType hexType, Enums.ResourceType resType) : base(terrain)
 {
     this.vertices = new List <Vertex> ();
     if (terrain == Enums.TerrainType.WATER)
     {
         this.hexType = Enums.HexType.WATER;
     }
     else if (hexType == Enums.HexType.WATER)
     {
         this.hexType = Enums.HexType.DESERT;
     }
     else
     {
         this.hexType = hexType;
     }
     this.resourceType = resType;
 }
예제 #4
0
    // Use this for initialization
    void Awake()
    {
        _SmartPanel.gameObject.SetActive(true);
        _vToHighlight = new List <Vertex> ();
        _eToHighlight = new List <Edge> ();
        recentMove    = MoveType.NONE;

        _UIMoveManager = GetComponent <UIMoveManager> ();


        _CurrentPlayer = GameObject.Find(Network.player.ipAddress).GetComponent <Player>();

        // Set UIMoveManager's Current Player to this instance's current player attribute
        _UIMoveManager.setCurrentPlayer(_CurrentPlayer);

        _PlayerHighlighter = _CurrentPlayer.GetComponent <HighLighter> ();

        if (_CurrentPlayer.gameObject.GetComponent <NetworkIdentity>().isLocalPlayer)
        {
            // Hide ContextPanel and its contents on startup
            setContextPanelChildren();
            _ContextPanel.gameObject.SetActive(false);
            _VertexButtonsPanel.gameObject.SetActive(false);
            _EdgeButtonsPanel.gameObject.SetActive(false);


            // Get the GameManager Component off of the CurrentPlayer object
            _GameManager = _CurrentPlayer.GetComponent <GameManager>();

            // Set the Trade Attributes to NONE. And the Maritime panel active to false
            _FromResource = Enums.ResourceType.NONE;
            _ToResource   = Enums.ResourceType.NONE;
            _MaritimeTradePanel.gameObject.SetActive(false);


            // Set the Dice Roll panel to true at start. Only shows the rollDice button at the right turns though
            _DiceRollPanel.gameObject.SetActive(true);
        }
    }
예제 #5
0
    // Make sure there are enough resources in the bank for a given dice roll
    private bool checkResources(Enums.ResourceType res, int n)
    {
        int total = 0;

        foreach (Hex h in BoardState.instance.hexPosition.Values)
        {
            // If a hex isn't the right type or number, continue
            if (h.getHexNumber() != n)
            {
                continue;
            }

            Enums.HexType hType = h.getHexType();
            if (getResourceFromHex(hType) != res)
            {
                continue;
            }

            // Get all the resources accumulated by all players
            foreach (Vertex v in h.getVertices())
            {
                GamePiece current = v.getOccupyingPiece();
                if (Object.ReferenceEquals(current, null))
                {
                    continue;
                }
                if (current.getPieceType() == Enums.PieceType.SETTLEMENT)
                {
                    total++;
                }
                if (current.getPieceType() == Enums.PieceType.CITY)
                {
                    if (res == Enums.ResourceType.BRICK)
                    {
                        total += 2;
                    }
                    else if (res == Enums.ResourceType.GRAIN)
                    {
                        total += 2;
                    }
                    else if (res != Enums.ResourceType.NONE)
                    {
                        total++;
                    }
                }
            }
        }

        // Check the amount against the bank
        int bankAmount = Bank.instance.getResourceAmount(res);

        if (bankAmount >= total)
        {
            return(true);
        }
        else
        {
            return(false);
        }
        return(true);
    }
예제 #6
0
    // Distribute the appropriate resources to all players
    private void distribute()
    {
        int num = firstDie + secondDie;

        // Make sure there are enough resources and commodities in the bank
        Dictionary <Enums.ResourceType, bool>  enoughRes  = new Dictionary <Enums.ResourceType, bool>();
        Dictionary <Enums.CommodityType, bool> enoughComs = new Dictionary <Enums.CommodityType, bool>();

        for (int i = 0; i < numResources; i++)
        {
            enoughRes.Add((Enums.ResourceType)i, checkResources((Enums.ResourceType)i, num));
        }
        for (int i = 0; i < numCommodities; i++)
        {
            enoughComs.Add((Enums.CommodityType)i, checkCommodities((Enums.CommodityType)i, num));
        }

        foreach (Hex h in BoardState.instance.hexPosition.Values)
        {
            // If a hex isn't the right number, or doesn't produce cards, continue
            if (h.getHexNumber() != num)
            {
                continue;
            }

            if (Object.ReferenceEquals(h, robberLocation))
            {
                continue;
            }
            Enums.HexType hType = h.getHexType();

            // Check if a hex produces gold
            bool gold = false;
            if (hType == Enums.HexType.GOLD)
            {
                gold = true;
            }

            Enums.ResourceType  res = getResourceFromHex(hType);
            Enums.CommodityType com = getCommodityFromHex(hType);
            if (res == Enums.ResourceType.NONE)
            {
                continue;
            }

            // Distribute all the resources
            foreach (Vertex v in h.getVertices())
            {
                GamePiece current = v.getOccupyingPiece();
                if (Object.ReferenceEquals(current, null))
                {
                    continue;
                }

                // Distribue resources for settlements
                if (current.getPieceType() == Enums.PieceType.SETTLEMENT)
                {
                    Debug.Log("Hex type: " + h.getHexType() + ", enough: " + enoughRes[res]);
                    Enums.Color ownerColor = current.getColor();
                    Player      p          = getPlayer(ownerColor);
                    if (res != Enums.ResourceType.NONE && enoughRes[res])
                    {
                        Bank.instance.withdrawResource(res, 1, p.isServer);
                        p.changeResource(res, 1);
                    }
                    else if (gold)
                    {
                        p.changeGoldCount(2);
                    }
                }

                // Distribute resources and commodities for cities
                if (current.getPieceType() == Enums.PieceType.CITY)
                {
                    Enums.Color ownerColor = current.getColor();
                    Player      p          = getPlayer(ownerColor);
                    if (com != Enums.CommodityType.NONE)
                    {
                        if (enoughRes[res])
                        {
                            Bank.instance.withdrawResource(res, 1, p.isServer);
                            p.changeResource(res, 1);
                        }
                        if (enoughComs[com])
                        {
                            Bank.instance.withdrawCommodity(com, 1, p.isServer);
                            p.changeCommodity(com, 1);
                        }
                    }
                    else if (res == Enums.ResourceType.BRICK && enoughRes[res])
                    {
                        Bank.instance.withdrawResource(res, 2, p.isServer);
                        p.changeResource(res, 2);
                    }
                    else if (res == Enums.ResourceType.GRAIN && enoughRes[res])
                    {
                        Bank.instance.withdrawResource(res, 2, p.isServer);
                        p.changeResource(res, 2);
                    }
                    else if (gold)
                    {
                        p.changeGoldCount(2);
                    }
                }
            }
        }
        //Distribute aqueduct cards
    }