Esempio n. 1
0
        public SudokuWrapper()
        {
            sudoku = new Sudoku.Game();

            int canWrite;

            sudoku.create();
            sudoku.write(out canWrite);
        }
Esempio n. 2
0
 public TimerRunnable(Game container)
 {
     this.container = container;
 }
Esempio n. 3
-1
 public OptionsListener(Game container)
 {
     this.container = container;
 }
Esempio n. 4
-1
 /// <summary>
 /// Form OnLoad event. Initializes the game object
 /// and sets the Add More Puzzles open dialog initial
 /// directory (can't put it in Sudoku.Designer.cs because it
 /// doesn't seem to access Application.ExecutablePath).
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Sudoku_Load(object sender, EventArgs e)
 {
     this.game = new Game(grpBoxPuzzle);
     this.openAddNewPuzzles.InitialDirectory =
         System.IO.Path.GetDirectoryName(Application.ExecutablePath);
 }
Esempio n. 5
-1
        /// <summary>
        /// constructer that creates the puzzle with supplied string. 
        /// It also sorts the squares into groupings of rows, columns, 
        /// and blocks.
        /// </summary>
        /// <param name="game">
        /// This is the game that this puzzle is a member of.
        /// </param>
        /// <param name="puzzle">
        /// String representing the puzzle to be solved.
        /// </param>
        public Puzzle(Game game, String puzzle)
        {
            this.game = game;
            this.puzzleString = puzzle;
            int charPos = 1; // 1 instead of 0 to avoid difficulty character.

            // Initialize square groupings:
            for (int g = 0; g < 9; g++)
            {
                this.rows[g] = new Group();
                this.columns[g] = new Group();
                this.blocks[g] = new Group();
            }

            // Put squares into puzzle array:
            for (int i = 0; i < 9; i++)     // create 9 rows
            {
                for (int j = 0; j < 9; j++, charPos++) // create 9 columns
                {
                    // check if its a fixed square:
                    if (PuzzleString[charPos] == "F"[0])
                    {
                        charPos++;            // must turn the char into a
                                              // string, then parse as int
                        this.puzzle[i,j] = new FixedSquare(this, i, j,
                                               int.Parse(
                                               this.PuzzleString[charPos].
                                               ToString()));
                    }
                    // else it's a user square:
                    else
                    {
                        this.puzzle[i, j] = new UserSquare(this, i, j,
                                                int.Parse(
                                                this.PuzzleString[charPos].
                                                ToString()));
                    }
                    this.puzzle[i, j].InitButton();  // Position button on grid.
                    this.game.GetGrid().Controls.Add(
                          this.puzzle[i,j].Button);  // Add button to grid.

                    // add squares to rows and columns groupings:
                    this.rows[i].AddSquare(this.puzzle[i, j]);
                    this.columns[j].AddSquare(this.puzzle[i, j]);
                }
            }

            // add squares into groupings of blocks
            //   (look at python script for algorithm development):
            for (int k = 0; k < 3; k++)
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 9; j++)
                    {
                        // calculate correct block group (perhaps more
                        // complicated than need-be):
                        int blockIndex = (((i/3)+1)*((j/3)+1)+(3*k))-1;
                        this.blocks[blockIndex].AddSquare(
                                                    this.puzzle[(i+(3*k)), j]);
                    }
                }
            }

            // Select the first usersquare in the puzzle so that pressing a
            //  control button does not crash the program.
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (this.puzzle[i, j] is UserSquare)
                    {
                        this.puzzle[i, j].Button.Select();
                        this.puzzle[i, j].Button.PerformClick();
                        return;
                    }
                }
            }
        }
Esempio n. 6
-1
 /// <summary>
 /// Load game variable into the puzzle after deserialization (because
 /// game object is not serialized).
 /// </summary>
 /// <param name="game">game to load</param>
 public void Load(Game game)
 {
     // re-create game after deserializing saved game:
     this.game = game;
     for (int i = 0; i < 9; i++)
     {
         for (int j = 0; j < 9; j++)
         {
             // reinitialize each button and add it to the grid.
             this.puzzle[i, j].InitButton();
             this.game.GetGrid().Controls.Add(this.puzzle[i, j].Button);
         }
     }
 }