コード例 #1
0
        private IResponse ProcessRequest(IGameRequest request)
        {
            Verbose(20, $"{request} in {GameState} #{_turnNumber.Value}");
            switch (GameState.Value)
            {
            //case EGameState.None:
            //    return Response.Ok;
            //case EGameState.Start:
            //    return TryStartGame(request as StartGame);
            //case EGameState.Mulligan:
            //    return TryRejectCards(request as RejectCards);
            //case EGameState.PlaceKing:
            //    return TryPlaceKing(request as PlacePiece);
            //case EGameState.TurnEnd:
            //    return TryTurnEnd(request as TurnEnd);
            case EGameState.PlayTurn:
                switch (request.Action)
                {
                case EActionType.TurnEnd:
                    return(TryTurnEnd(request as TurnEnd));

                case EActionType.Resign:
                    return(TryResign(request as Resign));

                case EActionType.CastSpell:
                    return(TryCastSpell(request as CastSpell));

                case EActionType.PlacePiece:
                    return(TryPlacePiece(request as PlacePiece));

                case EActionType.Battle:
                    return(TryBattle(request as Battle));

                case EActionType.MovePiece:
                    return(TryMovePiece(request as MovePiece));

                case EActionType.GiveItem:
                    return(TryGiveItem(request as GiveItem));

                default:
                    return(NotImplemented(request, $"{request}"));
                }

            case EGameState.Completed:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(NotImplemented(request));
        }
コード例 #2
0
        public override IGameResponse ProcessRequest <T>(IGameRequest request)
        {
            IGameResponse response = null;

            if (request is GetPlacementRequest)
            {
                GetPlacementRequest gpr = (GetPlacementRequest)request;
                response = GetPlacementRequest(gpr);
            }
            else
            {
                throw new NotImplementedException();
            }

            return(response);
        }
コード例 #3
0
        protected T _Post <T>(IGameRequest request)
            where T : IGameResponse
        {
            // Convert object to JSON, then JSON to bytes
            var requestJson  = JsonConvert.SerializeObject(request);
            var requestBytes = Encoding.UTF8.GetBytes(requestJson);

            // Send over the web
            WebClient client = new WebClient();

            client.Headers.Add("Content-Type", "application/json");
            var responseBytes = client.UploadData(_Uri, requestBytes);

            // Convert bytes to JSON, then JSON to object
            var responseJson = Encoding.UTF8.GetString(responseBytes);
            var response     = JsonConvert.DeserializeObject <T>(responseJson);

            return(response);
        }
コード例 #4
0
        public IResponse Arbitrate(IGameRequest request)
        {
            Assert.IsNotNull(request);
            var response = ProcessRequest(request);

            Verbose(10, $"Arbitrate: {request} {response}");
            var player = request.Owner as IPlayerModel;

            if (!response.Failed)
            {
            }

            player?.Result(request, response);

            _lastResponse.Value = new RequestResponse {
                Request = request, Response = response
            };
            return(response);
        }
コード例 #5
0
        public void OnRequestReceived(IGameRequest request)
        {
            int requestStringResource;

            switch (request.Type)
            {
            case GameRequest.TypeGift:
                requestStringResource = Resource.String.new_gift_received;
                break;

            case GameRequest.TypeWish:
                requestStringResource = Resource.String.new_request_received;
                break;

            default:
                return;
            }

            Toast.MakeText(this, requestStringResource, ToastLength.Long).Show();
            updateRequestCounts();
        }
コード例 #6
0
 public override IGameResponse ProcessRequest <T>(IGameRequest request)
 {
     if (request is GetShipPlacementRequest)
     {
         GetShipPlacementResponse response = GetShipPlacements((GetShipPlacementRequest)request);
         return(response);
     }
     else if (request is GetShotRequest)
     {
         GetShotResponse response = GetShot((GetShotRequest)request);
         return(response);
     }
     else if (request is InformationUpdatedRequest)
     {
         NonResponse response = InformationUpdated((InformationUpdatedRequest)request);
         return(response);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
コード例 #7
0
 public override IGameResponse ProcessRequest <T>(IGameRequest request)
 {
     return(_Post <T>(request));
 }
コード例 #8
0
 protected MockModelPlayerBase(EColor color)
     : base(color)
 {
     _Pass    = new Pass(this);
     _EndTurn = new TurnEnd(this);
 }
コード例 #9
0
 public abstract IGameResponse ProcessRequest <T>(IGameRequest request) where T : IGameResponse;