Ejemplo n.º 1
0
        private static void PrepareDataToSave(MatchOutcome results, DateTime dateTime, User winner, User loser, out MatchEncounter m1, out MatchEncounter m2)
        {
            m1 = null;
            m2 = null;

            if (results.PlayerNumberWinner != PlayerNumber.None)
            {
                m1 = new MatchEncounter
                {
                    User = winner,
                    UserRival = loser,
                    UserGestureType = results.Winner.Gesture,
                    UserRivalGestureType = results.Loser.Gesture,
                    Result = MatchResult.Win,
                    Date = dateTime
                };

                m2 = new MatchEncounter
                {
                    User = loser,
                    UserRival = winner,
                    UserGestureType = results.Loser.Gesture,
                    UserRivalGestureType = results.Winner.Gesture,
                    Result = MatchResult.Lose,
                    Date = dateTime
                };

                winner.WinCount++;
                loser.LostCount++;
            }
            else
            {
                m1 = new MatchEncounter
                {
                    User = winner,
                    UserRival = loser,
                    UserGestureType = results.Winner.Gesture,
                    UserRivalGestureType = results.Loser.Gesture,
                    Result = MatchResult.Tie,
                    Date = dateTime
                };

                m2 = new MatchEncounter
                {
                    User = loser,
                    UserRival = winner,
                    UserGestureType = results.Loser.Gesture,
                    UserRivalGestureType = results.Winner.Gesture,
                    Result = MatchResult.Tie,
                    Date = dateTime
                };

                winner.TieCount++;
                loser.TieCount++;
            }
        }
Ejemplo n.º 2
0
        public void SaveStats(MatchOutcome results)
        {
            using (var session = _store.OpenSession())
            {
                var dateTime = DateTime.UtcNow;
                MatchEncounter m1;
                MatchEncounter m2;
                var winner = session.Load<User>(results.Winner.UserId);
                var loser = session.Load<User>(results.Loser.UserId);

                PrepareDataToSave(results, dateTime, winner, loser, out m1, out m2);

                session.Store(m1);
                session.Store(m2);
                session.SaveChanges();

            }
        }
Ejemplo n.º 3
0
        private MatchOutcome Engage(Client clientOne, Client clientTwo)
        {
            var p = new Player(PlayerNumber.PlayerOne, clientOne.Gesture);
            var p2 = new Player(PlayerNumber.PlayerTwo, clientTwo.Gesture);

            PlayerNumber winner;
            var fought = _engageComponent.TryEngage(p, p2, out winner);

            var results = new MatchOutcome();
            results.PlayerNumberWinner = winner;
            if (results.PlayerNumberWinner == PlayerNumber.PlayerOne)
            {
                results.Winner = clientOne;
                results.Loser = clientTwo;
            }
            else if (results.PlayerNumberWinner == PlayerNumber.PlayerTwo)
            {
                results.Winner = clientTwo;
                results.Loser = clientOne;
            }
            else if (winner == PlayerNumber.None)
            {
                results.Winner = clientOne;
                results.Loser = clientTwo;
            }

            _statComponent.SaveStats(results);

            var legends = WinnerLoserLengendGenerator.GenerateLegend(results.Winner, results.Loser);

            results.WinnerLegend = legends.WinnerLegend;
            results.LoserLegend = legends.LoserLegend;

            if (winner == PlayerNumber.None)
            {
                results.Winner = null;
                results.Loser = null;
            }

            return results;
        }