Esempio n. 1
0
        public void Run()
        {
            this.runMainMenu();

            int[][] generatedSudoku = this.generateSudoku();

            this.boardManager.GenerateBoard();
            this.boardManager.InitializeFields(generatedSudoku);
            this.boardManager.DrawFieldsContentAndUpdateBoard();
            this.boardManager.InitializeButtons();

            while (true)
            {
                ConsoleManager.DefaultColors();
                ConsoleKeyInfo pressedKey = ConsoleManager.ReadKey();
                ConsoleManager.SetCursorPosition(this.mouse.PositionX, this.mouse.PositionY);

                int  oldPositionX           = this.mouse.PositionX;
                int  oldPositionY           = this.mouse.PositionY;
                char charToRefreshAfterMove = this.boardManager.GetCharByPosition(this.mouse.PositionX, this.mouse.PositionY);
                ConsoleManager.WriteSingleChar();

                switch (pressedKey.Key)
                {
                case ConsoleKey.UpArrow: this.mouse.PositionY--;
                    break;

                case ConsoleKey.DownArrow: this.mouse.PositionY++;
                    break;

                case ConsoleKey.LeftArrow: this.mouse.PositionX--;
                    break;

                case ConsoleKey.RightArrow: this.mouse.PositionX++;
                    break;

                case ConsoleKey.Enter: this.resolveOperation(this.mouse.PositionY, this.mouse.PositionX);
                    break;

                default:
                    break;
                }

                ConsoleManager.SetCursorPosition(oldPositionX, oldPositionY);
                ConsoleManager.WriteSingleChar(charToRefreshAfterMove);
                ConsoleManager.SetCursorPosition(this.mouse.PositionX, this.mouse.PositionY);
                Console.ForegroundColor = MouseConstants.MouseDefaultColor;
                ConsoleManager.WriteSingleChar(MouseConstants.MouseSymbol);
            }
        }
Esempio n. 2
0
        public void UpdateField(Field field)
        {
            if (!field.IsImmutable)
            {
                field.Content[0, 0] = FieldConstants.EmptyFieldSymbol;
            }

            ConsoleManager.SetCursorPosition(field.MinCol, field.MinRow);
            int maxRow = field.MinRow + FieldConstants.FieldRows;
            int maxCol = field.MinCol + FieldConstants.FieldCols;

            for (int row = field.MinRow, contentRow = 0; row < maxRow; row++, contentRow++)
            {
                for (int col = field.MinCol, contentCol = 0; col < maxCol; col++, contentCol++)
                {
                    ConsoleManager.SetCursorPosition(col, row);
                    ConsoleManager.WriteSingleChar(field.Content[contentRow, contentCol]);
                    this.board[row][col] = field.Content[contentRow, contentCol];
                }
            }

            ConsoleManager.DefaultColors();
        }