This commit is contained in:
elizaveta 2024-03-27 02:25:40 +04:00
parent d50ab78037
commit 442c51b679
8 changed files with 219 additions and 207 deletions

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tank;
namespace Tank.Drowings;
public enum DirectionType
{

View File

@ -3,15 +3,16 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tank.Entities;
namespace Tank;
namespace Tank.Drowings;
public class DrawningTank
public class DrawningMachine
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityTank? EntityTank { get; private set; }
public EntityMachine? EntityMachine { get; protected set; }
/// <summary>
/// Ширина окна
/// </summary>
@ -23,11 +24,11 @@ public class DrawningTank
/// <summary>
/// Левая координата прорисовки автомобиля
/// </summary>
private int? _startPosX;
protected int? _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки автомобиля
/// </summary>
private int? _startPosY;
protected int? _startPosY;
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
@ -36,26 +37,42 @@ public class DrawningTank
/// Высота прорисовки автомобиля
/// </summary>
private readonly int _drawningTankHeight = 105;
/// <summary>
/// Инициализация свойств
/// Пустой конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="pushka">Признак наличия обвеса</param>
/// <param name="pulemet">Признак наличия антикрыла</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pushka, bool pulemet)
private DrawningMachine()
{
EntityTank = new EntityTank();
EntityTank.Init(speed, weight, bodyColor, additionalColor, pushka, pulemet);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawningMachine(int speed, double weight, Color bodyColor) : this()
{
EntityMachine = new EntityMachine(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор для наследников
/// </summary>
/// <param name="_drawningTankWidth">Ширина прорисовки автомобиля</param>
/// <param name="_drawningTankHeight">Высота прорисовки автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
protected DrawningMachine(int _drawningTankWidth, int _drawningTankHeight) : this()
{
_drawningTankWidth = _drawningTankWidth;
_drawningTankHeight = _drawningTankHeight;
}
/// <summary>
/// Установка границ поля
/// </summary>
/// <param name="width">Ширина поля</param>
@ -115,7 +132,7 @@ public class DrawningTank
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityTank == null || !_startPosX.HasValue ||
if (EntityMachine == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return false;
@ -124,23 +141,23 @@ public class DrawningTank
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityTank.Step > 0)
_startPosX -= (int)EntityTank.Step;
if (_startPosX.Value - EntityMachine.Step > 0)
_startPosX -= (int)EntityMachine.Step;
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntityTank.Step > 0)
_startPosY -= (int)EntityTank.Step;
if (_startPosY.Value - EntityMachine.Step > 0)
_startPosY -= (int)EntityMachine.Step;
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + _drawningTankWidth + EntityTank.Step < _pictureWidth)
_startPosX += (int)EntityTank.Step;
if (_startPosX.Value + _drawningTankWidth + EntityMachine.Step < _pictureWidth)
_startPosX += (int)EntityMachine.Step;
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + _drawningTankHeight + EntityTank.Step < _pictureHeight)
_startPosY += (int)EntityTank.Step;
if (_startPosY.Value + _drawningTankHeight + EntityMachine.Step < _pictureHeight)
_startPosY += (int)EntityMachine.Step;
return true;
default:
return false;
@ -150,24 +167,16 @@ public class DrawningTank
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (EntityTank == null || !_startPosX.HasValue ||
if (EntityMachine == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityTank.AdditionalColor);
Brush bodyBrush = new SolidBrush(EntityTank.BodyColor);
//linii v gusenice
Point p4 = new Point(_startPosX.Value + 100, _startPosY.Value + 10);
Point p5 = new Point(_startPosX.Value + 100, _startPosY.Value + 10);
Point p6 = new Point(_startPosX.Value + 100, _startPosY.Value + 10);
Point p7 = new Point(_startPosX.Value + 100, _startPosY.Value + 10);
Point[] p_pulemet = { p4, p5, p6, p7 };
g.FillPolygon(additionalBrush, p_pulemet);
Brush bodyBrush = new SolidBrush(EntityMachine.BodyColor);
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 45, 150, 60);
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 60, 33, 33);
@ -194,17 +203,5 @@ public class DrawningTank
g.FillRectangle(bodyBrush, _startPosX.Value + 30, _startPosY.Value + 10, 100, 30);
g.FillRectangle(bodyBrush, _startPosX.Value + 5, _startPosY.Value + 40, 140, 25);
//if(EntityTank.Pushka)
// g.FillRectangle(additionalBrush, _startPosX.Value + 120, _startPosY.Value + 20, 100, 15);
//if (EntityTank.Pulemet)
//{
// Point p = new Point(_startPosX.Value + 75, _startPosY.Value + 10);
// Point p1 = new Point(_startPosX.Value + 80, _startPosY.Value + 1);
// Point p2 = new Point(_startPosX.Value + 87, _startPosY.Value + 2);
// Point p3 = new Point(_startPosX.Value + 80, _startPosY.Value + 10);
// Point[] p_pulemet = { p, p1, p2, p3 };
// g.FillPolygon(additionalBrush, p_pulemet);
//}
}
}

