public IActionResult Sleep() { Tamagochi Retrievegochi = HttpContext.Session.GetObjectFromJson <Tamagochi>("tamagachi"); Retrievegochi.Fullness -= 5; Retrievegochi.Happiness -= 5; Retrievegochi.Energy += 15; HttpContext.Session.SetObjectAsJson("tamagachi", Retrievegochi); ViewBag.tamagachi = Retrievegochi; if (Retrievegochi.Fullness <= 0 || Retrievegochi.Happiness <= 0 || Retrievegochi.Energy <= 0) { game Retrievegame = HttpContext.Session.GetObjectFromJson <game>("gameover"); Retrievegame.over = true; HttpContext.Session.SetObjectAsJson("gameover", Retrievegame); ViewBag.game = Retrievegame; } if (Retrievegochi.Fullness >= 100 && Retrievegochi.Happiness >= 100 && Retrievegochi.Energy >= 100) { game Retrievegame = HttpContext.Session.GetObjectFromJson <game>("gameover"); Retrievegame.over = true; HttpContext.Session.SetObjectAsJson("gameover", Retrievegame); ViewBag.game = Retrievegame; } return(RedirectToAction("dojodachi")); }
public IActionResult Play() { Tamagochi Retrievegochi = HttpContext.Session.GetObjectFromJson <Tamagochi>("tamagachi"); Random rand = new Random(); bool Likes = true; if (rand.Next(0, 4) == 0) { Likes = false; } Retrievegochi.Energy -= 5; if (Likes == true) { Retrievegochi.Happiness += rand.Next(5, 11); } HttpContext.Session.SetObjectAsJson("tamagachi", Retrievegochi); ViewBag.tamagachi = Retrievegochi; if (Retrievegochi.Fullness <= 0 || Retrievegochi.Happiness <= 0 || Retrievegochi.Energy <= 0) { game Retrievegame = HttpContext.Session.GetObjectFromJson <game>("gameover"); Retrievegame.over = true; HttpContext.Session.SetObjectAsJson("gameover", Retrievegame); ViewBag.game = Retrievegame; } if (Retrievegochi.Fullness >= 100 && Retrievegochi.Happiness >= 100 && Retrievegochi.Energy >= 100) { game Retrievegame = HttpContext.Session.GetObjectFromJson <game>("gameover"); Retrievegame.over = true; HttpContext.Session.SetObjectAsJson("gameover", Retrievegame); ViewBag.game = Retrievegame; } return(RedirectToAction("dojodachi")); }
public ActionResult DeleteConfirmed(int id) { Tamagochi tamagotchi = _tamagotchiRepo.GetById(id); _tamagotchiRepo.Remove(tamagotchi); RepositoryLocator.Repositories.Save(); return(RedirectToAction("Index")); }
public ViewResult dojodachi() { Tamagochi Retrievegochi = HttpContext.Session.GetObjectFromJson <Tamagochi>("tamagachi"); game Retrievegame = HttpContext.Session.GetObjectFromJson <game>("gameover"); ViewBag.game = Retrievegame; ViewBag.tamagachi = Retrievegochi; return(View()); }
public IActionResult Index() { Tamagochi Guygar = new Tamagochi(20, 20, 3, 50); game game = new game(); HttpContext.Session.Clear(); HttpContext.Session.SetObjectAsJson("tamagachi", Guygar); HttpContext.Session.SetObjectAsJson("gameover", game); return(View()); }
public ActionResult Edit([Bind(Include = "Id,Name,Age,Currency,Level,Health,Hapinness,Alive")] Tamagochi tamagotchi) { if (ModelState.IsValid) { _tamagotchiRepo.Update(tamagotchi); RepositoryLocator.Repositories.Save(); return(RedirectToAction("Index")); } return(View(tamagotchi)); }
public static void SavedPlayer(Tamagochi player) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/Save.ck"; FileStream stream = new FileStream(path, FileMode.Create); TamagochiData data = new TamagochiData(player); formatter.Serialize(stream, data); stream.Close(); }
public void CreateTamagochi(TamagochiType type, string name) { if (_tamagochi == null) { _tamagochi = TamagochiCreator.CreateTamagochi(type); _tamagochi.Name = name; } else { throw new InvalidOperationException(); } }
// GET: Tamagotchi/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tamagochi tamagotchi = _tamagotchiRepo.GetById(id); if (tamagotchi == null) { return(HttpNotFound()); } return(View(tamagotchi)); }
public void Update(Tamagochi obj) { Tamagochi t = _db.Tamagochis.FirstOrDefault(a => a.Id == obj.Id); if (t != null) { t.Name = obj.Name; t.Level = obj.Level; t.Health = obj.Health; t.Hapinness = obj.Hapinness; t.Age = obj.Age; t.Alive = obj.Alive; t.Currency = obj.Currency; } }
public void TamagotchiDatabaseRemove() { // Arrange ITamagotchiRepository repository; Mock <DbSet <Tamagochi> > set; Mock <TamagotchiEntities> context; GetContext(out repository, out set, out context); Tamagochi t = set.Object.Where(x => x.Id == 1).ToList()[0]; // Act repository.Remove(t); // Assert set.Verify(x => x.Remove(It.IsAny <Tamagochi>()), Times.Once()); Assert.AreEqual(0, set.Object.Where(x => x.Id == 1).ToList().Count); }
public IActionResult Work() { Tamagochi Retrievegochi = HttpContext.Session.GetObjectFromJson <Tamagochi>("tamagachi"); Retrievegochi.Energy -= 5; Random rand = new Random(); Retrievegochi.Meals += rand.Next(1, 4); HttpContext.Session.SetObjectAsJson("tamagachi", Retrievegochi); ViewBag.tamagachi = Retrievegochi; if (Retrievegochi.Fullness <= 0 || Retrievegochi.Happiness <= 0 || Retrievegochi.Energy <= 0) { game Retrievegame = HttpContext.Session.GetObjectFromJson <game>("gameover"); Retrievegame.over = true; HttpContext.Session.SetObjectAsJson("gameover", Retrievegame); ViewBag.game = Retrievegame; } return(RedirectToAction("dojodachi")); }
public void TamagotchiDatabaseUpdate() { // Arrange ITamagotchiRepository repository; Mock <DbSet <Tamagochi> > set; Mock <TamagotchiEntities> context; GetContext(out repository, out set, out context); Tamagochi t = new Tamagochi() { Id = 1, Name = "Daano v Ethopie", Level = 0, Age = 0, Alive = 1, Currency = 100, Hapinness = 0, Health = 100 }; // Act repository.Add(t); // Assert set.Verify(x => x.Add(It.IsAny <Tamagochi>()), Times.Once()); List <Tamagochi> updated = set.Object.Where(x => x.Id == 1).ToList(); Assert.AreEqual(2, updated.Count); Assert.AreEqual(1, updated[0].Id); Assert.AreEqual("Daano v Ethopie", updated[0].Name); Assert.AreEqual(0, updated[0].Level); Assert.AreEqual(0, updated[0].Age); Assert.AreEqual(1, updated[0].Alive); Assert.AreEqual(100, updated[0].Currency); Assert.AreEqual(0, updated[0].Hapinness); Assert.AreEqual(100, updated[0].Health); }
public void Add(Tamagochi obj) { _db.Tamagochis.Add(obj); }
public TamagochiData(Tamagochi tamagochi) { hambre = tamagochi.hambre; amor = tamagochi.amor; }
public void Add(Tamagochi obj) { _tamagotchiList.Add(obj); }
public void Remove(Tamagochi obj) { _tamagotchiList.Remove(obj); }
public void Remove(Tamagochi obj) { _db.Tamagochis.Remove(obj); }