コード例 #1
0
    public void GenerateBoard()
    {
        // Start hex generation.

        List <string> terrainPoolCopy = terrainPool.OfType <string>().ToList();
        List <int>    numberPoolCopy  = numberPool.OfType <int>().ToList();

        int terrainPoolSize = terrainPool.Length;
        int numberPoolSize  = numberPool.Length;

        // Generate terrain.
        foreach (Hex hex in hexes)
        {
            // Generate random number in range.
            int    terrainIndex      = Random.Range(0, terrainPoolSize);
            string chosenTerrainName = terrainPoolCopy[terrainIndex];
            terrainPoolCopy.RemoveAt(terrainIndex);
            hex.SetMaterial(chosenTerrainName);
            terrainPoolSize--;


            if (chosenTerrainName == "Desert")
            {
                hex.SetNumber(7);
            }
        }

        // Exhaust sixes.
        while (sixes != 0)
        {
            do
            {
                Hex hex = RandomHexWithNoNumber();
                if (hex.NeighbourHasRedNumber() == false)
                {
                    hex.SetNumber(6);
                    sixes--;
                    break;
                }
            } while (true);
        }

        // Exhaust eights.
        while (eights != 0)
        {
            do
            {
                Hex hex = RandomHexWithNoNumber();
                if (hex.NeighbourHasRedNumber() == false)
                {
                    hex.SetNumber(8);

                    eights--;
                    break;
                }
            } while (true);
        }

        // Now exhaust the rest of the number pool randomly.
        foreach (Hex hex in hexes)
        {
            if (hex.GetNumber() == 0)
            {
                int numberIndex  = Random.Range(0, numberPoolSize);
                int chosenNumber = numberPoolCopy[numberIndex];

                // Get first hex without a number.
                numberPoolCopy.RemoveAt(numberIndex);
                hex.SetNumber(chosenNumber);
                numberPoolSize--;
            }
        }


        // Generate harbour path bonuses.

        List <HarbourPath.HarbourBonus> harbourBonusPoolCopy = harbourBonusPool.OfType <HarbourPath.HarbourBonus>().ToList();

        int harbourPoolSize = harbourBonusPool.Length;

        foreach (HarbourPath harbourPath in harbourPaths)
        {
            int bonusIndex = Random.Range(0, harbourPoolSize);
            HarbourPath.HarbourBonus chosenBonus = harbourBonusPoolCopy[bonusIndex];

            harbourBonusPoolCopy.RemoveAt(bonusIndex);

            harbourPath.SetHarbourBonus(chosenBonus);

            harbourPoolSize--;
        }

        // Shuffle the development deck.

        GameObject.Find("DevelopmentCardDeck").GetComponent <DevelopmentCardDeck>().Init();
    }
コード例 #2
0
 public void AddHarbourBonus(HarbourPath.HarbourBonus bonus)
 {
     harbourBonuses.Add(bonus);
 }