Compare commits

...

11 Commits
main ... Lab2

Author SHA1 Message Date
0cc4d81353 fix 2023-10-17 01:42:07 +04:00
6e4ffe95d8 Fix 2023-10-15 22:58:40 +04:00
d5b447bf0f Fixed 2023-10-15 20:34:13 +04:00
4bc51728fe Fixed 2023-10-15 20:14:11 +04:00
821102b9ed Done 2023-10-13 00:01:01 +04:00
2419848c25 done 2023-10-13 00:00:42 +04:00
d9c313d1bf Merge branch 'Lab1' of http://student.git.athene.tech/YourDax/PIbd-23_Tikhonenkov_A.E_AntiAircraftGun into Lab1 2023-10-12 20:52:09 +04:00
a0db4e8315 Доделал 2023-10-12 20:51:18 +04:00
b48aa06661 #тут было контрольное задание 2023-10-11 03:30:11 +04:00
cb138fd554 Добавил 2 свойства-признака 2023-10-11 03:25:57 +04:00
9512284e54 Done 2023-10-11 03:10:41 +04:00
26 changed files with 1198 additions and 71 deletions

View File

@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -1,9 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33110.190
VisualStudioVersion = 17.5.33530.505
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AntiAirCraftGun", "AntiAirCraftGun\AntiAirCraftGun.csproj", "{FB18B709-9154-45E0-8BD8-28822B29FB4B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AntiAircraftGun", "AntiAircraftGun.csproj", "{40C43023-14E0-4146-82EE-7A5A7384992F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,15 +11,15 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FB18B709-9154-45E0-8BD8-28822B29FB4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB18B709-9154-45E0-8BD8-28822B29FB4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB18B709-9154-45E0-8BD8-28822B29FB4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB18B709-9154-45E0-8BD8-28822B29FB4B}.Release|Any CPU.Build.0 = Release|Any CPU
{40C43023-14E0-4146-82EE-7A5A7384992F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40C43023-14E0-4146-82EE-7A5A7384992F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40C43023-14E0-4146-82EE-7A5A7384992F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40C43023-14E0-4146-82EE-7A5A7384992F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EB48B08E-3934-47B3-94AF-DF58D18CDB32}
SolutionGuid = {990D8FF3-8567-49C7-90F4-1811AB7EB423}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun
{
public enum DirectionType
{
/// <summary>
/// Вверх
/// </summary>
Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4
}
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AntiAircraftGun.Enitites;
using static System.Windows.Forms.AxHost;
namespace AntiAircraftGun.DrawingObjects
{
public class AdvancedDrawingAntiAirCraftGun : BaseDrawingAntiAirCraftGun
{
private Point[] points = new Point[4];
public AdvancedDrawingAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool rocket,bool radar, int width, int height) :
base(speed, weight, bodyColor, additionalColor, width, height)
{
AntiAirСraftGun = new EntityAdvancedAntiAirCraftGun(speed, weight, bodyColor, additionalColor, dopColor, rocket,radar);
}
public override void DrawTransport(Graphics g)
{
if (AntiAirСraftGun is not EntityAdvancedAntiAirCraftGun advancedGun)
{
return;
}
Pen pen = new Pen(Color.Black);
Brush bodyBrush = new SolidBrush(AntiAirСraftGun.BodyColor);
Brush additionalBrush = new SolidBrush(AntiAirСraftGun.AdditionalColor);
base.DrawTransport(g);
Brush dopBrush = new SolidBrush(advancedGun.DopColor);
Pen dopPen = new Pen(advancedGun.DopColor);
if (advancedGun.Rocket)
{
points[0] = new Point(_startPosX, _startPosY + 30);
points[1] = new Point(_startPosX + 95, _startPosY + 5);
points[2] = new Point(_startPosX + 92, _startPosY);
points[3] = new Point(_startPosX, _startPosY + 25);
g.FillPolygon(dopBrush, points);
g.DrawPolygon(pen, points);
}
if (advancedGun.Radar)
{
g.DrawLine(dopPen, _startPosX + 105, _startPosY + 20, _startPosX +105, _startPosY + 5);
g.FillPie(dopBrush, _startPosX + 81, _startPosY-15, 30, 30, -45, 180);
g.DrawLine(dopPen, _startPosX + 98, _startPosY , _startPosX + 93, _startPosY + 10);
g.FillEllipse(dopBrush, _startPosX + 88, _startPosY -10, 10, 10);
}
}
}
}

View File

@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AntiAircraftGun.Enitites;
namespace AntiAircraftGun.DrawingObjects
{
public class BaseDrawingAntiAirCraftGun
{
public EntityAntiAirCraftGun? AntiAirСraftGun { get; protected set; }
private readonly int _pictureWidth;
private readonly int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected int _zenitWidth = 110;
protected int _zenitHeight = 60;
public BaseDrawingAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
AntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor);
}
protected BaseDrawingAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int carWidth, int carHeight)
{
_pictureWidth = width;
_pictureHeight = height;
_zenitWidth = carWidth;
_zenitHeight = carHeight;
AntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor);
}
public void SetPosition(int x, int y)
{
if (AntiAirСraftGun == null) return;
_startPosX = x;
_startPosY = y;
if (x < 0 || y < 0 || x + _zenitWidth >= _pictureWidth || y + _zenitHeight >= _pictureHeight)
{
_startPosX = 1;
_startPosY = 1;
}
}
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY => _startPosY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _zenitWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _zenitHeight;
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному направлению</returns>
public bool CanMove(DirectionType direction)
{
if (AntiAirСraftGun == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - AntiAirСraftGun.Step > 0,
//вверх
DirectionType.Up => _startPosY - AntiAirСraftGun.Step > 0,
// вправо
DirectionType.Right =>_startPosX + AntiAirСraftGun.Step + _zenitWidth < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + AntiAirСraftGun.Step + _zenitHeight < _pictureHeight,
_ => false,
};
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || AntiAirСraftGun == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
_startPosX -= (int)AntiAirСraftGun.Step;
break;
//вверх
case DirectionType.Up:
_startPosY -= (int)AntiAirСraftGun.Step;
break;
// вправо
case DirectionType.Right:
_startPosX += (int)AntiAirСraftGun.Step;
break;
//вниз
case DirectionType.Down:
_startPosY += (int)AntiAirСraftGun.Step;
break;
}
}
public virtual void DrawTransport(Graphics g)
{
Pen pen = Pens.Black;
Brush bodyBrush = new SolidBrush(AntiAirСraftGun.BodyColor);
Brush additionalBrush = new SolidBrush(AntiAirСraftGun.AdditionalColor);
g.FillEllipse(additionalBrush, _startPosX, _startPosY + 40, 110, 10);
g.DrawEllipse(pen, _startPosX, _startPosY + 40, 110, 10);
g.FillRectangle(bodyBrush, _startPosX, _startPosY + 30, 110, 10);
g.DrawRectangle(pen, _startPosX, _startPosY + 30, 110, 10);
g.FillRectangle(bodyBrush, _startPosX + 80, _startPosY + 10, 30, 20);
g.DrawRectangle(pen, _startPosX + 80, _startPosY + 10, 30, 20);
for (int i = 0; i < 4; i++)
{
Rectangle trackRect = new Rectangle(_startPosX + 20 + i * 19, _startPosY + 40, 10, 10);
g.DrawEllipse(pen, trackRect);
g.FillEllipse(Brushes.Black, trackRect);
}
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun.Enitites
{
public class EntityAdvancedAntiAirCraftGun : EntityAntiAirCraftGun
{
public Color DopColor { get; private set; }
public bool Rocket { get; private set; }
public bool Radar { get; private set; }
public EntityAdvancedAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor,Color dopColor, bool rocket, bool radar)
: base(speed, weight, bodyColor, additionalColor)
{
DopColor = dopColor;
Rocket = rocket;
Radar = radar;
}
}
}

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun.Enitites
{
public class EntityAntiAirCraftGun
{
/// <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 double Step => (double)Speed * 100 / Weight;
/// <summary>
/// Конструктор с параметрами
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
}
}
}

