//The coroutine for the munchkins to show up one by one as they enter the clinic. public IEnumerator appear(GameBuilder1 world) { //First, let's get the # of sick munchkins from WorldModel int sick = world.retDay(1).get("totalSymps"); //And we start "total" with 0, before incrementing it all the up to the # of sick Mooches. total = 0; if (total <= healthy.Count) { //Now we wanna increment total all the way till the actual # of sick, // or healthy.Count, which is the # of seats available in clinic. while (total < sick && total < healthy.Count) { total += 1; uncured = total; for (int i = 0; i < total; i++) { GameObject sickPeep = healthy [i]; sickPeep.GetComponent <SpriteRenderer> ().sprite = unTreated; sickPeep.GetComponent <SpriteRenderer> ().color = new Color(1f, .5f, .5f); } //yield return to give off the one-by-one pseudo-animation effect. //Realize that we used 1f/sick to control the speed of animation: The more sick, the faster, so that you don't get bored watching. yield return(new WaitForSecondsRealtime(1f / sick)); } } yield return(new WaitForSecondsRealtime(.5f)); }
public void onStart(Initializer init, GameBuilder1 world) { lefty = GameObject.Find("Slider_left"); righty = GameObject.Find("Slider_right"); //generate available number list availableNumList = new List <int>(); for (int i = 0; i < rowCount * colCount; i++) { availableNumList.Add(i); } int numSick = world.retDay(1).get("totalSymps"); int numCuredA = world.retDay(1).get("totala"); int numCuredB = world.retDay(1).get("totalb"); total = numSick; totalCuredA = numCuredA; totalCuredB = numCuredB; //set size of the prefab healthyPrefab.GetComponent <Transform> ().localScale = new Vector3(radius / rowCount, radius / rowCount, 1); for (int j = -Mathf.FloorToInt(rowCount / 2f); j < Mathf.CeilToInt(rowCount / 2f); j++) { for (int i = -Mathf.CeilToInt(colCount / 2f); i < Mathf.FloorToInt(colCount / 2f); i++) { GameObject newPeep = Instantiate(healthyPrefab, new Vector3(i * 15f / colCount + .1f, -j * 3f / rowCount + 3.3f, 0), Quaternion.identity); healthy.Add(newPeep); newPeep.GetComponent <Rigidbody2D> ().velocity = new Vector3(Random.Range(-velocity, velocity), Random.Range(-velocity, velocity), 0); } } }
//adjust globals after creatures are cured public void cure(Initializer init, GameBuilder1 world) { int cured = world.retDay(1).get("totalCuredDay"); totalSick -= cured; totalCuredA = world.retDay(1).get("curedAnum"); totalCuredB = world.retDay(1).get("curedbnum"); }
public void cure(Initializer init, GameBuilder1 world) { int cured = world.retDay(1).get("totalCuredDay"); int target = total - cured; total = target; totalCuredA = world.retDay(1).get("totala"); totalCuredB = world.retDay(1).get("totalb"); }
// Updates text associated with test tube, funds remaining, and news panel after you cure some people public void updateText(GameBuilder1 world, int i) { totalCuredA.text = "Total Cured: " + world.retDay(i).get("totalA"); totalCuredB.text = "Total Cured: " + world.retDay(i).get("totalB"); totalTrtA.text = "Total Treatment Given: " + world.retDay(i).get("totalTrtA"); totalTrtB.text = "Total Treatment Given: " + world.retDay(i).get("totalTrtB"); funds.text = "Funds Left: " + (init.getParam("fund") - world.retDay(i).get("totalCost")) + "$"; fundsAnimation.SetFloat("fund_remaining", (float)((init.getParam("fund") - world.retDay(i).get("totalCost")) / init.getParam("fund"))); ai.text = "You cured " + world.retDay(1).get("totalCuredDay") + " people"; }
//for every consequent daily update; public void nextDay(GameBuilder1 world, int i) { maxValA = (float)world.retDay(i).get("totalTrtA"); maxValB = (float)world.retDay(i).get("totalTrtB"); maxValSetter(a, b, maxValA, maxValB); curValsSetter(a, b, fnd, (float)world.retDay(i).get("totalA"), (float)world.retDay(i).get("totalB"), (float)maxValFunds - world.retDay(i).get("totalCost")); }
//The coroutine for curing muchkins with treatment A and B. The cured ones are color-coded accordingly as well. public IEnumerator cure(Initializer init, GameBuilder1 world) { //Total cured int cured = world.retDay(1).get("totalCuredDay"); //Cured by treatment A and B int curedA = world.retDay(1).get("curedAnum"); int curedB = world.retDay(1).get("curedbnum"); //Total # of sick minus total # of cured is the # uncured, hence the name "target". int target = total - cured; //set uncured to total first, and we'll decrement it to target later! uncured = total; //Calculate how many rows of sick Munch'es there're in the clinic. int rows = Mathf.CeilToInt((float)total / colCount); //color people cured by A for (int j = 0; j < colCount; j++) { for (int i = 0; i <= rows; i++) { int location = i * colCount + j; if (location < total) { GameObject sickPeep = healthy [location]; if (uncured > (total - curedA)) { sickPeep.GetComponent <SpriteRenderer> ().sprite = healed; sickPeep.GetComponent <SpriteRenderer> ().color = new Color(.3f, 1f, .3f); uncured -= 1; } } } } //color people cured by B for (int i = colCount - 1; i >= 0; i--) { for (int j = rows; j >= 0; j--) { int location = j * colCount + i; if (location < total) { GameObject sickPeep = healthy [location]; if (uncured > (total - curedA - curedB)) { sickPeep.GetComponent <SpriteRenderer> ().sprite = healed; sickPeep.GetComponent <SpriteRenderer> ().color = new Color(.3f, .3f, 1f); uncured -= 1; } } } } yield return(new WaitForSecondsRealtime(1f)); }
//creates and adds the updated stats lines to the file; public void nextDayAdder(GameBuilder1 world, Initializer init) { double[] pars = paramGen(world.retDay(1), init); String[] tempInput = new String[23]; for (int i = 0; i < 23; i++) { tempInput [i] = "" + pars [i]; } rowInputs.Add(tempInput); fileCA(); }
public IEnumerator catchDisease(GameBuilder1 world) { int newSick = world.retDay(1).get("totalSymps") - total; for (int i = total + totalCuredA + totalCuredB; i <= totalCuredA + totalCuredB + total + newSick; i++) { GameObject sickPeep = healthy [i]; sickPeep.GetComponent <SpriteRenderer> ().color = new Color(1f, 0, 0); } total = total + newSick; yield return(new WaitForSecondsRealtime(1f)); }
public IEnumerator disappear(GameBuilder1 world) { Color sick = new Color(1f, 0, 0); foreach (GameObject sickPeep in healthy) { if (sickPeep.GetComponent <SpriteRenderer> ().color == sick) { sickPeep.SetActive(false); } } yield return(null); }
//on start, create a new world/game (the call to constructor automatically // adds the first day initial params and displays it); void Awake() { lefty = GameObject.Find("Slider_left"); righty = GameObject.Find("Slider_right"); nextDay = GameObject.Find("NextDay").GetComponent <Button> (); state = 0; world = new GameBuilder1(init, spawner, spawner2); fill.dayOne(world, init); clicked = false; checker = false; StartCoroutine(spawner2.disappear()); StartCoroutine(spawner.appear(world)); csv = new CSVC(init.fileP()); }
public void jAdder(GameBuilder1 world, Initializer init, WorldModel wM) { String jS; if (wM.gameState() != "none") { jS = JsonUtility.ToJson(new JSONData(world, init)); } else { jS = JsonUtility.ToJson(new JSONData(world, init)) + ","; } jBuilder += jS; }
public void onStart(Initializer init, GameBuilder1 world) { lefty = GameObject.Find("Slider_left"); righty = GameObject.Find("Slider_right"); //generate available number list availableNumList = new List <int>(); for (int i = 0; i < rowCount * colCount; i++) { availableNumList.Add(i); } int numSick = world.retDay(1).get("totalSymps"); total = 0; uncured = 0; //set size of the prefab healthyPrefab.GetComponent <Transform> ().localScale = new Vector3(radius / rowCount, radius / rowCount, 1); //Instantiate a 2D array of healthyPrefabs int count = 0; for (int j = -Mathf.FloorToInt(rowCount / 2f); j < Mathf.CeilToInt(rowCount / 2f); j++) { for (int i = -Mathf.CeilToInt(colCount / 2f); i < Mathf.FloorToInt(colCount / 2f); i++) { //The first 5 seats are always colored purplish to indicate the winning condition. if (count < 5) { //The new Vector3 positions of the prefabs are hard coded to fit the screen. //Can be adjusted if the designs change in the future (Yes, I'm talking to you, future coders:)) GameObject newPeep = Instantiate(healthyPrefab, new Vector3(i * 9.8f / colCount + -2.6f, -j * 4.2f / rowCount - .7f, 0), Quaternion.identity); newPeep.GetComponent <SpriteRenderer> ().color = new Color(0.2f, 0f, 0.2f); //Add the instantiated GameObject into healthy List to keep track of them (and modify later!). healthy.Add(newPeep); //Cool little particle collision effect that you can experiment with by setting the velocity param in the WorldModel. newPeep.GetComponent <Rigidbody2D> ().velocity = new Vector3(Random.Range(-velocity, velocity), Random.Range(-velocity, velocity), 0); } else { //The othe seats are generated as regular healthyPrefabs. The rest is exactly the same as above. GameObject newPeep = Instantiate(healthyPrefab, new Vector3(i * 9.8f / colCount + -2.6f, -j * 4.2f / rowCount - .7f, 0), Quaternion.identity); healthy.Add(newPeep); newPeep.GetComponent <Rigidbody2D> ().velocity = new Vector3(Random.Range(-velocity, velocity), Random.Range(-velocity, velocity), 0); } count++; } } }
//To set up all the objects and the maxVals if the ydon't vary later; public void dayOne(GameBuilder1 world, Initializer init) { a = GameObject.Find("TubeL").GetComponent <FaceScript> (); b = GameObject.Find("TubeR").GetComponent <FaceScript> (); fnd = GameObject.Find("FundsBar").GetComponent <FaceScript> (); maxValA = (float)world.retDay(1).get("totalTrtA"); maxValB = (float)world.retDay(1).get("totalTrtB"); maxValFunds = (float)init.getParam("fund"); maxValSetter(a, b, maxValA, maxValB); fnd.MaxValue = maxValFunds; curValsSetter(a, b, fnd, (float)world.retDay(1).get("totalA"), (float)world.retDay(1).get("totalB"), (float)maxValFunds); }
public void onStart(Initializer init, GameBuilder1 world) { lefty = GameObject.Find("Slider_left"); righty = GameObject.Find("Slider_right"); //generate available number list availableNumList = new List <int>(); //randomNumList = new List<int> (); for (int i = 0; i < rowCount * colCount; i++) { availableNumList.Add(i); } //generate random list for sick people int numSick = world.retDay(1).get("totalSymps"); int numCuredA = world.retDay(1).get("totala"); int numCuredB = world.retDay(1).get("totalb"); //int totalPop = (int)(init.getParam ("population") / 2); //total = Mathf.RoundToInt(numSick * 100f / totalPop); total = numSick; totalCuredA = numCuredA; totalCuredB = numCuredB; //randomNumList = generateSick (availableNumList, randomNumList, total); //set size of the prefab healthyPrefab.GetComponent <Transform> ().localScale = new Vector3(radius / rowCount, radius / rowCount, 1); for (int j = -Mathf.FloorToInt(rowCount / 2f); j < Mathf.CeilToInt(rowCount / 2f); j++) { for (int i = -Mathf.CeilToInt(colCount / 2f); i < Mathf.FloorToInt(colCount / 2f); i++) { GameObject newPeep = Instantiate(healthyPrefab, new Vector3(i * 15f / colCount + .1f, -j * 3f / rowCount + 3.3f, 0), Quaternion.identity); healthy.Add(newPeep); newPeep.GetComponent <Rigidbody2D> ().velocity = new Vector3(Random.Range(-velocity, velocity), Random.Range(-velocity, velocity), 0); } } //healthy[0].GetComponent<SpriteRenderer> ().enabled = false; for (int i = 0; i < total; i++) { GameObject sickPeep = healthy [i]; sickPeep.GetComponent <SpriteRenderer> ().color = new Color(1f, 0, 0); //sickPeep.GetComponent <SpriteRenderer> ().sprite = skull; } }
//animation for new creatures catching the disease public IEnumerator catchDisease(GameBuilder1 world) { int newSick = world.retDay(1).get("totalSymps") - totalSick; for (int i = 0; i < newSick; i++) { GameObject sickPeep = healthyPop [i]; sickPop.Add(sickPeep); healthyPop.Remove(sickPeep); sickPeep.GetComponent <SpriteRenderer> ().color = new Color(1f, .4f, .4f); yield return(null); } totalSick = totalSick + newSick; yield return(new WaitForSecondsRealtime(.5f)); }
public IEnumerator catchDisease(GameBuilder1 world, Initializer init) { Color curea = new Color(0, 1f, 0); Color cureb = new Color(0, 0, 1f); Color stillSick = new Color(1f, 0, 0); int newSick = world.retDay(1).get("totalSymps") - (world.retDay(2).get("totalSymps") - world.retDay(2).get("totalCuredDay")); int healthyNum = (int)(init.getParam("population") / 2) - world.retDay(2).get("totalCuredTotal") - total - newSick - 1; int i = 0; if (newSick < healthyNum) { while (i < newSick) { foreach (GameObject sickPeep in healthy) { if (sickPeep.GetComponent <SpriteRenderer> ().color != curea && sickPeep.GetComponent <SpriteRenderer> ().color != cureb && sickPeep.GetComponent <SpriteRenderer> ().color != stillSick && random() == true && i < newSick) { sickPeep.GetComponent <SpriteRenderer> ().color = new Color(1f, 0, 0); i++; } } } } else { foreach (GameObject sickPeep in healthy) { if (sickPeep.GetComponent <SpriteRenderer> ().color != curea && sickPeep.GetComponent <SpriteRenderer> ().color != cureb && sickPeep.GetComponent <SpriteRenderer> ().color != stillSick) { sickPeep.GetComponent <SpriteRenderer> ().color = new Color(1f, 0, 0); } else { yield return(null); } } } total = total + newSick; yield return(null); }
public JSONData(GameBuilder1 world, Initializer init) { Day cur = world.retDay(1); playerID = PlayerData.playerdata.playerID; groupID = PlayerData.playerdata.groupID; day = cur.get("day"); population = (int)init.getParam("population"); budget = (int)init.getParam("fund") - cur.get("totalCost"); availToTreat = cur.get("totalSymps"); aTreat = cur.get("sickTrtA"); aCure = cur.get("curedANum"); bTreat = cur.get("sickTrtB"); bCure = cur.get("curedBNum"); aCost = (int)init.getParam("costA") * cur.get("sickTrtA"); bCost = (int)init.getParam("costB") * cur.get("sickTrtB"); sickCost = cur.get("totalSymps") * 100; }
public IEnumerator buttonClicked(Initializer init, GameBuilder1 world) { int numSick = world.retDay(1).get("totalSymps"); if (total <= healthy.Count) { while (total <= numSick && total <= healthy.Count) { for (int i = 0; i < total; i++) { GameObject sickPeep = healthy [i]; sickPeep.GetComponent <SpriteRenderer> ().color = new Color(1f, 0, 0); } total += 1; } } yield return(null); }
public void onStart(Initializer init, GameBuilder1 world) { //initialize globals returnClinic = false; appearInPopulation = false; totalSick = world.retDay(1).get("totalSymps"); totalCuredA = 0; totalCuredB = 0; int totalHealthy = (int)(init.getParam("population") - totalSick); //set size of the prefab healthyPrefab.GetComponent <Transform> ().localScale = new Vector3(radius / rowCount, radius / rowCount, 1); //instantiate all the creatures in a grid for (int j = -Mathf.FloorToInt(rowCount / 2f); j < Mathf.CeilToInt(rowCount / 2f); j++) { for (int i = -Mathf.CeilToInt(colCount / 2f); i < Mathf.FloorToInt(colCount / 2f); i++) { float rand = Random.Range(0, 2); if (rand < 0.3) { GameObject newPeep = Instantiate(jigglyHealthy, new Vector3(i * 15f / colCount + .1f, -j * 3f / rowCount + 3.2f, 0), Quaternion.identity); healthyPop.Add(newPeep); newPeep.GetComponent <Rigidbody2D> ().velocity = new Vector3(Random.Range(-velocity, velocity), Random.Range(-velocity, velocity), 0); } else { GameObject newPeep = Instantiate(healthyPrefab, new Vector3(i * 15f / colCount + .1f, -j * 3f / rowCount + 3.2f, 0), Quaternion.identity); healthyPop.Add(newPeep); newPeep.GetComponent <Rigidbody2D> ().velocity = new Vector3(Random.Range(-velocity, velocity), Random.Range(-velocity, velocity), 0); } } } //remove the creatures who are sick initially for (int i = 0; i < totalSick; i++) { GameObject sick = healthyPop [i]; healthyPop.Remove(sick); Destroy(sick); } }
//creates and adds the first day and init. params to the .csv; public void firstDayAdder(GameBuilder1 world, Initializer init) { string[] labels = new string[] { "Day", "# Healthy", "# Symptoms", "Diseased", "Tot Symp", "Strategy A", "Strategy B", "# TRT A", "# TRT B", "Available to TRT", "Disease TRT A #", "Disease TRT B #", "Rand A", "Rand B", "TRT A Cures", "TRT B Cures", "Recover", "total cured for day", "Sum Disease Cured", "Check", "Catch Disease", "Trt Cost", "Sick Cost" }; double[] pars = paramGen(world.retDay(1), init); String[] tempInput = new String[23]; for (int i = 0; i < 23; i++) { tempInput [i] = labels [i]; } rowInputs.Add(tempInput); tempInput = new String[23]; for (int i = 0; i < 23; i++) { tempInput [i] = "" + pars [i]; } rowInputs.Add(tempInput); fileCA(); }
//checks if the player has reached a lose/win state; public static string check(GameBuilder1 world, Initializer init) { Day today = world.retDay(1); Day prev; if (world.totalDays() > 1) { prev = world.retDay(2); if (world.totalDays() >= init.getParam("dayLimit") || (today.get("totalSymps") / init.getParam("population")) >= .3 || prev.get("totalCost") >= (int)init.getParam("fund")) { Debug.Log("You Lost. Day: " + world.totalDays() + ", Percent Diseased: " + (today.get("sickNum") / init.getParam("population")) + ", Total Cost: " + today.get("totalCost") + "."); return("lost"); } else if (today.get("totalSymps") <= init.getParam("goalPeople")) { Debug.Log("You won! Day: " + world.totalDays() + ", Percent Diseased: " + (today.get("sickNum") / init.getParam("population")) + ", Total Cost: " + today.get("totalcost") + "."); return("won"); } else { return("none"); } } else { return("none"); } }
public IEnumerator cure(Initializer init, GameBuilder1 world) { //int sick = world.retDay (1).get ("totalSymps"); int cured = world.retDay(1).get("totalCuredDay"); int target = total - cured; if (total <= healthy.Count) { while (total > target) { for (int i = 0; i < total; i++) { GameObject sickPeep = healthy [i]; sickPeep.GetComponent <SpriteRenderer> ().color = new Color(1f, 0, 0); } total -= 1; yield return(new WaitForSecondsRealtime(.01f)); //Debug.Log ("currently sick pop: " + total + ", and my target is: " + n + ". Still going? " + (total>=n)); } } yield return(null); }
public IEnumerator buttonClicked(Initializer init, GameBuilder1 world) { int numSick = world.retDay(1).get("totalSymps"); //int totalPop = (int)(init.getParam ("population") * 0.3); //total = Mathf.RoundToInt(numSick * 100f / totalPop); //total = numSick; if (total <= healthy.Count) { //int catchD = numSick - total; while (total <= numSick && total <= healthy.Count) { for (int i = 0; i < total; i++) { GameObject sickPeep = healthy [i]; sickPeep.GetComponent <SpriteRenderer> ().color = new Color(1f, 0, 0); } total += 1; //yield return new WaitForSecondsRealtime (.01f); //Debug.Log ("currently sick pop: " + total + ", and my target is: " + n + ". Still going? " + (total>=n)); } } yield return(null); }
public void AddData(GameBuilder1 world, Initializer init) { Day cur = world.retDay(1); Debug.Log("AddData called: Day " + cur.get("day")); this.dateTime.Add(DateTime.Now); this.playerID.Add(PlayerData.playerdata.playerID); this.groupID.Add(PlayerData.playerdata.groupID); this.day.Add(cur.get("day")); this.population.Add((int)init.getParam("population")); this.budget.Add((int)init.getParam("fund") - cur.get("totalCost")); this.availToTreat.Add(cur.get("totalSymps")); this.aTreat.Add(cur.get("sickTrtA")); this.aCure.Add(cur.get("curedANum")); this.bTreat.Add(cur.get("sickTrtB")); this.bCure.Add(cur.get("curedBNum")); this.aCost.Add((int)init.getParam("costA") * cur.get("sickTrtA")); this.bCost.Add((int)init.getParam("costB") * cur.get("sickTrtB")); this.sickCost.Add(cur.get("totalSymps") * (int)init.getParam("sickCost")); this.pVal.Add(GetPValue(cur.get("curedANum"), cur.get("curedBNum"), cur.get("sickTrtA"), cur.get("sickTrtB"))); //scoreList.UpdateTable(); }
//updates the news panel with number of patients at the beginning of the next day public void sickUpdate(GameBuilder1 world) { ai.text = "Number of Patients: " + world.retDay(1).get("totalSymps") + "."; }
//updates news panel and day number after some more people catch the disease, called in WorldModel public void updateDay(GameBuilder1 world, int i) { dayNum.text = "Day: " + world.retDay(i).get("day") + "/" + init.getParam("dayLimit"); ai.text = Math.Abs(world.retDay(1).get("totalSymps") - (world.retDay(2).get("totalSymps") - world.retDay(2).get("totalCuredDay"))) + " more people caught the disease today"; }