/// <summary>
 /// Create the match and returns your ID
 /// </summary>
 /// <param name="pMatch">Match Object</param>
 /// <returns>Número da partida</returns>
 public int CreateMatch(DML.Match pMatch)
 {
     /*Inserindo no banco*/
     IUnitOfWork.Executar(IUnitOfWork.MontaInsertPorAttributo(pMatch).ToString());
     /*Retornando ID da partida*/
     return(CurrentMatch(pMatch.Player1).ID);
 }
Beispiel #2
0
        /// <summary>
        /// Create a match and returns your id
        /// </summary>
        /// <param name="pMatch">Match object</param>
        /// <returns>Math id</returns>
        public int CreateMatch(DML.Match pMatch)
        {
            if (CurrentMatch(pMatch.Player1) != null)
            {
                throw new Exception("Jogador 1 já possui uma partida iniciada");
            }
            if (CurrentMatch(pMatch.Player2) != null)
            {
                throw new Exception("Jogador 2 já possui uma partida iniciada");
            }

            try
            {
                IDispatcherMatch.BeginTransaction();
                int matchId = IDispatcherMatch.CreateMatch(pMatch);
                IBoMatchSpecialPower.RegisterSpecialPowerToMatch(matchId);
                IDispatcherMatch.Commit();
                return(matchId);
            }
            catch (Exception ex)
            {
                IDispatcherMatch.Rollback();
                throw;
            }
        }
        public List <DML.Match> Get()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("SELECT ID, Player1, Player2, Player1Ready, Player2Ready, Status, CurrentPlayer, Winner, MatchContrl FROM Match WITH(NOLOCK)");

            DataSet ds = IUnitOfWork.Consulta(stringBuilder.ToString());

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                List <DML.Match> matchs = new List <DML.Match>();

                DML.Match match;
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    match = new DML.Match();

                    if (row["ID"] != DBNull.Value)
                    {
                        match.ID = Convert.ToInt32(row["ID"]);
                    }
                    if (row["Player1"] != DBNull.Value)
                    {
                        match.Player1 = Convert.ToInt32(row["Player1"]);
                    }
                    if (row["Player2"] != DBNull.Value)
                    {
                        match.Player2 = Convert.ToInt32(row["Player2"]);
                    }
                    if (row["Player1Ready"] != DBNull.Value)
                    {
                        match.Player1Ready = Convert.ToInt32(row["Player1Ready"]);
                    }
                    if (row["Player2Ready"] != DBNull.Value)
                    {
                        match.Player2Ready = Convert.ToInt32(row["Player2Ready"]);
                    }
                    if (row["Status"] != DBNull.Value)
                    {
                        match.Status = (MatchStatus)Convert.ToInt32(row["Status"]);
                    }
                    if (row["CurrentPlayer"] != DBNull.Value)
                    {
                        match.CurrentPlayer = Convert.ToInt32(row["CurrentPlayer"]);
                    }
                    if (row["Winner"] != DBNull.Value)
                    {
                        match.Winner = Convert.ToInt32(row["Winner"]);
                    }
                    if (row["MatchContrl"] != DBNull.Value)
                    {
                        match.Controle = Convert.ToInt32(row["MatchContrl"]);
                    }

                    matchs.Add(match);
                }
                return(matchs);
            }
            return(new List <DML.Match>());
        }
Beispiel #4
0
        /// <summary>
        /// Update a match and returns your id
        /// </summary>
        /// <param name="pMatch">Match object</param>
        /// <returns>Math id</returns>
        public void UpdateMatch(DML.Match pMatch)
        {
            if (pMatch.ID <= 0)
            {
                throw new ArgumentOutOfRangeException(paramName: nameof(pMatch.ID), message: "ID cannot be lower ou equal zero");
            }

            if (pMatch == null)
            {
                throw new ArgumentNullException(paramName: nameof(pMatch), message: "Match is required");
            }

            IDispatcherMatch.UpdateMatch(pMatch);
        }
Beispiel #5
0
        /// <summary>
        /// Create a match and returns your id
        /// </summary>
        /// <param name="pMatch">Match object</param>
        /// <returns>Math id</returns>
        public int CreateMatch(DML.Match pMatch)
        {
            if (CurrentMatch(pMatch.Player1) != null)
            {
                throw new Exception("Jogador 1 já possui uma partida iniciada");
            }
            if (CurrentMatch(pMatch.Player2) != null)
            {
                throw new Exception("Jogador 2 já possui uma partida iniciada");
            }

            pMatch.StatusDaPartida = DML.Enumerados.MatchStatus.Created;
            return(IDispatcherPartida.CurrentMatch(pMatch.Player1).ID);
        }
        /// <summary>
        /// Search the player's current game (With status started)
        /// </summary>
        /// <param name="pPlayerID">Player ID</param>
        /// <returns>Partida atual</returns>
        public DML.Match CurrentMatch(int pPlayerID)
        {
            #region Query
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.AppendLine("DECLARE @ID_JOGADOR INT");
            stringBuilder.AppendLine($"SET @ID_JOGADOR = {pPlayerID}");
            stringBuilder.AppendLine("SELECT");
            stringBuilder.AppendLine("  ID,");
            stringBuilder.AppendLine("  PLAYER1,");
            stringBuilder.AppendLine("  PLAYER2,");
            stringBuilder.AppendLine("  STATUS");
            stringBuilder.AppendLine("FROM MATCH WITH(NOLOCK)");
            stringBuilder.AppendLine("WHERE PLAYER1 = @ID_JOGADOR OR PLAYER2 = @ID_JOGADOR");
            #endregion

            DataSet   ds      = IUnitOfWork.Consulta(stringBuilder.ToString());
            DML.Match partida = new DML.Match();

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != DBNull.Value)
                {
                    partida.ID = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"]);
                }

                if (ds.Tables[0].Rows[0]["PLAYER1"] != DBNull.Value)
                {
                    partida.Player1 = Convert.ToInt32(ds.Tables[0].Rows[0]["PLAYER1"]);
                }

                if (ds.Tables[0].Rows[0]["PLAYER2"] != DBNull.Value)
                {
                    partida.Player2 = Convert.ToInt32(ds.Tables[0].Rows[0]["PLAYER2"]);
                }

                if (ds.Tables[0].Rows[0]["STATUS"] != DBNull.Value)
                {
                    partida.StatusDaPartida = (MatchStatus)Convert.ToInt32(ds.Tables[0].Rows[0]["STATUS"]);
                }

                return(partida);
            }
            return(null);
        }
        /// <summary>
        /// Update the match and returns your ID
        /// </summary>
        /// <param name="pMatch">Match Object</param>
        /// <returns>Número da partida</returns>
        public void UpdateMatch(DML.Match match)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("DECLARE @ID INT,   ");
            stringBuilder.AppendLine("  @PLAYER1READY INT,");
            stringBuilder.AppendLine("  @PLAYER2READY INT,");
            stringBuilder.AppendLine("  @STATUS INT");

            stringBuilder.AppendLine($"SET @ID = {match.ID}");
            stringBuilder.AppendLine($"SET @PLAYER1READY = '{match.Player1Ready}'");
            stringBuilder.AppendLine($"SET @PLAYER2READY = '{match.Player2Ready}'");
            stringBuilder.AppendLine($"SET @STATUS = '{Convert.ToInt32(match.Status)}'");

            stringBuilder.AppendLine("UPDATE Match");
            stringBuilder.AppendLine("SET");
            stringBuilder.AppendLine("  Player1Ready = @PLAYER1READY,");
            stringBuilder.AppendLine("  Player2Ready = @PLAYER2READY,");
            stringBuilder.AppendLine("  Status = @STATUS");

            IUnitOfWork.Executar(stringBuilder.ToString());
        }
        /// <summary>
        /// Search the player's current game (With status started)
        /// </summary>
        /// <param name="pPlayerID">Player ID</param>
        /// <returns>Partida atual</returns>
        public DML.Match CurrentMatch(int pPlayerID)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("DECLARE @ID_JOGADOR INT");
            stringBuilder.AppendLine($"SET @ID_JOGADOR = {pPlayerID}");
            stringBuilder.AppendLine("SELECT");
            stringBuilder.AppendLine("  ID,");
            stringBuilder.AppendLine("  PLAYER1,");
            stringBuilder.AppendLine("  PLAYER2,");
            stringBuilder.AppendLine("  PLAYER1READY,");
            stringBuilder.AppendLine("  PLAYER2READY,");
            stringBuilder.AppendLine("  CURRENTPLAYER,");
            stringBuilder.AppendLine("  STATUS");
            stringBuilder.AppendLine("FROM MATCH WITH(NOLOCK)");
            stringBuilder.AppendLine("WHERE (PLAYER1 = @ID_JOGADOR OR PLAYER2 = @ID_JOGADOR)");
            stringBuilder.AppendLine($"AND STATUS <> {Convert.ToInt32(MatchStatus.Closed)}");

            DataSet ds = IUnitOfWork.Consulta(stringBuilder.ToString());

            DML.Match partida = new DML.Match();

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != DBNull.Value)
                {
                    partida.ID = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"]);
                }

                if (ds.Tables[0].Rows[0]["PLAYER1"] != DBNull.Value)
                {
                    partida.Player1 = Convert.ToInt32(ds.Tables[0].Rows[0]["PLAYER1"]);
                }

                if (ds.Tables[0].Rows[0]["PLAYER2"] != DBNull.Value)
                {
                    partida.Player2 = Convert.ToInt32(ds.Tables[0].Rows[0]["PLAYER2"]);
                }

                if (ds.Tables[0].Rows[0]["PLAYER1READY"] != DBNull.Value)
                {
                    partida.Player1Ready = Convert.ToInt32(ds.Tables[0].Rows[0]["PLAYER1READY"]);
                }

                if (ds.Tables[0].Rows[0]["PLAYER2READY"] != DBNull.Value)
                {
                    partida.Player2Ready = Convert.ToInt32(ds.Tables[0].Rows[0]["PLAYER2READY"]);
                }

                if (ds.Tables[0].Rows[0]["CURRENTPLAYER"] != DBNull.Value)
                {
                    partida.CurrentPlayer = Convert.ToInt32(ds.Tables[0].Rows[0]["CURRENTPLAYER"]);
                }

                if (ds.Tables[0].Rows[0]["STATUS"] != DBNull.Value)
                {
                    partida.Status = (MatchStatus)Convert.ToInt32(ds.Tables[0].Rows[0]["STATUS"]);
                }

                return(partida);
            }
            return(null);
        }