예제 #1
0
        public IActionResult Index()
        {
            if (HttpContext.Session.GetInt32("dachimade") == null)
            {
                Dojodachi dachi = new Dojodachi();
                HttpContext.Session.SetObjectAsJson("dachi", dachi);
                HttpContext.Session.SetInt32("dachimade", 1);
            }

            Dojodachi Dachi = HttpContext.Session.GetObjectFromJson <Dojodachi>("dachi");

            ViewBag.energy    = Dachi.energy;
            ViewBag.happiness = Dachi.happiness;
            ViewBag.fullness  = Dachi.fullness;
            ViewBag.meals     = Dachi.meals;

            if (Dachi.fullness <= 0 || Dachi.happiness <= 0)
            {
                return(RedirectToAction("Loss"));
            }

            if (Dachi.happiness > 100 && Dachi.fullness > 100 && Dachi.energy > 100)
            {
                return(RedirectToAction("Win"));
            }

            ViewBag.message = HttpContext.Session.GetString("message");

            return(View());
        }
예제 #2
0
        public IActionResult Reset()
        {
            Dojodachi hector = new Dojodachi();

            HttpContext.Session.SetObjectAsJson("pet", hector);
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public IActionResult Sleep()
        {
            Dojodachi hector = HttpContext.Session.GetObjectFromJson <Dojodachi>("pet");

            hector.Sleep();
            HttpContext.Session.SetObjectAsJson("pet", hector);
            return(RedirectToAction("Index"));
        }
예제 #4
0
 public IActionResult Index()
 {
     Dojodachi newDojoDachi = new Dojodachi();
     HttpContext.Session.SetInt32("Fullness", newDojoDachi.Fullness);
     HttpContext.Session.SetInt32("Happiness", newDojoDachi.Happiness);
     HttpContext.Session.SetInt32("Meals", newDojoDachi.Meals);
     HttpContext.Session.SetInt32("Energy", newDojoDachi.Energy);
     return View("Index", newDojoDachi);
 }
예제 #5
0
        public IActionResult Work()
        {
            Dojodachi Dachi = HttpContext.Session.GetObjectFromJson <Dojodachi>("dachi");

            Dachi.Work();

            HttpContext.Session.SetObjectAsJson("dachi", Dachi);
            HttpContext.Session.SetString("message", "You made Dachi work for food");

            return(RedirectToAction("Index"));
        }
예제 #6
0
        public IActionResult Feed()
        {
            Dojodachi Dachi = HttpContext.Session.GetObjectFromJson <Dojodachi>("dachi");

            Dachi.Feed();

            HttpContext.Session.SetObjectAsJson("dachi", Dachi);
            HttpContext.Session.SetString("message", "You fed Dachi");

            return(RedirectToAction("Index"));
        }
        public JsonResult Sleep([FromBody] Dojodachi tempDojodachi)
        {
            tempDojodachi.sleep();
            string msg = $"Your Lil' Devil slept all night (Energy: +15, Fullness: -5, Happiness: -5)";

            var data = new {
                dojodachi = tempDojodachi,
                message   = msg
            };

            return(Json(data));
        }
        public JsonResult Work([FromBody] Dojodachi tempDojodachi)
        {
            int    meals = tempDojodachi.work();
            string msg   = $"Your Lil' Devil worked all day (Meals: +{meals}, Energy: -5)";

            var data = new {
                dojodachi = tempDojodachi,
                message   = msg
            };

            return(Json(data));
        }
        public JsonResult Play([FromBody] Dojodachi tempDojodachi)
        {
            int    happiness = tempDojodachi.play();
            string msg       = $"Your Lil' Devil enjoyed play time (Happiness: +{happiness}, Energy: -5)";

            if (happiness <= 0)
            {
                msg = "Your Lil' Devil didn't enjoy play time (Energy: -5)";
            }

            var data = new {
                dojodachi = tempDojodachi,
                message   = msg
            };

            return(Json(data));
        }
        public JsonResult Feed([FromBody] Dojodachi tempDojodachi)
        {
            int    fullness = tempDojodachi.feed();
            string msg      = $"You fed your Lil' Devil (Fullness: +{fullness}, Meals: -1)";

            if (fullness <= 0)
            {
                msg = "Your Lil' Devil didn't like the meal that you provided (Meals: -1)";
            }

            var data = new {
                dojodachi = tempDojodachi,
                message   = msg
            };

            return(Json(data));
        }
예제 #11
0
 public IActionResult Index()
 {
     if (HttpContext.Session.GetObjectFromJson <Dojodachi>("pet") == null)
     {
         Dojodachi hector = new Dojodachi();
         HttpContext.Session.SetObjectAsJson("pet", hector);
     }
     ViewBag.hector = HttpContext.Session.GetObjectFromJson <Dojodachi>("pet");
     if (ViewBag.hector.fullness < 1 || ViewBag.hector.happiness < 1)
     {
         ViewBag.hector.message = "I died.";
     }
     if (ViewBag.hector.fullness == 100 && ViewBag.hector.happiness >= 100 && ViewBag.hector.energy == 100)
     {
         ViewBag.hector.message = "You took good care of me, I am eternally grateful.";
     }
     return(View("Index"));
 }
예제 #12
0
        public IActionResult Process(string action)
        {
            // Random rand = new Random();
            // string action = "earn";
            // int goldThisTime = 0;
            Dojodachi game = HttpContext.Session.GetObjectAsJson <Dojodachi>("game");

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

            case "Playing":
                game.Play();

                break;

            case "Working":
                game.Work();

                break;

            default:
                game.Sleep();

                break;
            }

            // Golding game = HttpContext.Session.GetObjectAsJson<Golding>("game");

            // action = goldThisTime < 0 ? "lose" : action;
            // game.Gold += goldThisTime;
            // game.Activities.Add(
            //     $"You {action} {goldThisTime} from the {building} ({DateTime.Now.ToString("g")})"
            // );
            game.CheckDojodachi();
            HttpContext.Session.SetObjectAsJson("game", game);
            return(RedirectToAction("Index"));
        }
        public IActionResult Action(string action) // 'action' is the form input 'name'
        {
            Dojodachi myDD = HttpContext.Session.GetObjectFromJson <Dojodachi>("Dojodachi");

            ViewBag.GameStatus = "playing";
            Random rand = new Random();

            switch (action)
            {
            case "feed":
                if (myDD.Meals < 1)
                {
                    TempData["Reaction"] = "No meals to feed!";
                }
                else     // -1 Meal >> 75% chance of +5-10 Fullness
                {
                    myDD.Meals -= 1;
                    if (rand.Next(4) > 0)    // > 25%
                    {
                        int temp = rand.Next(5, 11);
                        myDD.Fullness += temp;

                        TempData["Reaction"] = $"Yum! Fullness + {temp}";
                    }
                    else
                    {
                        TempData["Reaction"] = "Yuck!";
                    }
                }
                break;

            case "play":
                if (myDD.Energy < 5)
                {
                    TempData["Reaction"] = "Need 5 energy!";
                }
                else     // -5 Energy >> 75% chance of +5-10 Happiness
                {
                    myDD.Energy -= 5;
                    if (rand.Next(4) > 0)    // > 25%
                    {
                        int temp = rand.Next(5, 11);
                        myDD.Happiness += temp;

                        TempData["Reaction"] = $"That was fun! Happiness increased by {temp}!";
                    }
                    else
                    {
                        TempData["Reaction"] = $"That wasn't so fun..";
                    }
                }
                break;

            case "work":
                if (myDD.Energy < 5)
                {
                    TempData["Reaction"] = "Need 5 energy!";
                }
                else     // -5 Energy >> +1-3 Meals
                {
                    myDD.Energy -= 5;
                    int temp = rand.Next(1, 4);
                    myDD.Meals += temp;

                    TempData["Reaction"] = $"Meals increased by {temp}!";
                }
                break;

            case "sleep":     // -5 Fullness & Happiness >> +15 Energy
                myDD.Energy    += 15;
                myDD.Fullness  -= 5;
                myDD.Happiness -= 5;

                TempData["Reaction"] = $"Energy increased by 15!";
                break;

            default:
                // default is used if there isn't a matching case
                TempData["Reaction"] = "Action input error found!";
                break;
            }

            if (myDD.Energy >= 100 && myDD.Fullness >= 100 && myDD.Happiness >= 100)
            {
                TempData["Reaction"] = "Congratulations! You won!";
                ViewBag.GameStatus   = "gameover";
            }
            else if (myDD.Fullness <= 0 || myDD.Happiness <= 0)
            {
                TempData["Reaction"] = "Your Dojodachi has passed away...";
                ViewBag.GameStatus   = "gameover";
            }

            HttpContext.Session.SetObjectAsJson("Dojodachi", myDD);
            ViewBag.Dojodachi = myDD; // This way we don't have to redirect to Index() to set it.

            return(View("Index"));
        }