Exemple #1
0
        private void StartMatch(RealtimePlayer firstPlayer, RealtimePlayer secondPlayer, int matchLength, int turnLength)
        {
            LeaveRoom(firstPlayer);
            LeaveRoom(secondPlayer);

            int matchID = -1;

            // Generacion de los datos de inicializacion para el partido. No valen con los del RealtimePlayer, hay que refrescarlos.
            using (SoccerDataModelDataContext theContext = new SoccerDataModelDataContext())
            {
                matchID = CreateDatabaseMatch(theContext, firstPlayer, secondPlayer);
                FillRealtimePlayerData(theContext, firstPlayer);
                FillRealtimePlayerData(theContext, secondPlayer);
            }

            RealtimeMatch theNewMatch = new RealtimeMatch(matchID, firstPlayer, secondPlayer, matchLength, turnLength, this);
            mMatches.Add(theNewMatch);

            firstPlayer.TheMatch = theNewMatch;
            secondPlayer.TheMatch = theNewMatch;

            firstPlayer.TheConnection.Invoke("PushedStartMatch", firstPlayer.ClientID, secondPlayer.ClientID);
            secondPlayer.TheConnection.Invoke("PushedStartMatch", firstPlayer.ClientID, secondPlayer.ClientID);
        }
Exemple #2
0
        internal RealtimeMatchResult OnFinishMatch(RealtimeMatch realtimeMatch)
        {
            RealtimeMatchResult matchResult = null;

            RealtimePlayer player1 = realtimeMatch.GetRealtimePlayer(RealtimeMatch.PLAYER_1);
            RealtimePlayer player2 = realtimeMatch.GetRealtimePlayer(RealtimeMatch.PLAYER_2);

            using (SoccerDataModelDataContext theContext = new SoccerDataModelDataContext())
            {
                Player bddPlayer1 = GetPlayerForRealtimePlayer(theContext, player1);
                Player bddPlayer2 = GetPlayerForRealtimePlayer(theContext, player2);

                // Los BDDPlayers se actualizan dentro de la funcion (... old GiveMatchRewards)
                matchResult = new RealtimeMatchResult(theContext, realtimeMatch, bddPlayer1, bddPlayer2);

                // Actualizacion del BDDMatch...
                BDDModel.Match theBDDMatch = (from m in theContext.Matches
                                                where m.MatchID == realtimeMatch.MatchID
                                                select m).FirstOrDefault();

                theBDDMatch.DateEnded = DateTime.Now;
                theBDDMatch.WasTooManyTimes = matchResult.WasTooManyTimes;
                theBDDMatch.WasJust = matchResult.WasJust;
                theBDDMatch.WasAbandoned = matchResult.WasAbandoned;
                theBDDMatch.WasAbandonedSameIP = matchResult.WasAbandonedSameIP;

                // ... y de las MatchParticipations de la BDD
                (from p in theContext.MatchParticipations
                    where p.MatchParticipationID == player1.MatchParticipationID
                    select p).FirstOrDefault().Goals = matchResult.GetGoalsFor(player1);

                (from p in theContext.MatchParticipations
                    where p.MatchParticipationID == player2.MatchParticipationID
                    select p).FirstOrDefault().Goals = matchResult.GetGoalsFor(player2);

                theContext.SubmitChanges();
            }

            player1.PlayerData = null;
            player2.PlayerData = null;
            player1.MatchParticipationID = -1;
            player2.MatchParticipationID = -1;
            player1.TheMatch = null;
            player2.TheMatch = null;

            // Borramos el match, dejamos que ellos se unan a la habitacion
            mMatches.Remove(realtimeMatch);

            return matchResult;
        }