Добавление родителей и ввод конструкторов

This commit is contained in:
TUSHKANCH11K 2024-03-18 00:19:14 +04:00
parent 9d823f93b0
commit 112d2ec455
10 changed files with 382 additions and 154 deletions

View File

@ -1,4 +1,4 @@
namespace SelfPropelledArtilleryUnit;
namespace SelfPropelledArtilleryUnit.Drawnings;
/// <summary>
/// Направление перемещения
/// </summary>

View File

@ -1,14 +1,18 @@
namespace SelfPropelledArtilleryUnit;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
using SelfPropelledArtilleryUnit.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class DrawningSelfPropelledArtilleryUnit
namespace SelfPropelledArtilleryUnit.Drawnings;
public class DrawningPropelledArtillery
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntitySelfPropelledArtilleryUnit? EntitySelfPropelledArtilleryUnit { get; private set; }
public EntityPropelledArtillery? EntityPropelledArtillery { get; protected set; }
/// <summary>
/// Ширина окна
@ -23,43 +27,57 @@ public class DrawningSelfPropelledArtilleryUnit
/// <summary>
/// Левая координата прорисовки cамоходной арт. установки
/// </summary>
private int? _startPosX;
protected int? _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки cамоходной арт. установки
/// </summary>
private int? _startPosY;
protected int? _startPosY;
/// <summary>
/// Ширина прорисовки cамоходной арт. установки
/// </summary>
private readonly int _drawningSelfPropelledArtilleryUnitWidth = 135;
private readonly int _drawningPropelledArtilleryWidth = 135;
/// <summary>
/// Высота прорисовки cамоходной арт. установки
/// </summary>
private readonly int _drawningSelfPropelledArtilleryUnitHeight = 105;
private readonly int _drawningPropelledArtilleryHeight = 105;
/// <summary>
/// Инициализация полей объекта-класса Самоходная арт. установка
/// Пустой конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="turretCannon">Признак наличия башни</param>
/// <param name="launchBattery">Признак наличия орудия</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool turretCannon, bool launchBattery)
private DrawningPropelledArtillery()
{
EntitySelfPropelledArtilleryUnit = new EntitySelfPropelledArtilleryUnit();
EntitySelfPropelledArtilleryUnit.Init(speed, weight, bodyColor, additionalColor, turretCannon, launchBattery);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawningPropelledArtillery(int speed, double weight, Color bodyColor): this()
{
EntityPropelledArtillery = new EntityPropelledArtillery(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор для наследников
/// </summary>
/// <param name="drawningPropelledArtilleryWidth">Ширина прорисовки cамоходной арт. установки</param>
/// <param name="drawningPropelledArtilleryHeight">Высота прорисовки cамоходной арт. установки</param>
protected DrawningPropelledArtillery(int drawningPropelledArtilleryWidth, int drawningPropelledArtilleryHeight):this()
{
_drawningPropelledArtilleryWidth = drawningPropelledArtilleryWidth;
_drawningPropelledArtilleryHeight = drawningPropelledArtilleryHeight;
}
/// <summary>
/// Установка границ поля
/// </summary>
@ -68,7 +86,7 @@ public class DrawningSelfPropelledArtilleryUnit
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height)
{
if (_drawningSelfPropelledArtilleryUnitWidth > width || _drawningSelfPropelledArtilleryUnitHeight > height)
if (_drawningPropelledArtilleryWidth > width || _drawningPropelledArtilleryHeight > height)
{
return false;
}
@ -77,14 +95,14 @@ public class DrawningSelfPropelledArtilleryUnit
_pictureHeight = height;
if (_startPosX.HasValue || _startPosY.HasValue)
{
if (_startPosX + _drawningSelfPropelledArtilleryUnitWidth > _pictureWidth)
if (_startPosX + _drawningPropelledArtilleryWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningSelfPropelledArtilleryUnitWidth;
_startPosX = _pictureWidth - _drawningPropelledArtilleryWidth;
}
else if (_startPosX < 0) _startPosX = 0;
if (_startPosY + _drawningSelfPropelledArtilleryUnitHeight > _pictureHeight)
if (_startPosY + _drawningPropelledArtilleryHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningSelfPropelledArtilleryUnitHeight;
_startPosY = _pictureHeight - _drawningPropelledArtilleryHeight;
}
else if (_startPosY < 0) _startPosY = 0;
}
@ -105,16 +123,16 @@ public class DrawningSelfPropelledArtilleryUnit
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
// то надо изменить координаты, чтобы он оставался в этих границах
if (x + _drawningSelfPropelledArtilleryUnitWidth > _pictureWidth)
if (x + _drawningPropelledArtilleryWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningSelfPropelledArtilleryUnitWidth;
_startPosX = _pictureWidth - _drawningPropelledArtilleryWidth;
}
else if (x < 0) _startPosX = 0;
else _startPosX = x;
if (y + _drawningSelfPropelledArtilleryUnitHeight > _pictureHeight)
if (y + _drawningPropelledArtilleryHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningSelfPropelledArtilleryUnitHeight;
_startPosY = _pictureHeight - _drawningPropelledArtilleryHeight;
}
else if (y < 0) _startPosY = 0;
else _startPosY = y;
@ -128,7 +146,7 @@ public class DrawningSelfPropelledArtilleryUnit
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntitySelfPropelledArtilleryUnit == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityPropelledArtillery == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
@ -137,30 +155,30 @@ public class DrawningSelfPropelledArtilleryUnit
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntitySelfPropelledArtilleryUnit.Step > 0)
if (_startPosX.Value - EntityPropelledArtillery.Step > 0)
{
_startPosX -= (int)EntitySelfPropelledArtilleryUnit.Step;
_startPosX -= (int)EntityPropelledArtillery.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntitySelfPropelledArtilleryUnit.Step > 0)
if (_startPosY.Value - EntityPropelledArtillery.Step > 0)
{
_startPosY -= (int)EntitySelfPropelledArtilleryUnit.Step;
_startPosY -= (int)EntityPropelledArtillery.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX + _drawningSelfPropelledArtilleryUnitWidth + EntitySelfPropelledArtilleryUnit.Step < _pictureWidth)
if (_startPosX + _drawningPropelledArtilleryWidth + EntityPropelledArtillery.Step < _pictureWidth)
{
_startPosX += (int)EntitySelfPropelledArtilleryUnit.Step;
_startPosX += (int)EntityPropelledArtillery.Step;
}
return true;
// вниз
case DirectionType.Down:
if (_startPosY + _drawningSelfPropelledArtilleryUnitHeight + EntitySelfPropelledArtilleryUnit.Step < _pictureHeight)
if (_startPosY + _drawningPropelledArtilleryHeight + EntityPropelledArtillery.Step < _pictureHeight)
{
_startPosY += (int)EntitySelfPropelledArtilleryUnit.Step;
_startPosY += (int)EntityPropelledArtillery.Step;
}
return true;
default:
@ -173,16 +191,16 @@ public class DrawningSelfPropelledArtilleryUnit
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (EntitySelfPropelledArtilleryUnit == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityPropelledArtillery == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntitySelfPropelledArtilleryUnit.AdditionalColor);
g.DrawEllipse(pen, _startPosX.Value + 0, _startPosY.Value + 75, 30, 30);
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 75, 30, 30);
@ -234,28 +252,7 @@ public class DrawningSelfPropelledArtilleryUnit
g.FillRectangle(brOlive, _startPosX.Value + 0, _startPosY.Value + 65, 120, 13);//
if (EntitySelfPropelledArtilleryUnit.TurretCannon)
{
g.FillEllipse(additionalBrush, _startPosX.Value + 26, _startPosY.Value + 35, 50, 30);
g.FillRectangle(additionalBrush, _startPosX.Value + 25, _startPosY.Value + 36, 20, 29);
g.FillRectangle(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 45, 60, 5);
g.FillEllipse(additionalBrush, _startPosX.Value + 113, _startPosY.Value + 42, 20, 10);
}
if (EntitySelfPropelledArtilleryUnit.LaunchBattery)
{
g.FillRectangle(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 45, 20, 20);
g.FillPolygon(additionalBrush, new Point[]
{
new Point(_startPosX.Value + 0, _startPosY.Value + 15), new Point(_startPosX.Value + 0, _startPosY.Value + 65),
new Point(_startPosX.Value + 20, _startPosY.Value + 65), new Point(_startPosX.Value + 20, _startPosY.Value + 45),
new Point(_startPosX.Value + 0, _startPosY.Value + 15)
});
g.FillEllipse(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 5, 10, 30);
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 15, 20, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 25, 15, 5);
}
}
}

