Добавление новой логики формы FormSailboat
This commit is contained in:
parent
8f8380b986
commit
0a07bace59
13
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
13
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
@ -37,6 +37,7 @@
|
||||
buttonCreateSailboat = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
buttonSelectBoat = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxSailboat).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -140,11 +141,22 @@
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
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
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
Controls.Add(buttonSelectBoat);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateSailboat);
|
||||
@ -173,5 +185,6 @@
|
||||
private Button buttonCreateSailboat;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonSelectBoat;
|
||||
}
|
||||
}
|
@ -12,28 +12,19 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sailboat
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Парусная лодка"
|
||||
/// </summary>
|
||||
public partial class FormSailboat : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawingBoat? _drawingBoat;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawingBoat? SelectedBoat { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация формы
|
||||
/// </summary>
|
||||
public FormSailboat()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedBoat = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод прорисовки лодки
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingBoat == null)
|
||||
@ -47,40 +38,45 @@ namespace Sailboat
|
||||
pictureBoxSailboat.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать лодку"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
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);
|
||||
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать улучшеную лодку"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateSailboat_Click(object sender, EventArgs e)
|
||||
{
|
||||
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)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailboat.Width, pictureBoxSailboat.Height);
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_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));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonCreateSailboat_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
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));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение размеров формы
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingBoat == null)
|
||||
@ -106,11 +102,6 @@ namespace Sailboat
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Шаг"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingBoat == null)
|
||||
@ -146,5 +137,11 @@ namespace Sailboat
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedBoat = _drawingBoat;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user