예제 #1
0
        private Gameboard ConvertGenericListToGameboard(ObservableCollection <GenericEditorItem> list)
        {
            // Create defining lists for collation later
            List <Residence> residentialList = new List <Residence>();
            List <string>    residentialSets = new List <string>();
            List <Station>   stationsList    = new List <Station>();
            List <Utility>   utilitiesList   = new List <Utility>();
            List <Tax>       taxationIndexes = new List <Tax>();
            List <int>       chanceIndexes   = new List <int>();
            List <int>       cChestIndexes   = new List <int>();

            foreach (GenericEditorItem item in list)
            {
                switch (item.Type)
                {
                case 0:     // Residential
                    if (item.Name == "Protected")
                    {
                        break;
                    }
                    residentialList.Add(new Residence(null)
                    {
                        Position = item.Index,
                        Name     = item.Name,
                        Set      = item.Set,
                        Price    = item.Price,
                        HouseIncrementationPrice = item.HouseIncrementationCost,
                        Hex  = item.PropertyHex,
                        Rent = item.Rent.ToArray()
                    });
                    if (!residentialSets.Contains(item.Set))
                    {
                        residentialSets.Add(item.Set);
                    }
                    break;

                case 1:     // Station
                    stationsList.Add(new Station(null)
                    {
                        Position = item.Index,
                        Name     = item.Name,
                        Set      = item.Set,
                        Price    = item.Price,
                        Hex      = item.PropertyHex,
                    });
                    break;

                case 2:     // Utility
                    utilitiesList.Add(new Utility(null)
                    {
                        Position = item.Index,
                        Name     = item.Name,
                        Set      = item.Set,
                        Price    = item.Price,
                        Hex      = item.PropertyHex,
                    });
                    break;

                case 3:     // Chance tile
                    chanceIndexes.Add(item.Index);
                    break;

                case 4:     // Community chest tile
                    cChestIndexes.Add(item.Index);
                    break;

                case 5:     // Chance tile
                    taxationIndexes.Add(new Tax(null)
                    {
                        Name     = item.Name,
                        Position = item.Index,
                        Cost     = item.Price
                    });
                    break;
                }
            }
            // Now we need to assemble these collections into an output gameboard
            Gameboard outputGameboard = new Gameboard(null);

            // Do the residences
            outputGameboard.Residences = new Dictionary <string, List <Residence> >();
            foreach (string set in residentialSets)
            {
                List <Residence> residencesOfSet = new List <Residence>();
                foreach (Residence res in residentialList)
                {
                    if (res.Set == set)
                    {
                        residencesOfSet.Add(res);
                    }
                }
                outputGameboard.Residences.Add(set, residencesOfSet);
            }
            // Residences done! Onto stations and utilities
            outputGameboard.Stations           = stationsList;
            outputGameboard.StationsRent       = StationRents.ToArray();
            outputGameboard.Utilities          = utilitiesList;
            outputGameboard.UtilityMultipliers = UtilityRents.ToArray();
            // Properties done! Deal with taxation, chance and community chest
            outputGameboard.TaxIndexes    = taxationIndexes;
            outputGameboard.ChanceIndexes = chanceIndexes.ToArray();
            outputGameboard.ChestIndexes  = cChestIndexes.ToArray();
            return(outputGameboard);
        }
예제 #2
0
        private void _UpdateStationUtilityRentCounts(object sender)
        {
            Console.WriteLine("Refreshing station and utility rent counters");
            int stations = 0; int utilities = 0;

            foreach (GenericEditorItem item in Board)
            {
                if (item.Type == 1)
                {
                    // Station
                    Console.WriteLine("Found a station at index: " + item.Index);
                    stations++;
                }
                else if (item.Type == 2)
                {
                    // Utility
                    Console.WriteLine("Found a utility at index: " + item.Index);
                    utilities++;
                }
            }
            Console.WriteLine("Counted utilities " + utilities + ", and stations " + stations);
            // Change the numbers where needed
            if (stations > StationRents.Count())
            {
                // Need to add an additional integer to StationsRent
                for (int i = StationRents.Count(); i < stations; i++)
                {
                    Console.WriteLine("Adding a station to a list of " + StationRents.Count());
                    StationRents.Add(0);
                }
            }
            else if (stations < StationRents.Count())
            {
                // Need to remove the unnecessary integers from the end!
                ObservableCollection <int> newList = new ObservableCollection <int>();
                for (int i = 0; i < stations; i++)
                {
                    newList.Add(StationRents[i]);
                    Console.WriteLine("Adding stations, index " + i + ": " + StationRents[i]);
                }
                StationRents = newList;
            }
            // Repeat such a process for the utilities
            // Change the numbers where needed
            if (utilities > UtilityRents.Count())
            {
                // Need to add an additional integer to UtilityRent
                for (int i = UtilityRents.Count(); i < utilities; i++)
                {
                    UtilityRents.Add(0);
                }
            }
            else if (utilities < UtilityRents.Count())
            {
                // Need to remove the unnecessary integers from the end!
                ObservableCollection <int> newList = new ObservableCollection <int>();
                for (int i = 0; i < utilities; i++)
                {
                    newList.Add(UtilityRents[i]);
                }
                UtilityRents = newList;
            }
            Console.WriteLine("Two route done");
            // Force visual updates
            OnPropertyChanged("StationRents");
            OnPropertyChanged("UtilityRents");
            Console.WriteLine("Returning");
        }