public ActionResult OnSaveGame() { GameBusinessService gameBS = new GameBusinessService(); game.Id = gameBS.saveGame(game); AccountBusinessService accountBS = new AccountBusinessService(); UserModel user = accountBS.getUser(Int32.Parse(Session["user_id"].ToString())); user.ActiveGameId = game.Id; accountBS.UpdateUser(user); return(View("~/Views/Game/Board.cshtml", game)); }
public ActionResult Register(UserModel user) { AccountBusinessService bs = new AccountBusinessService(); user.ActiveGameId = -1; if (bs.Register(user)) { return(View("Login", user)); } else { return(View("RegisterFail")); } }
public ActionResult OnReveal(string coords) { string[] array = coords.Split('|'); int y = int.Parse(array[0]); int x = int.Parse(array[1]); if (!game.Board.TheGrid[y, x].Flagged) { GameBusinessService bs = new GameBusinessService(game); game.Board = bs.revealOneCell(game.Board.TheGrid[y, x]); if (game.Board.TheGrid[y, x].Bomb) { game.Stopwatch.Stop(); AccountBusinessService accountBS = new AccountBusinessService(); accountBS.ResetActiveGame(Int32.Parse(Session["user_id"].ToString())); return(View("~/Views/Game/Loss.cshtml")); } if (bs.gameWin()) { game.Stopwatch.Stop(); ScoreModel score = new ScoreModel(bs.calculateScore(game), game.Board.Difficulty, Int32.Parse(Session["user_id"].ToString())); bs.saveScore(score); AccountBusinessService accountBS = new AccountBusinessService(); accountBS.ResetActiveGame(Int32.Parse(Session["user_id"].ToString())); return(View("~/Views/Game/Win.cshtml", score)); } } AjaxOptions ajaxOptions = new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "game" }; Tuple <GameModel, AjaxOptions> tuple = new Tuple <GameModel, AjaxOptions>(game, ajaxOptions); return(PartialView("~/Views/Game/_boardInfo.cshtml", tuple)); }
public ActionResult Login(UserModel user) { AccountBusinessService bs = new AccountBusinessService(); // -1 means login failed int loggedInId = bs.Authenticate(user); if (loggedInId != -1) { Session["user_id"] = loggedInId; return(View("~/Views/Home/Index.cshtml")); } else { return(View("LoginFail")); } }
// GET: Game public ActionResult Index() { AccountBusinessService accountBS = new AccountBusinessService(); GameBusinessService gameBS = new GameBusinessService(); int userActiveGameId = accountBS.getUser(Int32.Parse(Session["user_id"].ToString())).ActiveGameId; if (userActiveGameId != -1) { GameModel partialGame = new GameModel(); partialGame.Id = userActiveGameId; GameBusinessService bs = new GameBusinessService(); game = bs.getGame(partialGame); return(View("~/Views/Game/Board.cshtml", game)); } return(View("Index")); }