Пример #1
0
        public static int GetGameExperienceEarned(PlayerGameStats stats)
        {
            // Add 1000 experience for a playing the game.
            int exp = 1000;

            if (stats.IsWinner)
            {
                exp += 500;
            }

            if (stats.PerformedFirstPeel)
            {
                exp += 50;
            }

            exp += stats.NumberOfPeels * 20;

            return exp;
        }
Пример #2
0
        public void Initialize()
        {
            _testGameMoveDataPoint = new GameMoveDataPoint { MoveType = MoveType.Dump, Player = "NewPlayer", TimeOfMove = 5 };

            _playerGameStats = new PlayerGameStats
                {
                    AvgTimeBetweenDumps = 10,
                    AvgTimeBetweenPeels = 5,
                    IsWinner = true,
                    NumberOfDumps = 3,
                    NumberOfPeels = 0,
                    PerformedFirstPeel = false,
                    RawGameData = new List<GameMoveDataPoint>() {_testGameMoveDataPoint, _testGameMoveDataPoint, _testGameMoveDataPoint}
                };

            _gameData = new GameData {GameDuration = 10, GameHost = "GameHost", GameStartTime = DateTime.Now, Winner = "NewPlayer"};
            _gameData.GameMoves.Add(_testGameMoveDataPoint);
            _gameData.GameMoves.Add(_testGameMoveDataPoint);
            _gameData.PlayerDictionary.Add("NewPlayer", _playerGameStats);
            _gameData.PlayerDictionary.Add("NewPlayer2", _playerGameStats);

            _gameDataList = new GameDataList();
            _gameDataList._GameData.Add(_gameData);
            _gameDataList._GameData.Add(_gameData);

            _stringPacketV1 = new PacketV1
                {
                    PacketType = PacketType.c_QueryIfAliasAvailable,
                    Data = "Mobius",
                    Recipients = null,
                    Sender = "*****@*****.**"
                };

            _IBinarySerializablePacketV1 = new PacketV1
            {
                PacketType = PacketType.c_UploadGameData,
                Data = _gameData,
                Recipients = null,
                Sender = "*****@*****.**"
            };

            _packetBase = new PacketBase
                {
                    PacketVersion = PacketVersion.Version1,
                    Data = _stringPacketV1
                };
        }
Пример #3
0
        /// <summary>
        /// Processes the data of this particular game by created player game stats for each player
        /// present in the game.
        /// </summary>
        public void ProcessGameData()
        {
            var activePlayers = new List <string>();
            var isFirstPeel   = true;

            GameDuration = GameMoves.Last().TimeOfMove;

            if (GameDuration <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          string.Format("Game Duration must be positive. GameDuration = {0}",
                                        GameDuration));
            }

            try
            {
                foreach (var dataPoint in GameMoves)
                {
                    var curPlayer = dataPoint.Player;

                    if (PlayerDictionary[curPlayer] == null)
                    {
                        PlayerDictionary[curPlayer] = new PlayerGameStats();
                        activePlayers.Add(curPlayer);
                    }

                    PlayerDictionary[curPlayer].RawGameData.Add(dataPoint);

                    if ((dataPoint.MoveType == MoveType.Peel) && isFirstPeel)
                    {
                        isFirstPeel = false;
                        PlayerDictionary[curPlayer].PerformedFirstPeel = true;
                    }
                }

                foreach (var activePlayer in activePlayers)
                {
                    // Iterate through the player's game moves.
                    foreach (var dataPoint in PlayerDictionary[activePlayer].RawGameData)
                    {
                        switch (dataPoint.MoveType)
                        {
                        case MoveType.Dump:
                            PlayerDictionary[activePlayer].NumberOfDumps++;
                            break;

                        case MoveType.Peel:
                            PlayerDictionary[activePlayer].NumberOfPeels++;
                            break;

                        case MoveType.Victory:
                            PlayerDictionary[activePlayer].IsWinner = true;
                            Winner = activePlayer;
                            break;
                        }
                    }

                    PlayerDictionary[activePlayer].AvgTimeBetweenDumps =
                        PlayerDictionary[activePlayer].NumberOfDumps / GameDuration;

                    PlayerDictionary[activePlayer].AvgTimeBetweenPeels =
                        PlayerDictionary[activePlayer].NumberOfPeels / GameDuration;
                }


                //
                // Create a blank PlayerGameStats object for all inactive players
                //

                var inactivePlayerKeys = PlayerDictionary
                                         .Where(kvp => kvp.Value == null)
                                         .Select(kvp => kvp.Key).ToList();

                foreach (var key in inactivePlayerKeys)
                {
                    PlayerDictionary[key] = new PlayerGameStats();
                }
            }
            catch (KeyNotFoundException e)
            {
#if DEBUG
                throw e;
#endif
            }
        }
