Beispiel #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);
    }
Beispiel #2
0
 public Hex(Enums.TerrainType terrain, Enums.HexType hexType) : 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;
     }
 }
Beispiel #3
0
    // Get a commodity from a hex
    public Enums.CommodityType getCommodityFromHex(Enums.HexType hType)
    {
        switch (hType)
        {
        case Enums.HexType.FOREST:
            return(Enums.CommodityType.PAPER);

        case Enums.HexType.MOUNTAIN:
            return(Enums.CommodityType.COIN);

        case Enums.HexType.PASTURE:
            return(Enums.CommodityType.CLOTH);

        default:
            return(Enums.CommodityType.NONE);
        }
    }
Beispiel #4
0
    // get a resource from a hex
    public Enums.ResourceType getResourceFromHex(Enums.HexType hType)
    {
        switch (hType)
        {
        case Enums.HexType.FIELD:
            return(Enums.ResourceType.GRAIN);

        case Enums.HexType.FOREST:
            return(Enums.ResourceType.LUMBER);

        case Enums.HexType.HILL:
            return(Enums.ResourceType.BRICK);

        case Enums.HexType.MOUNTAIN:
            return(Enums.ResourceType.ORE);

        case Enums.HexType.PASTURE:
            return(Enums.ResourceType.WOOL);

        default:
            return(Enums.ResourceType.NONE);
        }
    }
Beispiel #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);
    }
Beispiel #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
    }