View File

@ -1,39 +0,0 @@
namespace AntiAirCraftGun
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </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();
}
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.
/// </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 = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace AntiAirCraftGun
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,179 @@
namespace AntiAircraftGun
{
partial class FormAntiAirCraftGun
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </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();
}
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.
/// </summary>
private void InitializeComponent()
{
this.pictureBoxAntiAircraftGun = new System.Windows.Forms.PictureBox();
this.CreateAdavancedAntiAirCraftGun = new System.Windows.Forms.Button();
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.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.CreateAntiAirCraftGun = new System.Windows.Forms.Button();
this.Step = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit();
this.SuspendLayout();
//
// pictureBoxAntiAircraftGun
//
this.pictureBoxAntiAircraftGun.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxAntiAircraftGun.Location = new System.Drawing.Point(0, 0);
this.pictureBoxAntiAircraftGun.Name = "pictureBoxAntiAircraftGun";
this.pictureBoxAntiAircraftGun.Size = new System.Drawing.Size(1491, 628);
this.pictureBoxAntiAircraftGun.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxAntiAircraftGun.TabIndex = 0;
this.pictureBoxAntiAircraftGun.TabStop = false;
//
// CreateAdavancedAntiAirCraftGun
//
this.CreateAdavancedAntiAirCraftGun.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.CreateAdavancedAntiAirCraftGun.Location = new System.Drawing.Point(32, 577);
this.CreateAdavancedAntiAirCraftGun.Name = "CreateAdavancedAntiAirCraftGun";
this.CreateAdavancedAntiAirCraftGun.Size = new System.Drawing.Size(183, 23);
this.CreateAdavancedAntiAirCraftGun.TabIndex = 1;
this.CreateAdavancedAntiAirCraftGun.Text = "Создать с дополнениями";
this.CreateAdavancedAntiAirCraftGun.UseVisualStyleBackColor = true;
this.CreateAdavancedAntiAirCraftGun.Click += new System.EventHandler(this.CreateAdvancedAintiAirCraftGun_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AntiAircraftGun.Properties.Resources.strelkaLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(1265, 562);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 2;
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::AntiAircraftGun.Properties.Resources.strelkaTop;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(1301, 526);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 3;
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::AntiAircraftGun.Properties.Resources.strelkaRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(1337, 562);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 4;
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::AntiAircraftGun.Properties.Resources.strelkaDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(1301, 562);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// comboBoxStrategy
//
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxStrategy.FormattingEnabled = true;
this.comboBoxStrategy.Items.AddRange(new object[] {
"Двигаться в центер ",
"Двигаться в правый нижний угол"});
this.comboBoxStrategy.Location = new System.Drawing.Point(1244, 28);
this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(170, 23);
this.comboBoxStrategy.TabIndex = 6;
//
// CreateAntiAirCraftGun
//
this.CreateAntiAirCraftGun.Location = new System.Drawing.Point(221, 577);
this.CreateAntiAirCraftGun.Name = "CreateAntiAirCraftGun";
this.CreateAntiAirCraftGun.Size = new System.Drawing.Size(185, 23);
this.CreateAntiAirCraftGun.TabIndex = 7;
this.CreateAntiAirCraftGun.Text = "Создать обычный";
this.CreateAntiAirCraftGun.UseVisualStyleBackColor = true;
this.CreateAntiAirCraftGun.Click += new System.EventHandler(this.CreateAntiAirCraftGun_Click);
//
// Step
//
this.Step.Location = new System.Drawing.Point(1323, 61);
this.Step.Name = "Step";
this.Step.Size = new System.Drawing.Size(75, 23);
this.Step.TabIndex = 8;
this.Step.Text = "Шаг";
this.Step.UseVisualStyleBackColor = true;
this.Step.Click += new System.EventHandler(this.ButtonStep_Click);
//
// FormAntiAirCraftGun
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1491, 628);
this.Controls.Add(this.Step);
this.Controls.Add(this.CreateAntiAirCraftGun);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.CreateAdavancedAntiAirCraftGun);
this.Controls.Add(this.pictureBoxAntiAircraftGun);
this.Name = "FormAntiAirCraftGun";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxAntiAircraftGun;
private Button CreateAdavancedAntiAirCraftGun;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
private ComboBox comboBoxStrategy;
private Button CreateAntiAirCraftGun;
private Button Step;
}
}

