Лабораторная 3

This commit is contained in:
evasina2312@gmail.com 2022-10-27 15:46:11 +04:00
parent 8b62bbfab7
commit 000c848d81
8 changed files with 419 additions and 101 deletions

View File

@ -168,6 +168,7 @@
this.buttonSelectTank.TabIndex = 8; this.buttonSelectTank.TabIndex = 8;
this.buttonSelectTank.Text = "Выбрать"; this.buttonSelectTank.Text = "Выбрать";
this.buttonSelectTank.UseVisualStyleBackColor = true; this.buttonSelectTank.UseVisualStyleBackColor = true;
this.buttonSelectTank.Click += new System.EventHandler(this.buttonSelectTank_Click);
// //
// FormMachine // FormMachine
// //

View File

@ -40,7 +40,13 @@ namespace ProjectMachine
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_machine = new DrawningMachine(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_machine = new DrawningMachine(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData(); SetData();
Draw(); Draw();
} }
@ -110,7 +116,7 @@ namespace ProjectMachine
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonSelectCar_Click(object sender, EventArgs e) private void buttonSelectTank_Click(object sender, EventArgs e)
{ {
SelectedTank = _machine; SelectedTank = _machine;
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;

View File

@ -28,12 +28,199 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.groupBoxTools = new System.Windows.Forms.GroupBox();
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.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveTank = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddTank = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBoxTools
//
this.groupBoxTools.Controls.Add(this.buttonLeft);
this.groupBoxTools.Controls.Add(this.buttonUp);
this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.buttonDown);
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.groupBoxTools.Controls.Add(this.buttonRemoveTank);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonAddTank);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(807, 0);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(233, 546);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты";
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectMachine.Properties.Resources.лево;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(69, 491);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(34, 30);
this.buttonLeft.TabIndex = 13;
this.buttonLeft.Text = " \r\n\r\n";
this.buttonLeft.UseVisualStyleBackColor = true;
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::ProjectMachine.Properties.Resources.вверх;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(105, 455);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(34, 30);
this.buttonUp.TabIndex = 12;
this.buttonUp.Text = " \r\n\r\n";
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::ProjectMachine.Properties.Resources.право;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(141, 491);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(34, 30);
this.buttonRight.TabIndex = 11;
this.buttonRight.Text = " \r\n\r\n";
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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::ProjectMachine.Properties.Resources.вниз;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(105, 491);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(34, 30);
this.buttonDown.TabIndex = 10;
this.buttonDown.Text = " \r\n\r\n";
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Город"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(26, 35);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(199, 28);
this.comboBoxSelectorMap.TabIndex = 9;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(25, 379);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
this.buttonShowOnMap.TabIndex = 6;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(25, 291);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
this.buttonShowStorage.TabIndex = 5;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonRemoveTank
//
this.buttonRemoveTank.Location = new System.Drawing.Point(25, 205);
this.buttonRemoveTank.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRemoveTank.Name = "buttonRemoveTank";
this.buttonRemoveTank.Size = new System.Drawing.Size(200, 47);
this.buttonRemoveTank.TabIndex = 4;
this.buttonRemoveTank.Text = "Удалить танк";
this.buttonRemoveTank.UseVisualStyleBackColor = true;
this.buttonRemoveTank.Click += new System.EventHandler(this.ButtonRemoveTank_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(26, 170);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(199, 27);
this.maskedTextBoxPosition.TabIndex = 3;
this.maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddTank
//
this.buttonAddTank.Location = new System.Drawing.Point(25, 82);
this.buttonAddTank.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddTank.Name = "buttonAddTank";
this.buttonAddTank.Size = new System.Drawing.Size(200, 47);
this.buttonAddTank.TabIndex = 2;
this.buttonAddTank.Text = "Добавить танк";
this.buttonAddTank.UseVisualStyleBackColor = true;
this.buttonAddTank.Click += new System.EventHandler(this.ButtonAddTank_Click);
//
// pictureBox
//
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(807, 546);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetTank
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(1040, 546);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetTank";
this.Text = "FormMapWithSetTank"; this.Text = "FormMapWithSetTank";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
} }
#endregion #endregion
private GroupBox groupBoxTools;
private PictureBox pictureBox;
private Button buttonShowOnMap;
private Button buttonShowStorage;
private Button buttonRemoveTank;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddTank;
private ComboBox comboBoxSelectorMap;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
} }
} }

