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();
        }
示例#2
0
        private void resolveOperation(int mouseRow, int mouseCol)
        {
            Field  fieldMatch  = this.boardManager.SearchForField(mouseCol, mouseRow);
            Button buttonMatch = this.boardManager.SearchForButton(mouseCol, mouseRow);

            if (fieldMatch != null)
            {
                ConsoleManager.SetCursorPosition(BoardConstants.InformationCol, BoardConstants.InformationRow);
                ConsoleManager.SetColor(BoardConstants.DefaultPromptColor);
                ConsoleManager.Write(BoardConstants.PromptUserForNumberInput);

                ConsoleKeyInfo pressedKey = ConsoleManager.ReadKey();

                AsciiNumberFactory asciiNumberFactory = this.modulesManager.GetService <AsciiNumberFactory>();

                switch (pressedKey.Key)
                {
                case ConsoleKey.NumPad0:
                case ConsoleKey.D0:
                    fieldMatch.Value   = 0;
                    fieldMatch.Content = asciiNumberFactory.GetNumberAscii(0);
                    break;

                case ConsoleKey.NumPad1:
                case ConsoleKey.D1:
                    fieldMatch.Value   = 1;
                    fieldMatch.Content = asciiNumberFactory.GetNumberAscii(1);
                    break;

                case ConsoleKey.NumPad2:
                case ConsoleKey.D2:
                    fieldMatch.Value   = 2;
                    fieldMatch.Content = asciiNumberFactory.GetNumberAscii(2);
                    break;

                case ConsoleKey.NumPad3:
                case ConsoleKey.D3:
                    fieldMatch.Value   = 3;
                    fieldMatch.Content = asciiNumberFactory.GetNumberAscii(3);
                    break;

                case ConsoleKey.NumPad4:
                case ConsoleKey.D4:
                    fieldMatch.Value   = 4;
                    fieldMatch.Content = asciiNumberFactory.GetNumberAscii(4);
                    break;

                case ConsoleKey.NumPad5:
                case ConsoleKey.D5:
                    fieldMatch.Value   = 5;
                    fieldMatch.Content = asciiNumberFactory.GetNumberAscii(5);
                    break;

                case ConsoleKey.NumPad6:
                case ConsoleKey.D6:
                    fieldMatch.Value   = 6;
                    fieldMatch.Content = asciiNumberFactory.GetNumberAscii(6);
                    break;

                case ConsoleKey.NumPad7:
                case ConsoleKey.D7:
                    fieldMatch.Value   = 7;
                    fieldMatch.Content = asciiNumberFactory.GetNumberAscii(7);
                    break;

                case ConsoleKey.NumPad8:
                case ConsoleKey.D8:
                    fieldMatch.Value   = 8;
                    fieldMatch.Content = asciiNumberFactory.GetNumberAscii(8);
                    break;

                case ConsoleKey.NumPad9:
                case ConsoleKey.D9:
                    fieldMatch.Value   = 9;
                    fieldMatch.Content = asciiNumberFactory.GetNumberAscii(9);
                    break;

                default:
                    break;
                }

                ConsoleManager.DefaultColors();
                this.boardManager.UpdateField(fieldMatch);

                ConsoleManager.SetCursorPosition(BoardConstants.InformationCol, BoardConstants.InformationRow);
                ConsoleManager.Clear(BoardConstants.PromptUserForNumberInput.Length);
            }
            else if (buttonMatch != null)
            {
                string commandName = buttonMatch.Id;

                CommandFactory commandFactory = this.modulesManager.GetService <CommandFactory>();
                ICommand       cmd            = commandFactory.GetCommand(commandName);

                cmd.Execute(this.boardManager.Fields);
            }

            ConsoleManager.SetCursorPosition(mouseCol, mouseRow);
        }