Exemple #1
0
        public IActionResult Index()
        {
            Dachi dachi = HttpContext.Session.GetObjectFromJson <Dachi>("dachi");

            if (dachi == null)
            {
                dachi = new Dachi();
            }
            ViewBag.happiness = dachi.happiness;
            ViewBag.fullness  = dachi.fullness;
            ViewBag.energy    = dachi.energy;
            ViewBag.meals     = dachi.meals;
            if (TempData["done"] != null)
            {
                ViewBag.done = TempData["done"];
            }
            else
            {
                ViewBag.done = "false";
            }
            if (TempData["message"] != null)
            {
                ViewBag.message = TempData["message"];
            }
            else
            {
                ViewBag.message = "Choose an action";
            }
            HttpContext.Session.SetObjectAsJson("dachi", dachi);
            return(View("Game"));
        }
Exemple #2
0
        public IActionResult Index()
        {
            Dachi dachi;

            // If the session does not exist
            if (HttpContext.Session.GetObjectFromJson <Dachi>("dachi") == null)
            {
                dachi = new Dachi();
                HttpContext.Session.SetObjectAsJson("dachi", dachi);
            }
            else
            {
                dachi = HttpContext.Session.GetObjectFromJson <Dachi>("dachi");
                //When refresh the page after loss or win
                //Reset the game
                if (dachi.energy >= 100 && dachi.fullness >= 100 && dachi.happiness >= 100)
                {
                    dachi = new Dachi();
                    HttpContext.Session.SetObjectAsJson("dachi", dachi);
                }
                else if (dachi.fullness <= 0 || dachi.happiness <= 0)
                {
                    dachi = new Dachi();
                    HttpContext.Session.SetObjectAsJson("dachi", dachi);
                }
            }

            ViewBag.dachi = dachi;
            // System.Console.WriteLine(dachi.happiness);
            return(View());
        }
Exemple #3
0
        public IActionResult Restart()
        {
            Dachi dachi = HttpContext.Session.GetObjectFromJson <Dachi>("Dachi");

            HttpContext.Session.SetObjectAsJson("Dachi", dachi);
            return(View());
        }
        public IActionResult Home()
        {
            Dachi myPet = new Dachi();

            HttpContext.Session.SetObjectAsJson("myPet", myPet);
            return(View(myPet));
        }
Exemple #5
0
        public IActionResult Reset()
        {
            Dachi dachi = new Dachi();

            HttpContext.Session.Clear();
            return(RedirectToAction("Index"));
        }
        public IActionResult Lose()
        {
            Dachi myPet = HttpContext.Session.GetObjectFromJson <Dachi>("myPet");

            ViewBag.message = "Sorry, your pet died!";
            return(View("Lose", myPet));
        }
