示例#1
0
        public IActionResult Index()
        {
            // created an instance of a pet named Louie
            Dachi Louie = new Dachi()
            {
                Happiness = 20,
                Fullness  = 20,
                Energy    = 100,
                Meals     = 3
            };

            if (HttpContext.Session.GetInt32("Happiness") == null)
            {
                HttpContext.Session.SetInt32("Happiness", 20);
                HttpContext.Session.SetInt32("Fullness", 20);
                HttpContext.Session.SetInt32("Energy", 50);
                HttpContext.Session.SetInt32("Meals", 3);
                HttpContext.Session.SetString("Message", "I am only an eel");
            }
            // don't put ViewBag in if statement ya div
            ViewBag.Happiness = HttpContext.Session.GetInt32("Happiness");
            ViewBag.Fullness  = HttpContext.Session.GetInt32("Fullness");
            ViewBag.Energy    = HttpContext.Session.GetInt32("Energy");
            ViewBag.Meals     = HttpContext.Session.GetInt32("Meals");
            ViewBag.Message   = HttpContext.Session.GetString("Message");



            return(View());
        }
示例#2
0
        public IActionResult Interaction(string id)
        {
            string interaction       = id;
            string interactionResult = null;
            Dachi  Billy             = HttpContext.Session.GetObjectFromJson <Dachi>("Billy");

            if (interaction == "Feed")
            {
                interactionResult = Billy.Feed();
            }
            if (interaction == "Play")
            {
                interactionResult = Billy.Play();
            }
            if (interaction == "Sleep")
            {
                interactionResult = Billy.Sleep();
            }
            if (interaction == "Work")
            {
                interactionResult = Billy.Work();
            }
            if (interaction == "Restart")
            {
                HttpContext.Session.Clear(); return(RedirectToAction("Index"));
            }
            HttpContext.Session.SetString("interactionResult", interactionResult);
            HttpContext.Session.SetObjectAsJson("Billy", Billy);
            ViewBag.interactionResult = interactionResult;
            ViewBag.Billy             = Billy;
            return(View("Index"));
        }
示例#3
0
        public IActionResult Index()
        {
            if (HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi") == null)
            {
                Dachi dojo = new Dachi();
                HttpContext.Session.SetObjectAsJson("CurrDachi", dojo);
                ViewBag.fullness  = dojo.fullness;
                ViewBag.happiness = dojo.happiness;
                ViewBag.meals     = dojo.meals;
                ViewBag.energy    = dojo.energy;
            }

            // If energy, fullness, and happiness are all raised to over 100, you win! a restart button should be displayed.
            else if (HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi").fullness >= 100 && HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi").happiness >= 100 && HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi").energy >= 100)
            {
                return(RedirectToAction("Win"));
            }

            // If fullness or happiness ever drop to 0, you lose, and a restart button should be displayed.
            else if (HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi").fullness == 0 || HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi").happiness == 0)
            {
                return(RedirectToAction("Lose"));
            }

            else
            {
                ViewBag.fullness  = HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi").fullness;
                ViewBag.happiness = HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi").happiness;
                ViewBag.meals     = HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi").meals;
                ViewBag.energy    = HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi").energy;
            }
            return(View());
        }
示例#4
0
        public IActionResult Index()
        {
			if(HttpContext.Session.GetString("startsession") == null)
			{
				Dachi this_dachi = new Dachi(20,20,3,50);
				HttpContext.Session.SetObjectAsJson("myDachi", this_dachi);
				HttpContext.Session.SetString("startsession", "true");
				TempData["Pic"] = "Start.gif";
				ViewBag.Response = "Look at your cute new Dojodachi!";
			}
			Dachi myDachi = HttpContext.Session.GetObjectFromJson<Dachi>("myDachi");
			if(myDachi.Fullness <= 0 || myDachi.Happiness <= 0)
			{
				ViewBag.Pic = "Died.gif";
				ViewBag.Response = "Your Dojodachi has passed away...";
			}
			else if(myDachi.Energy>100 && myDachi.Fullness>100 && myDachi.Happiness>100)
			{
				ViewBag.Pic = "Won.gif";
				ViewBag.Response = "Congratulations! You Won!";
			}
			else{
				ViewBag.Response = TempData["Response"];
				ViewBag.Pic = TempData["Pic"];
			}
            return View(myDachi);
        }
