Добавление кнопок. Обновление логики формы.
This commit is contained in:
parent
054f03921c
commit
b7e22a4fd5
64
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
64
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
@ -33,7 +33,10 @@
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonCreate = new Button();
|
||||
buttonCreateBoat = new Button();
|
||||
buttonCreateSailboat = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxSailboat).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -95,23 +98,57 @@
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
// buttonCreateBoat
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 412);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(94, 29);
|
||||
buttonCreate.TabIndex = 5;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBoat.Location = new Point(149, 391);
|
||||
buttonCreateBoat.Name = "buttonCreateBoat";
|
||||
buttonCreateBoat.Size = new Size(131, 50);
|
||||
buttonCreateBoat.TabIndex = 5;
|
||||
buttonCreateBoat.Text = "Создать лодку";
|
||||
buttonCreateBoat.UseVisualStyleBackColor = true;
|
||||
buttonCreateBoat.Click += buttonCreateBoat_Click;
|
||||
//
|
||||
// buttonCreateSailboat
|
||||
//
|
||||
buttonCreateSailboat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateSailboat.Location = new Point(12, 391);
|
||||
buttonCreateSailboat.Name = "buttonCreateSailboat";
|
||||
buttonCreateSailboat.Size = new Size(131, 50);
|
||||
buttonCreateSailboat.TabIndex = 6;
|
||||
buttonCreateSailboat.Text = "Создать парусную лодку";
|
||||
buttonCreateSailboat.UseVisualStyleBackColor = true;
|
||||
buttonCreateSailboat.Click += buttonCreateSailboat_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "До центра", "До края" });
|
||||
comboBoxStrategy.Location = new Point(719, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(151, 28);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Location = new Point(776, 46);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(94, 29);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
//
|
||||
// FormSailboat
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateSailboat);
|
||||
Controls.Add(buttonCreateBoat);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
@ -132,6 +169,9 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreateBoat;
|
||||
private Button buttonCreateSailboat;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Sailboat.DrawingObjects;
|
||||
using Sailboat.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -10,47 +12,78 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sailboat
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Парусная лодка"
|
||||
/// </summary>
|
||||
public partial class FormSailboat : Form
|
||||
{
|
||||
private DrawingSailboat? _drawingSailboat;
|
||||
private EntitySailboat? _entitySailboat;
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawingBoat? _drawingBoat;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация формы
|
||||
/// </summary>
|
||||
public FormSailboat()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод прорисовки лодки
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingSailboat == null)
|
||||
if (_drawingBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxSailboat.Width,
|
||||
pictureBoxSailboat.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingSailboat.DrawTransport(gr);
|
||||
_drawingBoat.DrawTransport(gr);
|
||||
pictureBoxSailboat.Image = bmp;
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать лодку"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingSailboat = new DrawingSailboat();
|
||||
|
||||
_drawingSailboat.Init(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)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxSailboat.Width, pictureBoxSailboat.Height);
|
||||
|
||||
_drawingSailboat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_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);
|
||||
_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 (_drawingSailboat == null)
|
||||
if (_drawingBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -58,19 +91,60 @@ namespace Sailboat
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingSailboat.MoveTransport(DirectionType.Up);
|
||||
_drawingBoat.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingSailboat.MoveTransport(DirectionType.Down);
|
||||
_drawingBoat.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingSailboat.MoveTransport(DirectionType.Left);
|
||||
_drawingBoat.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingSailboat.MoveTransport(DirectionType.Right);
|
||||
_drawingBoat.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Шаг"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawingObjectBoat(_drawingBoat), pictureBoxSailboat.Width,
|
||||
pictureBoxSailboat.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user