Ejemplo n.º 1
0
        public void OnPost()
        {
            if (!Request.Form.TryGetValue("x", out var strX))
            {
                IsError   = true;
                StatusMsg = "Missing x coordinate!";
                return;
            }

            if (!Request.Form.TryGetValue("y", out var strY))
            {
                IsError   = true;
                StatusMsg = "Missing y coordinate!";
                return;
            }

            // Check if the specified location can be attacked
            if (!InputValidator.CheckValidAttackLocation(ActiveGame.NextPlayer, strX, strY, out var pos))
            {
                IsError   = true;
                StatusMsg = "Invalid attack location!";
                return;
            }

            // Make the attack
            var result = PlayerLogic.AttackPlayer(ActiveGame.NextPlayer, pos);

            // Return whatever
            var move = new Move(ActiveGame.CurrentPlayer, ActiveGame.NextPlayer, pos, result);

            // Get next player
            var lastTurn = ActiveGame.RoundCounter;

            ActiveGame.CyclePlayers();

            if (lastTurn != ActiveGame.RoundCounter)
            {
                IsDisplaySave = true;
            }

            IsStatus  = true;
            StatusMsg = $"It was a {result}!";
        }
Ejemplo n.º 2
0
        public void OnGet()
        {
            // Get action param
            if (!Request.Query.TryGetValue("action", out var action))
            {
                return;
            }

            // Get id param
            if (!Request.Query.TryGetValue("id", out var id))
            {
                return;
            }

            Action = action.ToString().ToLower().Trim();
            Id     = id.ToString().ToLower().Trim();

            // Check params
            if (string.IsNullOrEmpty(Action) || string.IsNullOrEmpty(id) || !int.TryParse(id, out _))
            {
                return;
            }

            if (Action.Equals("delete"))
            {
                GameSaver.Delete(int.Parse(Id));
                IsStatus    = true;
                StatusMsg   = "Game deleted!";
                BackBtnHref = "List";
            }
            else if (Action.Equals("load"))
            {
                // Load game from database into active static context
                GameSaver.Load(int.Parse(Id));

                ActiveGame.CyclePlayers();

                IsStatus    = true;
                StatusMsg   = "Game loaded!";
                OkBtnText   = "Start game";
                BackBtnHref = "Play";
            }
        }