View File

@ -0,0 +1,58 @@
using Tank.Entities;
namespace Tank.Drowings;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningTank : DrawningMachine
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="pushka">Признак наличия обвеса</param>
/// <param name="pulemet">Признак наличия антикрыла</param>
public DrawningTank(int speed, double weight, Color bodyColor, Color additionalColor, bool pushka, bool pulemet) : base(218, 105)
{
EntityMachine = new EntityTank(speed, weight, bodyColor, additionalColor, pushka, pulemet);
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public override void DrawTransport(Graphics g)
{
if (EntityMachine == null || EntityMachine is not EntityTank tank || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
base.DrawTransport(g);
Brush additionalBrush = new SolidBrush(tank.AdditionalColor);
if (tank.Pushka)
g.FillRectangle(additionalBrush, _startPosX.Value + 120, _startPosY.Value + 20, 100, 15);
_startPosX += 10;
_startPosY += 5;
base.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 5;
if (tank.Pulemet)
{
Point p = new Point(_startPosX.Value + 75, _startPosY.Value + 10);
Point p1 = new Point(_startPosX.Value + 80, _startPosY.Value + 1);
Point p2 = new Point(_startPosX.Value + 87, _startPosY.Value + 2);
Point p3 = new Point(_startPosX.Value + 80, _startPosY.Value + 10);
Point[] p_pulemet1 = { p, p1, p2, p3 };
g.FillPolygon(additionalBrush, p_pulemet1);
}
}
}

View File

@ -0,0 +1,39 @@
namespace Tank.Entities;
/// <summary>
/// Класс-сущность "Машина"
/// </summary>
public class EntityMachine
{
/// <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>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => Speed * 100 / Weight;
public EntityMachine(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}

View File

@ -1,19 +1,7 @@
namespace Tank;
namespace Tank.Entities;
public class EntityTank
public class EntityTank : EntityMachine
{
/// <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>
@ -27,10 +15,7 @@ public class EntityTank
/// </summary>
public bool Pulemet { get; private set; }
public bool Gusenica { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля
/// </summary>
@ -41,14 +26,11 @@ public class EntityTank
/// <param name="pushka">Признак наличия обвеса</param>
/// <param name="pulemet">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pushka, bool pulemet)
public EntityTank(int speed, double weight, Color bodyColor, Color additionalColor, bool pushka, bool pulemet) : base(speed, weight, bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Pushka = pushka;
Pulemet = pulemet;
}
}

View File

@ -1,137 +1,63 @@
namespace Tank
{
partial class FormTank
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Tank {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class FormTank {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal FormTank() {
}
/// <summary>
/// Clean up any resources being used.
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tank.FormTank", typeof(FormTank).Assembly);
resourceMan = temp;
}
return resourceMan;
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
private void InitializeComponent()
{
pictureBoxTank = new PictureBox();
buttonCreate = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonRight = new Button();
buttonDown = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit();
SuspendLayout();
//
// pictureBoxTank
//
pictureBoxTank.AccessibleRole = AccessibleRole.None;
pictureBoxTank.Dock = DockStyle.Fill;
pictureBoxTank.Location = new Point(0, 0);
pictureBoxTank.Name = "pictureBoxTank";
pictureBoxTank.Size = new Size(1235, 854);
pictureBoxTank.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxTank.TabIndex = 1;
pictureBoxTank.TabStop = false;
pictureBoxTank.Click += ButtonMove_Click;
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 796);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(150, 46);
buttonCreate.TabIndex = 2;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreateTank_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.left;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(1021, 786);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(45, 45);
buttonLeft.TabIndex = 3;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.up;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(1072, 735);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(45, 45);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.right;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(1123, 786);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(45, 45);
buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.down;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(1072, 786);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(45, 45);
buttonDown.TabIndex = 6;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// FormTank
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1235, 854);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxTank);
Name = "FormTank";
Text = "Танк";
((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit();
ResumeLayout(false);
PerformLayout();
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
#endregion
private PictureBox pictureBoxTank;
private Button buttonCreate;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
}
}
}

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tank.Drowings;
namespace Tank
{
@ -61,6 +62,12 @@ namespace Tank
100));
Draw();
}
private void InitializeComponent()
{
}
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary>

View File

@ -9,6 +9,11 @@
</PropertyGroup>
<ItemGroup>
<Compile Update="FormTank.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>FormTank.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
@ -17,6 +22,10 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="FormTank.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>FormTank.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>