View File

@ -0,0 +1,125 @@
using AntiAircraftGun.DrawingObjects;
using AntiAircraftGun.MovementStrategy;
namespace AntiAircraftGun
{
public partial class FormAntiAirCraftGun : Form
{
private BaseDrawingAntiAirCraftGun _drawingAntiAirCraftGun;
private AbstractStrategy? _abstractStrategy;
public FormAntiAirCraftGun()
{
InitializeComponent();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingAntiAirCraftGun == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void Draw()
{
if (_drawingAntiAirCraftGun == null)
{
return;
}
Bitmap bmp = new Bitmap(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingAntiAirCraftGun.DrawTransport(gr);
pictureBoxAntiAircraftGun.Image = bmp;
}
private void CreateAdvancedAintiAirCraftGun_Click(object sender, EventArgs e)
{
Random random = new Random();
_drawingAntiAirCraftGun = new AdvancedDrawingAntiAirCraftGun(
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)), // Äîï. öâåò
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), // Äîï. öâåò äëÿ EntityAdvancedAntiAircraftGun
Convert.ToBoolean(random.Next(2)), // Rocket
Convert.ToBoolean(random.Next(2)),
pictureBoxAntiAircraftGun.Width,
pictureBoxAntiAircraftGun.Height
);
_drawingAntiAirCraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void CreateAntiAirCraftGun_Click(object sender, EventArgs e)
{
Random random = new Random();
_drawingAntiAirCraftGun = new BaseDrawingAntiAirCraftGun(
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)), // Äîï. öâåò
pictureBoxAntiAircraftGun.Width,
pictureBoxAntiAircraftGun.Height
);
_drawingAntiAirCraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawingAntiAirCraftGun == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawingObjectAntiAirCraftGun(_drawingAntiAirCraftGun), pictureBoxAntiAircraftGun.Width,
pictureBoxAntiAircraftGun.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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

@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace AntiAircraftGun.MovementStrategy
{
public abstract class AbstractStrategy
{
/// <summary>
/// Перемещаемый объект
/// </summary>
private IMoveableObject? _moveableObject;
/// <summary>
/// Статус перемещения
/// </summary>
private Status _state = Status.NotInit;
/// <summary>
/// Ширина поля
/// </summary>
protected int FieldWidth { get; private set; }
/// <summary>
/// Высота поля
/// </summary>
protected int FieldHeight { get; private set; }
/// <summary>
/// Статус перемещения
/// </summary>
public Status GetStatus() { return _state; }
/// <summary>
/// Установка данных
/// </summary>
/// <param name="moveableObject">Перемещаемый объект</param>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
public void SetData(IMoveableObject moveableObject, int width, int
height)
{
if (moveableObject == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
/// <summary>
/// Шаг перемещения
/// </summary>
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
/// <summary>
/// Перемещение влево
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveLeft() => MoveTo(DirectionType.Left);
/// <summary>
/// Перемещение вправо
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
protected bool MoveRight() => MoveTo(DirectionType.Right);
/// <summary>
/// Перемещение вверх
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveUp() => MoveTo(DirectionType.Up);
/// <summary>
/// Перемещение вниз
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveDown() => MoveTo(DirectionType.Down);
/// <summary>
/// Параметры объекта
/// </summary>
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
/// <summary>
/// Шаг объекта
/// </summary>
/// <returns></returns>
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
/// <summary>
/// Перемещение к цели
/// </summary>
protected abstract void MoveToTarget();
/// <summary>
/// Достигнута ли цель
/// </summary>
/// <returns></returns>
protected abstract bool IsTargetDestinaion();
/// <summary>
/// Попытка перемещения в требуемом направлении
/// </summary>
/// <param name="directionType">Направление</param>
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AntiAircraftGun.DrawingObjects;
namespace AntiAircraftGun.MovementStrategy
{
public class DrawingObjectAntiAirCraftGun : IMoveableObject
{
private readonly BaseDrawingAntiAirCraftGun? _drawningAntiAirCraftGun = null;
public DrawingObjectAntiAirCraftGun(BaseDrawingAntiAirCraftGun drawningCar)
{
_drawningAntiAirCraftGun = drawningCar;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningAntiAirCraftGun == null || _drawningAntiAirCraftGun.AntiAirСraftGun ==
null)
{
return null;
}
return new ObjectParameters(_drawningAntiAirCraftGun.GetPosX,
_drawningAntiAirCraftGun.GetPosY, _drawningAntiAirCraftGun.GetWidth, _drawningAntiAirCraftGun.GetHeight);
}
}
public int GetStep => (int)(_drawningAntiAirCraftGun?.AntiAirСraftGun?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawningAntiAirCraftGun?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawningAntiAirCraftGun?.MoveTransport(direction);
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun.MovementStrategy
{
public interface IMoveableObject
{
/// <summary>
/// Получение координаты X объекта
/// </summary>
ObjectParameters? GetObjectPosition { get; }
/// <summary>
/// Шаг объекта
/// </summary>
int GetStep { get; }
/// <summary>
/// Проверка, можно ли переместиться по нужному направлению
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
bool CheckCanMove(DirectionType direction);
/// <summary>
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
void MoveObject(DirectionType direction);
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun.MovementStrategy
{
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun.MovementStrategy
{
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun.MovementStrategy
{
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
/// <summary>
/// Левая граница
/// </summary>
public int LeftBorder => _x;
/// <summary>
/// Верхняя граница
/// </summary>
public int TopBorder => _y;
/// <summary>
/// Правая граница
/// </summary>
public int RightBorder => _x + _width;
/// <summary>
/// Нижняя граница
/// </summary>
public int DownBorder => _y + _height;
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleHorizontal => _x + _width / 2;
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleVertical => _y + _height / 2;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина</param>
/// <param name="height">Высота</param>
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun.MovementStrategy
{
public enum Status
{
NotInit,
InProgress,
Finish
}
}

View File

@ -1,17 +1,17 @@
namespace AntiAirCraftGun
namespace AntiAircraftGun
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormAntiAirCraftGun());
}
}
}

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AntiAircraftGun.Properties {
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 Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[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("AntiAircraftGun.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap strelkaDown {
get {
object obj = ResourceManager.GetObject("strelkaDown", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap strelkaLeft {
get {
object obj = ResourceManager.GetObject("strelkaLeft", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap strelkaRight {
get {
object obj = ResourceManager.GetObject("strelkaRight", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap strelkaTop {
get {
object obj = ResourceManager.GetObject("strelkaTop", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -117,4 +117,17 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="strelkaDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\strelkaDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="strelkaTop" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\strelkaTop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="strelkaLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\strelkaLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="strelkaRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\strelkaRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB