Пример #1
0
    // Make sure there are enough commodities in the bank for a given dice roll
    private bool checkCommodities(Enums.CommodityType com, 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 (getCommodityFromHex(hType) != com)
            {
                continue;
            }

            // Get all the commodities 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.CITY)
                {
                    switch (com)
                    {
                    case Enums.CommodityType.NONE:
                        break;

                    default:
                        total++;
                        break;
                    }
                }
            }
        }

        // Check the amount against the bank
        int bankAmount = Bank.instance.getCommodityAmount(com);

        if (bankAmount >= total)
        {
            return(true);
        }
        else
        {
            return(false);
        }
        return(true);
    }
Пример #2
0
    // Upgrade a development chart in the specified field
    public bool upgradeDevChart(Enums.DevChartType dev, int[] commodities,
                                List <GamePiece> pieces, int[] devChart, bool server)
    {
        // Check if the knight can be upgraded
        if (!ma.canUpgradeDevChart(dev, commodities, pieces, devChart))
        {
            return(false);
        }

        Player current = GameManager.instance.getCurrentPlayer();

        Enums.CommodityType com = (CommodityType)((int)dev);
        int level    = devChart[(int)dev];
        int newLevel = level + 1;

        // Spend the correct resources
        current.changeCommodity(com, -level);
        Bank.instance.depositCommodity(com, level, current.isServer);

        current.upgradeDevChart(dev);

        if (newLevel == 3)
        {
            if (dev == Enums.DevChartType.TRADE)
            {
                for (int i = 0; i < 3; i++)
                {
                    current.updateCommodityRatio(com, 2);
                }
            }
            else if (dev == Enums.DevChartType.SCIENCE)
            {
                current.makeAqueduct();
            }
        }

        // Metropolis

        return(true);
    }
Пример #3
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
    }