Пример #4
0
        /// <summary>
        /// Processes the data of this particular game by created player game stats for each player
        /// present in the game.
        /// </summary>
        public void ProcessGameData()
        {
            var activePlayers = new List<string>();
            var isFirstPeel = true;

            GameDuration = GameMoves.Last().TimeOfMove;

            if (GameDuration <= 0)
            {
                throw new ArgumentOutOfRangeException(
                        string.Format("Game Duration must be positive. GameDuration = {0}",
                        GameDuration));
            }

            try
            {

                foreach (var dataPoint in GameMoves)
                {
                    var curPlayer = dataPoint.Player;

                    if (PlayerDictionary[curPlayer] == null)
                    {
                        PlayerDictionary[curPlayer] = new PlayerGameStats();
                        activePlayers.Add(curPlayer);
                    }

                    PlayerDictionary[curPlayer].RawGameData.Add(dataPoint);

                    if ((dataPoint.MoveType == MoveType.Peel) && isFirstPeel)
                    {
                        isFirstPeel = false;
                        PlayerDictionary[curPlayer].PerformedFirstPeel = true;
                    }
                }

                foreach (var activePlayer in activePlayers)
                {
                    // Iterate through the player's game moves.
                    foreach (var dataPoint in PlayerDictionary[activePlayer].RawGameData)
                    {
                        switch (dataPoint.MoveType)
                        {
                            case MoveType.Dump:
                                PlayerDictionary[activePlayer].NumberOfDumps++;
                                break;

                            case MoveType.Peel:
                                PlayerDictionary[activePlayer].NumberOfPeels++;
                                break;

                            case MoveType.Victory:
                                PlayerDictionary[activePlayer].IsWinner = true;
                                Winner = activePlayer;
                                break;
                        }
                    }

                    PlayerDictionary[activePlayer].AvgTimeBetweenDumps =
                            PlayerDictionary[activePlayer].NumberOfDumps / GameDuration;

                    PlayerDictionary[activePlayer].AvgTimeBetweenPeels =
                            PlayerDictionary[activePlayer].NumberOfPeels / GameDuration;
                }

                //
                // Create a blank PlayerGameStats object for all inactive players
                //

                var inactivePlayerKeys = PlayerDictionary
                        .Where(kvp => kvp.Value == null)
                        .Select(kvp => kvp.Key).ToList();

                foreach (var key in inactivePlayerKeys)
                {
                    PlayerDictionary[key] = new PlayerGameStats();
                }
            }
            catch(KeyNotFoundException e)
            {
            #if DEBUG
                throw e;
            #endif
            }
        }
Пример #5
0
        private static GameData CreateTestDataSet()
        {
            var dataSet = new GameData { GameDuration = 50, GameHost = "AGameHost", Winner = "NewPlayer" };

            dataSet.GameMoves.Add(new GameMoveDataPoint("Player", 5, MoveType.Peel));

            var stats = new PlayerGameStats()
            {
                AvgTimeBetweenDumps = 5,
                AvgTimeBetweenPeels = 5,
                NumberOfDumps = 3,
                NumberOfPeels = 3,
                PerformedFirstPeel = true,
                IsWinner = false,
                RawGameData = new List<GameMoveDataPoint>() { new GameMoveDataPoint("Me", 1, MoveType.Peel) }
            };

            dataSet.PlayerDictionary.Add("NewPlayer", stats);
            return dataSet;
        }