コード例 #1
0
    //update timer and other time-related variables
    public void UpdateTimer(MainTycoonScript script)
    {
        //if player is busy, update timer
        if (busy != "")
        {
            timer -= Time.deltaTime;
            if (timer <= 0)                 //if timer reaches 0, player finishes event
            {
                UpdateStatusBar(0, script); //update status bar so it scales to 0
                //add money based and popualarity to player stas
                switch (busy)
                {
                case "sponsor speech":
                    money += PROFIT_SPONSOR_SPEECH;
                    UpdateMoney(script);
                    break;

                case "super pac":
                    money += PROFIT_SUPER_PAC;
                    UpdateMoney(script);
                    break;
                }
                //set busy back to zero
                busy = "";
                //set timer to 0 so Status Bar scales to 0
                timer = 0f;
            }
            else
            {
                UpdateStatusBar(timer / DAY_LENGTH, script); //update status bar, accounting for DAY_LENGTH
            }
        }
    }
コード例 #2
0
    //update size of status bar
    private void UpdateStatusBar(float timeRemainingEvent, MainTycoonScript script)
    {
        //get status bar and change x scale based on time elapsed
        Vector3 scale = new Vector3(1, 0.3f, 1);

        //x scale will be time left divided by total time
        switch (busy)
        {
        case "sponsor speech":
            scale = new Vector3(timeRemainingEvent / TIME_SPONSOR_SPEECH, 0.3f, 1);
            break;

        case "super pac":
            scale = new Vector3(timeRemainingEvent / TIME_SUPER_PAC, 0.3f, 1);
            break;

        case "town hall":
            scale = new Vector3(timeRemainingEvent / TIME_TOWN_HALL, 0.3f, 1);
            break;

        case "television ad":
            scale = new Vector3(timeRemainingEvent / TIME_TELEVISION_AD, 0.3f, 1);
            break;

        case "conference":
            scale = new Vector3(timeRemainingEvent / TIME_CONFERENCE, 0.3f, 1);
            break;
        }
        var statusBar = script.transform.FindChild("StatusBar"); //get status bar and apply changes

        statusBar.transform.localScale = scale;
    }
コード例 #3
0
 //Conference is event is bought
 public void Conference(MainTycoonScript script)
 {
     if (busy == "" && money >= COST_CONFERENCE)
     {
         //if not already busy and has enough money, set busy to "conference", subtract money and add length to timer
         busy   = "conference";
         timer  = TIME_CONFERENCE * DAY_LENGTH;
         money -= COST_CONFERENCE;
         UpdateMoney(script);
         popularity.UpdatePopularity(script, script.GetPolicyValues(), MULTIPLIER_CONFERENCE);
     }
 }
コード例 #4
0
 //Television Ad event is bought
 public void TelevisionAd(MainTycoonScript script)
 {
     if (busy == "" && money >= COST_TELEVISION_AD)
     {
         //if not already busy and has enough money, set busy to "television ad", subtract money and add length to timer
         busy   = "television ad";
         timer  = TIME_TELEVISION_AD * DAY_LENGTH;
         money -= COST_TELEVISION_AD;
         UpdateMoney(script);
         popularity.UpdatePopularity(script, script.GetPolicyValues(), MULTIPLIER_TELEVISION_AD);
     }
 }
コード例 #5
0
 //Town Hall event is bought
 public void TownHall(MainTycoonScript script)
 {
     if (busy == "" && money >= COST_TOWN_HALL)
     {
         //if not already busy and has enough money, set busy to "town hall", subtract money and add length to timer
         busy   = "town hall";
         timer  = TIME_TOWN_HALL * DAY_LENGTH;
         money -= COST_TOWN_HALL;
         UpdateMoney(script);
         popularity.UpdatePopularity(script, script.GetPolicyValues(), MULTIPLIER_TIME_HALL);
     }
 }
コード例 #6
0
    public Text sceneTimerDays;    //timer text in scene (for displaying days until next fight)

    public CalendarHandler(MainTycoonScript script, float dayLength, Text dayText, Text monthText)
    {
        calendar        = new DateTime(2016, 4, 20);
        SECONDS_PER_DAY = dayLength;
        dayTimer        = SECONDS_PER_DAY;
        DAYS_IN_CYCLE   = MainTycoonScript.DAYS_PER_CYCLE;

        calendarDayText   = dayText;
        calendarMonthText = monthText;
        sceneTimerTime    = GameObject.Find("TimeUntil").gameObject.GetComponent <Text>();
        sceneTimerDays    = GameObject.Find("DaysUntil").gameObject.GetComponent <Text>();
    }
コード例 #7
0
    //update amount of money displayed
    public void UpdateMoney(MainTycoonScript script)
    {
        //get text from child
        Text yourStats = script.transform.FindChild("Canvas").FindChild("YourStats").GetComponent <Text>();

        string[] lines = yourStats.text.Split('\n'); //split yourStats string into lines and edit relevant line
        lines[0] = "Money: $" + money.ToString();

        yourStats.text = "";        //reset text
        foreach (string s in lines) //re-add (now edited) lines to child Text object
        {
            yourStats.text += s + "\n";
        }
    }
コード例 #8
0
    //updates popularity based on state stats
    public void UpdatePopularity(MainTycoonScript script, float[] values, float differenceMultiplier)
    {
        float difference = 0;

        PolicyScript[] policyScripts = script.transform.FindChild("Canvas").FindChild("Policies").GetComponentsInChildren <PolicyScript>();
        for (int i = 0; i < values.Length; i++)
        {
            //update the median in each policy script
            policyScripts[i].UpdateMedian();
            difference += Math.Abs(values[i] - MainTycoonScript.states[currentState].policyLeanings[i]);
        }

        difference /= 4f;                   //divide by 4 since there are 4 values (max difference is 100)
        difference *= differenceMultiplier; //multiplier by multiplier (since some events are less effective)
        popularity  = 100f - difference;    //popularity is just max (100) minus difference between policy leanings and player values

        //float difference = 0;
        //PolicyScript[] policyScripts = script.transform.FindChild("Canvas").FindChild("Policies").GetComponentsInChildren<PolicyScript>();
        //for (int i = 0; i < values.Length; i++)
        //{
        //    //update the median in each policy script
        //    policyScripts[i].UpdateMedian();

        //    //get overall difference (sum of all 4 differences for policy)
        //    float tempDif = values[i] - policyFactors[currentState, i];
        //    difference += tempDif;
        //}
        //difference /= 4;
        //popularity = 100f - (difference * differenceMultiplier);

        //update text
        Text statsText = script.transform.FindChild("Canvas").FindChild("YourStats").GetComponent <Text>();

        string[] newStatText = statsText.text.Split('\n');
        newStatText[1] = String.Format("Popularity: {0:N1}%", popularity);

        statsText.text = string.Empty;
        foreach (string line in newStatText)
        {
            statsText.text += line + "\n";
        }
    }