Exemple #7
0
 public Dachi sleep(Dachi dachi)
 {
     dachi.energy   += 15;
     dachi.fullness -= 5;
     dachi.happy    -= 5;
     return(dachi);
 }
        public IActionResult Create(Dachi dachi)
        {
            if (ModelState.IsValid)
            {
                HttpContext.Session.GetString("name");
                HttpContext.Session.SetString("name", dachi.Name);
                HttpContext.Session.GetInt32("fullness");
                HttpContext.Session.SetInt32("fullness", 50);
                HttpContext.Session.GetInt32("happiness");
                HttpContext.Session.SetInt32("happiness", 20);
                HttpContext.Session.GetInt32("meals");
                HttpContext.Session.SetInt32("meals", 3);
                HttpContext.Session.GetInt32("energy");
                HttpContext.Session.SetInt32("energy", 50);
                HttpContext.Session.GetString("msg");
                HttpContext.Session.SetString("msg", "Hello, Let's play.");

                dachi.Name      = HttpContext.Session.GetString("name");
                dachi.Fullness  = (int)HttpContext.Session.GetInt32("fullness");
                dachi.Happiness = (int)HttpContext.Session.GetInt32("happiness");
                dachi.Meals     = (int)HttpContext.Session.GetInt32("meals");
                dachi.Energy    = (int)HttpContext.Session.GetInt32("energy");
                dachi.Msg       = HttpContext.Session.GetString("msg");
                return(RedirectToAction("Dojodachi", dachi));
            }
            else
            {
                return(View("Index"));
            }
        }
        public IActionResult Feed(Dachi dachi)
        {
            if (HttpContext.Session.GetInt32("meals") > 0)
            {
                Random ranMeal = new Random();
                if (ranMeal.Next(1, 5) == 1)
                {
                    int?meal = HttpContext.Session.GetInt32("meals") - 1;
                    HttpContext.Session.SetInt32("meals", (int)meal);
                    HttpContext.Session.SetString("msg", $"You feed {HttpContext.Session.GetString("name")} and it did not like the food.");
                }
                else
                {
                    int?meal = HttpContext.Session.GetInt32("meals") - 1;
                    HttpContext.Session.SetInt32("meals", (int)meal);
                    Random rand    = new Random();
                    int    newMeal = rand.Next(5, 10);
                    int?   full    = HttpContext.Session.GetInt32("fullness") + newMeal;
                    HttpContext.Session.SetInt32("fullness", (int)full);

                    HttpContext.Session.SetString("msg", $"You feed {HttpContext.Session.GetString("name")} and it received fullness +{newMeal}.");
                }
            }

            dachi.Name      = HttpContext.Session.GetString("name");
            dachi.Fullness  = (int)HttpContext.Session.GetInt32("fullness");
            dachi.Happiness = (int)HttpContext.Session.GetInt32("happiness");
            dachi.Meals     = (int)HttpContext.Session.GetInt32("meals");
            dachi.Energy    = (int)HttpContext.Session.GetInt32("energy");
            dachi.Msg       = HttpContext.Session.GetString("msg");
            return(RedirectToAction("Dojodachi", dachi));
        }
Exemple #10
0
        public IActionResult Sleep()
        {
            Dachi DachiInfo = HttpContext.Session.GetObjectFromJson <Dachi>("DachiInfo");

            DachiInfo.sleep();
            HttpContext.Session.SetObjectAsJson("DachiInfo", DachiInfo);
            return(RedirectToAction("Index"));
        }
        public IActionResult Win()
        {
            Dachi myPet = HttpContext.Session.GetObjectFromJson <Dachi>("myPet");

            ViewBag.message = "Congrats! You Won!";

            return(View("Win", myPet));
        }
Exemple #12
0
        public JsonResult Sleep()
        {
            Dachi dachi = HttpContext.Session.GetObjectFromJson <Dachi>("Dachi");

            dachi.sleep();
            HttpContext.Session.SetObjectAsJson("Dachi", dachi);
            return(Json(dachi));
        }
Exemple #13
0
        public IActionResult Sleep()
        {
            Dachi CurrDachiData = HttpContext.Session.GetObjectFromJson <Dachi>("DachiData");

            CurrDachiData.sleep();
            HttpContext.Session.SetObjectAsJson("DachiData", CurrDachiData);
            return(RedirectToAction("Index"));
        }
Exemple #14
0
        public Dachi work(Dachi dachi)
        {
            dachi.energy -= 5;
            Random rando = new Random();
            int    roll  = rando.Next(1, 4);

            dachi.meals += roll;

            return(dachi);
        }
Exemple #15
0
        public IActionResult Sleep()
        {
            List <Dachi> ret   = HttpContext.Session.GetObjectFromJson <List <Dachi> >("dachi");
            Dachi        dachi = (Dachi)ret[0];

            TempData["response"] = dachi.sleep();
            List <object> dachilist = new List <object>();

            dachilist.Add(dachi);
            HttpContext.Session.SetObjectAsJson("dachi", dachilist);
            return(RedirectToAction("Index"));
        }
        public IActionResult Sleep()
        {
            Dachi myPet = HttpContext.Session.GetObjectFromJson <Dachi>("myPet");

            myPet.Energy    += 15;
            myPet.Fullness  -= 5;
            myPet.Happiness -= 5;
            HttpContext.Session.SetObjectAsJson("myPet", myPet);
            HttpContext.Session.SetString("Message", "Comfy! Gained 15 Engergy but lost both Fullness and Happiness each by 5");
            HttpContext.Session.SetString("Image", "~/images/sleep.png");
            return(RedirectToAction("AfterActivity"));
        }
