예제 #1
0
    private async void Start()
    {
        try
        {
            var response = await ApiWrapper.GamePrices();

            var propertyPricesArray = (JArray)response["properties"];
            var propertyPrices      = new List <int>(propertyPricesArray.Count);
            foreach (var price in propertyPricesArray)
            {
                var p = (int)price["price"];
                propertyPrices.Add(p);
            }

            var taxPricesArray = (JArray)response["taxes"];
            var taxPrices      = new List <int>(taxPricesArray.Count);
            foreach (var price in taxPricesArray)
            {
                var p = (int)price["price"];
                taxPrices.Add(p);
            }

            LoadPrices(propertyPrices, taxPrices);
        }
        catch (Exception e)
        {
            Debug.Log(e); // TODO: Show error to player
        }
    }
예제 #2
0
    private async void Start()
    {
        try
        {
            var response = await ApiWrapper.GamePrices();

            var propertyPricesArray = (JArray)response["properties"];
            propertiesList = new List <PropertyCard>(propertyPricesArray.Count);
            stationsList   = new List <StationCard>(propertyPricesArray.Count);
            utilitiesList  = new List <UtilityCard>(propertyPricesArray.Count);
            foreach (var property in propertyPricesArray)
            {
                var propertyName = property["name"].ToString();
                var color        = property["color"]?.ToString();
                var location     = (int)property["location"];
                var rents        = ((JArray)property["rents"]).Select(rent => (int)rent).ToArray();
                var mortgage     = (int)property["mortgage"];

                var type = (int)property["type"];
                switch (type)
                {
                case 0:
                {
                    var houseCosts = (JArray)response["houses"];

                    var houseCost = (int)houseCosts[location / 10];

                    var card = new PropertyCard(propertyName, color, location, rents, houseCost, mortgage);
                    propertiesList.Add(card);
                    break;
                }

                case 1:
                {
                    var card = new StationCard(propertyName, location, rents, mortgage);
                    stationsList.Add(card);
                    break;
                }

                default:
                {
                    var card = new UtilityCard(propertyName, location, rents, mortgage);
                    utilitiesList.Add(card);
                    break;
                }
                }
            }
        }
        catch (Exception e)
        {
            Debug.Log(e); // TODO: Show error to player
        }
    }