Exemplo n.º 1
0
        // Taking a GameLocator list builds the play_list
        void BuildPlayList(GameLocator [] all_games)
        {
            if ((game_type & GameSession.Types.Custom) == GameSession.Types.Custom)
            {
                throw new InvalidOperationException();
            }

            ArrayListIndicesRandom indices = new ArrayListIndicesRandom(all_games.Length);

            indices.Initialize();
            play_list.Clear();

            // Decide which game types are part of the list
            bool logic, memory, calculation, verbal;

            if ((game_type & GameSession.Types.AllGames) == GameSession.Types.AllGames)
            {
                logic = memory = calculation = verbal = true;
            }
            else
            {
                logic       = (game_type & GameSession.Types.LogicPuzzles) == GameSession.Types.LogicPuzzles;
                calculation = (game_type & GameSession.Types.Calculation) == GameSession.Types.Calculation;
                memory      = (game_type & GameSession.Types.Memory) == GameSession.Types.Memory;
                verbal      = (game_type & GameSession.Types.VerbalAnalogies) == GameSession.Types.VerbalAnalogies;
            }

            // Create item arrays for games types
            List <int> logic_indices       = new List <int> ();
            List <int> calculation_indices = new List <int> ();
            List <int> memory_indices      = new List <int> ();
            List <int> verbal_indices      = new List <int> ();

            if (logic)
            {
                logic_indices.AddRange(indices.Where(a => all_games[a].GameType == GameTypes.LogicPuzzle));
            }

            if (memory)
            {
                memory_indices.AddRange(indices.Where(a => all_games[a].GameType == GameTypes.Memory));
            }

            if (calculation)
            {
                calculation_indices.AddRange(indices.Where(a => all_games[a].GameType == GameTypes.Calculation));
            }

            if (verbal)
            {
                verbal_indices.AddRange(indices.Where(a => all_games[a].GameType == GameTypes.VerbalAnalogy));
            }

            CreateListWithDistributedGameTypes(logic_indices, calculation_indices, memory_indices, verbal_indices);
            enumerator = play_list.GetEnumerator();
        }
Exemplo n.º 2
0
 void UpdateEnumerator()
 {
     if (RandomOrder == true)
     {
         ArrayListIndicesRandom random = new ArrayListIndicesRandom(play_list.Count);
         random.RandomizeFromArray(play_list);
         enumerator = random.GetEnumerator();
     }
     else
     {
         enumerator = play_list.GetEnumerator();
     }
 }
Exemplo n.º 3
0
        // Taking a GameLocator list builds the play_list
        void BuildPlayList(List <GameLocator> all_games)
        {
            if ((game_type & GameSession.Types.Custom) == GameSession.Types.Custom)
            {
                throw new InvalidOperationException();
            }

            play_list.Clear();

            ArrayListIndicesRandom indices = new ArrayListIndicesRandom(all_games.Count);

            indices.Initialize();

            List <int> logic_indices = new List <int> (cnt_logic);
            List <int> calculation_indices = new List <int> (cnt_calculation);
            List <int> memory_indices = new List <int> (cnt_memory);
            List <int> verbal_indices = new List <int> (cnt_verbal);
            bool       logic, memory, calculation, verbal;

            // Decide which game_types are part of the game
            if ((game_type & GameSession.Types.AllGames) == GameSession.Types.AllGames)
            {
                logic = memory = calculation = verbal = true;
            }
            else
            {
                logic       = (game_type & GameSession.Types.LogicPuzzles) == GameSession.Types.LogicPuzzles;
                calculation = (game_type & GameSession.Types.Calculation) == GameSession.Types.Calculation;
                memory      = (game_type & GameSession.Types.Memory) == GameSession.Types.Memory;
                verbal      = (game_type & GameSession.Types.VerbalAnalogies) == GameSession.Types.VerbalAnalogies;
            }

            // Create arrays by game type
            for (int n = 0; n < all_games.Count; n++)
            {
                switch (all_games [indices [n]].GameType)
                {
                case GameTypes.LogicPuzzle:
                    if (logic)
                    {
                        logic_indices.Add(indices [n]);
                    }
                    break;

                case GameTypes.Memory:
                    if (memory)
                    {
                        memory_indices.Add(indices [n]);
                    }
                    break;

                case GameTypes.Calculation:
                    if (calculation)
                    {
                        calculation_indices.Add(indices [n]);
                    }
                    break;

                case GameTypes.VerbalAnalogy:
                    if (verbal)
                    {
                        verbal_indices.Add(indices [n]);
                    }
                    break;

                default:
                    throw new InvalidOperationException("Unknown value");
                }
            }

            int    total = logic_indices.Count + memory_indices.Count + calculation_indices.Count + verbal_indices.Count;
            int    pos_logic, pos_memory, pos_calculation, pos_verbal;
            Random random = new Random();

            pos_logic = pos_memory = pos_calculation = pos_verbal = 0;

            while (play_list.Count < total)
            {
                switch (random.Next(3))
                {
                case 0:
                    if (pos_calculation < calculation_indices.Count)
                    {
                        play_list.Add(calculation_indices[pos_calculation++]);
                    }
                    if (pos_logic < logic_indices.Count)
                    {
                        play_list.Add(logic_indices[pos_logic++]);
                    }
                    if (pos_memory < memory_indices.Count)
                    {
                        play_list.Add(memory_indices[pos_memory++]);
                    }
                    if (pos_verbal < verbal_indices.Count)
                    {
                        play_list.Add(verbal_indices[pos_verbal++]);
                    }
                    break;

                case 1:
                    if (pos_memory < memory_indices.Count)
                    {
                        play_list.Add(memory_indices[pos_memory++]);
                    }
                    if (pos_calculation < calculation_indices.Count)
                    {
                        play_list.Add(calculation_indices[pos_calculation++]);
                    }
                    if (pos_verbal < verbal_indices.Count)
                    {
                        play_list.Add(verbal_indices[pos_verbal++]);
                    }
                    if (pos_logic < logic_indices.Count)
                    {
                        play_list.Add(logic_indices[pos_logic++]);
                    }
                    break;

                case 2:
                    if (pos_calculation < calculation_indices.Count)
                    {
                        play_list.Add(calculation_indices[pos_calculation++]);
                    }
                    if (pos_verbal < verbal_indices.Count)
                    {
                        play_list.Add(verbal_indices[pos_verbal++]);
                    }
                    if (pos_memory < memory_indices.Count)
                    {
                        play_list.Add(memory_indices[pos_memory++]);
                    }
                    if (pos_logic < logic_indices.Count)
                    {
                        play_list.Add(logic_indices[pos_logic++]);
                    }
                    break;
                }
            }
            enumerator = play_list.GetEnumerator();
        }