public ActionResult Register(Player account) { if (ModelState.IsValid) { using (SimGameEntities db = new SimGameEntities()) { db.Players.Add(account); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = "Succesfully registered."; } return(RedirectToAction("Login")); }
public ActionResult NewDay() { Session["Message"] = null; City c = db.Cities.ToList().First(); if (c.Villagers <= 0) { return(RedirectToAction("Loser")); } else { if (c.Houses > c.Villagers) { int villagersMovingIn = Convert.ToInt32(c.Houses - c.Villagers); Session["Message"] = $"A new villager moved in!"; } c.Villagers = c.Houses; } if (c.Villagers >= 10) { return(RedirectToAction("Winner")); } else { c.Water += c.Wells; c.Food += c.Farm; for (int i = 0; i < c.Villagers; i++) { if (c.Water >= 1) { c.Water -= 1; } else { if (c.Villagers > 0) { c.Villagers--; } } if (c.Food >= 1 && c.Villagers > 0) { c.Food--; } else { if (c.Villagers > 0) { c.Villagers--; } } } if (c.Villagers <= 0) { return(RedirectToAction("Loser")); } c.Day++; c.Actions = c.Villagers; db.Cities.AddOrUpdate(c); db.SaveChanges(); } return(RedirectToAction("Game")); }