Готовая лабораторная
This commit is contained in:
parent
6dceedfa0d
commit
d71beac455
@ -27,20 +27,21 @@ namespace WarmlyShip.DrawingObjects
|
||||
}
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Pen anchor = new(Color.Black, 4);
|
||||
Brush additionalBrush = new SolidBrush(EntityWarmlyShip.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(warmlyShip.AdditionalColor);
|
||||
base.DrawTransport(g);
|
||||
//отсек для топлива
|
||||
Brush brGray = new SolidBrush(Color.Gray);
|
||||
if (EntityWarmlyShip.Section)
|
||||
if (warmlyShip.Section)
|
||||
{
|
||||
g.FillEllipse(brGray, _startPosX + 130, _startPosY + 130, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 130, _startPosY + 130, 20, 20);
|
||||
}
|
||||
//трубы
|
||||
if (EntityWarmlyShip.Pipes)
|
||||
if (warmlyShip.Pipes)
|
||||
{
|
||||
g.FillRectangle(brGray, _startPosX + 55, _startPosY, 25, 80);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY, 25, 80);
|
||||
g.DrawRectangle(pen, _startPosX + 55, _startPosY, 25, 80);
|
||||
g.FillRectangle(brGray, _startPosX + 90, _startPosY + 20, 25, 60);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 90, _startPosY + 20, 25, 60);
|
||||
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 20, 25, 60);
|
||||
}
|
||||
}
|
||||
|
98
WarmlyShip/WarmlyShip/FormWarmlyShip.Designer.cs
generated
98
WarmlyShip/WarmlyShip/FormWarmlyShip.Designer.cs
generated
@ -29,11 +29,14 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxWarmlyShip = new System.Windows.Forms.PictureBox();
|
||||
this.buttonCreateWarmlyShip = new System.Windows.Forms.Button();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarmlyShip)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -47,73 +50,109 @@
|
||||
this.pictureBoxWarmlyShip.TabIndex = 0;
|
||||
this.pictureBoxWarmlyShip.TabStop = false;
|
||||
//
|
||||
// buttonCreateWarmlyShip
|
||||
//
|
||||
this.buttonCreateWarmlyShip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateWarmlyShip.Location = new System.Drawing.Point(12, 389);
|
||||
this.buttonCreateWarmlyShip.Name = "buttonCreateWarmlyShip";
|
||||
this.buttonCreateWarmlyShip.Size = new System.Drawing.Size(163, 50);
|
||||
this.buttonCreateWarmlyShip.TabIndex = 1;
|
||||
this.buttonCreateWarmlyShip.Text = "Создать теплоход с трубами";
|
||||
this.buttonCreateWarmlyShip.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateWarmlyShip.Click += new System.EventHandler(this.buttonCreateWarmlyShip_Click);
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(31, 411);
|
||||
this.buttonCreate.Location = new System.Drawing.Point(197, 389);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(94, 30);
|
||||
this.buttonCreate.TabIndex = 1;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(122, 50);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать теплоход";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click_1);
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::WarmlyShip.Properties.Resources.left_arrow;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(703, 411);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(720, 411);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 2;
|
||||
this.buttonLeft.TabIndex = 3;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::WarmlyShip.Properties.Resources.upper_arrow;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(739, 375);
|
||||
this.buttonUp.Location = new System.Drawing.Point(756, 375);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 3;
|
||||
this.buttonUp.TabIndex = 4;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::WarmlyShip.Properties.Resources.right_arrow;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(775, 411);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 4;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::WarmlyShip.Properties.Resources.down_arrow;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(739, 411);
|
||||
this.buttonDown.Location = new System.Drawing.Point(756, 411);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 5;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::WarmlyShip.Properties.Resources.right_arrow;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(792, 411);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 6;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxStrategy.FormattingEnabled = true;
|
||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||
"К центру",
|
||||
"К краю"});
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(720, 13);
|
||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28);
|
||||
this.comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
this.buttonStep.Location = new System.Drawing.Point(756, 56);
|
||||
this.buttonStep.Name = "buttonStep";
|
||||
this.buttonStep.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonStep.TabIndex = 8;
|
||||
this.buttonStep.Text = "Шаг";
|
||||
this.buttonStep.UseVisualStyleBackColor = true;
|
||||
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||
//
|
||||
// FormWarmlyShip
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(882, 453);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.buttonCreateWarmlyShip);
|
||||
this.Controls.Add(this.pictureBoxWarmlyShip);
|
||||
this.Name = "FormWarmlyShip";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
@ -127,10 +166,13 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxWarmlyShip;
|
||||
private Button buttonCreateWarmlyShip;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
}
|
||||
}
|
@ -1,21 +1,17 @@
|
||||
using WarmlyShip.DrawingObjects;
|
||||
using WarmlyShip.MovementStrategy;
|
||||
|
||||
namespace WarmlyShip
|
||||
{
|
||||
public partial class FormWarmlyShip : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawingWarmlyShip? _drawingWarmlyShip;
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
/// </summary>
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public FormWarmlyShip()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè òåïëîõîäà
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingWarmlyShip == null)
|
||||
@ -28,32 +24,32 @@ namespace WarmlyShip
|
||||
_drawingWarmlyShip.DrawTransport(gr);
|
||||
pictureBoxWarmlyShip.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingWarmlyShip = new DrawingWarmlyShip();
|
||||
_drawingWarmlyShip.Init(random.Next(100, 300),
|
||||
_drawingWarmlyShip = new DrawingWarmlyShip(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
||||
_drawingWarmlyShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonCreateWarmlyShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingWarmlyShip = new DrawingWarmlyShipWithPipes(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)),
|
||||
pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
||||
_drawingWarmlyShip.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 (_drawingWarmlyShip == null)
|
||||
@ -79,47 +75,41 @@ namespace WarmlyShip
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
||||
private void buttonCreate_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingWarmlyShip = new DrawingWarmlyShip ();
|
||||
_drawingWarmlyShip.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)),
|
||||
pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
||||
_drawingWarmlyShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingWarmlyShip == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingWarmlyShip.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingWarmlyShip.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingWarmlyShip.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingWarmlyShip.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawingObjectShip(_drawingWarmlyShip), pictureBoxWarmlyShip.Width,
|
||||
pictureBoxWarmlyShip.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