Example #1
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            //Game.Board = "1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 2 0 2 0 2 2 0 2 0 2 0 2 0 0 2 0 2 0 2 0 2";
            Game.IsTurn    = true;
            Game.gameState = 0;
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _db.Game.Add(Game);
            await _db.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #2
0
        public async Task <IActionResult> OnPostCheck(string buttonval)
        {
            var xy = Array.ConvertAll(buttonval.Split(' '), int.Parse).ToList();
            int x  = xy[0];
            int y  = xy[1];

            Board = new Board(Game.Board);
            if (Board.PossibleMoves(x, y))
            {
                Game.IsTurn = !Game.IsTurn;
            }

            var GameFromDb = await _db.Game.FirstOrDefaultAsync(s => s.Id == Game.Id);

            GameFromDb.Board = Board.SaveBoard(Board.Storage);

            await _db.SaveChangesAsync();

            return(Page());
        }