diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DirectionType.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DirectionType.cs new file mode 100644 index 0000000..aac0d0b --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DirectionType.cs @@ -0,0 +1,26 @@ +namespace SelfPropelledArtilleryUnit; +/// +/// Направление перемещения +/// +public enum DirectionType +{ + /// + /// Вверх + /// + Up = 1, + + /// + /// Вниз + /// + Down = 2, + + /// + /// Влево + /// + Left = 3, + + /// + /// Вправо + /// + Right = 4 +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtilleryUnit.cs new file mode 100644 index 0000000..55e8adb --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtilleryUnit.cs @@ -0,0 +1,158 @@ +namespace SelfPropelledArtilleryUnit; +/// +/// Класс, отвечающий за прорисовку и перемещение объекта-сущности +/// + +public class DrawningSelfPropelledArtilleryUnit +{ + /// + /// Класс-сущность + /// + public EntitySelfPropelledArtilleryUnit? EntitySelfPropelledArtilleryUnit { get; private set; } + + /// + /// Ширина окна + /// + private int? _pictureWidth; + + /// + /// Высота окна + /// + private int? _pictureHeight; + + /// + /// Левая координата прорисовки cамоходной арт. установки + /// + private int? _startPosX; + + /// + /// Верхняя кооридната прорисовки cамоходной арт. установки + /// + private int? _startPosY; + + /// + /// Ширина прорисовки cамоходной арт. установки + /// + private readonly int _drawningSelfPropelledArtilleryUnitWidth = 0; + + /// + /// Высота прорисовки cамоходной арт. установки + /// + private readonly int _drawningSelfPropelledArtilleryUnitHeight = 0; + + /// + /// Инициализация полей объекта-класса Самоходная арт. установка + /// + /// Скорость + /// Вес автомобиля + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия башни + /// Признак наличия орудия + /// Признак наличия залповой батарей сзади + + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool towerHeight, bool theWeapon, bool multipleLaunchBattery) + { + EntitySelfPropelledArtilleryUnit = new EntitySelfPropelledArtilleryUnit(); + EntitySelfPropelledArtilleryUnit.Init(speed, weight, bodyColor, additionalColor, towerHeight, theWeapon, multipleLaunchBattery); + _pictureWidth = null; + _pictureHeight = null; + _startPosX = null; + _startPosY = null; + } + + /// + /// Установка границ поля + /// + /// Ширина поля + /// Высота поля + /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах + public bool SetPictureSize(int width, int height) + { + // TODO проверка, что объект "влезает" в размеры поля + // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена + _pictureWidth = width; + _pictureHeight = height; + return true; + } + + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + + // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы + // то надо изменить координаты, чтобы он оставался в этих границах + _startPosX = x; + _startPosY = y; + } + + + /// + /// Изменение направления перемещения + /// + /// Направление + /// true - перемещене выполнено, false - перемещение невозможно + public bool MoveTransport(DirectionType direction) + { + if (EntitySelfPropelledArtilleryUnit == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return false; + } + + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX.Value - EntitySelfPropelledArtilleryUnit.Step > 0) + { + _startPosX -= (int)EntitySelfPropelledArtilleryUnit.Step; + } + return true; + //вверх + case DirectionType.Up: + if (_startPosY.Value - EntitySelfPropelledArtilleryUnit.Step > 0) + { + _startPosY -= (int)EntitySelfPropelledArtilleryUnit.Step; + } + return true; + // вправо + case DirectionType.Right: + if (_startPosX.Value + EntitySelfPropelledArtilleryUnit.Step < MaxWidth) + { + _startPosX += (int)EntitySelfPropelledArtilleryUnit.Step; + } + return true; + //вниз + case DirectionType.Down: + if (_startPosY.Value + EntitySelfPropelledArtilleryUnit.Step < MaxHeight) + { + _startPosY += (int)EntitySelfPropelledArtilleryUnit.Step; + } + return true; + default: + return false; + } + } + + + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (EntitySelfPropelledArtilleryUnit == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + } +} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntitySelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntitySelfPropelledArtilleryUnit.cs new file mode 100644 index 0000000..8b09f15 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntitySelfPropelledArtilleryUnit.cs @@ -0,0 +1,65 @@ +namespace SelfPropelledArtilleryUnit; +/// +/// Класс-сущность "Самоходная арт. установка " +/// +public internal class EntitySelfPropelledArtilleryUnit +{ + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weight { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Дополнительный цвет (для опциональных элементов) + /// + public Color AdditionalColor { get; private set; } + + /// + /// Признак (опция) наличия башни + /// + public bool TowerHeight { get; private set; } + + /// + /// Признак (опция) наличия орудия + /// + public bool TheWeapon { get; private set; } + + /// + /// Признак (опция) наличия залповой батарей сзади + /// + public bool МultipleLaunchBattery { get; private set; } + + public double Step => Speed * 100 / Weight; + + /// + /// Инициализация полей объекта-класса Самоходная арт. установка + /// + /// Скорость + /// Вес автомобиля + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия башни + /// Признак наличия орудия + /// Признак наличия залповой батарей сзади + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool towerHeight, bool theWeapon, bool multipleLaunchBattery) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + TowerHeight = towerHeight; + TheWeapon = theWeapon; + МultipleLaunchBattery = multipleLaunchBattery; + } +} + diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form1.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form1.Designer.cs deleted file mode 100644 index 28dfa19..0000000 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form1.Designer.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace SelfPropelledArtilleryUnit -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - SuspendLayout(); - // - // Form1 - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(783, 549); - Name = "Form1"; - Text = "Form1"; - ResumeLayout(false); - } - - #endregion - } -} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form1.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form1.cs deleted file mode 100644 index eb3b153..0000000 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace SelfPropelledArtilleryUnit -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form1.resx b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form1.resx deleted file mode 100644 index af32865..0000000 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file