private Field[] generateFields(string gameType, char[][] generatedSudoku)
        {
            IAsciiFactory asciiFactory = this.asciiFactoriesFactory.Create(gameType);

            int topLeftFieldStartRow = FieldConstants.FieldMinY;

            int offset = 1; // Used to overcome borders

            List <Field> fields = new List <Field>();

            // Loop over the generated array of digits and create new field object
            for (int row = 0; row < generatedSudoku.Length; row++)
            {
                int topLeftFieldStartCol = FieldConstants.FieldMinX;

                for (int col = 0; col < generatedSudoku[row].Length; col++)
                {
                    char[,] asciiSymbol = asciiFactory.GetAsciiCharacter(generatedSudoku[row][col].ToString());
                    Field newField = this.fieldFactory.Create(topLeftFieldStartCol, topLeftFieldStartRow, asciiSymbol, generatedSudoku[row][col], generatedSudoku[row][col] != '0', row, col);

                    if (newField.Value == 0)
                    {
                        newField.Content[0, 0] = FieldConstants.EmptyFieldSymbol;
                    }

                    fields.Add(newField);
                    topLeftFieldStartCol += FieldConstants.FieldCols + offset;
                }

                topLeftFieldStartRow += FieldConstants.FieldRows + offset;
            }

            return(fields.ToArray());
        }
Beispiel #2
0
        private void resolveAction(string gameType)
        {
            Field  fieldMatch  = this.searchField();
            Button buttonMatch = this.searchButton();

            if (fieldMatch != null)
            {
                this.interfaceService.SetCoordinates(BoardConstants.InformationRow, BoardConstants.InformationCol);
                this.interfaceService.SetForegroundColor(BoardConstants.DefaultPromptColor);
                this.writerService.Write(BoardConstants.PromptUserForInput);

                string pressedKey = this.readerService.ReadKeyboardInput().Last().ToString();

                IAsciiFactory asciiFactory = this.asciiFactoriesFactory.Create(gameType);
                char[,] asciiContent = asciiFactory.GetAsciiCharacter(pressedKey);

                IGameValueStrategy concreteValueStrategy = this.gameValueStrategyFactory.GetConcreteStrategy(pressedKey);

                // Validate and update field
                if (asciiContent != null && concreteValueStrategy != null)
                {
                    char value = concreteValueStrategy.GetValue();

                    fieldMatch.Value   = value;
                    fieldMatch.Content = asciiContent;

                    this.setDefaultColors();
                    this.updateBoard(fieldMatch);
                    this.drawNewField(fieldMatch);
                }
                else
                {
                    // ToDo If no strategy is registered in di container
                }

                this.setDefaultColors();
                this.clearUserPrompt();
            }
            else if (buttonMatch != null)
            {
                string commandName = buttonMatch.Id;

                IInGameCommand command = this.inGameCommandFactory.Create(commandName);
                command?.Execute();
            }
        }