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:
commit
cc4a71da04
@ -59,22 +59,24 @@
|
||||
<Compile Include="FormBoat.Designer.cs">
|
||||
<DependentUpon>FormBoat.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FormMap.cs">
|
||||
<Compile Include="FormMapWithSetBoats.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FormMap.Designer.cs">
|
||||
<DependentUpon>FormMap.cs</DependentUpon>
|
||||
<Compile Include="FormMapWithSetBoats.Designer.cs">
|
||||
<DependentUpon>FormMapWithSetBoats.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="IDrawingObject.cs" />
|
||||
<Compile Include="MapWithSetBoatsGeneric.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SecondMap.cs" />
|
||||
<Compile Include="SetBoatsGeneric.cs" />
|
||||
<Compile Include="SimpleMap.cs" />
|
||||
<EmbeddedResource Include="FormBoat.resx">
|
||||
<DependentUpon>FormBoat.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FormMap.resx">
|
||||
<DependentUpon>FormMap.cs</DependentUpon>
|
||||
<EmbeddedResource Include="FormMapWithSetBoats.resx">
|
||||
<DependentUpon>FormMapWithSetBoats.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
|
@ -9,7 +9,7 @@ namespace Catamaran
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran
|
||||
{
|
||||
internal class DrawingBoat
|
||||
public class DrawingBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran
|
||||
{
|
||||
internal class EntityBoat
|
||||
public class EntityBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
|
28
Catamaran/FormBoat.Designer.cs
generated
28
Catamaran/FormBoat.Designer.cs
generated
@ -38,6 +38,8 @@
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = 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();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -142,12 +144,36 @@
|
||||
this.buttonCreate.Text = "Cteate";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
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
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
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.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
@ -177,6 +203,8 @@
|
||||
private System.Windows.Forms.Button buttonLeft;
|
||||
private System.Windows.Forms.Button buttonRight;
|
||||
private System.Windows.Forms.Button buttonCreate;
|
||||
private System.Windows.Forms.Button buttonCreateModif;
|
||||
private System.Windows.Forms.Button buttonSelectBoat;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@ namespace Catamaran
|
||||
public partial class FormBoat : Form
|
||||
{
|
||||
private DrawingBoat _catamaran;
|
||||
public DrawingBoat SelectedBoat { get; private set; }
|
||||
|
||||
public FormBoat()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -24,17 +26,26 @@ namespace Catamaran
|
||||
_catamaran?.DrawTransport(gr);
|
||||
pictureBoxCatamaran.Image = bmp;
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
private void SetData()
|
||||
{
|
||||
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),
|
||||
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_catamaran.Catamaran.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_catamaran.Catamaran.Weight}";
|
||||
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();
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
@ -64,5 +75,37 @@ namespace Catamaran
|
||||
_catamaran?.ChangeBorders(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace Catamaran
|
||||
{
|
||||
partial class FormMap
|
||||
partial class FormMapWithSetBoats
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -28,93 +28,108 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.pictureBoxCatamaran = new System.Windows.Forms.PictureBox();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonRemoveBoat = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonAddBoat = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// statusStrip1
|
||||
// groupBoxTools
|
||||
//
|
||||
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelColor});
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 436);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Size = new System.Drawing.Size(826, 32);
|
||||
this.statusStrip1.TabIndex = 0;
|
||||
this.statusStrip1.Text = "statusStrip1";
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRemoveBoat);
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddBoat);
|
||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||
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.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 25);
|
||||
this.toolStripStatusLabelSpeed.Text = "Speed";
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(24, 402);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
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.toolStripStatusLabelWeight.Size = new System.Drawing.Size(68, 25);
|
||||
this.toolStripStatusLabelWeight.Text = "Weight";
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(24, 344);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
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.toolStripStatusLabelColor.Size = new System.Drawing.Size(55, 25);
|
||||
this.toolStripStatusLabelColor.Text = "Color";
|
||||
this.buttonRemoveBoat.Location = new System.Drawing.Point(24, 271);
|
||||
this.buttonRemoveBoat.Name = "buttonRemoveBoat";
|
||||
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.pictureBoxCatamaran.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCatamaran.Name = "pictureBoxCatamaran";
|
||||
this.pictureBoxCatamaran.Size = new System.Drawing.Size(826, 436);
|
||||
this.pictureBoxCatamaran.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxCatamaran.TabIndex = 1;
|
||||
this.pictureBoxCatamaran.TabStop = false;
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(24, 201);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(191, 26);
|
||||
this.maskedTextBoxPosition.TabIndex = 2;
|
||||
//
|
||||
// buttonUp
|
||||
// buttonAddBoat
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Catamaran.Properties.Resources.Up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(683, 344);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 2;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
this.buttonAddBoat.Location = new System.Drawing.Point(24, 123);
|
||||
this.buttonAddBoat.Name = "buttonAddBoat";
|
||||
this.buttonAddBoat.Size = new System.Drawing.Size(191, 32);
|
||||
this.buttonAddBoat.TabIndex = 1;
|
||||
this.buttonAddBoat.Text = "AddBoat";
|
||||
this.buttonAddBoat.UseVisualStyleBackColor = true;
|
||||
this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click_1);
|
||||
//
|
||||
// buttonDown
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Catamaran.Properties.Resources.Down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(683, 380);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 3;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"SimpleMap",
|
||||
"SecondMap"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(24, 51);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(191, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
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.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.Size = new System.Drawing.Size(30, 30);
|
||||
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.BackgroundImage = global::Catamaran.Properties.Resources.Right;
|
||||
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.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 5;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
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.buttonCreate.Location = new System.Drawing.Point(14, 380);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(70, 30);
|
||||
this.buttonCreate.TabIndex = 6;
|
||||
this.buttonCreate.Text = "Cteate";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Catamaran.Properties.Resources.Up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(40, 450);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 2;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
// buttonDown
|
||||
//
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"SimpleMap",
|
||||
"SecondMap"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 7;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged);
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Catamaran.Properties.Resources.Down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(40, 480);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 3;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
// pictureBox
|
||||
//
|
||||
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(117, 380);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(102, 30);
|
||||
this.buttonCreateModif.TabIndex = 8;
|
||||
this.buttonCreateModif.Text = "Modification";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(653, 557);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMap
|
||||
// FormMapWithSetBoats
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(826, 468);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
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.ClientSize = new System.Drawing.Size(956, 557);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Name = "FormMapWithSetBoats";
|
||||
this.Text = "FormMapWithSetBoats";
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
this.groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.StatusStrip statusStrip1;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelColor;
|
||||
private System.Windows.Forms.PictureBox pictureBoxCatamaran;
|
||||
|
||||
private System.Windows.Forms.GroupBox groupBoxTools;
|
||||
private System.Windows.Forms.ComboBox comboBoxSelectorMap;
|
||||
private System.Windows.Forms.PictureBox pictureBox;
|
||||
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 buttonDown;
|
||||
private System.Windows.Forms.Button buttonLeft;
|
||||
private System.Windows.Forms.Button buttonRight;
|
||||
private System.Windows.Forms.Button buttonCreate;
|
||||
private System.Windows.Forms.ComboBox comboBoxSelectorMap;
|
||||
private System.Windows.Forms.Button buttonCreateModif;
|
||||
}
|
||||
}
|
165
Catamaran/FormMapWithSetBoats.cs
Normal file
165
Catamaran/FormMapWithSetBoats.cs
Normal 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("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
193
Catamaran/MapWithSetBoatsGeneric.cs
Normal file
193
Catamaran/MapWithSetBoatsGeneric.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace Catamaran
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormMap());
|
||||
Application.Run(new FormMapWithSetBoats());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
113
Catamaran/SetBoatsGeneric.cs
Normal file
113
Catamaran/SetBoatsGeneric.cs
Normal 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];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user