Ejemplo n.º 1
0
        private static Int32 GetMaskedValue(DifficultyLevels level)
        {
            Int32 min;
            Int32 max;

            switch (level)
            {
            case DifficultyLevels.VeryEasy:                 // If the difficulty level is very easy
                min = 50;                                   // Number of given is between 50 and 60
                max = 60;
                break;

            case DifficultyLevels.Easy:                     // If the difficulty level is easy
                min = 36;                                   // Number of given is between 36 and 49
                max = 49;
                break;

            case DifficultyLevels.Medium:                   // If the difficulty level is medium
                min = 32;                                   // Number of given is between 32 and 35
                max = 35;
                break;

            case DifficultyLevels.Hard:                     // If the difficulty level is hard
                min = 28;                                   // Number of given is between 28 and 31
                max = 31;
                break;

            default:                                        // Default is expert level.
                min = 22;                                   // Number of given is between 22 and 27
                max = 27;
                break;
            }
            return(RandomClass.GetRandomInt(min, max));      // Return a random number between the min and max
        }
Ejemplo n.º 2
0
        private void GenerateGrid()
        {
            List <Int32>[] available = InitializeArray();                       // Initialize the list
            Int32          index     = 0;                                       // Set the index pointer to zero

            do
            {
                if (available[index].Count > 0)                                        // If more number available
                {
                    Int32     i    = RandomClass.GetRandomInt(available[index].Count); // Get a random number
                    CellClass item = new CellClass(index, available[index][i]);        // Create a new
                    if (Conflicts(item))                                               // Any conflicts with existing cells?
                    {
                        available[index].RemoveAt(i);                                  // Yes, remove it from the available list
                        item = null;                                                   // Clear the CellClass pointer
                    }
                    else
                    {                                                           // No conflicts
                        _cells[index] = item;                                   // Save the CellClass to the array
                        item          = null;                                   // Clear the CellClass pointer
                        available[index].RemoveAt(i);                           // Remove it from the available list
                        index++;                                                // Increment the index pointer
                    }
                }
                else
                {                                                               // No more number available
                    available[index] = InitArray();                             // Re-initialize the available list
                    index--;                                                    // To back one spot
                    _cells[index] = null;                                       // Clear the array pointer
                }
            } while (index < 81);                                               // Keep looping until there are no more cells to process
        }
Ejemplo n.º 3
0
 private static void CheckInstance()
 {
     if (_instance == null)                          // Is the instance variable null?
     {
         lock (_instanceLock)                        // Yes, obtain a lock on the instance object
         {
             if (_instance == null)                  // Check if the instance variable is null again
             {
                 _instance = new RandomClass();      // Instantiate a Random class
                 _instance.InitInstance();           // Initialize the instance
             }
         }
     }
 }
Ejemplo n.º 4
0
        private static CellIndex FindRandomCell(List <CellClass> list)
        {
            Int32 index = RandomClass.GetRandomInt(list.Count - 1);             // Find a random cell in the list

            return(list[index].CellIndex);                                      // Return the CellIndex of the selected cell
        }