Merge pull request 'Presnyakova V.V Lab_3' (#8) from Lab_3 into Lab_2

Reviewed-on: http://student.git.athene.tech/Victoria_Presnyakova/Pibd-22_Presnyakova.V.V_Catamaran_Base/pulls/8
This commit is contained in:
Евгений Эгов 2022-11-11 09:12:27 +04:00
commit cc4a71da04
13 changed files with 684 additions and 231 deletions

View File

@ -59,22 +59,24 @@
<Compile Include="FormBoat.Designer.cs"> <Compile Include="FormBoat.Designer.cs">
<DependentUpon>FormBoat.cs</DependentUpon> <DependentUpon>FormBoat.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="FormMap.cs"> <Compile Include="FormMapWithSetBoats.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="FormMap.Designer.cs"> <Compile Include="FormMapWithSetBoats.Designer.cs">
<DependentUpon>FormMap.cs</DependentUpon> <DependentUpon>FormMapWithSetBoats.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="IDrawingObject.cs" /> <Compile Include="IDrawingObject.cs" />
<Compile Include="MapWithSetBoatsGeneric.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SecondMap.cs" /> <Compile Include="SecondMap.cs" />
<Compile Include="SetBoatsGeneric.cs" />
<Compile Include="SimpleMap.cs" /> <Compile Include="SimpleMap.cs" />
<EmbeddedResource Include="FormBoat.resx"> <EmbeddedResource Include="FormBoat.resx">
<DependentUpon>FormBoat.cs</DependentUpon> <DependentUpon>FormBoat.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="FormMap.resx"> <EmbeddedResource Include="FormMapWithSetBoats.resx">
<DependentUpon>FormMap.cs</DependentUpon> <DependentUpon>FormMapWithSetBoats.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>

View File

@ -9,7 +9,7 @@ namespace Catamaran
/// <summary> /// <summary>
/// Направление перемещения /// Направление перемещения
/// </summary> /// </summary>
internal enum Direction public enum Direction
{ {
None = 0, None = 0,
Up = 1, Up = 1,

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Catamaran namespace Catamaran
{ {
internal class DrawingBoat public class DrawingBoat
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Catamaran namespace Catamaran
{ {
internal class EntityBoat public class EntityBoat
{ {
/// <summary> /// <summary>
/// Скорость /// Скорость

View File

@ -38,6 +38,8 @@
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button(); this.buttonCreate = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.buttonSelectBoat = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -142,12 +144,36 @@
this.buttonCreate.Text = "Cteate"; this.buttonCreate.Text = "Cteate";
this.buttonCreate.UseVisualStyleBackColor = true; this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonCreateModif
//
this.buttonCreateModif.Location = new System.Drawing.Point(90, 380);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(108, 30);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "CreateModif";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
//
// buttonSelectBoat
//
this.buttonSelectBoat.Location = new System.Drawing.Point(204, 384);
this.buttonSelectBoat.Name = "buttonSelectBoat";
this.buttonSelectBoat.Size = new System.Drawing.Size(113, 26);
this.buttonSelectBoat.TabIndex = 8;
this.buttonSelectBoat.Text = "SelectBoat";
this.buttonSelectBoat.UseVisualStyleBackColor = true;
this.buttonSelectBoat.Click += new System.EventHandler(this.buttonSelectBoat_Click);
// //
// CatamaranForm // CatamaranForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(796, 461); this.ClientSize = new System.Drawing.Size(796, 461);
this.Controls.Add(this.buttonSelectBoat);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonCreate); this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonLeft);
@ -177,6 +203,8 @@
private System.Windows.Forms.Button buttonLeft; private System.Windows.Forms.Button buttonLeft;
private System.Windows.Forms.Button buttonRight; private System.Windows.Forms.Button buttonRight;
private System.Windows.Forms.Button buttonCreate; private System.Windows.Forms.Button buttonCreate;
private System.Windows.Forms.Button buttonCreateModif;
private System.Windows.Forms.Button buttonSelectBoat;
} }
} }

View File

@ -13,6 +13,8 @@ namespace Catamaran
public partial class FormBoat : Form public partial class FormBoat : Form
{ {
private DrawingBoat _catamaran; private DrawingBoat _catamaran;
public DrawingBoat SelectedBoat { get; private set; }
public FormBoat() public FormBoat()
{ {
InitializeComponent(); InitializeComponent();
@ -24,17 +26,26 @@ namespace Catamaran
_catamaran?.DrawTransport(gr); _catamaran?.DrawTransport(gr);
pictureBoxCatamaran.Image = bmp; pictureBoxCatamaran.Image = bmp;
} }
private void SetData()
private void buttonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new Random(); Random rnd = new Random();
_catamaran = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_catamaran.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), _catamaran.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height); pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_catamaran.Catamaran.Speed}"; toolStripStatusLabelSpeed.Text = $"Скорость: {_catamaran.Catamaran.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_catamaran.Catamaran.Weight}"; toolStripStatusLabelWeight.Text = $"Вес: {_catamaran.Catamaran.Weight}";
toolStripStatusLabelColor.Text = $"Цвет:{ _catamaran.Catamaran.BodyColor.Name}"; toolStripStatusLabelColor.Text = $"Цвет: { _catamaran.Catamaran.BodyColor.Name}";
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_catamaran = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw(); Draw();
} }
private void buttonMove_Click(object sender, EventArgs e) private void buttonMove_Click(object sender, EventArgs e)
@ -64,5 +75,37 @@ namespace Catamaran
_catamaran?.ChangeBorders(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height); _catamaran?.ChangeBorders(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
Draw(); Draw();
} }
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
rnd.Next(0, 256));
ColorDialog dialogDop = new ColorDialog();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_catamaran = new DrawingCatamaran(rnd.Next(100, 300), rnd.Next(1000, 2000),
color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Выбрать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSelectBoat_Click(object sender, EventArgs e)
{
SelectedBoat = _catamaran;
DialogResult = DialogResult.OK;
}
} }
} }

