Inheritance: GameSessionHistory
Ejemplo n.º 1
0
        public GameSession()
        {
            id           = 0;
            game_manager = new GameManager();
            game_time    = TimeSpan.Zero;

            timer          = new System.Timers.Timer();
            timer.Elapsed += TimerUpdater;
            timer.Interval = (1 * 1000);             // 1 second

            controler      = new ViewsControler(this);
            Status         = SessionStatus.NotPlaying;
            player_history = new PlayerHistory();
            history        = new GameSessionHistoryExtended();
        }
Ejemplo n.º 2
0
        public GameSession()
        {
            id = 0;
            game_manager = new GameManager ();
            game_time = TimeSpan.Zero;

            timer = new System.Timers.Timer ();
            timer.Elapsed += TimerUpdater;
            timer.Interval = (1 * 1000); // 1 second

            controler = new ViewsControler (this);
            Status = SessionStatus.NotPlaying;
            player_history = new PlayerHistory ();
            history = new GameSessionHistoryExtended ();
        }
Ejemplo n.º 3
0
        public GameSession(ITranslations translations)
        {
            Translations = translations;
            id           = 0;
            game_manager = new GameManager();
            play_list    = new GameSessionPlayList(game_manager);
            game_time    = TimeSpan.Zero;

            timer          = new System.Timers.Timer();
            timer.Elapsed += TimerUpdater;
            timer.Interval = (1 * 1000);             // 1 second

            controler      = new ViewsControler(translations, this);
            Status         = SessionStatus.NotPlaying;
            player_history = new PlayerHistory();
            history        = new GameSessionHistoryExtended();
        }
Ejemplo n.º 4
0
        public GameSession(ITranslations translations)
        {
            Translations = translations;
            id = 0;
            game_manager = new GameManager ();
            play_list = new GameSessionPlayList (game_manager);
            game_time = TimeSpan.Zero;

            timer = new System.Timers.Timer ();
            timer.Elapsed += TimerUpdater;
            timer.Interval = (1 * 1000); // 1 second

            controler = new ViewsControler (translations, this);
            Status = SessionStatus.NotPlaying;
            player_history = new PlayerHistory ();
            history = new GameSessionHistoryExtended ();
        }
Ejemplo n.º 5
0
        //
        // Applies scoring formula to the session
        //
        static int SessionScoreFormula(ref GameSessionHistoryExtended history, GameTypes type, GameDifficulty difficulty)
        {
            int    logbase, scored, played, won;
            double score, factor;

            switch (difficulty)
            {
            case GameDifficulty.Easy:
                logbase = 10;
                break;

            case GameDifficulty.Medium:
                logbase = 20;
                break;

            case GameDifficulty.Master:
                logbase = 30;
                break;

            default:
                throw new InvalidOperationException("Invalid switch value");
            }

            switch (type)
            {
            case GameTypes.LogicPuzzle:
                scored = history.LogicRawScore;
                played = history.LogicPlayed;
                won    = history.LogicWon;
                break;

            case GameTypes.Memory:
                scored = history.MemoryRawScore;
                played = history.MemoryPlayed;
                won    = history.MemoryWon;
                break;

            case GameTypes.Calculation:
                scored = history.MathRawScore;
                played = history.MathPlayed;
                won    = history.MathWon;
                break;

            case GameTypes.VerbalAnalogy:
                scored = history.VerbalRawScore;
                played = history.VerbalPlayed;
                won    = history.VerbalWon;
                break;

            default:
                throw new InvalidOperationException("Invalid switch value");
            }

            // Simple percentage of games won vs played
            score = scored > 0 ? scored / played * 10 : 0;

            // Puts score of the game in prespective for the whole game
            factor = Math.Log(won + 2, logbase);              // +2 to avoid log 0

            score = score * factor;

            if (score > 100)
            {
                score = 100;
            }

            return((int)score);
        }
Ejemplo n.º 6
0
        /*
         *      Session
         */


        /*
         *      How the game session is scored
         *
         * Every game has a scoring algorithm that scores the player performance within the game.
         *        This takes into account time used and tips (result is from 0 to 10)
         * The results are added to the games and scores arrays where we store the results for
         *        the different game types (verbal, logic, etc)
         * We apply a SessionScoreFormula function that balances the total result with the number of
         *        games played (is not the same 100% games won playing 2 than 10 games) and the difficulty
         *
         *      The final result is a number from 0 to 100
         */
        static public void SessionUpdateHistoryScore(ref GameSessionHistoryExtended history, GameTypes type, GameDifficulty difficulty, int game_score)
        {
            bool won;
            int  components = 0;

            won = (game_score > 0 ? true : false);

            if (won == true)
            {
                history.GamesWon++;
            }

            switch (type)
            {
            case GameTypes.LogicPuzzle:
                history.LogicRawScore += game_score;
                history.LogicPlayed++;
                if (won)
                {
                    history.LogicWon++;
                }
                history.LogicScore = SessionScoreFormula(ref history, type, difficulty);
                break;

            case GameTypes.Memory:
                history.MemoryRawScore += game_score;
                history.MemoryPlayed++;
                if (won)
                {
                    history.MemoryWon++;
                }
                history.MemoryScore = SessionScoreFormula(ref history, type, difficulty);
                break;

            case GameTypes.Calculation:
                history.MathRawScore += game_score;
                history.MathPlayed++;
                if (won)
                {
                    history.MathWon++;
                }
                history.MathScore = SessionScoreFormula(ref history, type, difficulty);
                break;

            case GameTypes.VerbalAnalogy:
                history.VerbalRawScore += game_score;
                history.VerbalPlayed++;
                if (won)
                {
                    history.VerbalWon++;
                }
                history.VerbalScore = SessionScoreFormula(ref history, type, difficulty);
                break;

            default:
                throw new InvalidOperationException("Invalid switch value");
            }

            history.TotalScore = 0;

            // Updates total score taking only into account played game types
            if (history.LogicScore >= 0)
            {
                history.TotalScore += history.LogicScore;
                components++;
            }

            if (history.MemoryScore >= 0)
            {
                history.TotalScore += history.MemoryScore;
                components++;
            }

            if (history.MathScore >= 0)
            {
                history.TotalScore += history.MathScore;
                components++;
            }

            if (history.VerbalScore >= 0)
            {
                history.TotalScore += history.VerbalScore;
                components++;
            }

            history.TotalScore = history.TotalScore / components;
        }