View File

@ -12,9 +12,153 @@ namespace ProjectMachine
{ {
public partial class FormMapWithSetTank : Form public partial class FormMapWithSetTank : Form
{ {
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetTankGeneric<DrawningObject, AbstractMap> _mapTankCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetTank() public FormMapWithSetTank()
{ {
InitializeComponent(); 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 "Простая карта":
map = new SimpleMap();
break;
case "Город":
map = new TownMap();
break;
}
if (map != null)
{
_mapTankCollectionGeneric = new MapWithSetTankGeneric<DrawningObject, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapTankCollectionGeneric = null;
} }
} }
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddTank_Click(object sender, EventArgs e)
{
if (_mapTankCollectionGeneric == null)
{
return;
}
FormMachine form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObject tank = new(form.SelectedTank);
if ((_mapTankCollectionGeneric + tank) > -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveTank_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 ((_mapTankCollectionGeneric - pos) != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapTankCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapTankCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapTankCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapTankCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapTankCollectionGeneric == 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 = _mapTankCollectionGeneric.MoveObject(dir);
}
}
}

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <root>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">

View File

@ -26,11 +26,11 @@ namespace ProjectMachine
/// <summary> /// <summary>
/// Размер занимаемого объектом места (ширина) /// Размер занимаемого объектом места (ширина)
/// </summary> /// </summary>
private readonly int _placeSizeWidth = 210; private readonly int _placeSizeWidth = 200;
/// <summary> /// <summary>
/// Размер занимаемого объектом места (высота) /// Размер занимаемого объектом места (высота)
/// </summary> /// </summary>
private readonly int _placeSizeHeight = 90; private readonly int _placeSizeHeight = 70;
/// <summary> /// <summary>
/// Набор объектов /// Набор объектов
/// </summary> /// </summary>
@ -58,11 +58,11 @@ namespace ProjectMachine
/// Перегрузка оператора сложения /// Перегрузка оператора сложения
/// </summary> /// </summary>
/// <param name="map"></param> /// <param name="map"></param>
/// <param name="car"></param> /// <param name="tank"></param>
/// <returns></returns> /// <returns></returns>
public static bool operator + (MapWithSetTankGeneric<T, U> map, T car) public static int operator +(MapWithSetTankGeneric<T, U> map, T tank)
{ {
return map._setTank.Insert(car); return map._setTank.Insert(tank);
} }
/// <summary> /// <summary>
/// Перегрузка оператора вычитания /// Перегрузка оператора вычитания
@ -70,8 +70,7 @@ namespace ProjectMachine
/// <param name="map"></param> /// <param name="map"></param>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public static bool operator -(MapWithSetTankGeneric<T, U> map, int public static T operator -(MapWithSetTankGeneric<T, U> map, int position)
position)
{ {
return map._setTank.Remove(position); return map._setTank.Remove(position);
} }
@ -81,10 +80,11 @@ namespace ProjectMachine
/// <returns></returns> /// <returns></returns>
public Bitmap ShowSet() public Bitmap ShowSet()
{ {
Shaking();
Bitmap bmp = new(_pictureWidth, _pictureHeight); Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr); DrawBackground(gr);
DrawCars(gr); DrawTanks(gr);
return bmp; return bmp;
} }
/// <summary> /// <summary>
@ -96,10 +96,10 @@ namespace ProjectMachine
Shaking(); Shaking();
for (int i = 0; i < _setTank.Count; i++) for (int i = 0; i < _setTank.Count; i++)
{ {
var car = _setTank.Get(i); var tank = _setTank.Get(i);
if (car != null) if (tank != null)
{ {
return _map.CreateMap(_pictureWidth, _pictureHeight, car); return _map.CreateMap(_pictureWidth, _pictureHeight, tank);
} }
} }
return new(_pictureWidth, _pictureHeight); return new(_pictureWidth, _pictureHeight);
@ -150,7 +150,9 @@ namespace ProjectMachine
/// <param name="g"></param> /// <param name="g"></param>
private void DrawBackground(Graphics g) private void DrawBackground(Graphics g)
{ {
Pen pen = new(Color.Black, 3); Pen pen = new(Color.Black, 6);
Brush br = new SolidBrush(Color.Moccasin);
g.FillRectangle(br, 0, 0, _pictureWidth, _pictureHeight);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{ {
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
@ -166,12 +168,23 @@ namespace ProjectMachine
/// Метод прорисовки объектов /// Метод прорисовки объектов
/// </summary> /// </summary>
/// <param name="g"></param> /// <param name="g"></param>
private void DrawCars(Graphics g) private void DrawTanks(Graphics g)
{ {
for (int i = 0; i < _setTank.Count; i++) int i = 0;
int j = 0;
for (int k = 0; k < _setTank.Count; k++)
{ {
// TODO установка позиции _setTank.Get(k)?.SetObject(j + 10, i + 20, _pictureWidth, _pictureHeight);
_setTank.Get(i)?.DrawningObject(g); _setTank.Get(k)?.DrawningObject(g);
if (j >= _pictureWidth - 2*_placeSizeWidth)
{
j = 0;
i += _placeSizeHeight;
}
else
{
j += _placeSizeWidth;
}
} }
} }
} }

View File

@ -11,7 +11,7 @@ namespace ProjectMachine
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormMap()); Application.Run(new FormMapWithSetTank());
} }
} }
} }

