static void Main(string[] args) { Serializer serializer = new Serializer(9, "Обществознание"); CrosswordGame crosswordGame; for (int i = 0; i < 10; i++) { crosswordGame = new CrosswordGame(serializer.TermList); crosswordGame.GetMatrixOnConsole(); Console.WriteLine(); } Console.ReadKey(); }
public CrosswordGamePage(CrosswordGame crosswordGame) { InitializeComponent(); this.Width = SystemParameters.PrimaryScreenWidth; this.Height = SystemParameters.PrimaryScreenHeight; this._crosswordGame = crosswordGame; _crosswordTerms = crosswordGame.CrossWordTerms; _matrix = crosswordGame.CrosswordMatrix; _width = _matrix.GetLength(1); _height = _matrix.GetLength(0); CrosswordCanvas.Width = this.Width - 30; CrosswordCanvas.Height = (this.Height - 30) * 0.6; _mainWordTag = _crosswordTerms[0]; _writtenMainWordLetters = new bool[_height]; PrepareForm(); }
private void CrosswordStartBTN_Click(object sender, RoutedEventArgs e) { int lvl = LevelCheck(); _crosswordGame = new CrosswordGame(Serializer.TermList, lvl); if (_crosswordGame.IsReady) { if (!_isPdfSaving) { CrosswordGamePage crosswordGamePage = new CrosswordGamePage(_crosswordGame); crosswordGamePage.ShowDialog(); } } else { MessageBox.Show("Не удалось создать кроссворд, попробуйте добавить больше слов в словарь."); } }
private void CrosswordSaveToPdf(CrosswordGame game) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "pdf files (*.pdf)|*.pdf"; saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments); saveFileDialog.RestoreDirectory = false; DialogResult result = saveFileDialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { string fileName = saveFileDialog.FileName; FileStream fStream = new FileStream(Path.Combine(fileName), FileMode.Create); Document document = new Document(PageSize.A4, 10, 10, 50, 10); PdfWriter writer = PdfWriter.GetInstance(document, fStream); document.Open(); //шрифт для кириллицы BaseFont baseFont = BaseFont.CreateFont("image/arial.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font font = new Font(baseFont, Font.DEFAULTSIZE, Font.NORMAL); Font numFont = new Font(baseFont, 5, Font.NORMAL); //создание таблицы Phrase task = new Phrase("Решите кроссворд", font); Paragraph header = new Paragraph(task); header.Alignment = Element.ALIGN_CENTER; header.SpacingAfter = 30; document.Add(header); int count = 1; PdfPTable table = new PdfPTable(game.CrosswordMatrix.GetLength(1)); table.WidthPercentage = 100; table.DefaultCell.Border = Rectangle.NO_BORDER; char whiteSpaceChar = ' '; float cellHeight = document.PageSize.Width / game.CrosswordMatrix.GetLength(1); for (int i = 0; i < game.CrosswordMatrix.GetLength(0); i++) { bool firstLetterOfWord = !(_crosswordGame.CrossWordTerms[i + 1] == null); var numPhrase = new Phrase(count.ToString() + ".", numFont); for (int j = 0; j < game.CrosswordMatrix.GetLength(1); j++) { if (game.CrosswordMatrix[i, j] != null) { if (game.CrosswordMatrix[i, j].Letter != whiteSpaceChar) { if (game.MainWordHorizontalIndex == j) { if (firstLetterOfWord) { table.AddCell(new PdfPCell() { BackgroundColor = Color.LIGHT_GRAY, FixedHeight = cellHeight, Phrase = numPhrase }); firstLetterOfWord = false; } else { table.AddCell(new PdfPCell() { BackgroundColor = Color.LIGHT_GRAY, FixedHeight = cellHeight }); } } else { if (firstLetterOfWord) { table.AddCell(new PdfPCell() { FixedHeight = cellHeight, Phrase = numPhrase }); firstLetterOfWord = false; } else { table.AddCell(new PdfPCell() { FixedHeight = cellHeight }); } } } else { table.AddCell(new PdfPCell() { Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); } } else { table.AddCell(new PdfPCell() { Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); } } if (_crosswordGame.CrossWordTerms[i + 1] != null) { count++; } } table.SpacingAfter = 30; document.Add(table); task = new Phrase("По вертикали: ", font); header = new Paragraph(task); header.Alignment = Element.ALIGN_LEFT; header.SpacingAfter = 30; document.Add(header); var mainWord = game.CrossWordTerms[0]; Phrase phrase = new Phrase("1. " + mainWord.Description, font); Paragraph paragraph = new Paragraph(phrase); paragraph.SpacingAfter = 30; document.Add(paragraph); count = 1; task = new Phrase("По горизонтали: ", font); header = new Paragraph(task); header.Alignment = Element.ALIGN_LEFT; header.SpacingAfter = 30; document.Add(header); for (int i = 1; i < game.CrossWordTerms.Length; i++) { if (game.CrossWordTerms[i] != null) { phrase = new Phrase(count + ". " + game.CrossWordTerms[i].Description, font); paragraph = new Paragraph(phrase); paragraph.SpacingAfter = 10; document.Add(paragraph); count++; } } document.Close(); writer.Close(); fStream.Close(); var msgBoxResult = MessageBox.Show("Просмотреть файл?", "PDF", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes); if (msgBoxResult == MessageBoxResult.Yes) { System.Diagnostics.Process.Start(fileName); } } }