View File

@ -1,97 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Catamaran
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
/// <summary>
/// Заполнение информации по объекту
/// </summary>
/// <param name="car"></param>
private void SetData(DrawingBoat catamaran)
{
toolStripStatusLabelSpeed.Text = $"Скорость: {catamaran.Catamaran.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {catamaran.Catamaran.Weight}";
toolStripStatusLabelColor.Text = $"Цвет: { catamaran.Catamaran.BodyColor.Name}";
pictureBoxCatamaran.Image = _abstractMap.CreateMap(pictureBoxCatamaran.Width,pictureBoxCatamaran.Height,new DrawingObjectBoat(catamaran));
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
var _catamaran = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
//_catamaran.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
//pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
SetData(_catamaran);
}
private void buttonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBoxCatamaran.Image = _abstractMap?.MoveObject(dir);
}
private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorMap.Text)
{
case "SimpleMap":
_abstractMap = new SimpleMap();
break;
case "SecondMap":
_abstractMap = new SecondMap();
break;
}
}
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new Random();
var catamaran = new DrawingCatamaran(rnd.Next(100, 300), rnd.Next(1000,
2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0,
256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0,
256)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,
2)));
SetData(catamaran);
}
}
}

View File

@ -1,6 +1,6 @@
namespace Catamaran namespace Catamaran
{ {
partial class FormMap partial class FormMapWithSetBoats
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@ -28,93 +28,108 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.buttonShowOnMap = new System.Windows.Forms.Button();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.buttonShowStorage = new System.Windows.Forms.Button();
this.toolStripStatusLabelColor = new System.Windows.Forms.ToolStripStatusLabel(); this.buttonRemoveBoat = new System.Windows.Forms.Button();
this.pictureBoxCatamaran = new System.Windows.Forms.PictureBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonUp = new System.Windows.Forms.Button(); this.buttonAddBoat = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button(); this.pictureBox = new System.Windows.Forms.PictureBox();
this.statusStrip1.SuspendLayout(); this.groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// statusStrip1 // groupBoxTools
// //
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.toolStripStatusLabelSpeed, this.groupBoxTools.Controls.Add(this.buttonRemoveBoat);
this.toolStripStatusLabelWeight, this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.toolStripStatusLabelColor}); this.groupBoxTools.Controls.Add(this.buttonAddBoat);
this.statusStrip1.Location = new System.Drawing.Point(0, 436); this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.statusStrip1.Name = "statusStrip1"; this.groupBoxTools.Controls.Add(this.buttonLeft);
this.statusStrip1.Size = new System.Drawing.Size(826, 32); this.groupBoxTools.Controls.Add(this.buttonRight);
this.statusStrip1.TabIndex = 0; this.groupBoxTools.Controls.Add(this.buttonUp);
this.statusStrip1.Text = "statusStrip1"; this.groupBoxTools.Controls.Add(this.buttonDown);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(653, 0);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(303, 557);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools";
// //
// toolStripStatusLabelSpeed // buttonShowOnMap
// //
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; this.buttonShowOnMap.Location = new System.Drawing.Point(24, 402);
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 25); this.buttonShowOnMap.Name = "buttonShowOnMap";
this.toolStripStatusLabelSpeed.Text = "Speed"; this.buttonShowOnMap.Size = new System.Drawing.Size(191, 31);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "ShowOnMap";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
// //
// toolStripStatusLabelWeight // buttonShowStorage
// //
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; this.buttonShowStorage.Location = new System.Drawing.Point(24, 344);
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(68, 25); this.buttonShowStorage.Name = "buttonShowStorage";
this.toolStripStatusLabelWeight.Text = "Weight"; this.buttonShowStorage.Size = new System.Drawing.Size(191, 33);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "ShowStorage";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
// //
// toolStripStatusLabelColor // buttonRemoveBoat
// //
this.toolStripStatusLabelColor.Name = "toolStripStatusLabelColor"; this.buttonRemoveBoat.Location = new System.Drawing.Point(24, 271);
this.toolStripStatusLabelColor.Size = new System.Drawing.Size(55, 25); this.buttonRemoveBoat.Name = "buttonRemoveBoat";
this.toolStripStatusLabelColor.Text = "Color"; this.buttonRemoveBoat.Size = new System.Drawing.Size(191, 30);
this.buttonRemoveBoat.TabIndex = 3;
this.buttonRemoveBoat.Text = "RemoveBoat";
this.buttonRemoveBoat.UseVisualStyleBackColor = true;
this.buttonRemoveBoat.Click += new System.EventHandler(this.buttonRemoveBoat_Click);
// //
// pictureBoxCatamaran // maskedTextBoxPosition
// //
this.pictureBoxCatamaran.Dock = System.Windows.Forms.DockStyle.Fill; this.maskedTextBoxPosition.Location = new System.Drawing.Point(24, 201);
this.pictureBoxCatamaran.Location = new System.Drawing.Point(0, 0); this.maskedTextBoxPosition.Mask = "00";
this.pictureBoxCatamaran.Name = "pictureBoxCatamaran"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.pictureBoxCatamaran.Size = new System.Drawing.Size(826, 436); this.maskedTextBoxPosition.Size = new System.Drawing.Size(191, 26);
this.pictureBoxCatamaran.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.maskedTextBoxPosition.TabIndex = 2;
this.pictureBoxCatamaran.TabIndex = 1;
this.pictureBoxCatamaran.TabStop = false;
// //
// buttonUp // buttonAddBoat
// //
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonAddBoat.Location = new System.Drawing.Point(24, 123);
this.buttonUp.BackgroundImage = global::Catamaran.Properties.Resources.Up; this.buttonAddBoat.Name = "buttonAddBoat";
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonAddBoat.Size = new System.Drawing.Size(191, 32);
this.buttonUp.Location = new System.Drawing.Point(683, 344); this.buttonAddBoat.TabIndex = 1;
this.buttonUp.Name = "buttonUp"; this.buttonAddBoat.Text = "AddBoat";
this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonAddBoat.UseVisualStyleBackColor = true;
this.buttonUp.TabIndex = 2; this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click_1);
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
// //
// buttonDown // comboBoxSelectorMap
// //
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.comboBoxSelectorMap.FormattingEnabled = true;
this.buttonDown.BackgroundImage = global::Catamaran.Properties.Resources.Down; this.comboBoxSelectorMap.Items.AddRange(new object[] {
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; "SimpleMap",
this.buttonDown.Location = new System.Drawing.Point(683, 380); "SecondMap"});
this.buttonDown.Name = "buttonDown"; this.comboBoxSelectorMap.Location = new System.Drawing.Point(24, 51);
this.buttonDown.Size = new System.Drawing.Size(30, 30); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.buttonDown.TabIndex = 3; this.comboBoxSelectorMap.Size = new System.Drawing.Size(191, 28);
this.buttonDown.UseVisualStyleBackColor = true; this.comboBoxSelectorMap.TabIndex = 0;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
// //
// buttonLeft // buttonLeft
// //
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Catamaran.Properties.Resources.Left; this.buttonLeft.BackgroundImage = global::Catamaran.Properties.Resources.Left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(647, 372); this.buttonLeft.Location = new System.Drawing.Point(10, 472);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4; this.buttonLeft.TabIndex = 4;
@ -126,84 +141,75 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Catamaran.Properties.Resources.Right; this.buttonRight.BackgroundImage = global::Catamaran.Properties.Resources.Right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(719, 372); this.buttonRight.Location = new System.Drawing.Point(70, 472);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5; this.buttonRight.TabIndex = 5;
this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
// //
// buttonCreate // buttonUp
// //
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCreate.Location = new System.Drawing.Point(14, 380); this.buttonUp.BackgroundImage = global::Catamaran.Properties.Resources.Up;
this.buttonCreate.Name = "buttonCreate"; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonCreate.Size = new System.Drawing.Size(70, 30); this.buttonUp.Location = new System.Drawing.Point(40, 450);
this.buttonCreate.TabIndex = 6; this.buttonUp.Name = "buttonUp";
this.buttonCreate.Text = "Cteate"; this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonCreate.UseVisualStyleBackColor = true; this.buttonUp.TabIndex = 2;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
// //
// comboBoxSelectorMap // buttonDown
// //
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.comboBoxSelectorMap.FormattingEnabled = true; this.buttonDown.BackgroundImage = global::Catamaran.Properties.Resources.Down;
this.comboBoxSelectorMap.Items.AddRange(new object[] { this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
"SimpleMap", this.buttonDown.Location = new System.Drawing.Point(40, 480);
"SecondMap"}); this.buttonDown.Name = "buttonDown";
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.buttonDown.TabIndex = 3;
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 28); this.buttonDown.UseVisualStyleBackColor = true;
this.comboBoxSelectorMap.TabIndex = 7; this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged);
// //
// buttonCreateModif // pictureBox
// //
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.buttonCreateModif.Location = new System.Drawing.Point(117, 380); this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.buttonCreateModif.Name = "buttonCreateModif"; this.pictureBox.Name = "pictureBox";
this.buttonCreateModif.Size = new System.Drawing.Size(102, 30); this.pictureBox.Size = new System.Drawing.Size(653, 557);
this.buttonCreateModif.TabIndex = 8; this.pictureBox.TabIndex = 1;
this.buttonCreateModif.Text = "Modification"; this.pictureBox.TabStop = false;
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
// //
// FormMap // FormMapWithSetBoats
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(826, 468); this.ClientSize = new System.Drawing.Size(956, 557);
this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.comboBoxSelectorMap); this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.buttonCreate); this.Name = "FormMapWithSetBoats";
this.Controls.Add(this.buttonRight); this.Text = "FormMapWithSetBoats";
this.Controls.Add(this.buttonLeft); this.groupBoxTools.ResumeLayout(false);
this.Controls.Add(this.buttonDown); this.groupBoxTools.PerformLayout();
this.Controls.Add(this.buttonUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.Controls.Add(this.pictureBoxCatamaran);
this.Controls.Add(this.statusStrip1);
this.Name = "FormMap";
this.Text = "Map";
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpeed; private System.Windows.Forms.GroupBox groupBoxTools;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelWeight; private System.Windows.Forms.ComboBox comboBoxSelectorMap;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelColor; private System.Windows.Forms.PictureBox pictureBox;
private System.Windows.Forms.PictureBox pictureBoxCatamaran; private System.Windows.Forms.Button buttonShowOnMap;
private System.Windows.Forms.Button buttonShowStorage;
private System.Windows.Forms.Button buttonRemoveBoat;
private System.Windows.Forms.MaskedTextBox maskedTextBoxPosition;
private System.Windows.Forms.Button buttonAddBoat;
private System.Windows.Forms.Button buttonUp; private System.Windows.Forms.Button buttonUp;
private System.Windows.Forms.Button buttonDown; private System.Windows.Forms.Button buttonDown;
private System.Windows.Forms.Button buttonLeft; private System.Windows.Forms.Button buttonLeft;
private System.Windows.Forms.Button buttonRight; private System.Windows.Forms.Button buttonRight;
private System.Windows.Forms.Button buttonCreate;
private System.Windows.Forms.ComboBox comboBoxSelectorMap;
private System.Windows.Forms.Button buttonCreateModif;
} }
} }

View File

@ -0,0 +1,165 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Catamaran
{
public partial class FormMapWithSetBoats : Form
{
private MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap> _mapBoatsCollectionGeneric;
public FormMapWithSetBoats()
{
InitializeComponent();
}
/// <summary>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "SimpleMap":
map = new SimpleMap();
break;
case "SecondMap":
map = new SecondMap();
break;
}
if (map != null)
{
_mapBoatsCollectionGeneric = new MapWithSetBoatsGeneric<DrawingObjectBoat, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapBoatsCollectionGeneric = null;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonRemoveBoat_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapBoatsCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonShowStorage_Click(object sender, EventArgs e)
{
if (_mapBoatsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapBoatsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapBoatsCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonMove_Click(object sender, EventArgs e)
{
if (_mapBoatsCollectionGeneric == null)
{
return;
}
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBox.Image = _mapBoatsCollectionGeneric.MoveObject(dir);
}
private void buttonAddBoat_Click_1(object sender, EventArgs e)
{
if (_mapBoatsCollectionGeneric == null)
{
return;
}
FormBoat form = new FormBoat();
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectBoat boat = new DrawingObjectBoat(form.SelectedBoat);
if (_mapBoatsCollectionGeneric + boat != null)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
}
}

View File

@ -0,0 +1,193 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran
{
/// <summary>
/// Карта с набром объектов под нее
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class MapWithSetBoatsGeneric<T, U>
where T : class, IDrawingObject
where U : AbstractMap
{
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetBoatsGeneric<T> _setBoats;
/// <summary>
/// Карта
/// </summary>
private readonly U _map;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="map"></param>
public MapWithSetBoatsGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setBoats = new SetBoatsGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="map"></param>
/// <param name="Boat"></param>
/// <returns></returns>
///
public static int operator +(MapWithSetBoatsGeneric<T, U> map, T Boat)
{
return map._setBoats.Insert(Boat);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="map"></param>
/// <param name="position"></param>
/// <returns></returns>
public static T operator -(MapWithSetBoatsGeneric<T, U> map, int position)
{
return map._setBoats.Remove(position);
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowSet()
{
Bitmap bmp = new Bitmap(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawBoats(gr);
return bmp;
}
/// <summary>
/// Просмотр объекта на карте
/// </summary>
/// <returns></returns>
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setBoats.Count; i++)
{
var Boat = _setBoats.Get(i);
if (Boat != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, Boat);
}
}
return new Bitmap(_pictureWidth, _pictureHeight);
}
/// <summary>
/// Перемещение объекта по крате
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new Bitmap(_pictureWidth, _pictureHeight);
}
/// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary>
private void Shaking()
{
int j = _setBoats.Count - 1;
for (int i = 0; i < _setBoats.Count; i++)
{
if (_setBoats.Get(i) == null)
{
for (; j > i; j--)
{
var Boat = _setBoats.Get(j);
if (Boat != null)
{
_setBoats.Insert(Boat, i);
_setBoats.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new Pen(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i *
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
for (int k = 0; k < 7; k++)
{
g.DrawEllipse(pen, i * _placeSizeWidth + 15 * k, j * _placeSizeHeight, 15, 15);
g.DrawEllipse(pen, i * _placeSizeWidth + 15 * k, j * _placeSizeHeight - 15, 15, 15);
}
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
for (int k = 0; k < 6 * 4; k++)
{
g.DrawEllipse(pen, i * _placeSizeWidth, 0 + 15 * k, 15, 15);
}
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawBoats(System.Drawing.Graphics g)
{
int numberOfSeatsInWidth = _pictureWidth / _placeSizeWidth;
int numberOfSeatsInHeight = _pictureHeight / _placeSizeHeight;
int bottomLine = (numberOfSeatsInHeight - 1) * _placeSizeHeight;
for (int i = 0; i < _setBoats.Count; i++)
{
// TODO установка позиции
_setBoats.Get(i)?.SetObject(i % numberOfSeatsInWidth * _placeSizeWidth, bottomLine - i / numberOfSeatsInWidth * _placeSizeHeight, _pictureWidth, _pictureHeight);
_setBoats.Get(i)?.DrawingObject(g);
}
}
}
}

View File

@ -16,7 +16,7 @@ namespace Catamaran
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMap()); Application.Run(new FormMapWithSetBoats());
} }
} }
} }

View File

@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran
{
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T"></typeparam>
internal class SetBoatsGeneric<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private readonly T[] _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Length;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetBoatsGeneric(int count)
{
_places = new T[count];
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="boat">Добавляемая лодка </param>
/// <returns></returns>
public int Insert(T boat)
{
for (int i = 0; i < Count; i++)
{
if (_places[i] == null)
{
_places[i] = boat;
return i;
}
}
return -1;
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="boat">Добавляемая лодка</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public int Insert(T boat, int position)
{
// TODO проверка позиции
if (position < 0 || position >= Count) return -1;
// TODO проверка, что элемент массива по этой позиции пустой,если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
if (_places[position] == null)
{
_places[position] = boat;
return position;
}
else
{
for (int i = position + 1; i < Count; i++)
{
if (_places[i] == null)
{
for (int j = i - 1; j >= position; j--)
{
_places[j + 1] = _places[j];
}
_places[position] = boat;
return position;
}
}
return -1;
}
// TODO вставка по позиции
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Remove(int position)
{
// TODO проверка позиции
if (position < 0 || position >= Count) return null;
// TODO удаление объекта из массива, присовив элементу массива значение null
T removed = _places[position];
_places[position] = null;
return removed;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Get(int position)
{
// TODO проверка позиции
if (position < 0 || position >= Count) return null;
return _places[position];
}
}
}