Добавление новой логики формы FormSailboat

This commit is contained in:
Софья Якобчук 2023-11-28 02:00:40 +04:00
parent 8f8380b986
commit 0a07bace59
2 changed files with 54 additions and 44 deletions

View File

@ -37,6 +37,7 @@
buttonCreateSailboat = new Button(); buttonCreateSailboat = new Button();
comboBoxStrategy = new ComboBox(); comboBoxStrategy = new ComboBox();
buttonStep = new Button(); buttonStep = new Button();
buttonSelectBoat = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxSailboat).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxSailboat).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -140,11 +141,22 @@
buttonStep.UseVisualStyleBackColor = true; buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += buttonStep_Click; buttonStep.Click += buttonStep_Click;
// //
// buttonSelectBoat
//
buttonSelectBoat.Location = new Point(137, 243);
buttonSelectBoat.Name = "buttonSelectBoat";
buttonSelectBoat.Size = new Size(122, 40);
buttonSelectBoat.TabIndex = 9;
buttonSelectBoat.Text = "Выбрать лодку";
buttonSelectBoat.UseVisualStyleBackColor = true;
buttonSelectBoat.Click += buttonSelectBoat_Click;
//
// FormSailboat // FormSailboat
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(882, 453); ClientSize = new Size(882, 453);
Controls.Add(buttonSelectBoat);
Controls.Add(buttonStep); Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy); Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateSailboat); Controls.Add(buttonCreateSailboat);
@ -173,5 +185,6 @@
private Button buttonCreateSailboat; private Button buttonCreateSailboat;
private ComboBox comboBoxStrategy; private ComboBox comboBoxStrategy;
private Button buttonStep; private Button buttonStep;
private Button buttonSelectBoat;
} }
} }

View File

@ -12,28 +12,19 @@ using System.Windows.Forms;
namespace Sailboat namespace Sailboat
{ {
/// <summary>
/// Форма работы с объектом "Парусная лодка"
/// </summary>
public partial class FormSailboat : Form public partial class FormSailboat : Form
{ {
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawingBoat? _drawingBoat; private DrawingBoat? _drawingBoat;
private AbstractStrategy? _abstractStrategy; private AbstractStrategy? _abstractStrategy;
public DrawingBoat? SelectedBoat { get; private set; }
/// <summary>
/// Инициализация формы
/// </summary>
public FormSailboat() public FormSailboat()
{ {
InitializeComponent(); InitializeComponent();
_abstractStrategy = null;
SelectedBoat = null;
} }
/// <summary>
/// Метод прорисовки лодки
/// </summary>
private void Draw() private void Draw()
{ {
if (_drawingBoat == null) if (_drawingBoat == null)
@ -47,40 +38,45 @@ namespace Sailboat
pictureBoxSailboat.Image = bmp; pictureBoxSailboat.Image = bmp;
} }
/// <summary>
/// Обработка нажатия кнопки "Создать лодку"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateBoat_Click(object sender, EventArgs e) private void buttonCreateBoat_Click(object sender, EventArgs e)
{ {
Random random = new(); Random random = new();
_drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxSailboat.Width, pictureBoxSailboat.Height); Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, ColorDialog dialog = new();
100)); if (dialog.ShowDialog() == DialogResult.OK)
Draw(); {
} color = dialog.Color;
}
/// <summary> _drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxSailboat.Width, pictureBoxSailboat.Height);
/// Обработка нажатия кнопки "Создать улучшеную лодку" _drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
/// </summary> Draw();
/// <param name="sender"></param> }
/// <param name="e"></param>
private void buttonCreateSailboat_Click(object sender, EventArgs e) private void buttonCreateSailboat_Click(object sender, EventArgs e)
{ {
Random random = new(); Random random = new();
_drawingBoat = new DrawingSailboat(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Convert.ToBoolean(random.Next(0, 2)), ColorDialog dialog = new();
Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailboat.Width, pictureBoxSailboat.Height); if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
if (dialog.ShowDialog() == DialogResult.OK)
{
dopColor = dialog.Color;
}
_drawingBoat = new DrawingSailboat(random.Next(100, 300),
random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxSailboat.Width, pictureBoxSailboat.Height);
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }
/// <summary>
/// Изменение размеров формы
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonMove_Click(object sender, EventArgs e) private void buttonMove_Click(object sender, EventArgs e)
{ {
if (_drawingBoat == null) if (_drawingBoat == null)
@ -106,11 +102,6 @@ namespace Sailboat
Draw(); Draw();
} }
/// <summary>
/// Обработка нажатия кнопки "Шаг"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonStep_Click(object sender, EventArgs e) private void buttonStep_Click(object sender, EventArgs e)
{ {
if (_drawingBoat == null) if (_drawingBoat == null)
@ -146,5 +137,11 @@ namespace Sailboat
_abstractStrategy = null; _abstractStrategy = null;
} }
} }
private void buttonSelectBoat_Click(object sender, EventArgs e)
{
SelectedBoat = _drawingBoat;
DialogResult = DialogResult.OK;
}
} }
} }