Ejemplo n.º 7
0
        //
        // Applies scoring formula to the session
        //
        static int SessionScoreFormula(ref GameSessionHistoryExtended history, GameTypes type, GameDifficulty difficulty)
        {
            int logbase, scored, played, won;
            double score, factor;

            switch (difficulty) {
            case GameDifficulty.Easy:
                logbase = 10;
                break;
            case GameDifficulty.Medium:
                logbase = 20;
                break;
            case GameDifficulty.Master:
                logbase = 30;
                break;
            default:
                throw new InvalidOperationException ("Invalid switch value");
            }

            switch (type) {
            case GameTypes.LogicPuzzle:
                scored = history.LogicRawScore;
                played = history.LogicPlayed;
                won = history.LogicWon;
                break;
            case GameTypes.Memory:
                scored = history.MemoryRawScore;
                played = history.MemoryPlayed;
                won = history.MemoryWon;
                break;
            case GameTypes.Calculation:
                scored = history.MathRawScore;
                played = history.MathPlayed;
                won = history.MathWon;
                break;
            case GameTypes.VerbalAnalogy:
                scored = history.VerbalRawScore;
                played = history.VerbalPlayed;
                won = history.VerbalWon;
                break;
            default:
                throw new InvalidOperationException ("Invalid switch value");
            }

            // Simple percentage of games won vs played
            score = scored > 0 ? scored / played * 10 : 0;

            // Puts score of the game in prespective for the whole game
            factor = Math.Log (won + 2, logbase); // +2 to avoid log 0

            score = score * factor;

            if (score > 100) score = 100;

            return (int) score;
        }
Ejemplo n.º 8
0
        /*
            Session
        */
        /*
            How the game session is scored

            * Every game has a scoring algorithm that scores the player performance within the game.
           	  This takes into account time used and tips (result is from 0 to 10)
            * The results are added to the games and scores arrays where we store the results for
              the different game types (verbal, logic, etc)
            * We apply a SessionScoreFormula function that balances the total result with the number of
          		  games played (is not the same 100% games won playing 2 than 10 games) and the difficulty

            The final result is a number from 0 to 100
        */
        public static void SessionUpdateHistoryScore(ref GameSessionHistoryExtended history, GameTypes type, GameDifficulty difficulty, int game_score)
        {
            bool won;
            int components = 0;

            won = (game_score > 0 ? true : false);

            if (won == true) {
                history.GamesWon++;
            }

            switch (type) {
            case GameTypes.LogicPuzzle:
                history.LogicRawScore += game_score;
                history.LogicPlayed++;
                if (won) history.LogicWon++;
                history.LogicScore = SessionScoreFormula (ref history, type, difficulty);
                break;
            case GameTypes.Memory:
                history.MemoryRawScore += game_score;
                history.MemoryPlayed++;
                if (won) history.MemoryWon++;
                history.MemoryScore = SessionScoreFormula (ref history, type, difficulty);
                break;
            case GameTypes.Calculation:
                history.MathRawScore += game_score;
                history.MathPlayed++;
                if (won) history.MathWon++;
                history.MathScore = SessionScoreFormula (ref history, type, difficulty);
                break;
            case GameTypes.VerbalAnalogy:
                history.VerbalRawScore += game_score;
                history.VerbalPlayed++;
                if (won) history.VerbalWon++;
                history.VerbalScore = SessionScoreFormula (ref history, type, difficulty);
                break;
            default:
                throw new InvalidOperationException ("Invalid switch value");
            }

            history.TotalScore = 0;

            // Updates total score taking only into account played game types
            if (history.LogicScore >= 0) {
                history.TotalScore += history.LogicScore;
                components++;
            }

            if (history.MemoryScore >= 0) {
                history.TotalScore += history.MemoryScore;
                components++;
            }

            if (history.MathScore >= 0) {
                history.TotalScore += history.MathScore;
                components++;
            }

            if (history.VerbalScore >= 0) {
                history.TotalScore += history.VerbalScore;
                components++;
            }

            history.TotalScore = history.TotalScore / components;
        }