public IActionResult GameOver()
        {
            match = JsonConvert.DeserializeObject <Match>(HttpContext.Session.GetString("match"));
            int player1Pairs = match.Player1.Pile.Count() / 2;
            int player2Pairs = match.Player2.Pile.Count() / 2;

            if (player1Pairs > player2Pairs)
            {
                string id      = User.FindFirstValue(ClaimTypes.NameIdentifier);
                GoFish results = new GoFish
                {
                    UserId = id,
                    Wins   = 1
                };
                if (ModelState.IsValid)
                {
                    _context.GoFish.Add(results);
                    _context.SaveChanges();
                }
                match.Message = $"Game Over: You won!  You had {player1Pairs} pairs and the computer had {player2Pairs} pairs";
            }
            else if (player1Pairs < player2Pairs)
            {
                string id      = User.FindFirstValue(ClaimTypes.NameIdentifier);
                GoFish results = new GoFish
                {
                    UserId = id,
                    Losses = 1
                };
                if (ModelState.IsValid)
                {
                    _context.GoFish.Add(results);
                    _context.SaveChanges();
                }
                match.Message = $"Game Over: The computer won.  You had {player1Pairs} pairs and the computer had {player2Pairs} pairs";
            }
            else if (player1Pairs == player2Pairs)
            {
                string id      = User.FindFirstValue(ClaimTypes.NameIdentifier);
                GoFish results = new GoFish
                {
                    UserId = id,
                    Ties   = 1
                };
                if (ModelState.IsValid)
                {
                    _context.GoFish.Add(results);
                    _context.SaveChanges();
                }
                match.Message = $"Game Over: You tied!  You had {player1Pairs} pairs and the computer had {player2Pairs} pairs";
            }
            return(View(match));
        }
Exemplo n.º 2
0
        public ServerForm()
        {
            InitializeComponent();
            if (!(new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator))
            {
                MessageBox.Show("Run as administrator!");
                Close();
            }
            Game.PlayerConnectedEvent    += Game_PlayerConnectedEvent;
            Game.PlayerDisconnectedEvent += Game_PlayerDisconnectedEvent;

            game = new GoFish(new GameRules());
        }