public IActionResult Index() { //Create an instance of the GameBoardViewModel GameBoardViewModel game = new GameBoardViewModel(); //Instantiate the game business class gameRules = new GameBusinessService(); //Setup the game board gameBoard = gameRules.SetupGame(10, gameBoard); gameStatus = "In Progress"; MyLogger.GetInstance().Info("Session - " + HttpContext.Session.GetString("username")); //If the session is not empty - user logged in if (!string.IsNullOrEmpty(HttpContext.Session.GetString("username"))) { //Grab their username userName = HttpContext.Session.GetString("username"); } else { userName = ""; } game.GameBoard = gameBoard; game.numOfClick = clicks; game.UserName = userName; //Pass the GameBoardViewModel with the next view return(View("Index", game)); }
public ActionResult OnGetHighScores() { GameBusinessService bs = new GameBusinessService(); List <IEnumerable <ScoreModel> > highScores = bs.getHighScores(); return(View("~/Views/Game/HighScores.cshtml", highScores)); }
public string GetGameModel(string id) { GameBusinessService service = new GameBusinessService(); int gameId = Int32.Parse(id); string dto = service.GetById(id); return(dto); }
public ActionResult OnGetGame(int game_id) { GameModel partialGame = new GameModel(); partialGame.Id = game_id; GameBusinessService bs = new GameBusinessService(); game = bs.getGame(partialGame); return(View("~/Views/Game/Board.cshtml", game)); }
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 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 OnSetDifficulty(int difficulty) { game = new GameModel(); BoardModel board = new BoardModel(difficulty); game.Board = board; GameBusinessService bs = new GameBusinessService(game); game.Board = bs.setupBoard(game.Board); game.Stopwatch = new Stopwatch(); game.Stopwatch.Start(); return(View("~/Views/Game/Board.cshtml", game)); }
public DTO GetAllScores() { GameBusinessService bs = new GameBusinessService(); List <ScoreModel> scores = new List <ScoreModel>(); scores = bs.getAllScores(); if (scores.Count == 0) { DTO dto = new DTO(-1, "No scores found", scores); return(dto); } else { DTO dto = new DTO(0, "OK", scores); return(dto); } }
public DTO GetScore(string id) { GameBusinessService bs = new GameBusinessService(); List <ScoreModel> score = new List <ScoreModel>(); score.Add(bs.getScore(Int32.Parse(id))); if (score[0] == null) { DTO dto = new DTO(-1, "Score does not exist", null); return(dto); } else { DTO dto = new DTO(0, "OK", score); return(dto); } }
// 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")); }