Exemplo n.º 1
0
        // -------------------------------------------------------------------------------
        public static void Start()
        {
            //
            s_RowIndex    = 0;
            s_ColumnIndex = 0;

            GridGenerator.Start();
            s_Grids       = GridGenerator.Grids;
            s_GridsSolver = GridGenerator.GridsSolver;

            //
            while (isConstant(s_Grids, 0, s_ColumnIndex))
            {
                if (s_ColumnIndex > 8)
                {
                    s_ColumnIndex = 0;
                }
                s_ColumnIndex++;
            }

            //GridDebug.T(s_ColumnIndex, "s_ColumnIndex");
            Show(s_Grids);

            GridControl.Solver(s_Grids);
            MessageText.SudokuMenu();
            MessageText.SudokuStatus();
            MessageText.SudokuNewGame();

            Keyboard();
        }
Exemplo n.º 2
0
        // -------------------------------------------------------------------------------
        public static void GameOver()
        {
            //
            Show(s_GridsSolver);
            MessageText.SudokuGameOver();

            Console.ReadKey();
            Start();
        }
Exemplo n.º 3
0
        // -------------------------------------------------------------------------------
        public static bool Edit(Grid[,] Grids, int RowIndex, int ColumnIndex, int Mode = 1)
        {
            //
            bool FlagError = false;

            s_RowIndex    = RowIndex;
            s_ColumnIndex = ColumnIndex;
            s_Grids       = Grids;

            s_Node   = Grids[RowIndex, ColumnIndex].Node;
            s_Row    = Grids[RowIndex, ColumnIndex].Row;
            s_Column = Grids[RowIndex, ColumnIndex].Column;
            s_Value  = Grids[RowIndex, ColumnIndex].Value;

            if (Mode == 1)
            {
                Clear(Grids);
            }

            //if (_Row(Grids))
            //if (_Column(Grids))
            //if (_Node(Grids))
            //if (_Row(Grids) | _Column(Grids))
            if (_Node() | _Column() | _Row())
            {
                FlagError = true;
                Grids[RowIndex, ColumnIndex].Control = Grid.Flag.ERROR;
                MessageText.SudokuError();
            }
            else
            {
                Grids[RowIndex, ColumnIndex].Control = Grid.Flag.OK;
                MessageText.SudokuOk();
            }

            if (Mode == 1)
            {
                Solver();
            }

            Grids[RowIndex, ColumnIndex].Edit();

            //ShowText();

            return(FlagError);
        }
Exemplo n.º 4
0
        // -------------------------------------------------------------------------------
        public static bool All(Grid[,] Grids)
        {
            // Проверка всей сетки.
            bool FlagError = false;

            Clear(Grids);

            for (int Row = 0; Row < 9; Row++)
            {
                for (int Column = 0; Column < 9; Column++)
                {
                    if (Edit(Grids, Row, Column, 0))
                    {
                        FlagError = true;
                    }
                }
            }


            if (FlagError)
            {
                MessageText.SudokuError(); // Есть ошибки.
            }
            else
            {
                if (Global.isStatusGridsFull())
                {
                    MessageText.SudokuVictory(); // Вы выиграли. Судока решена.
                }
                else
                {
                    MessageText.SudokuOk(); // Ошибок нет.
                }
            }

            return(FlagError);
        }
Exemplo n.º 5
0
        // -------------------------------------------------------------------------------
        public static void Solver()
        {
            // Проверка - заполнены все сетки.
            Global.StatusGridsFull = 0;

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (s_Grids[i, j].Value != 0)
                    {
                        Global.StatusGridsFull++;
                    }
                }
            }

            //
            if (Global.isStatusGridsFull())
            {
                All(s_Grids);
            }

            MessageText.SudokuStatus();
        }