예제 #1
0
        private async Task SendDisconectMessage(string clientId, string gameId)
        {
            var tbState = new TableStateVm()
            {
                ActionRequied = "Disconnect"
            };

            await this.Clients.Client(clientId).SendAsync("Disconnect");

            await this.Groups.RemoveFromGroupAsync(clientId, gameId);
        }
예제 #2
0
        public async Task InitializeGameHub()
        {
            gameHubConnection = new HubConnectionBuilder()
                                .WithUrl(ServerAddress + "/belotHub")
                                .Build();

            gameHubConnection.On <PlayerStateVm, string>(ChannelConstants.PlayerStateChange, async(ps, eventName) =>
            {
                this.playerState    = ps;
                this.cardToBePlayed = null;
                Console.WriteLine("PlayerStateChange");
                Console.WriteLine(eventName);

                if (eventName == null)
                {
                }
                //Console.WriteLine(ps.ActionRequired);
                else if (eventName == "GameStart")
                {
                    //Console.WriteLine("GameStart State Update");
                }
                else if (eventName.Contains("Deal"))
                {
                    //Console.WriteLine(JsonConvert.SerializeObject(ps));
                }
                else if (eventName.Contains("Play"))
                {
                    //Console.WriteLine(JsonConvert.SerializeObject(ps));
                }
                else if (eventName.Contains("ViewScore"))
                {
                    //Console.WriteLine("ViewScore");
                    //Console.WriteLine(JsonConvert.SerializeObject(ps));
                }

                if (playerState != null)
                {
                    if (playerState.ActionRequired == "Wait")
                    {
                        return;
                    }
                    else if (playerState.ActionRequired == "Bidding")
                    {
                        Thread.Sleep(1000);
                        await this.Announce(playerState.PossibleBids[0]);
                    }
                    else if (playerState.ActionRequired == "ConfirmDeal")
                    {
                        Thread.Sleep(1000);
                        await this.Deal();
                    }
                    else if (playerState.ActionRequired == "PlayCard")
                    {
                        Thread.Sleep(1000);
                        await this.PlayCard();
                    }
                }
            });

            gameHubConnection.On <JoinGameRes>(ChannelConstants.JoinGameAnswer, (res) =>
            {
                Console.WriteLine("JoinRespons");
                Console.WriteLine(res.Success);
            });

            gameHubConnection.On <TableStateVm>(ChannelConstants.TableUpdate, (tu) =>
            {
                Console.WriteLine("TableUpdate");
                this.tableStateVm = tu;

                if (tu.ActionRequied == "ViewScore")
                {
                    Console.WriteLine("ViewScore - Table Update");
                    Console.WriteLine(JsonConvert.SerializeObject(tu));
                }
            });


            await gameHubConnection.StartAsync();

            var joinReq = new JoinGameReq()
            {
                PlayerName = this.UserId,
                GameName   = this.GameName,
                Seat       = int.Parse(this.Seat)
            };

            Thread.Sleep(int.Parse(this.Seat) * 500);
            await gameHubConnection.SendAsync("JoinGame", joinReq);
        }