Exemple #1
0
        public IActionResult FeedDachi(int energy, int fullness, int happiness, int meals, object Feed)
        {
            Dachi moddachi    = HttpContext.Session.GetObjectFromJson <Dachi>("gotchi");
            int   modmeals    = Convert.ToInt32(HttpContext.Session.GetInt32("mealslevel"));
            int   modfullness = Convert.ToInt32(HttpContext.Session.GetInt32("fullnesslevel"));

            moddachi.Feed(modmeals, modfullness);
            HttpContext.Session.SetInt32("mealslevel", modmeals);
            HttpContext.Session.SetInt32("fullnesslevel", modfullness);
            HttpContext.Session.SetObjectAsJson("gotchi", moddachi);
            // moddachi.Meals = meals;
            // moddachi.Fullness = fullness;
            return(Redirect("/"));
        }
        public IActionResult Update(string action)
        {
            string oldDachi = HttpContext.Session.GetString("getDachi");
            Dachi  dachi    = JsonConvert.DeserializeObject <Dachi>(oldDachi);
            Random rand     = new Random();

            switch (action)
            {
            case "Feed":
                dachi.Feed();
                break;

            case "Play":
                dachi.Play();
                break;

            case "Work":
                dachi.Work();
                break;

            case "Sleep":
                dachi.Sleep();
                break;
            }
            if (dachi.Fullness < 1 || dachi.Happiness < 1)
            {
                dachi.Messages = "Your DojoDachi has died :(";
                string newDachi = JsonConvert.SerializeObject(dachi);
                HttpContext.Session.SetString("getDachi", newDachi);
            }
            else if (dachi.Energy > 99 && dachi.Fullness > 99 && dachi.Happiness > 99)
            {
                dachi.Messages = "Congrats! You've won! You have done a good job raising your DojoDachi!";
                string newDachi = JsonConvert.SerializeObject(dachi);
                HttpContext.Session.SetString("getDachi", newDachi);
            }
            else
            {
                string newDachi = JsonConvert.SerializeObject(dachi);
                HttpContext.Session.SetString("getDachi", newDachi);
            }
            return(RedirectToAction("Index"));
        }