Ejemplo n.º 1
0
        public void OnGet()
        {
            // Players have not been defined yet
            if (ActiveGame.Players == null || ActiveGame.Players.Count == 0)
            {
                IsInvalidAccess = true;
                return;
            }

            // There's no current player so set it
            if (ActiveGame.CurrentPlayer == null || ActiveGame.NextPlayer == null)
            {
                ActiveGame.InitPlayerPointers();

                // Just to get rid of IDE warnings
                if (ActiveGame.CurrentPlayer == null || ActiveGame.NextPlayer == null)
                {
                    throw new NullReferenceException();
                }
            }

            // Players haven't placed ships yet
            if (ActiveGame.CurrentPlayer.Ships.FirstOrDefault(ship => ship.IsPlaced) == null)
            {
                IsInvalidAccess = true;
                return;
            }

            if (Request.Query.ContainsKey("save"))
            {
                GameSaver.Save();
                IsStatus  = true;
                StatusMsg = "Game saved!";
                return;
            }

            // There's a winner
            if (ActiveGame.TrySetWinner())
            {
                IsWinner  = true;
                StatusMsg = $"The winner of the game is {ActiveGame.Winner.Name}!";
                return;
            }

            MainTitle       = $"{ActiveGame.CurrentPlayer.Name} is attacking {ActiveGame.NextPlayer.Name}";
            IsDisplayBoards = true;
        }