View File

@ -0,0 +1,58 @@
using SelfPropelledArtilleryUnit.Entities;
namespace SelfPropelledArtilleryUnit.Drawnings;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningSelfPropelledArtilleryUnit : DrawningPropelledArtillery
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="turretCannon">Признак наличия башни</param>
/// <param name="launchBattery">Признак наличия орудия</param>
public DrawningSelfPropelledArtilleryUnit(int speed, double weight, Color bodyColor, Color additionalColor, bool turretCannon, bool launchBattery) : base(135, 105)
{
EntityPropelledArtillery = new EntitySelfPropelledArtilleryUnit(speed, weight, bodyColor, additionalColor, turretCannon, launchBattery);
//дописать
}
public override void DrawTransport(Graphics g)
{
if (EntityPropelledArtillery == null || EntityPropelledArtillery is not EntitySelfPropelledArtilleryUnit selfpropelledartilleryunit || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(selfpropelledartilleryunit.AdditionalColor);
if (selfpropelledartilleryunit.TurretCannon)
{
g.FillEllipse(additionalBrush, _startPosX.Value + 26, _startPosY.Value + 35, 50, 30);
g.FillRectangle(additionalBrush, _startPosX.Value + 25, _startPosY.Value + 36, 20, 29);
g.FillRectangle(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 45, 60, 5);
g.FillEllipse(additionalBrush, _startPosX.Value + 113, _startPosY.Value + 42, 20, 10);
}
if (selfpropelledartilleryunit.LaunchBattery)
{
g.FillRectangle(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 45, 20, 20);
g.FillPolygon(additionalBrush, new Point[]
{
new Point(_startPosX.Value + 0, _startPosY.Value + 15), new Point(_startPosX.Value + 0, _startPosY.Value + 65),
new Point(_startPosX.Value + 20, _startPosY.Value + 65), new Point(_startPosX.Value + 20, _startPosY.Value + 45),
new Point(_startPosX.Value + 0, _startPosY.Value + 15)
});
g.FillEllipse(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 5, 10, 30);
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 15, 20, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 25, 15, 5);
}
base.DrawTransport(g);
}
}

