Beispiel #1
0
        public OutInitMatchVM CreateMatch(InInitMatchVM pModel)
        {
            OutInitMatchVM outIniciarPartidaVM = new OutInitMatchVM();

            if (ModelState.IsValid)
            {
                try
                {
                    outIniciarPartidaVM.ID = IBoMatch.CreateMatch(new Match.DML.Match()
                    {
                        Player1 = pModel.Player1,
                        Player2 = pModel.Player2
                    });
                    outIniciarPartidaVM.HttpStatus = StatusCodes.Status201Created;
                    outIniciarPartidaVM.Message    = $"Partida {outIniciarPartidaVM.ID} iniciada com sucesso!";
                }
                catch (Exception ex)
                {
                    outIniciarPartidaVM.HttpStatus = StatusCodes.Status400BadRequest;
                    outIniciarPartidaVM.Message    = $"Erro ao iniciar a partida! {ex.Message}";
                }
            }
            else
            {
                outIniciarPartidaVM.Message    = "Objeto de entrada não está valido!";
                outIniciarPartidaVM.HttpStatus = StatusCodes.Status400BadRequest;
            }

            return(outIniciarPartidaVM);
        }
Beispiel #2
0
        public async Task Connect(string myConnectionId, string partnerCode, string myCode)
        {
            var player        = playerObject.FindPlayerByCode(myCode);
            var partnerPlayer = playerObject.FindPlayerByCode(partnerCode);

            if (!BondAlreadyExists(partnerCode, myCode))
            {
                connections.PlayersBinded.Add(new PlayerBinded(myCode, partnerCode));
            }

            var partnerConnectionId = GetConnectionId(partnerCode);

            var currentMatchPlayer  = matchObject.CurrentMatch(player.Login);
            var currentMatchPartner = matchObject.CurrentMatch(partnerPlayer.Login);

            var matchId = currentMatchPartner?.ID;

            if (currentMatchPlayer is null || currentMatchPartner is null || !PlayersAlreadyInSameMatch(currentMatchPlayer, currentMatchPartner))
            {
                matchId = matchObject.CreateMatch(new Match()
                {
                    Player1       = player.ID,
                    Player2       = partnerPlayer.ID,
                    CurrentPlayer = partnerPlayer.ID
                });
            }

            ChangePlayerReady(partnerCode, isReady: false);
            ChangePlayerReady(myCode, isReady: false);

            await Clients.Caller.SendAsync("Connected", matchId, player, partnerPlayer);

            await Clients.Client(partnerConnectionId).SendAsync("Connected", matchId, partnerPlayer, player);
        }