示例#5
0
        public IActionResult Action(string activity)
        {
            switch (activity)
            {
            case "feed":
            {
                Dachi.Feed();
                break;
            }

            case "play":
            {
                Dachi.Play();
                break;
            }

            case "work":
            {
                Dachi.Work();
                break;
            }

            case "sleep":
            {
                Dachi.Sleep();
                break;
            }
            }
            return(RedirectToAction("Index"));
        }
示例#6
0
        public IActionResult Index()
        {
            // int? count = HttpContext.Session.GetInt32("count");
            if (dojodachi == null)     //checking to see if session exists
            {
                dojodachi = new Dachi; //if session doesn't exist, set it to 1
            }
            else
            {
                HttpContext.Session.SetInt32("count", ((int)HttpContext.Session.GetInt32("count") + 1)); //if the session exists, increment by 1
            }

            string chars   = "abcdefghijklmnopqrstuvwxyz0123456789";
            string builder = "";
            Random random  = new Random();

            for (int i = 0; i < 15; i++)
            {
                builder += chars[random.Next(0, chars.Length)];
            }

            // var count = HttpContext.Session.GetInt32("Count");
            // if(count == null)
            // {
            //     count = 0;
            // }

            ViewBag.count           = HttpContext.Session.GetInt32("count");
            ViewBag.random_passcode = builder;
            return(View("index"));
        }
示例#7
0
 public IActionResult Index()
 {
     if (HttpContext.Session.GetObjectFromJson <Dachi>("dachi") == null)
     {
         Dachi dachi = new Dachi();
         HttpContext.Session.SetObjectAsJson("dachi", dachi);
         ViewBag.Fullness  = HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Fullness;
         ViewBag.Happiness = HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Happiness;
         ViewBag.Meals     = HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Meals;
         ViewBag.Energy    = HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Energy;
         ViewBag.Message   = HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Message;
     }
     else if (HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Energy >= 100 && HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Fullness >= 100 && HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Happiness >= 100)
     {
         return(RedirectToAction("win"));
     }
     else if (HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Fullness <= 0 || HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Happiness <= 0)
     {
         return(RedirectToAction("lose"));
     }
     else
     {
         ViewBag.Fullness  = HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Fullness;
         ViewBag.Happiness = HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Happiness;
         ViewBag.Meals     = HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Meals;
         ViewBag.Energy    = HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Energy;
         ViewBag.Message   = HttpContext.Session.GetObjectFromJson <Dachi>("dachi").Message;
     }
     return(View("index"));
 }
示例#8
0
        public IActionResult Sleep()
        {
            Dachi sessionPet = HttpContext.Session.GetObjectFromJson <Dachi>("pet");

            sessionPet.Sleep();
            HttpContext.Session.SetObjectAsJson("pet", sessionPet);
            return(RedirectToAction("Index"));
        }
示例#9
0
        public IActionResult SleepDachi()
        {
            Dachi CurrDachiData = HttpContext.Session.GetObjectFromJson <Dachi>("DachiData");

            CurrDachiData.Sleep();
            HttpContext.Session.SetObjectAsJson("DachiData", CurrDachiData);
            return(RedirectToAction("Index"));
        }
        public IActionResult Sleep()
        {
            Dachi myDachi = HttpContext.Session.GetObjectFromJson <Dachi>("MyDojodachi");

            myDachi.Sleep();
            HttpContext.Session.SetObjectAsJson("MyDojodachi", myDachi);
            return(RedirectToAction("Dojodachi"));
        }
示例#11
0
        public IActionResult Nap()
        {
            Dachi DachiInfoUp = HttpContext.Session.GetObjectFromJson <Dachi>("DachiInfo");

            DachiInfoUp.Sleep();
            HttpContext.Session.SetObjectAsJson("DachiInfo", DachiInfoUp);
            return(RedirectToAction("Index"));
        }
示例#12
0
        public IActionResult Play(string gameType)
        {
            Dachi currDachi = getDachiFromSession();        //you're getting the dachi from session into object currDachi

            TempData["message"] = currDachi.Play(gameType); //This invokes the function Play from the currDachi, the dachi model, & returns a string
            setDachiInSession(currDachi);                   //this set the new numbers into session
            return(RedirectToAction("Index"));
        }
        public IActionResult Play(string gameType)
        {
            Dachi currDachi = getDachiFromSession();

            TempData["message"] = currDachi.Play(gameType);
            setDachiSession(currDachi);
            return(RedirectToAction("Index"));
        }
示例#14
0
        public IActionResult Sleep()
        {
            Dachi dachi = HttpContext.Session.GetObjectFromJson <Dachi>("dachi");

            dachi.Sleep();
            HttpContext.Session.SetObjectAsJson("dachi", dachi);
            return(RedirectToAction("index"));
        }
示例#15
0
		public IActionResult Sleep()
		{
			Dachi myDachi = HttpContext.Session.GetObjectFromJson<Dachi>("myDachi");
			string response = myDachi.Sleep();
			HttpContext.Session.SetObjectAsJson("myDachi", myDachi);
			TempData["Response"] = response;
			TempData["Pic"] = "Sleep.gif";
			return RedirectToAction("Index");
		}
        public IActionResult Play()
        {
            Dachi dachi = GetDachi();

            TempData["original_happiness"] = dachi.Happiness;
            TempData["original_energy"]    = dachi.Energy;
            dachi.Play();
            SetDachi(dachi);
            return(RedirectToAction("Index"));
        }
        public IActionResult Feed()
        {
            Dachi dachi = GetDachi();

            TempData["original_fullness"] = dachi.Fullness;
            TempData["original_meals"]    = dachi.Meals;
            dachi.Feed();
            SetDachi(dachi);
            return(RedirectToAction("Index"));
        }
示例#18
0
		public IActionResult Feed()
		{
			Dachi myDachi = HttpContext.Session.GetObjectFromJson<Dachi>("myDachi");
			string response = myDachi.Feed();
			Console.WriteLine(myDachi.Fullness);
			HttpContext.Session.SetObjectAsJson("myDachi", myDachi);
			TempData["Response"] = response;
			TempData["Pic"] = "Eat.gif";
			return RedirectToAction("Index");
		}
示例#19
0
        public IActionResult Work()
        {
            Dachi  dojo = HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi");
            Random rand = new Random();

            dojo.energy = dojo.energy - 5;
            dojo.meals += rand.Next(1, 4);
            HttpContext.Session.SetObjectAsJson("CurrDachi", dojo);
            return(RedirectToAction("Index"));
        }
        public IActionResult Work()
        {
            Dachi dachi = GetDachi();

            TempData["original_energy"] = dachi.Energy;
            TempData["original_meals"]  = dachi.Meals;
            dachi.Work();
            SetDachi(dachi);
            return(RedirectToAction("Index"));
        }
示例#21
0
        public ViewResult Index()
        {
            Dachi newDachi = new Dachi();

            if (HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi") == null)
            {
                HttpContext.Session.SetObjectAsJson("CurrDachi", newDachi);
            }
            ViewBag.Dachi = HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi");
            return(View());
        }
示例#22
0
        public IActionResult Index()
        {
            if (HttpContext.Session.GetString("newGame") == null)
            {
                setDachiInSession();
            }

            Dachi model = getDachiFromSession();

            return(View(model)); //passing Dachi model object to view
        }
示例#23
0
        public IActionResult Sleep()
        {
            Dachi  dojo = HttpContext.Session.GetObjectFromJson <Dachi>("CurrDachi");
            Random rand = new Random();

            dojo.energy    = dojo.energy + 15;
            dojo.fullness  = dojo.fullness - 5;
            dojo.happiness = dojo.happiness - 5;
            HttpContext.Session.SetObjectAsJson("CurrDachi", dojo);
            return(RedirectToAction("Index"));
        }
 private void setDachiSession(Dachi dachi = null)
 {
     if (dachi == null)
     {
         dachi = new Dachi();
         HttpContext.Session.SetString("newGame", "true");
     }
     HttpContext.Session.SetInt32("happiness", dachi.Happiness);
     HttpContext.Session.SetInt32("fullness", dachi.Fullness);
     HttpContext.Session.SetInt32("energy", dachi.Energy);
     HttpContext.Session.SetInt32("meals", dachi.Meals);
 }
示例#25
0
        public IActionResult Index()
        {
            Dachi sessionPet = HttpContext.Session.GetObjectFromJson <Dachi>("pet");

            if (sessionPet == null)
            {
                sessionPet = new Dachi();
                HttpContext.Session.SetObjectAsJson("pet", sessionPet);
            }

            return(View("Index", sessionPet));
        }
示例#26
0
 public void setDachiInSession(Dachi dachi = null)
 //is this the default for dachi to be null
 {
     if (dachi == null)
     {
         dachi = new Dachi(); //this sets the object dachi with the default properties
         HttpContext.Session.SetString("newGame", "true");
     }
     HttpContext.Session.SetInt32("happiness", dachi.Happiness);
     HttpContext.Session.SetInt32("fullness", dachi.Fullness);
     HttpContext.Session.SetInt32("energy", dachi.Energy);
     HttpContext.Session.SetInt32("meals", dachi.Meals);
 }
示例#27
0
        public IActionResult FeedDachi()
        {
            Dachi CurrDachiData = HttpContext.Session.GetObjectFromJson <Dachi>("DachiData");

            if (CurrDachiData.Meals > 0)
            {
                CurrDachiData.Feed();
            }
            else
            {
                CurrDachiData.Status = "No more meals! Send your Dojodachi to work to earn more meals.";
            }
            HttpContext.Session.SetObjectAsJson("DachiData", CurrDachiData);
            return(RedirectToAction("Index"));
        }
示例#28
0
        public IActionResult PlayDachi()
        {
            Dachi CurrDachiData = HttpContext.Session.GetObjectFromJson <Dachi>("DachiData");

            if (CurrDachiData.Energy > 0)
            {
                CurrDachiData.Play();
            }
            else
            {
                CurrDachiData.Status = "No Energy... your Dachi cannot work or play. Dachi needs sleep.";
            }
            HttpContext.Session.SetObjectAsJson("DachiData", CurrDachiData);
            return(RedirectToAction("Index"));
        }
示例#29
0
        public IActionResult WorkDachi()
        {
            Dachi CurrDachiData = HttpContext.Session.GetObjectFromJson <Dachi>("DachiData");

            if (CurrDachiData.Energy > 0)
            {
                CurrDachiData.Work();
            }
            else
            {
                CurrDachiData.Status = "Your Dojodachi has no more energy.";
            }
            HttpContext.Session.SetObjectAsJson("DachiData", CurrDachiData);
            return(RedirectToAction("Index"));
        }
        private Dachi GetDachi()
        {
            Dachi dachi;

            if (HttpContext.Session.GetString("dachi") == null)
            {
                dachi = new Dachi();
                SetDachi(dachi);
            }
            else
            {
                dachi = JsonConvert.DeserializeObject <Dachi>(HttpContext.Session.GetString("dachi"));
            }
            return(dachi);
        }