View File

@ -0,0 +1,33 @@
namespace SelfPropelledArtilleryUnit.Entities;
public class EntityPropelledArtillery
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Шаг перемещения артеллерийской установки
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Конструктор сущности
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityPropelledArtillery(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}

View File

@ -0,0 +1,35 @@
namespace SelfPropelledArtilleryUnit.Entities;
public class EntitySelfPropelledArtilleryUnit : EntityPropelledArtillery
{
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак - Башня с орудием
/// </summary>
public bool TurretCannon { get; private set; }
/// <summary>
/// Признак - Залповая батарея сзади
/// </summary>
public bool LaunchBattery { get; private set; }
/// <summary>
/// Шаг перемещения артеллерийской установки
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса EntitySelfPropelledArtilleryUnit
/// </summary>
/// <param name="additionalcolor">Дополнительный цвет</param>
/// <param name="turretcannon">Башня с орудием</param>
/// <param name="launchbattery">Залповая батарея сзади</param>
public EntitySelfPropelledArtilleryUnit(int speed, double weight, Color bodycolor, Color additionalcolor, bool turretcannon, bool launchbattery) : base(speed, weight, bodycolor)
{
AdditionalColor = additionalcolor;
TurretCannon = turretcannon;
LaunchBattery = launchbattery;
}
}

View File

@ -1,61 +0,0 @@
namespace SelfPropelledArtilleryUnit;
/// <summary>
/// Класс-сущность "Самоходная арт. установка "
/// </summary>
public class EntitySelfPropelledArtilleryUnit
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак - Башня с орудием
/// </summary>
public bool TurretCannon { get; private set; }
/// <summary>
/// Признак - Залповая батарея сзади
/// </summary>
public bool LaunchBattery { get; private set; }
/// <summary>
/// Шаг перемещения артеллерийской установки
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса Самоходная арт. установка
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="turretCannon">Башня с орудием</param>
/// <param name="launchBattery">Залповая батарея сзади</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool turretCannon, bool launchBattery)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
TurretCannon = turretCannon;
LaunchBattery = launchBattery;
}
}

View File

@ -28,10 +28,16 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "FormSelfPropelledArtilleryUnit";
SuspendLayout();
//
// FormSelfPropelledArtilleryUnit
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(877, 442);
Name = "FormSelfPropelledArtilleryUnit";
Text = "FormSelfPropelledArtilleryUnit";
ResumeLayout(false);
}
#endregion

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -34,6 +34,7 @@
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
button1 = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxSelfPropelledArtilleryUnit).BeginInit();
SuspendLayout();
//
@ -49,13 +50,13 @@
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 438);
buttonCreate.Location = new Point(12, 446);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(94, 43);
buttonCreate.Size = new Size(226, 35);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать";
buttonCreate.Text = "Создать самоходную арт. установку";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
buttonCreate.Click += buttonCreateSelfPropelledArtilleryUnit_Click;
//
// buttonLeft
//
@ -105,11 +106,23 @@
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// button1
//
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
button1.Location = new Point(253, 446);
button1.Name = "button1";
button1.Size = new Size(226, 35);
button1.TabIndex = 6;
button1.Text = "Создать бронированную машину";
button1.UseVisualStyleBackColor = true;
button1.Click += buttonCreatePropelledArtillery_Click;
//
// SelfPropelledArtilleryUnit
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(923, 493);
Controls.Add(button1);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
@ -130,5 +143,6 @@
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
private Button button1;
}
}

View File

@ -7,12 +7,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SelfPropelledArtilleryUnit.Drawnings;
namespace SelfPropelledArtilleryUnit
{
public partial class SelfPropelledArtilleryUnit : Form
{
private DrawningSelfPropelledArtilleryUnit? _drawningSelfPropelledArtilleryUnit;
private DrawningPropelledArtillery? _drawningPropelledArtillery;
public SelfPropelledArtilleryUnit()
{
@ -20,32 +21,57 @@ namespace SelfPropelledArtilleryUnit
}
private void Draw()
{
if (_drawningSelfPropelledArtilleryUnit == null)
if (_drawningPropelledArtillery == null)
{
return;
}
Bitmap bmp = new(pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningSelfPropelledArtilleryUnit.DrawTransport(gr);
_drawningPropelledArtillery.DrawTransport(gr);
pictureBoxSelfPropelledArtilleryUnit.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
private void CreateObject(string type)
{
Random random = new();
_drawningSelfPropelledArtilleryUnit = new DrawningSelfPropelledArtilleryUnit();
_drawningSelfPropelledArtilleryUnit.Init(random.Next(100, 300), random.Next(1000, 3000),
switch (type)
{
case nameof(DrawningPropelledArtillery):
_drawningPropelledArtillery = new DrawningPropelledArtillery(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
break;
case nameof(DrawningSelfPropelledArtilleryUnit):
_drawningPropelledArtillery = new DrawningSelfPropelledArtilleryUnit(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
_drawningSelfPropelledArtilleryUnit.SetPictureSize(pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
_drawningSelfPropelledArtilleryUnit.SetPosition(random.Next(10, 100), random.Next(10, 100));
break;
default:
return;
}
_drawningPropelledArtillery.SetPictureSize(pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
_drawningPropelledArtillery.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Создать самоходную арт.установку"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateSelfPropelledArtilleryUnit_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSelfPropelledArtilleryUnit));
/// <summary>
/// Обработка нажатия кнопки "Создать бронированную машину"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreatePropelledArtillery_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPropelledArtillery));
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningSelfPropelledArtilleryUnit == null)
if (_drawningPropelledArtillery == null)
{
return;
}
@ -55,13 +81,13 @@ namespace SelfPropelledArtilleryUnit
switch (name)
{
case "buttonUp":
result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Up); break;
result = _drawningPropelledArtillery.MoveTransport(DirectionType.Up); break;
case "buttonDown":
result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Down); break;
result = _drawningPropelledArtillery.MoveTransport(DirectionType.Down); break;
case "buttonLeft":
result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Left); break;
result = _drawningPropelledArtillery.MoveTransport(DirectionType.Left); break;
case "buttonRight":
result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Right); break;
result = _drawningPropelledArtillery.MoveTransport(DirectionType.Right); break;
}
if (result)