Exemple #17
0
        public IActionResult WorkDachi(int energy, int fullness, int happiness, int meals, object Work)
        {
            Dachi moddachi  = HttpContext.Session.GetObjectFromJson <Dachi>("gotchi");
            int   modenergy = Convert.ToInt32(HttpContext.Session.GetInt32("energylevel"));
            int   modmeals  = Convert.ToInt32(HttpContext.Session.GetInt32("mealslevel"));

            moddachi.Work(modenergy, modmeals);
            HttpContext.Session.SetInt32("energylevel", modenergy);
            HttpContext.Session.SetInt32("mealslevel", modmeals);
            HttpContext.Session.SetObjectAsJson("gotchi", moddachi);
            // moddachi.Energy = energy;
            // moddachi.Meals = meals;
            return(Redirect("/"));
        }
Exemple #18
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("/"));
        }
Exemple #19
0
        public IActionResult PlayDachi(int energy, int fullness, int happiness, int meals, object Play)
        {
            Dachi moddachi     = HttpContext.Session.GetObjectFromJson <Dachi>("gotchi");
            int   modenergy    = Convert.ToInt32(HttpContext.Session.GetInt32("energylevel"));
            int   modhappiness = Convert.ToInt32(HttpContext.Session.GetInt32("happinesslevel"));

            moddachi.Play(modenergy, modhappiness);
            HttpContext.Session.SetInt32("energylevel", modenergy);
            HttpContext.Session.SetInt32("happinesslevel", modhappiness);
            HttpContext.Session.SetObjectAsJson("gotchi", moddachi);
            // moddachi.Happiness = happiness;
            // moddachi.Energy = energy;
            return(Redirect("/"));
        }
Exemple #20
0
        public IActionResult Work()
        {
            Dachi CurrDachiData = HttpContext.Session.GetObjectFromJson <Dachi>("DachiData");

            if (CurrDachiData.energy > 0)
            {
                CurrDachiData.work();
            }
            else
            {
                CurrDachiData.status = "No Energy... your Dachi cannot work.";
            }
            HttpContext.Session.SetObjectAsJson("DachiData", CurrDachiData);
            return(RedirectToAction("Index"));
        }
Exemple #21
0
        public IActionResult page()
        {
            Dachi meep = HttpContext.Session.GetObjectFromJson <Dachi>("dachi");
            int   en   = meep.energy;
            int   ful  = meep.fullness;
            int   me   = meep.meals;
            int   hap  = meep.happy;

            ViewBag.energy   = en;
            ViewBag.fullness = ful;
            ViewBag.meals    = me;
            ViewBag.happy    = hap;
            HttpContext.Session.SetObjectAsJson("dachi", meep);
            return(View("index"));
        }
Exemple #22
0
        public IActionResult Work()
        {
            Dachi DachiInfo = HttpContext.Session.GetObjectFromJson <Dachi>("DachiInfo");

            if (DachiInfo.energy >= 5)
            {
                DachiInfo.work();
            }
            else
            {
                DachiInfo.status = "Your dachi is too tired to work. It must sleep to gain energy.";
            }
            HttpContext.Session.SetObjectAsJson("DachiInfo", DachiInfo);
            return(RedirectToAction("Index"));
        }
Exemple #23
0
        public IActionResult Feed()
        {
            Dachi CurrDachiData = HttpContext.Session.GetObjectFromJson <Dachi>("DachiData");

            if (CurrDachiData.meals > 0)
            {
                CurrDachiData.feed();
            }
            else
            {
                CurrDachiData.status = "No Meals... your Dachi cannot eat. Work to earn meals.";
            }
            HttpContext.Session.SetObjectAsJson("DachiData", CurrDachiData);
            return(RedirectToAction("Index"));
        }
