コード例 #1
0
        public IActionResult Sleep()
        {
            // Status logic
            DojodachiModel dojodachi   = HttpContext.Session.GetObjectFromJson <DojodachiModel>("DD");
            string         sleepResult = dojodachi.sleep();

            HttpContext.Session.SetObjectAsJson("DD", dojodachi);

            // Result
            HttpContext.Session.SetString("Result", $"Michael had a good nap! +15 Energy, -5 Fullness, -5 Happiness.");

            // win/loss condition
            if (dojodachi.dead())
            {
                HttpContext.Session.SetString("Result", "Michael has moved along...");
                HttpContext.Session.SetString("Status", "Over");
            }
            if (dojodachi.gameWon())
            {
                HttpContext.Session.SetString("Result", "Congratulations! You won and Michael is proud of you.");
                HttpContext.Session.SetString("Status", "Over");
            }

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public IActionResult Feed()
        {
            string newButton = HttpContext.Session.GetString("Feed");

            HttpContext.Session.SetString("newButton", "Feed");
            DojodachiModel dog = HttpContext.Session.GetObjectFromJson <DojodachiModel>("dachi");

            if (dog.meals > 0)
            {
                Random rand = new Random();
                dog.meals--;
                var dontlike = rand.Next(0, 4);
                if (dontlike != 0)
                {
                    dog.fullness = rand.Next(5, 11);
                }
                else
                {
                    Console.WriteLine("Dog don't want to be feeded");
                }
            }
            else
            {
                Console.WriteLine("Out of meals");
            }
            HttpContext.Session.SetObjectAsJson("dochi", dog);
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public IActionResult Work()
        {
            // Status logic
            DojodachiModel dojodachi  = HttpContext.Session.GetObjectFromJson <DojodachiModel>("DD");
            string         workResult = dojodachi.work();

            HttpContext.Session.SetObjectAsJson("DD", dojodachi);

            // Result
            if (workResult == "noEnergy")
            {
                HttpContext.Session.SetString("Result", "Michael has no Energy left to make more videos...");
            }
            else
            {
                HttpContext.Session.SetString("Result", $"Michael made another video! +{workResult} Meals, -5 Energy.");
            }

            // win/loss condition
            if (dojodachi.dead())
            {
                HttpContext.Session.SetString("Result", "Michael has moved along...");
                HttpContext.Session.SetString("Status", "Over");
            }
            if (dojodachi.gameWon())
            {
                HttpContext.Session.SetString("Result", "Congratulations! You won and Michael is proud of you.");
                HttpContext.Session.SetString("Status", "Over");
            }

            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public IActionResult Play()
        {
            DojodachiModel ourSessionPet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("OurPetString");

            if (ourSessionPet.Energy > 4)
            {
                ourSessionPet.Energy -= 5;
                Random random   = new Random();
                int    HowHappy = random.Next(5, 11);
                int    Like     = random.Next(4);
                if (Like == 1)
                {
                    HttpContext.Session.SetString("Message", "Your Dojodachi didn't like that!");
                    HttpContext.Session.SetObjectAsJson("OurPetString", ourSessionPet);
                    return(RedirectToAction("Index"));
                }
                ourSessionPet.Happiness += HowHappy;
                HttpContext.Session.SetString("Message", $"You played with your Dojodachi! Happiness +{HowHappy}, Energy -5");
                HttpContext.Session.SetObjectAsJson("OurPetString", ourSessionPet);
                return(RedirectToAction("Index"));
            }
            HttpContext.Session.SetString("Message", "You need 5 energy to play with your Dojodachi");
            HttpContext.Session.SetObjectAsJson("OurPetString", ourSessionPet);
            return(RedirectToAction("Index"));
        }
コード例 #5
0
        public IActionResult Play()
        {
            string newButton = HttpContext.Session.GetString("Play");

            HttpContext.Session.SetString("newButton", "Play");
            DojodachiModel dog = HttpContext.Session.GetObjectFromJson <DojodachiModel>("dachi");

            if (dog.energy > 5)
            {
                dog.energy -= 5;
                Random rand     = new Random();
                var    dontlike = rand.Next(0, 4);
                if (dontlike == 0)
                {
                    Console.WriteLine("Did not enough playing now");
                }
                else if (dog.energy < 5)
                {
                    dog.happiness = rand.Next(5, 11);
                }
                HttpContext.Session.SetObjectAsJson("dochi", dog);
                Console.WriteLine("Out of meals");
            }
            // Random rand =new Random();
            // //////////////////////////////////Comenting out to check other version\\\\\\\\\\\\\\
            // Dog.happiness+=rand.Next(5,10);
            // int? Playenergy = HttpContext.Session.GetInt32("newButton");
            // HttpContext.Session.SetInt32("newButton", Dog.happiness);
            // Console.WriteLine("Time To Play");
            // Console.WriteLine(Dog.happiness);
            return(RedirectToAction("Index"));
        }
コード例 #6
0
        public IActionResult Play()
        {
            // Status logic
            DojodachiModel dojodachi  = HttpContext.Session.GetObjectFromJson <DojodachiModel>("DD");
            string         playResult = dojodachi.play();

            HttpContext.Session.SetObjectAsJson("DD", dojodachi);

            // Result
            if (playResult == "noEnergy")
            {
                HttpContext.Session.SetString("Result", "Michael has no Energy left to play or code...");
            }
            else if (playResult == "fail")
            {
                HttpContext.Session.SetString("Result", "Michael didn't like your code...");
            }
            else
            {
                HttpContext.Session.SetString("Result", $"You coded with Michael! +{playResult} Happiness, -5 Energy.");
            }

            // win/loss condition
            if (dojodachi.dead())
            {
                HttpContext.Session.SetString("Result", "Michael has moved along...");
                HttpContext.Session.SetString("Status", "Over");
            }
            if (dojodachi.gameWon())
            {
                HttpContext.Session.SetString("Result", "Congratulations! You won and Michael is proud of you.");
                HttpContext.Session.SetString("Status", "Over");
            }
            return(RedirectToAction("Index"));
        }
コード例 #7
0
        public IActionResult Index()
        {
            // Very first render: make Dojodachi obj
            if (HttpContext.Session.GetObjectFromJson <DojodachiModel>("DD") == null)
            {
                DojodachiModel dojodachi = new DojodachiModel();
                HttpContext.Session.SetObjectAsJson("DD", dojodachi);
            }
            ViewBag.DD = HttpContext.Session.GetObjectFromJson <DojodachiModel>("DD");

            // Very first render: start with a different line
            if (HttpContext.Session.GetString("Result") == null)
            {
                HttpContext.Session.SetString("Result", "Welcome! Let's get started.");
            }
            ViewBag.Result = HttpContext.Session.GetString("Result");

            // "Mode" for the bottom status bit
            if (HttpContext.Session.GetString("Status") == null)
            {
                HttpContext.Session.SetString("Status", "Regular");
            }
            ViewBag.Status = HttpContext.Session.GetString("Status");

            return(View());
        }
コード例 #8
0
        public IActionResult Reset()
        {
            DojodachiModel dojodachi = new DojodachiModel();

            HttpContext.Session.SetObjectAsJson("DD", dojodachi);
            HttpContext.Session.SetString("Result", "Welcome! Let's get started.");
            HttpContext.Session.SetString("Status", "Regular");
            return(RedirectToAction("Index"));
        }
コード例 #9
0
        public IActionResult Index()
        {
            DojodachiModel dog = HttpContext.Session.GetObjectFromJson <DojodachiModel>("dachi");

            if (dog == null)
            {
                dog = new DojodachiModel();
                HttpContext.Session.SetObjectAsJson("dachi", dog);
                return(View("Index", dog));
            }
            else
            {
                return(View("Index", dog));
            }
        }
コード例 #10
0
        public IActionResult Sleep()
        {
            DojodachiModel dog       = HttpContext.Session.GetObjectFromJson <DojodachiModel>("dachi");
            string         newButton = HttpContext.Session.GetString("Sleep");
            Random         rand      = new Random();

            dog.meals -= rand.Next(0, 5);
            int?PlayEnergy = HttpContext.Session.GetInt32("newButton");

            HttpContext.Session.SetInt32("newButton", dog.meals);
            Console.WriteLine("Time To Sleep");
            dog.meals     -= 5;
            dog.happiness -= 5;
            return(RedirectToAction("Index"));
        }
コード例 #11
0
        public IActionResult Work()
        {
            DojodachiModel dog       = HttpContext.Session.GetObjectFromJson <DojodachiModel>("dachi");
            string         newButton = HttpContext.Session.GetString("Work");
            Random         rand      = new Random();

            dog.energy -= rand.Next(1, 10);
            int?PlayEnergy = HttpContext.Session.GetInt32("newButton");

            HttpContext.Session.SetInt32("newButton", dog.energy);
            Console.WriteLine("Time To Work");
            Console.WriteLine(dog.energy);
            dog.energy -= 5;
            return(RedirectToAction("Index"));
        }
コード例 #12
0
        public IActionResult Sleep()
        {
            DojodachiModel ourSessionPet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("OurPetString");

            ourSessionPet.Energy    += 15;
            ourSessionPet.Fullness  -= 5;
            ourSessionPet.Happiness -= 5;
            if (ourSessionPet.Happiness < 1 || ourSessionPet.Fullness < 1)
            {
                HttpContext.Session.SetString("Message", "You Dojodachi died in it's sleep!");
                HttpContext.Session.SetObjectAsJson("OurPetString", ourSessionPet);
                return(RedirectToAction("Index"));
            }
            HttpContext.Session.SetString("Message", "Your Dojodachi went to sleep");
            HttpContext.Session.SetObjectAsJson("OurPetString", ourSessionPet);
            return(RedirectToAction("Index"));
        }
コード例 #13
0
        public IActionResult Work()
        {
            DojodachiModel ourSessionPet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("OurPetString");

            if (ourSessionPet.Energy > 4)
            {
                ourSessionPet.Energy -= 5;
                Random random  = new Random();
                int    HowMany = random.Next(4);
                ourSessionPet.Meals += HowMany;
                HttpContext.Session.SetString("Message", $"You put your Dojodachi to work! Meals {ourSessionPet.Meals}, Energy -5");
                HttpContext.Session.SetObjectAsJson("OurPetString", ourSessionPet);
                return(RedirectToAction("Index"));
            }
            HttpContext.Session.SetString("Message", "You need 5 energy to put your Dojodachi to work");
            HttpContext.Session.SetObjectAsJson("OurPetString", ourSessionPet);
            return(RedirectToAction("Index"));
        }
コード例 #14
0
        public IActionResult Index()
        {
            if (HttpContext.Session.GetString("Message") == null)
            {
                HttpContext.Session.SetString("Message", "Welcome to Dojodachi");
                DojodachiModel ourPet = new DojodachiModel()
                {
                    Fullness  = 20,
                    Happiness = 20,
                    Meals     = 3,
                    Energy    = 50
                };
                HttpContext.Session.SetObjectAsJson("OurPetString", ourPet);
                return(View(ourPet));
            }
            DojodachiModel ourSessionPet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("OurPetString");

            return(View(ourSessionPet));
        }
コード例 #15
0
 public IActionResult Sleep()
 {
     if (HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname") == null)
     {
         HttpContext.Session.SetObjectAsJson("petname", petname);
         DojodachiModel petTemp = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         if (petTemp.fullness > 0 && petTemp.happiness > 0)
         {
             petTemp.energy    += 15;
             petTemp.fullness  -= 5;
             petTemp.happiness -= 5;
             HttpContext.Session.SetObjectAsJson("petname", petTemp);
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         }
         else
         {
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
             HttpContext.Session.SetString("Message", "Dojodachi getting too much sleep. Get moving!");
             ViewBag.Message = HttpContext.Session.GetString("Message");
         }
     }
     else
     {
         DojodachiModel petTemp = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         if (petTemp.fullness > 0 && petTemp.happiness > 0)
         {
             petTemp.energy    += 15;
             petTemp.fullness  -= 5;
             petTemp.happiness -= 5;
             HttpContext.Session.SetObjectAsJson("petname", petTemp);
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         }
         else
         {
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
             HttpContext.Session.SetString("Message", "Dojodachi getting too much sleep. Get moving!");
             ViewBag.Message = HttpContext.Session.GetString("Message");
         }
     }
     return(View("Index"));
 }
コード例 #16
0
 public IActionResult Play()
 {
     if (HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname") == null)
     {
         HttpContext.Session.SetObjectAsJson("petname", petname);
         DojodachiModel petTemp = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         if (petTemp.energy > 0)
         {
             petTemp.energy    -= 5;
             petTemp.happiness += rand.Next(5, 11);
             HttpContext.Session.SetObjectAsJson("petname", petTemp);
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         }
         else
         {
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
             HttpContext.Session.SetString("Message", "No more energy to play. Get some rest!");
             ViewBag.Message = HttpContext.Session.GetString("Message");
         }
     }
     else
     {
         DojodachiModel petTemp = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         if (petTemp.energy > 0)
         {
             petTemp.energy    -= 5;
             petTemp.happiness += rand.Next(5, 11);
             HttpContext.Session.SetObjectAsJson("petname", petTemp);
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         }
         else
         {
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
             HttpContext.Session.SetString("Message", "No more energy to play. Get some rest!");
             ViewBag.Message = HttpContext.Session.GetString("Message");
         }
     }
     return(View("Index"));
 }
コード例 #17
0
 public IActionResult Feed()
 {
     if (HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname") == null)
     {
         HttpContext.Session.SetObjectAsJson("petname", petname);
         DojodachiModel petTemp = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         if (petTemp.meals > 0)
         {
             petTemp.meals    -= 1;
             petTemp.fullness += rand.Next(5, 11);
             HttpContext.Session.SetObjectAsJson("petname", petTemp);
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         }
         else
         {
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
             HttpContext.Session.SetString("Message", "Not enough meals to feed the dojodachi, go earn more!");
             ViewBag.Message = HttpContext.Session.GetString("Message");
         }
     }
     else
     {
         DojodachiModel petTemp = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         if (petTemp.meals > 0)
         {
             petTemp.meals    -= 1;
             petTemp.fullness += rand.Next(5, 11);
             HttpContext.Session.SetObjectAsJson("petname", petTemp);
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
         }
         else
         {
             ViewBag.pet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("petname");
             HttpContext.Session.SetString("Message", "Not enough meals to feed the dojodachi, go earn more!");
             ViewBag.Message = HttpContext.Session.GetString("Message");
         }
     }
     return(View("Index"));
 }
コード例 #18
0
        public IActionResult Feed()
        {
            DojodachiModel ourSessionPet = HttpContext.Session.GetObjectFromJson <DojodachiModel>("OurPetString");

            if (ourSessionPet.Meals > 0)
            {
                Random random = new Random();
                ourSessionPet.Meals -= 1;
                int howMuchFood = random.Next(5, 11);
                int Like        = random.Next(4);
                if (Like == 1)
                {
                    HttpContext.Session.SetString("Message", "Your Dojodachi didn't like that!");
                    HttpContext.Session.SetObjectAsJson("OurPetString", ourSessionPet);
                    return(RedirectToAction("Index"));
                }
                ourSessionPet.Fullness += howMuchFood;
                HttpContext.Session.SetString("Message", $"You fed your Dojodachi! Fullness +{howMuchFood}, Meals -1");
                HttpContext.Session.SetObjectAsJson("OurPetString", ourSessionPet);
                return(RedirectToAction("Index"));
            }
            HttpContext.Session.SetString("Message", "You need at least 1 meal to feed your Dojodochi");
            return(RedirectToAction("Index"));
        }
コード例 #19
0
        public IActionResult Feed()
        {
            // Status logic
            DojodachiModel dojodachi  = HttpContext.Session.GetObjectFromJson <DojodachiModel>("DD");
            string         feedResult = dojodachi.feed();

            HttpContext.Session.SetObjectAsJson("DD", dojodachi);

            // Result
            if (feedResult == "noMeals")
            {
                HttpContext.Session.SetString("Result", "Michael has no Meals left to be fed...");
            }
            else if (feedResult == "fail")
            {
                HttpContext.Session.SetString("Result", "Michael didn't like the meal...");
            }
            else
            {
                HttpContext.Session.SetString("Result", $"Michael had a good meal! +{feedResult} Fullness, -1 Meal.");
            }

            // win/loss condition
            if (dojodachi.dead())
            {
                HttpContext.Session.SetString("Result", "Michael has moved along...");
                HttpContext.Session.SetString("Status", "Over");
            }
            if (dojodachi.gameWon())
            {
                HttpContext.Session.SetString("Result", "Congratulations! You won and Michael is proud of you.");
                HttpContext.Session.SetString("Status", "Over");
            }

            return(RedirectToAction("Index"));
        }