// Draw a grid, and possibly also a checkerboard (if drawCheckerBoard == true), // that has "rows" rows and "columns" columns, and in which each cell has dimensions // "rectangleWidth" pixels by "rectangleHeight" private void DrawGrid(int rows, int columns, int rectangleWidth, int rectangleHeight, bool drawCheckerBoard) { Graphics grid = Graphics.FromImage(GridBitmap); SolidBrush fillColourBrush = new SolidBrush(Color.Red); //Needed only for checkerboard grid.Clear(GridPictureBox.BackColor); for (int row = 0; row <= rows; row++) { for (int column = 0; column <= columns; column++) { // Draw unfilled rectangle grid.DrawRectangle(Pens.Black, row * rectangleWidth, column * rectangleHeight, rectangleWidth, rectangleHeight); if (drawCheckerBoard) // Fill rectangle with black or red { // Select the brush colour (alternate red and black) fillColourBrush.Color = ((row + column) % 2 == 0) ? Color.Black : Color.Red; // Fill the rectangle grid.FillRectangle(fillColourBrush, row * rectangleWidth, column * rectangleHeight, rectangleWidth, rectangleHeight); } } } //Raise the 'Paint' event on 'GridPictureBox.' GridPictureBox.Refresh(); //Release resources used by the graphics object. grid.Dispose(); }
private void Glider_button_Click(object sender, EventArgs e) { GridPictureBox.Refresh(); try { Map_width = int.Parse(widthTextBox.Text); Map_height = int.Parse(heightTextBox.Text); } catch (System.FormatException) { System.Windows.Forms.MessageBox.Show("Upośledzony czy niespełna rozumu - tylko cyferki"); } Map = new Grid(Map_width, Map_height); Map.Map[Map_height / 2, Map_width / 2].setCellState(true); Map.Map[Map_height / 2, (Map_width / 2) - 1].setCellState(true); Map.Map[(Map_height / 2) - 1, (Map_width / 2) - 1].setCellState(true); Map.Map[(Map_height / 2) - 1, (Map_width / 2) - 2].setCellState(true); Map.Map[(Map_height / 2) - 2, Map_width / 2].setCellState(true); DrawCells(Map.Map); }
private void Random_button_Click(object sender, EventArgs e) { GridPictureBox.Refresh(); try { Map_width = int.Parse(widthTextBox.Text); Map_height = int.Parse(heightTextBox.Text); } catch (System.FormatException) { System.Windows.Forms.MessageBox.Show("Upośledzony czy niespełna rozumu - tylko cyferki"); } Random random = new Random(); Map = new Grid(Map_width, Map_height); for (int i = 0; i < Map_height; i++) { for (int j = 0; j < Map_width; j++) { Map.Map[i, j].setCellState(Convert.ToBoolean(random.Next(2))); } } DrawCells(Map.Map); }
private void DrawGrid_Click(object sender, EventArgs e) { click_counter = 0; GridPictureBox.Refresh(); try { Map_width = int.Parse(widthTextBox.Text); Map_height = int.Parse(heightTextBox.Text); numberOfStates = int.Parse(liczbaZarodkowCheckBox.Text); radius = int.Parse(promieniowoTextBox.Text); BC = bcComboBox.SelectedIndex; neighbourhoodType = neighbourhoodTypeTextBox.SelectedIndex; if (Map_width < 0 || Map_height < 0 || numberOfStates < 0 || radius < 0) { throw new System.FormatException(); } setColorTable(); Map = new Grid(Map_width, Map_height, numberOfStates + 1, radius, BC, neighbourhoodType); DrawCells(Map.Map); } catch (System.FormatException) { System.Windows.Forms.MessageBox.Show("Upośledzony czy niespełna rozumu - tylko cyferki"); } }
/// <summary> /// При изменении выделенного аккорда в визуальном списке отображает на картинке его зажатые лады, название и начальный лад /// при удалении аккорда, идет смена активного элемента и значение устантанавливается в нулевое положение (иначе null) /// </summary> private void ListOfChordNamesListBox_SelectedIndexChanged(object sender, EventArgs e) { if (ListOfChordNamesListBox.SelectedItem != null) { if (_listOfChords.Chords.Find(x => x.Name == ListOfChordNamesListBox.SelectedItem.ToString()) != null) { _graphic = GridPictureBox.CreateGraphics(); GridPictureBox.Refresh(); Chord selectedChord = _listOfChords.Chords.Find(x => x.Name == ListOfChordNamesListBox.SelectedItem.ToString()); // Временный класс для работы с ним ChordNameLabel.Text = ListOfChordNamesListBox.SelectedItem.ToString(); ChordBeginFretLabel.Text = _listOfChords.Chords.Find(x => x.Name == ListOfChordNamesListBox.SelectedItem.ToString()).BeginFret.ToString(); for (int i = 0; i < selectedChord.Points.Count; i++) { _draw.DrawPoint(_graphic, selectedChord.Points[i].X, selectedChord.Points[i].Y); } } } else { ListOfChordNamesListBox.SelectedIndex = -1; ChordBeginFretLabel.Text = ""; ChordNameLabel.Text = ""; GridPictureBox.Refresh(); } }
private void EraseButton_Click(object sender, EventArgs e) { Graphics grid = Graphics.FromImage(GridBitmap); grid.Clear(GridPictureBox.BackColor); GridPictureBox.Refresh(); // Raise the "Paint" event }
/// <summary> /// При нажатии создает точку где зажимается аккорд. Записывает координаты во временный контейнер /// </summary> private void GridPictureBox_MouseDown(object sender, MouseEventArgs e) { _graphic = GridPictureBox.CreateGraphics(); if (e.X > 50 && e.X < 230 && e.Y > 50 && e.Y < 260) { _tempCoordinatesList.Add(_draw.Point(e.X, e.Y, _graphic)); } }
private void JednorodnyButton_Click(object sender, EventArgs e) { setColorTable(); Random rand = new Random(); GridPictureBox.Refresh(); click_counter = 0; try { Map_width = int.Parse(widthTextBox.Text); Map_height = int.Parse(heightTextBox.Text); numberOfStates = int.Parse(liczbaZarodkowCheckBox.Text); columns = int.Parse(columnTextBox.Text); rows = int.Parse(rowsTextBox.Text); radius = int.Parse(promieniowoTextBox.Text); BC = bcComboBox.SelectedIndex; neighbourhoodType = neighbourhoodTypeTextBox.SelectedIndex; if (Map_width < 0 || Map_height < 0 || numberOfStates < 0 || columns < 0 || rows < 0 || radius < 0) { throw new System.FormatException(); } } catch (System.FormatException) { System.Windows.Forms.MessageBox.Show("Upośledzony czy niespełna rozumu - tylko cyferki"); return; } Map = new Grid(Map_width, Map_height, numberOfStates + 1, radius, BC, neighbourhoodType); int deltaRows = Map_height / rows; int deltaColumns = Map_width / columns; if (deltaRows == 0) { deltaRows = 1; } if (deltaColumns == 0) { deltaRows = 1; } int cellCounter = 1; for (int i = 0; i < rows; ++i) { for (int j = 0; j < columns; ++j) { if (cellCounter < numberOfStates + 1) { Map.Map[(i * deltaRows), (j * deltaColumns)].setCellState(cellCounter); cellCounter++; } } } DrawCells(Map.Map); }
/// <summary> /// Очищает все, создаёт пустую рабочую среду /// </summary> private void CreateNewLibraryButton_Click(object sender, EventArgs e) { NameOfCurrentLibraryLabel.Text = "Новая библиотека"; ChordNameLabel.Text = string.Empty; ChordBeginFretLabel.Text = string.Empty; GridPictureBox.Refresh(); ListOfChordNamesListBox.Items.Clear(); _listOfChords.Chords.Clear(); }
private void RandomStateButton_Click(object sender, EventArgs e) { setColorTable(); click_counter = 0; Random rand = new Random(); GridPictureBox.Refresh(); try { Map_width = int.Parse(widthTextBox.Text); Map_height = int.Parse(heightTextBox.Text); numberOfStates = int.Parse(liczbaZarodkowCheckBox.Text); radius = int.Parse(promieniowoTextBox.Text); BC = bcComboBox.SelectedIndex; neighbourhoodType = neighbourhoodTypeTextBox.SelectedIndex; if (Map_width < 0 || Map_height < 0 || numberOfStates < 0 || radius < 0) { throw new System.FormatException(); } } catch (System.FormatException) { System.Windows.Forms.MessageBox.Show("Upośledzony czy niespełna rozumu - tylko cyferki dodatnie"); return; } int RandomCounter = 1; int indexI, indexJ; Map = new Grid(Map_width, Map_height, numberOfStates + 1, radius, BC, neighbourhoodType); while (RandomCounter < numberOfStates + 1) { indexI = rand.Next(0, Map_height); indexJ = rand.Next(0, Map_width); if (Map.Map[indexI, indexJ].getCellState() == 0) { Map.Map[indexI, indexJ].setCellState(RandomCounter); RandomCounter++; } else { indexI = rand.Next(0, Map_height); indexJ = rand.Next(0, Map_width); } } DrawCells(Map.Map); }
private void RandomStateButton_Click(object sender, EventArgs e) { setColorTable(); click_counter = 0; Random rand = new Random(); GridPictureBox.Refresh(); try { Map_width = int.Parse(widthTextBox.Text); Map_height = int.Parse(heightTextBox.Text); numberOfStates = int.Parse(liczbaZarodkowCheckBox.Text); } catch (System.FormatException) { System.Windows.Forms.MessageBox.Show("Upośledzony czy niespełna rozumu - tylko cyferki"); return; } int RandomCounter = 1; int indexI, indexJ; Map = new Grid(Map_width, Map_height, numberOfStates + 1); while (RandomCounter < numberOfStates + 1) { indexI = rand.Next(0, Map_height); indexJ = rand.Next(0, Map_width); if (Map.Map[indexI, indexJ].getCellState() == 0) { Map.Map[indexI, indexJ].setCellState(RandomCounter); RandomCounter++; } else { indexI = rand.Next(0, Map_height); indexJ = rand.Next(0, Map_width); } } DrawCells(Map.Map); }
private void DrawGrid_Click(object sender, EventArgs e) { setColorTable(); click_counter = 0; GridPictureBox.Refresh(); try { Map_width = int.Parse(widthTextBox.Text); Map_height = int.Parse(heightTextBox.Text); numberOfStates = int.Parse(liczbaZarodkowCheckBox.Text); } catch (System.FormatException) { System.Windows.Forms.MessageBox.Show("Upośledzony czy niespełna rozumu - tylko cyferki"); } Map = new Grid(Map_width, Map_height, numberOfStates + 1); DrawCells(Map.Map); }
//Solution: //{ // { 8, 2, 4, 1, 3, 9, 5, 7, 6 }, // { 1, 6, 5, 4, 7, 2, 3, 9, 8 }, // { 3, 7, 9, 6, 8, 5, 1, 2, 4 }, // { 6, 1, 8, 5, 9, 7, 2, 4, 3 }, // { 5, 9, 2, 3, 4, 8, 7, 6, 1 }, // { 4, 3, 7, 2, 1, 6, 9, 8, 5 }, // { 2, 5, 3, 7, 6, 4, 8, 1, 9 }, // { 9, 4, 1, 8, 2, 3, 6, 5, 7 }, // { 7, 8, 6, 9, 5, 1, 4, 3, 2 } //}; #endregion #region Constructor Method public SudokuSolver() { InitializeComponent(); //Draw 9x9 Grid Graphics grid = Graphics.FromImage(gridBitmap); SolidBrush grayBrush = new SolidBrush(Color.LightGray); int rectWidth = 50, rectHeight = 50; for (int row = 0; row < 9; ++row) { for (int col = 0; col < 9; ++col) { Rectangle rect = new Rectangle(col * rectWidth, row * rectHeight, rectWidth, rectHeight); Color colour = SystemColors.Control; if (row < 3 || row > 5) { if (col >= 3 && col <= 5) { grid.FillRectangle(grayBrush, rect); colour = Color.LightGray; } } else { if (col < 3 || col > 5) { grid.FillRectangle(grayBrush, rect); colour = Color.LightGray; } } grid.DrawRectangle(Pens.Black, rect); GenerateNewBox(row.ToString() + col.ToString(), new Point(col * rectWidth + 28, row * rectHeight + 28), colour); } } GridPictureBox.Refresh(); // raise paint event of GridPictureBox GridPictureBox.SendToBack(); // send to back to input boxes are visible and available grid.Dispose(); // release graphics object }
private void GunButton_Click(object sender, EventArgs e) { GridPictureBox.Refresh(); widthTextBox.Text = "40"; heightTextBox.Text = "40"; try { Map_width = int.Parse(widthTextBox.Text); Map_height = int.Parse(heightTextBox.Text); } catch (System.FormatException) { System.Windows.Forms.MessageBox.Show("Upośledzony czy niespełna rozumu - tylko cyferki"); } Map = new Grid(Map_width, Map_height); Map.Map[19, 0].setCellState(true); Map.Map[19, 1].setCellState(true); Map.Map[20, 0].setCellState(true); Map.Map[20, 1].setCellState(true); Map.Map[19, 10].setCellState(true); Map.Map[20, 10].setCellState(true); Map.Map[21, 10].setCellState(true); Map.Map[18, 11].setCellState(true); Map.Map[22, 11].setCellState(true); Map.Map[17, 12].setCellState(true); Map.Map[17, 13].setCellState(true); Map.Map[23, 12].setCellState(true); Map.Map[23, 13].setCellState(true); Map.Map[20, 14].setCellState(true); Map.Map[19, 16].setCellState(true); Map.Map[20, 16].setCellState(true); Map.Map[21, 16].setCellState(true); Map.Map[18, 15].setCellState(true); Map.Map[22, 15].setCellState(true); Map.Map[20, 17].setCellState(true); Map.Map[17, 21].setCellState(true); Map.Map[18, 21].setCellState(true); Map.Map[19, 21].setCellState(true); Map.Map[17, 20].setCellState(true); Map.Map[18, 20].setCellState(true); Map.Map[19, 20].setCellState(true); Map.Map[16, 22].setCellState(true); Map.Map[20, 22].setCellState(true); Map.Map[16, 24].setCellState(true); Map.Map[15, 24].setCellState(true); Map.Map[20, 24].setCellState(true); Map.Map[21, 24].setCellState(true); Map.Map[18, 34].setCellState(true); Map.Map[18, 35].setCellState(true); Map.Map[17, 34].setCellState(true); Map.Map[17, 35].setCellState(true); DrawCells(Map.Map); }
/// <summary> /// Стирает все точки на сетке и очищает временный контейнер точек _tempCoordinatesList /// </summary> private void ClearButton_Click(object sender, EventArgs e) { GridPictureBox.Refresh(); _tempCoordinatesList.Clear(); }