View File

@ -32,39 +32,63 @@ namespace ProjectMachine
/// <summary> /// <summary>
/// Добавление объекта в набор /// Добавление объекта в набор
/// </summary> /// </summary>
/// <param name="car">Добавляемый автомобиль</param> /// <param name="car">Добавляемый танк</param>
/// <returns></returns> /// <returns></returns>
public bool Insert(T car) public int Insert(T tank)
{ {
// TODO вставка в начало набора if (tank == null)
return true; {
return -1;
}
for (int i = Count -1; i > 0; i--)
{
_places[i] = _places[i - 1];
}
_places[0] = tank;
return 0;
} }
/// <summary> /// <summary>
/// Добавление объекта в набор на конкретную позицию /// Добавление объекта в набор на конкретную позицию
/// </summary> /// </summary>
/// <param name="car">Добавляемый автомобиль</param> /// <param name="tank">Добавляемый танк</param>
/// <param name="position">Позиция</param> /// <param name="position">Позиция</param>
/// <returns></returns> /// <returns></returns>
public bool Insert(T car, int position) public int Insert(T tank, int position)
{ {
// TODO проверка позиции if (position < 0 || position > Count)
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то {
// проверка, что после вставляемого элемента в массиве есть пустой элемент return -1;
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента }
// TODO вставка по позиции int firstNullElementIndex = position; //индекс первого нулевого элемента
_places[position] = car; while(_places[firstNullElementIndex] != null)
return true; {
if (firstNullElementIndex >= Count)
{
return -1;
}
firstNullElementIndex++;
}
for (int i = firstNullElementIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = tank;
return 0;
} }
/// <summary> /// <summary>
/// Удаление объекта из набора с конкретной позиции /// Удаление объекта из набора с конкретной позиции
/// </summary> /// </summary>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public bool Remove(int position) public T Remove(int position)
{ {
// TODO проверка позиции if (_places[position] == null)
// TODO удаление объекта из массива, присовив элементу массива значение null {
return true; return null;
}
var result = _places[position];
_places[position] = null;
return result;
} }
/// <summary> /// <summary>
/// Получение объекта из набора по позиции /// Получение объекта из набора по позиции
@ -73,9 +97,12 @@ namespace ProjectMachine
/// <returns></returns> /// <returns></returns>
public T Get(int position) public T Get(int position)
{ {
// TODO проверка позиции if (_places[position] != null)
{
return _places[position]; return _places[position];
} }
return null;
}
} }
} }