Exemple #24
0
        public Dachi play(Dachi dachi)
        {
            Random rando = new Random();
            int    roll  = rando.Next(0, 4);

            if (roll >= 1)
            {
                int happi = rando.Next(5, 11);
                dachi.happy  += happi;
                dachi.energy -= 5;
            }
            else
            {
                dachi.energy -= 5;
            }
            return(dachi);
        }
Exemple #25
0
        public IActionResult Feed()
        {
            Dachi DachiInfo = HttpContext.Session.GetObjectFromJson <Dachi>("DachiInfo");

            if (DachiInfo.meals > 0)
            {
                System.Console.WriteLine("Dachi has meals");
                DachiInfo.feed();
            }
            else
            {
                System.Console.WriteLine("Dachi has no meals");
                DachiInfo.status = "You have no food! Your Dachi must work to earn meals.";
            }
            HttpContext.Session.SetObjectAsJson("DachiInfo", DachiInfo);
            return(RedirectToAction("Index"));
        }
 public IActionResult Index()
 {
     if (HttpContext.Session.GetString("getDachi") != null)
     {
         string oldDachi = HttpContext.Session.GetString("getDachi");
         Dachi  dachi    = JsonConvert.DeserializeObject <Dachi>(oldDachi);
         ViewBag.currentDachi = dachi;
     }
     else
     {
         Dachi dachi = new Dachi();
         ViewBag.currentDachi = dachi;
         string newDachi = JsonConvert.SerializeObject(dachi);
         HttpContext.Session.SetString("getDachi", newDachi);
     }
     return(View());
 }
Exemple #27
0
        public IActionResult Act(string act)
        {
            Dachi dachi = HttpContext.Session.GetObjectFromJson <Dachi>("dachi");

            if (act == "Feed")
            {
                TempData["message"] = dachi.feeding();
            }
            if (act == "Play")
            {
                TempData["message"] = dachi.playing();
            }
            if (act == "Work")
            {
                TempData["message"] = dachi.working();
            }
            if (act == "Sleep")
            {
                TempData["message"] = dachi.sleeping();
            }
            if (act == "Restart?")
            {
                HttpContext.Session.Clear();
                dachi = new Dachi();
            }
            string done = dachi.isDone();

            if (done == "win")
            {
                TempData["done"]    = "true";
                TempData["message"] = "Congratulations! You won!";
            }
            else if (done == "dead")
            {
                TempData["done"]    = "true";
                TempData["message"] = "Your dachi ded";
            }
            else
            {
                TempData["done"] = "false";
            }
            HttpContext.Session.SetObjectAsJson("dachi", dachi);
            return(RedirectToAction("Index"));
        }
Exemple #28
0
 public Dachi feed(Dachi dachi)
 {
     if (dachi.meals > 0)
     {
         Random rando = new Random();
         int    roll  = rando.Next(0, 4);
         if (roll >= 1)
         {
             int feed = rando.Next(5, 11);
             dachi.fullness += feed;
             dachi.meals    -= 1;
         }
         else
         {
             dachi.meals -= 1;
         }
     }
     return(dachi);
 }
        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"));
        }
Exemple #30
0
        [Route("")]     //associated route string (exclude the leading /)
        public IActionResult Index()
        {
            Dachi mypet = HttpContext.Session.GetObjectFromJson <Dachi>("DachiData");

            if (mypet == null)
            {
                HttpContext.Session.SetObjectAsJson("DachiData", new Dachi());
            }
            ViewBag.DachiData = HttpContext.Session.GetObjectFromJson <Dachi>("DachiData");
            if (ViewBag.DachiData.fullness < 1 || ViewBag.DachiData.happiness < 1)
            {
                ViewBag.DachiData.status = "Your Dachi just died...";
            }
            if (ViewBag.DachiData.fullness > 100 && ViewBag.DachiData.happiness > 100 && ViewBag.DachiData.energy > 100)
            {
                ViewBag.DachiData.status = "You won!";
            }
            return(View("Index"));
        }