файлы лабораторной

This commit is contained in:
Ivan_Starostin 2023-12-08 21:15:40 +04:00
parent 295bdabdb7
commit 20f939bb77
2 changed files with 57 additions and 27 deletions

View File

@ -37,6 +37,7 @@
ButtonCreateSuperLainer = new Button();
comboBoxStrategy = new ComboBox();
ButtonStep = new Button();
ButtonSelectLainer = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxLainer).BeginInit();
SuspendLayout();
//
@ -122,7 +123,7 @@
// comboBoxStrategy
//
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "центр", "край"});
comboBoxStrategy.Items.AddRange(new object[] { "центр", "край" });
comboBoxStrategy.Location = new Point(566, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28);
@ -138,11 +139,22 @@
ButtonStep.UseVisualStyleBackColor = true;
ButtonStep.Click += ButtonStep_Click;
//
// ButtonSelectLainer
//
ButtonSelectLainer.Location = new Point(369, 356);
ButtonSelectLainer.Name = "ButtonSelectLainer";
ButtonSelectLainer.Size = new Size(94, 29);
ButtonSelectLainer.TabIndex = 9;
ButtonSelectLainer.Text = "выбрать";
ButtonSelectLainer.UseVisualStyleBackColor = true;
ButtonSelectLainer.Click += ButtonSelectLainer_Click;
//
// LainerForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(729, 397);
Controls.Add(ButtonSelectLainer);
Controls.Add(ButtonStep);
Controls.Add(comboBoxStrategy);
Controls.Add(ButtonCreateSuperLainer);
@ -171,5 +183,6 @@
private Button ButtonCreateSuperLainer;
private ComboBox comboBoxStrategy;
private Button ButtonStep;
private Button ButtonSelectLainer;
}
}

View File

@ -6,9 +6,13 @@ namespace ProjectLainer
{
private DrawingLainer? _drawningLainer;
private AbstractStrategy? _abstractStrategy;
private AbstractStrategy? _strategy;
public DrawingLainer? SelectedLainer { get; private set; }
public LainerForm()
{
InitializeComponent();
_strategy = null;
SelectedLainer = null;
}
private void Draw()
{
@ -25,29 +29,39 @@ namespace ProjectLainer
private void ButtonCreateSuperLainer_Click(object sender, EventArgs e)
{
Random random = new();
Color mainColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
Color additColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
mainColor = dialog.Color;
}
if (dialog.ShowDialog() == DialogResult.OK)
{
additColor = dialog.Color;
}
_drawningLainer = new DrawningSuperLainer(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)),
random.Next(1000, 3000), mainColor, additColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxLainer.Width, pictureBoxLainer.Height);
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10,
100));
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonCreate_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;
}
_drawningLainer = new DrawingLainer(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
random.Next(1000, 3000), color,
pictureBoxLainer.Width, pictureBoxLainer.Height);
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10,
100));
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
@ -82,33 +96,36 @@ namespace ProjectLainer
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
_strategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
if (_strategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawningObjectLainer(_drawningLainer), pictureBoxLainer.Width,
pictureBoxLainer.Height);
comboBoxStrategy.Enabled = false;
_strategy.SetData(_drawningLainer.GetMoveableObject,
pictureBoxLainer.Width, pictureBoxLainer.Height);
}
if (_abstractStrategy == null)
if (_strategy == null)
{
return;
}
_abstractStrategy.MakeStep();
comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
if (_strategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
_strategy = null;
}
}
private void ButtonSelectLainer_Click(object sender, EventArgs e)
{
SelectedLainer = _drawningLainer;
DialogResult = DialogResult.OK;
}
}
}