Compare commits
7 Commits
main
...
Lab6_AntiA
Author | SHA1 | Date | |
---|---|---|---|
d24e418a8a | |||
181f8dac1e | |||
2374e686b4 | |||
c6fffe2777 | |||
32e13d828f | |||
4f2298a184 | |||
04cfe0d2b6 |
@ -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>
|
20
AntiAircraftGun/AntiAircraftGun/Direction.cs
Normal file
20
AntiAircraftGun/AntiAircraftGun/Direction.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
||||
//Вверх
|
||||
Up = 1,
|
||||
//Вниз
|
||||
Down = 2,
|
||||
//Влево
|
||||
Left = 3,
|
||||
//Вправо
|
||||
Right = 4,
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AntiAircraftGun.Entities;
|
||||
|
||||
namespace AntiAircraftGun.DrawningObjects
|
||||
{
|
||||
public class DrawingAntiAircraftGun : DrawningAircraftGun
|
||||
{
|
||||
// Конструктор
|
||||
public DrawingAntiAircraftGun(int speed, double weight, Color bodyColor, Color additionalColor, bool luke, bool zenitkaGun, bool radar, int width, int height) :
|
||||
base(speed, weight, bodyColor, width, height, 185, 128)
|
||||
{
|
||||
if (EntityAircraftGun != null)
|
||||
{
|
||||
EntityAircraftGun = new EntityAntiAircraftGun(speed, weight, bodyColor, additionalColor, luke, zenitkaGun, radar);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawZenitka(Graphics g)
|
||||
{
|
||||
if (EntityAircraftGun is not EntityAntiAircraftGun aircraftGun)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
pen.Width = 2;
|
||||
Brush additionalBrush = new SolidBrush(aircraftGun.AdditionalColor);
|
||||
// Два орудия у зенитки
|
||||
if (aircraftGun.ZenitkaGun)
|
||||
{
|
||||
Pen penTolst = new(Color.Black);
|
||||
penTolst.Width = 5;
|
||||
g.DrawLine(penTolst, startPosX + 105, startPosY + 63, startPosX + 175, startPosY + 13);
|
||||
g.DrawLine(penTolst, startPosX + 105, startPosY + 73, startPosX + 185, startPosY + 18);
|
||||
}
|
||||
base.DrawZenitka(g);
|
||||
// Лючек зенитки
|
||||
if (aircraftGun.Luke)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, startPosX + 80, startPosY + 43, 25, 10);
|
||||
}
|
||||
// Радар зенитки
|
||||
if (aircraftGun.Radar)
|
||||
{
|
||||
g.DrawLine(pen, startPosX + 35, startPosY + 78, startPosX + 35, startPosY + 26);
|
||||
g.DrawLine(pen, startPosX + 60, startPosY + 53, startPosX + 38, startPosY + 23);
|
||||
g.DrawLine(pen, startPosX + 18, startPosY + 31, startPosX + 52, startPosY + 18);
|
||||
g.DrawLine(pen, startPosX + 18, startPosY + 31, startPosX, startPosY + 18);
|
||||
g.DrawLine(pen, startPosX + 52, startPosY + 18, startPosX + 55, startPosY - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AntiAircraftGun.Entities;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
|
||||
namespace AntiAircraftGun.DrawningObjects
|
||||
{
|
||||
// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
public class DrawningAircraftGun
|
||||
{
|
||||
// Класс-сущность
|
||||
public EntityAircraftGun? EntityAircraftGun { get; protected set; }
|
||||
|
||||
// Ширина окна
|
||||
public int pictureWidth;
|
||||
|
||||
// Высота окна
|
||||
public int pictureHeight;
|
||||
|
||||
// Левая координата прорисовки зенитки
|
||||
protected int startPosX;
|
||||
|
||||
// Верхняя координата прорисовки зенитки
|
||||
protected int startPosY;
|
||||
|
||||
// Ширина прорисоки зенитки
|
||||
protected readonly int _zenitkaWidth = 185;
|
||||
|
||||
// Высота прорисовки зенитки
|
||||
protected readonly int _zenitkaHeight = 128;
|
||||
|
||||
// Координата Х объекта
|
||||
public int GetPosX => startPosX;
|
||||
// Координата Y объекта
|
||||
public int GetPosY => startPosY;
|
||||
// Ширина объекта
|
||||
public int GetWidth => _zenitkaWidth;
|
||||
// Высота объекта
|
||||
public int GetHeight => _zenitkaHeight;
|
||||
// Конструктор
|
||||
public DrawningAircraftGun(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
if (width < _zenitkaWidth) { return; }
|
||||
if (height < _zenitkaHeight) { return; }
|
||||
pictureWidth = width;
|
||||
pictureHeight = height;
|
||||
EntityAircraftGun = new EntityAircraftGun(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
// Конструктор
|
||||
protected DrawningAircraftGun(int speed, double weight, Color bodyColor, int width, int height, int zenitkaWidth, int zenitkaHeight)
|
||||
{
|
||||
pictureWidth = width;
|
||||
pictureHeight = height;
|
||||
_zenitkaWidth = zenitkaWidth;
|
||||
_zenitkaHeight = zenitkaHeight;
|
||||
EntityAircraftGun = new EntityAircraftGun(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
// Установка позиции
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0) { x = 0; }
|
||||
else if (x > pictureWidth) { x = pictureWidth; }
|
||||
if (y < 0) { y = 0; }
|
||||
else if (y > pictureHeight) { y = pictureHeight; }
|
||||
startPosX = x;
|
||||
startPosY = y;
|
||||
}
|
||||
|
||||
// Проверка, что объект может переместиться по указанному направлению
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityAircraftGun == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
// влево
|
||||
DirectionType.Left => startPosX - EntityAircraftGun.Step > 0,
|
||||
// вверх
|
||||
DirectionType.Up => startPosY - EntityAircraftGun.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => startPosX + EntityAircraftGun.Step + _zenitkaWidth < pictureWidth,
|
||||
// вниз
|
||||
DirectionType.Down => startPosY + EntityAircraftGun.Step + _zenitkaHeight < pictureHeight,
|
||||
};
|
||||
}
|
||||
|
||||
// Изменение направления перемещения
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
// влево
|
||||
case DirectionType.Left:
|
||||
startPosX -= (int)EntityAircraftGun.Step;
|
||||
break;
|
||||
// вверх
|
||||
case DirectionType.Up:
|
||||
startPosY -= (int)EntityAircraftGun.Step;
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
startPosX += (int)EntityAircraftGun.Step;
|
||||
break;
|
||||
// вниз
|
||||
case DirectionType.Down:
|
||||
startPosY += (int)EntityAircraftGun.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Прорисовка объекта
|
||||
public virtual void DrawZenitka(Graphics g)
|
||||
{
|
||||
if (EntityAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
pen.Width = 2;
|
||||
Brush additionalBrush = new SolidBrush(EntityAircraftGun.BodyColor);
|
||||
// Гусеница
|
||||
g.DrawEllipse(pen, startPosX, startPosY + 103, 150, 25);
|
||||
g.DrawEllipse(pen, startPosX + 5, startPosY + 110, 10, 10);
|
||||
g.DrawEllipse(pen, startPosX + 18, startPosY + 108, 15, 15);
|
||||
g.DrawEllipse(pen, startPosX + 36, startPosY + 107, 17, 17);
|
||||
g.DrawEllipse(pen, startPosX + 56, startPosY + 107, 17, 17);
|
||||
g.DrawEllipse(pen, startPosX + 76, startPosY + 107, 17, 17);
|
||||
g.DrawEllipse(pen, startPosX + 96, startPosY + 107, 17, 17);
|
||||
g.DrawEllipse(pen, startPosX + 116, startPosY + 108, 15, 15);
|
||||
g.DrawEllipse(pen, startPosX + 136, startPosY + 110, 10, 10);
|
||||
// Корпус зенитки
|
||||
Brush brGreen = new SolidBrush(Color.Green);
|
||||
g.FillRectangle(brGreen, startPosX + 20, startPosY + 78, 110, 25);
|
||||
// Башня зенитки
|
||||
g.FillRectangle(additionalBrush, startPosX + 45, startPosY + 53, 60, 25);
|
||||
}
|
||||
|
||||
// Получение объекта IMoveableObject из объекта DrawingAntiAircraftGun
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectAircraftGun(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AntiAircraftGun.Entities;
|
||||
|
||||
namespace AntiAircraftGun.DrawningObjects
|
||||
{
|
||||
public static class ExtentionDrawningAircraftGun
|
||||
{
|
||||
// Создание объекта из строки
|
||||
public static DrawningAircraftGun? CreateDrawningAircraftGun(this string info, char separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawningAircraftGun(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 7)
|
||||
{
|
||||
return new DrawingAntiAircraftGun(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), Color.FromName(strs[3]), Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]), width, height);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Получение данных для сохранения в файл
|
||||
public static string GetDataForSave(this DrawningAircraftGun drawningAircraftGun, char separatorForObject)
|
||||
{
|
||||
var aircraftgun = drawningAircraftGun.EntityAircraftGun;
|
||||
if (aircraftgun == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = $"{aircraftgun.Speed}{separatorForObject}{aircraftgun.Weight}{separatorForObject}{aircraftgun.BodyColor.Name}";
|
||||
if (aircraftgun is not EntityAntiAircraftGun antiAircraftGun)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{separatorForObject}{antiAircraftGun.AdditionalColor.Name}{separatorForObject}{antiAircraftGun.Radar}{separatorForObject}{antiAircraftGun.Luke}{separatorForObject}{antiAircraftGun.ZenitkaGun}";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.Entities
|
||||
{
|
||||
// Класс-сущность "Зенитка"
|
||||
public class EntityAircraftGun
|
||||
{
|
||||
public void Bodycolor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
// Скорость
|
||||
public int Speed { get; private set; }
|
||||
|
||||
// Вес
|
||||
public double Weight { get; private set; }
|
||||
|
||||
// Основной цвет
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
// Шаг перемещения зенитки
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
|
||||
// Конструктор с параметрами
|
||||
public EntityAircraftGun(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.Entities
|
||||
{
|
||||
// Класс-сущность "Стреляющая зенитка"
|
||||
public class EntityAntiAircraftGun : EntityAircraftGun
|
||||
{
|
||||
public void Additionalcolor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
// Доп. цвет
|
||||
public Color AdditionalColor { get; private set; }
|
||||
// Признак наличия люка
|
||||
public bool Luke { get; private set; }
|
||||
// Признак наличия зенитного орудия
|
||||
public bool ZenitkaGun { get; private set; }
|
||||
// признак наличия радара
|
||||
public bool Radar { get; private set; }
|
||||
|
||||
// Инициализация полей объекта-класса продвинутой зенитки
|
||||
public EntityAntiAircraftGun(int speed, double weight, Color bodyColor, Color additionalColor, bool luke, bool zenitkaGun, bool radar) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Luke = luke;
|
||||
ZenitkaGun = zenitkaGun;
|
||||
Radar = radar;
|
||||
}
|
||||
}
|
||||
}
|
39
AntiAircraftGun/AntiAircraftGun/Form1.Designer.cs
generated
39
AntiAircraftGun/AntiAircraftGun/Form1.Designer.cs
generated
@ -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
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
248
AntiAircraftGun/AntiAircraftGun/FormAircraftGunCollection.Designer.cs
generated
Normal file
248
AntiAircraftGun/AntiAircraftGun/FormAircraftGunCollection.Designer.cs
generated
Normal file
@ -0,0 +1,248 @@
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
partial class FormAircraftGunCollection
|
||||
{
|
||||
/// <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.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||
this.ButtonAddObject = new System.Windows.Forms.Button();
|
||||
this.ButtonDelObject = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||
this.ButtonAddAircraftGun = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveAircraftGun = new System.Windows.Forms.Button();
|
||||
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(12, 89);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(634, 354);
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.groupBox2);
|
||||
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.groupBox1.Controls.Add(this.ButtonAddAircraftGun);
|
||||
this.groupBox1.Controls.Add(this.ButtonRemoveAircraftGun);
|
||||
this.groupBox1.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.groupBox1.Location = new System.Drawing.Point(658, 6);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(236, 437);
|
||||
this.groupBox1.TabIndex = 1;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.listBoxStorages);
|
||||
this.groupBox2.Controls.Add(this.textBoxStorageName);
|
||||
this.groupBox2.Controls.Add(this.ButtonAddObject);
|
||||
this.groupBox2.Controls.Add(this.ButtonDelObject);
|
||||
this.groupBox2.Location = new System.Drawing.Point(19, 28);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(209, 222);
|
||||
this.groupBox2.TabIndex = 6;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Наборы";
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.ItemHeight = 15;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(30, 86);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(156, 79);
|
||||
this.listBoxStorages.TabIndex = 4;
|
||||
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged);
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
this.textBoxStorageName.Location = new System.Drawing.Point(30, 26);
|
||||
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||
this.textBoxStorageName.Size = new System.Drawing.Size(156, 23);
|
||||
this.textBoxStorageName.TabIndex = 3;
|
||||
//
|
||||
// ButtonAddObject
|
||||
//
|
||||
this.ButtonAddObject.Location = new System.Drawing.Point(30, 55);
|
||||
this.ButtonAddObject.Name = "ButtonAddObject";
|
||||
this.ButtonAddObject.Size = new System.Drawing.Size(156, 25);
|
||||
this.ButtonAddObject.TabIndex = 2;
|
||||
this.ButtonAddObject.Text = "Добавить набор";
|
||||
this.ButtonAddObject.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
|
||||
//
|
||||
// ButtonDelObject
|
||||
//
|
||||
this.ButtonDelObject.Location = new System.Drawing.Point(30, 171);
|
||||
this.ButtonDelObject.Name = "ButtonDelObject";
|
||||
this.ButtonDelObject.Size = new System.Drawing.Size(156, 25);
|
||||
this.ButtonDelObject.TabIndex = 2;
|
||||
this.ButtonDelObject.Text = "Удалить набор";
|
||||
this.ButtonDelObject.UseVisualStyleBackColor = true;
|
||||
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(49, 318);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(156, 23);
|
||||
this.maskedTextBoxNumber.TabIndex = 5;
|
||||
//
|
||||
// ButtonAddAircraftGun
|
||||
//
|
||||
this.ButtonAddAircraftGun.Location = new System.Drawing.Point(49, 285);
|
||||
this.ButtonAddAircraftGun.Name = "ButtonAddAircraftGun";
|
||||
this.ButtonAddAircraftGun.Size = new System.Drawing.Size(156, 27);
|
||||
this.ButtonAddAircraftGun.TabIndex = 2;
|
||||
this.ButtonAddAircraftGun.Text = "Добавить зенитку";
|
||||
this.ButtonAddAircraftGun.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddAircraftGun.Click += new System.EventHandler(this.ButtonAddAircraftGun_Click);
|
||||
//
|
||||
// ButtonRemoveAircraftGun
|
||||
//
|
||||
this.ButtonRemoveAircraftGun.Location = new System.Drawing.Point(49, 347);
|
||||
this.ButtonRemoveAircraftGun.Name = "ButtonRemoveAircraftGun";
|
||||
this.ButtonRemoveAircraftGun.Size = new System.Drawing.Size(156, 26);
|
||||
this.ButtonRemoveAircraftGun.TabIndex = 2;
|
||||
this.ButtonRemoveAircraftGun.Text = "Удалить зенитку";
|
||||
this.ButtonRemoveAircraftGun.UseVisualStyleBackColor = true;
|
||||
this.ButtonRemoveAircraftGun.Click += new System.EventHandler(this.ButtonRemoveAircraftGun_Click);
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(49, 379);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(156, 27);
|
||||
this.ButtonRefreshCollection.TabIndex = 2;
|
||||
this.ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.файлToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(906, 24);
|
||||
this.menuStrip.TabIndex = 2;
|
||||
this.menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
// файлToolStripMenuItem
|
||||
//
|
||||
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.SaveToolStripMenuItem,
|
||||
this.LoadToolStripMenuItem});
|
||||
this.файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
this.файлToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
|
||||
this.файлToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.SaveToolStripMenuItem.Text = "Сохранение";
|
||||
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.LoadToolStripMenuItem.Text = "Загрузка";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.FileName = "openFileDialog1";
|
||||
this.openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormAircraftGunCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(906, 450);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormAircraftGunCollection";
|
||||
this.Text = "Набор зениток";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.groupBox2.PerformLayout();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollection;
|
||||
private GroupBox groupBox1;
|
||||
private Button ButtonRefreshCollection;
|
||||
private Button ButtonRemoveAircraftGun;
|
||||
private Button ButtonAddAircraftGun;
|
||||
private Button ButtonDelObject;
|
||||
private Button ButtonAddObject;
|
||||
private TextBox textBoxStorageName;
|
||||
private ListBox listBoxStorages;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private GroupBox groupBox2;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem файлToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
193
AntiAircraftGun/AntiAircraftGun/FormAircraftGunCollection.cs
Normal file
193
AntiAircraftGun/AntiAircraftGun/FormAircraftGunCollection.cs
Normal file
@ -0,0 +1,193 @@
|
||||
using AntiAircraftGun.DrawningObjects;
|
||||
using AntiAircraftGun.Generics;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
public partial class FormAircraftGunCollection : Form
|
||||
{
|
||||
private readonly AntiAircraftGunsGenericStorage _storage;
|
||||
//private readonly AntiAircraftGunsGenericCollection<DrawningAircraftGun, DrawningObjectAircraftGun> _aircraftguns;
|
||||
public FormAircraftGunCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new AntiAircraftGunsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
// Заполнение listBoxObjects
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||
{
|
||||
listBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
// Обновление рисунка по набору
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowAntiAircraftGuns();
|
||||
}
|
||||
|
||||
// Удаление объекта из набора
|
||||
private void ButtonRemoveAircraftGun_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? String.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удалён");
|
||||
pictureBoxCollection.Image = obj.ShowAntiAircraftGuns();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void AddAircraftGun(DrawningAircraftGun aircraftGun)
|
||||
{
|
||||
aircraftGun.pictureWidth = pictureBoxCollection.Width;
|
||||
aircraftGun.pictureHeight = pictureBoxCollection.Height;
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (obj + aircraftGun)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowAntiAircraftGuns();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
// Добавление объекта в набор
|
||||
private void ButtonAddAircraftGun_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormAircraftGunConfig form = new FormAircraftGunConfig();
|
||||
form.Show();
|
||||
form.AddEvent(AddAircraftGun);
|
||||
}
|
||||
|
||||
// Удаление набора
|
||||
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"удалить объект {listBoxStorages.SelectedItem}?", "удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
|
||||
// Добавление набора в коллекцию
|
||||
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
// Выбор набора
|
||||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAntiAircraftGuns();
|
||||
}
|
||||
|
||||
// Обработка нажатия "Сохранение"
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.SaveData(saveFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Обработка нажатия "Загрузка"
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if(openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
ReloadObjects();
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
<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>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>132, 18</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>272, 18</value>
|
||||
</metadata>
|
||||
</root>
|
400
AntiAircraftGun/AntiAircraftGun/FormAircraftGunConfig.Designer.cs
generated
Normal file
400
AntiAircraftGun/AntiAircraftGun/FormAircraftGunConfig.Designer.cs
generated
Normal file
@ -0,0 +1,400 @@
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
partial class FormAircraftGunConfig
|
||||
{
|
||||
/// <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.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.labelModifiedObject = new System.Windows.Forms.Label();
|
||||
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.panelPurple = new System.Windows.Forms.Panel();
|
||||
this.panelBlack = new System.Windows.Forms.Panel();
|
||||
this.panelGray = new System.Windows.Forms.Panel();
|
||||
this.panelWhite = new System.Windows.Forms.Panel();
|
||||
this.panelYellow = new System.Windows.Forms.Panel();
|
||||
this.panelBlue = new System.Windows.Forms.Panel();
|
||||
this.panelGreen = new System.Windows.Forms.Panel();
|
||||
this.panelRed = new System.Windows.Forms.Panel();
|
||||
this.checkBoxGuns = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxLuke = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxRadar = new System.Windows.Forms.CheckBox();
|
||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.labelWeight = new System.Windows.Forms.Label();
|
||||
this.labelSpeed = new System.Windows.Forms.Label();
|
||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.panel9 = new System.Windows.Forms.Panel();
|
||||
this.LabelAdditionalColor = new System.Windows.Forms.Label();
|
||||
this.LabelColor = new System.Windows.Forms.Label();
|
||||
this.ButtonOk = new System.Windows.Forms.Button();
|
||||
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||
this.panel9.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.labelModifiedObject);
|
||||
this.groupBox1.Controls.Add(this.labelSimpleObject);
|
||||
this.groupBox1.Controls.Add(this.groupBox2);
|
||||
this.groupBox1.Controls.Add(this.checkBoxGuns);
|
||||
this.groupBox1.Controls.Add(this.checkBoxLuke);
|
||||
this.groupBox1.Controls.Add(this.checkBoxRadar);
|
||||
this.groupBox1.Controls.Add(this.numericUpDownWeight);
|
||||
this.groupBox1.Controls.Add(this.numericUpDownSpeed);
|
||||
this.groupBox1.Controls.Add(this.labelWeight);
|
||||
this.groupBox1.Controls.Add(this.labelSpeed);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(538, 264);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Параметры";
|
||||
//
|
||||
// labelModifiedObject
|
||||
//
|
||||
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelModifiedObject.Location = new System.Drawing.Point(380, 202);
|
||||
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||
this.labelModifiedObject.Size = new System.Drawing.Size(114, 42);
|
||||
this.labelModifiedObject.TabIndex = 9;
|
||||
this.labelModifiedObject.Text = "Продвинутый";
|
||||
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelModifiedObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||
this.labelModifiedObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelSimpleObject.Location = new System.Drawing.Point(238, 202);
|
||||
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||
this.labelSimpleObject.Size = new System.Drawing.Size(114, 42);
|
||||
this.labelSimpleObject.TabIndex = 8;
|
||||
this.labelSimpleObject.Text = "Простой";
|
||||
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelSimpleObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||
this.labelSimpleObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.panelPurple);
|
||||
this.groupBox2.Controls.Add(this.panelBlack);
|
||||
this.groupBox2.Controls.Add(this.panelGray);
|
||||
this.groupBox2.Controls.Add(this.panelWhite);
|
||||
this.groupBox2.Controls.Add(this.panelYellow);
|
||||
this.groupBox2.Controls.Add(this.panelBlue);
|
||||
this.groupBox2.Controls.Add(this.panelGreen);
|
||||
this.groupBox2.Controls.Add(this.panelRed);
|
||||
this.groupBox2.Location = new System.Drawing.Point(217, 28);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(302, 149);
|
||||
this.groupBox2.TabIndex = 7;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Цвета";
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||
this.panelPurple.Location = new System.Drawing.Point(235, 89);
|
||||
this.panelPurple.Name = "panelPurple";
|
||||
this.panelPurple.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelPurple.TabIndex = 7;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||
this.panelBlack.Location = new System.Drawing.Point(163, 89);
|
||||
this.panelBlack.Name = "panelBlack";
|
||||
this.panelBlack.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelBlack.TabIndex = 6;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||
this.panelGray.Location = new System.Drawing.Point(91, 89);
|
||||
this.panelGray.Name = "panelGray";
|
||||
this.panelGray.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelGray.TabIndex = 5;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||
this.panelWhite.Location = new System.Drawing.Point(21, 89);
|
||||
this.panelWhite.Name = "panelWhite";
|
||||
this.panelWhite.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelWhite.TabIndex = 4;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||
this.panelYellow.Location = new System.Drawing.Point(235, 22);
|
||||
this.panelYellow.Name = "panelYellow";
|
||||
this.panelYellow.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelYellow.TabIndex = 3;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||
this.panelBlue.Location = new System.Drawing.Point(163, 22);
|
||||
this.panelBlue.Name = "panelBlue";
|
||||
this.panelBlue.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelBlue.TabIndex = 2;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
||||
this.panelGreen.Location = new System.Drawing.Point(91, 22);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelGreen.TabIndex = 1;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||
this.panelRed.Location = new System.Drawing.Point(21, 22);
|
||||
this.panelRed.Name = "panelRed";
|
||||
this.panelRed.Size = new System.Drawing.Size(50, 50);
|
||||
this.panelRed.TabIndex = 0;
|
||||
//
|
||||
// checkBoxGuns
|
||||
//
|
||||
this.checkBoxGuns.AutoSize = true;
|
||||
this.checkBoxGuns.Location = new System.Drawing.Point(16, 202);
|
||||
this.checkBoxGuns.Name = "checkBoxGuns";
|
||||
this.checkBoxGuns.Size = new System.Drawing.Size(166, 19);
|
||||
this.checkBoxGuns.TabIndex = 6;
|
||||
this.checkBoxGuns.Text = "Признак наличия орудий";
|
||||
this.checkBoxGuns.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxLuke
|
||||
//
|
||||
this.checkBoxLuke.AutoSize = true;
|
||||
this.checkBoxLuke.Location = new System.Drawing.Point(16, 160);
|
||||
this.checkBoxLuke.Name = "checkBoxLuke";
|
||||
this.checkBoxLuke.Size = new System.Drawing.Size(162, 19);
|
||||
this.checkBoxLuke.TabIndex = 5;
|
||||
this.checkBoxLuke.Text = "Признак наличия лючка";
|
||||
this.checkBoxLuke.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxRadar
|
||||
//
|
||||
this.checkBoxRadar.AutoSize = true;
|
||||
this.checkBoxRadar.Location = new System.Drawing.Point(16, 119);
|
||||
this.checkBoxRadar.Name = "checkBoxRadar";
|
||||
this.checkBoxRadar.Size = new System.Drawing.Size(164, 19);
|
||||
this.checkBoxRadar.TabIndex = 4;
|
||||
this.checkBoxRadar.Text = "Признак наличия радара";
|
||||
this.checkBoxRadar.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
this.numericUpDownWeight.Location = new System.Drawing.Point(84, 75);
|
||||
this.numericUpDownWeight.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownWeight.Minimum = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
this.numericUpDownWeight.Size = new System.Drawing.Size(75, 23);
|
||||
this.numericUpDownWeight.TabIndex = 3;
|
||||
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(84, 28);
|
||||
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
this.numericUpDownSpeed.Size = new System.Drawing.Size(75, 23);
|
||||
this.numericUpDownSpeed.TabIndex = 2;
|
||||
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
this.labelWeight.AutoSize = true;
|
||||
this.labelWeight.Location = new System.Drawing.Point(16, 77);
|
||||
this.labelWeight.Name = "labelWeight";
|
||||
this.labelWeight.Size = new System.Drawing.Size(29, 15);
|
||||
this.labelWeight.TabIndex = 1;
|
||||
this.labelWeight.Text = "Вес:";
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
this.labelSpeed.AutoSize = true;
|
||||
this.labelSpeed.Location = new System.Drawing.Point(16, 30);
|
||||
this.labelSpeed.Name = "labelSpeed";
|
||||
this.labelSpeed.Size = new System.Drawing.Size(62, 15);
|
||||
this.labelSpeed.TabIndex = 0;
|
||||
this.labelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
this.pictureBoxObject.Location = new System.Drawing.Point(19, 58);
|
||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||
this.pictureBoxObject.Size = new System.Drawing.Size(278, 154);
|
||||
this.pictureBoxObject.TabIndex = 1;
|
||||
this.pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// panel9
|
||||
//
|
||||
this.panel9.AllowDrop = true;
|
||||
this.panel9.Controls.Add(this.LabelAdditionalColor);
|
||||
this.panel9.Controls.Add(this.LabelColor);
|
||||
this.panel9.Controls.Add(this.pictureBoxObject);
|
||||
this.panel9.Location = new System.Drawing.Point(566, 21);
|
||||
this.panel9.Name = "panel9";
|
||||
this.panel9.Size = new System.Drawing.Size(311, 222);
|
||||
this.panel9.TabIndex = 2;
|
||||
this.panel9.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||
this.panel9.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||
//
|
||||
// LabelAdditionalColor
|
||||
//
|
||||
this.LabelAdditionalColor.AllowDrop = true;
|
||||
this.LabelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.LabelAdditionalColor.Location = new System.Drawing.Point(172, 19);
|
||||
this.LabelAdditionalColor.Name = "LabelAdditionalColor";
|
||||
this.LabelAdditionalColor.Size = new System.Drawing.Size(125, 36);
|
||||
this.LabelAdditionalColor.TabIndex = 3;
|
||||
this.LabelAdditionalColor.Text = "Доп. цвет";
|
||||
this.LabelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.LabelAdditionalColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
|
||||
this.LabelAdditionalColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
this.LabelAdditionalColor.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// LabelColor
|
||||
//
|
||||
this.LabelColor.AllowDrop = true;
|
||||
this.LabelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.LabelColor.Location = new System.Drawing.Point(19, 19);
|
||||
this.LabelColor.Name = "LabelColor";
|
||||
this.LabelColor.Size = new System.Drawing.Size(125, 36);
|
||||
this.LabelColor.TabIndex = 2;
|
||||
this.LabelColor.Text = "Цвет";
|
||||
this.LabelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.LabelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop);
|
||||
this.LabelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
this.LabelColor.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
|
||||
//
|
||||
// ButtonOk
|
||||
//
|
||||
this.ButtonOk.Location = new System.Drawing.Point(585, 248);
|
||||
this.ButtonOk.Name = "ButtonOk";
|
||||
this.ButtonOk.Size = new System.Drawing.Size(125, 32);
|
||||
this.ButtonOk.TabIndex = 3;
|
||||
this.ButtonOk.Text = "Добавить";
|
||||
this.ButtonOk.UseVisualStyleBackColor = true;
|
||||
this.ButtonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
this.ButtonCancel.Location = new System.Drawing.Point(738, 248);
|
||||
this.ButtonCancel.Name = "ButtonCancel";
|
||||
this.ButtonCancel.Size = new System.Drawing.Size(125, 32);
|
||||
this.ButtonCancel.TabIndex = 3;
|
||||
this.ButtonCancel.Text = "Отмена";
|
||||
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormAircraftGunConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(901, 288);
|
||||
this.Controls.Add(this.ButtonCancel);
|
||||
this.Controls.Add(this.panel9);
|
||||
this.Controls.Add(this.ButtonOk);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Name = "FormAircraftGunConfig";
|
||||
this.Text = "Создание объекта";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||
this.panel9.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox1;
|
||||
private Label labelModifiedObject;
|
||||
private Label labelSimpleObject;
|
||||
private GroupBox groupBox2;
|
||||
private Panel panelPurple;
|
||||
private Panel panelBlack;
|
||||
private Panel panelGray;
|
||||
private Panel panelWhite;
|
||||
private Panel panelYellow;
|
||||
private Panel panelBlue;
|
||||
private Panel panelGreen;
|
||||
private Panel panelRed;
|
||||
private CheckBox checkBoxGuns;
|
||||
private CheckBox checkBoxLuke;
|
||||
private CheckBox checkBoxRadar;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelWeight;
|
||||
private Label labelSpeed;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Panel panel9;
|
||||
private Label LabelAdditionalColor;
|
||||
private Label LabelColor;
|
||||
private Button ButtonOk;
|
||||
private Button ButtonCancel;
|
||||
}
|
||||
}
|
135
AntiAircraftGun/AntiAircraftGun/FormAircraftGunConfig.cs
Normal file
135
AntiAircraftGun/AntiAircraftGun/FormAircraftGunConfig.cs
Normal file
@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using AntiAircraftGun.DrawningObjects;
|
||||
using AntiAircraftGun.Entities;
|
||||
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
public partial class FormAircraftGunConfig : Form
|
||||
{
|
||||
// Переменная выбранная зенитка
|
||||
DrawningAircraftGun? _aircraftGun = null;
|
||||
// Событие
|
||||
private event Action<DrawningAircraftGun>? EventAddAircraftGun;
|
||||
|
||||
public FormAircraftGunConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||
panelGray.MouseDown += PanelColor_MouseDown;
|
||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||
panelRed.MouseDown += PanelColor_MouseDown;
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
ButtonCancel.Click += (sender, e) => Close();
|
||||
}
|
||||
|
||||
private void DrawAircraftGun()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_aircraftGun?.SetPosition(5, 5);
|
||||
_aircraftGun?.DrawZenitka(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
|
||||
public void AddEvent(Action<DrawningAircraftGun> ev)
|
||||
{
|
||||
if (EventAddAircraftGun == null)
|
||||
{
|
||||
EventAddAircraftGun = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddAircraftGun += ev;
|
||||
}
|
||||
}
|
||||
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_aircraftGun = new DrawningAircraftGun((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White,
|
||||
pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_aircraftGun = new DrawingAntiAircraftGun((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||||
checkBoxLuke.Checked, checkBoxGuns.Checked, checkBoxRadar.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
break;
|
||||
}
|
||||
DrawAircraftGun();
|
||||
}
|
||||
|
||||
private void ButtonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddAircraftGun?.Invoke(_aircraftGun);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void LabelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_aircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (((Label)sender).Name)
|
||||
{
|
||||
case "LabelColor":
|
||||
_aircraftGun.EntityAircraftGun.Bodycolor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
case "LabelAdditionalColor":
|
||||
if (_aircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
(_aircraftGun.EntityAircraftGun as EntityAntiAircraftGun).Additionalcolor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
}
|
||||
DrawAircraftGun();
|
||||
}
|
||||
|
||||
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
AntiAircraftGun/AntiAircraftGun/FormAircraftGunConfig.resx
Normal file
60
AntiAircraftGun/AntiAircraftGun/FormAircraftGunConfig.resx
Normal 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>
|
206
AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs
generated
Normal file
206
AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.Designer.cs
generated
Normal file
@ -0,0 +1,206 @@
|
||||
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.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonCreateAntiAircraftGun = new System.Windows.Forms.Button();
|
||||
this.pictureBoxAntiAircraftGun = new System.Windows.Forms.PictureBox();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.ButtonCreateAntiAircraftGun_Click = new System.Windows.Forms.Button();
|
||||
this.ButtonStep_Click = new System.Windows.Forms.Button();
|
||||
this.ButtonSelectAircraftGun_Click = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// 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(884, 461);
|
||||
this.pictureBox.TabIndex = 0;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// 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.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(791, 373);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(35, 35);
|
||||
this.buttonUp.TabIndex = 11;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_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.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(750, 414);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(35, 35);
|
||||
this.buttonLeft.TabIndex = 10;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.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.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(791, 414);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(35, 35);
|
||||
this.buttonDown.TabIndex = 9;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.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.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(832, 414);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(35, 35);
|
||||
this.buttonRight.TabIndex = 8;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonCreateAntiAircraftGun
|
||||
//
|
||||
this.buttonCreateAntiAircraftGun.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateAntiAircraftGun.Location = new System.Drawing.Point(148, 406);
|
||||
this.buttonCreateAntiAircraftGun.Name = "buttonCreateAntiAircraftGun";
|
||||
this.buttonCreateAntiAircraftGun.Size = new System.Drawing.Size(186, 43);
|
||||
this.buttonCreateAntiAircraftGun.TabIndex = 7;
|
||||
this.buttonCreateAntiAircraftGun.Text = "Создать стреляющую зенитку";
|
||||
this.buttonCreateAntiAircraftGun.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateAntiAircraftGun.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
//
|
||||
// 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(884, 461);
|
||||
this.pictureBoxAntiAircraftGun.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxAntiAircraftGun.TabIndex = 6;
|
||||
this.pictureBoxAntiAircraftGun.TabStop = false;
|
||||
//
|
||||
// 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(633, 12);
|
||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(239, 23);
|
||||
this.comboBoxStrategy.TabIndex = 12;
|
||||
//
|
||||
// ButtonCreateAntiAircraftGun_Click
|
||||
//
|
||||
this.ButtonCreateAntiAircraftGun_Click.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreateAntiAircraftGun_Click.Location = new System.Drawing.Point(12, 406);
|
||||
this.ButtonCreateAntiAircraftGun_Click.Name = "ButtonCreateAntiAircraftGun_Click";
|
||||
this.ButtonCreateAntiAircraftGun_Click.Size = new System.Drawing.Size(111, 43);
|
||||
this.ButtonCreateAntiAircraftGun_Click.TabIndex = 13;
|
||||
this.ButtonCreateAntiAircraftGun_Click.Text = "Создать зенитку";
|
||||
this.ButtonCreateAntiAircraftGun_Click.UseVisualStyleBackColor = true;
|
||||
this.ButtonCreateAntiAircraftGun_Click.Click += new System.EventHandler(this.ButtonCreateAntiAircraftGun_Click_Click);
|
||||
//
|
||||
// ButtonStep_Click
|
||||
//
|
||||
this.ButtonStep_Click.Location = new System.Drawing.Point(812, 50);
|
||||
this.ButtonStep_Click.Name = "ButtonStep_Click";
|
||||
this.ButtonStep_Click.Size = new System.Drawing.Size(55, 42);
|
||||
this.ButtonStep_Click.TabIndex = 14;
|
||||
this.ButtonStep_Click.Text = "Шаг";
|
||||
this.ButtonStep_Click.UseVisualStyleBackColor = true;
|
||||
this.ButtonStep_Click.Click += new System.EventHandler(this.ButtonStep_Click_Click);
|
||||
//
|
||||
// ButtonSelectAircraftGun_Click
|
||||
//
|
||||
this.ButtonSelectAircraftGun_Click.Location = new System.Drawing.Point(349, 406);
|
||||
this.ButtonSelectAircraftGun_Click.Name = "ButtonSelectAircraftGun_Click";
|
||||
this.ButtonSelectAircraftGun_Click.Size = new System.Drawing.Size(120, 43);
|
||||
this.ButtonSelectAircraftGun_Click.TabIndex = 15;
|
||||
this.ButtonSelectAircraftGun_Click.Text = "Выбрать зенитку";
|
||||
this.ButtonSelectAircraftGun_Click.UseVisualStyleBackColor = true;
|
||||
this.ButtonSelectAircraftGun_Click.Click += new System.EventHandler(this.ButtonSelectAircraftGun_Click_Click);
|
||||
//
|
||||
// FormAntiAircraftGun
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||
this.Controls.Add(this.ButtonSelectAircraftGun_Click);
|
||||
this.Controls.Add(this.ButtonStep_Click);
|
||||
this.Controls.Add(this.ButtonCreateAntiAircraftGun_Click);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonCreateAntiAircraftGun);
|
||||
this.Controls.Add(this.pictureBoxAntiAircraftGun);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Name = "FormAntiAircraftGun";
|
||||
this.Text = "Зенитное орудие";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateAntiAircraftGun;
|
||||
private PictureBox pictureBoxAntiAircraftGun;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button ButtonCreateAntiAircraftGun_Click;
|
||||
private Button ButtonStep_Click;
|
||||
private Button ButtonSelectAircraftGun_Click;
|
||||
}
|
||||
}
|
139
AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs
Normal file
139
AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.cs
Normal file
@ -0,0 +1,139 @@
|
||||
using AntiAircraftGun.DrawningObjects;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
public partial class FormAntiAircraftGun : Form
|
||||
{
|
||||
private DrawningAircraftGun? _drawningAircraftGun;
|
||||
|
||||
private AbstractStrategy? abstractStrategy;
|
||||
|
||||
// Âûáðàííàÿ çåíèòêà
|
||||
public DrawningAircraftGun? SelectedAircraftGun { get; private set; }
|
||||
public FormAntiAircraftGun()
|
||||
{
|
||||
InitializeComponent();
|
||||
abstractStrategy = null;
|
||||
SelectedAircraftGun = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAircraftGun.DrawZenitka(gr);
|
||||
pictureBoxAntiAircraftGun.Image = bmp;
|
||||
}
|
||||
// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü ñòðåëÿþùóþ çåíèòêó"
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialog.Color;
|
||||
}
|
||||
|
||||
_drawningAircraftGun = new DrawingAntiAircraftGun(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAntiAircraftGun.Width,
|
||||
pictureBoxAntiAircraftGun.Height);
|
||||
_drawningAircraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü çåíèòêó"
|
||||
private void ButtonCreateAntiAircraftGun_Click_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawningAircraftGun = new DrawningAircraftGun(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
_drawningAircraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningAircraftGun.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningAircraftGun.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningAircraftGun.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningAircraftGun.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
||||
private void ButtonStep_Click_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
abstractStrategy.SetData(new DrawningObjectAircraftGun(_drawningAircraftGun), pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
}
|
||||
if (abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
comboBoxStrategy.Enabled = false;
|
||||
abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Âûáîð çåíèòêè
|
||||
private void ButtonSelectAircraftGun_Click_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedAircraftGun = _drawningAircraftGun;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
60
AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.resx
Normal file
60
AntiAircraftGun/AntiAircraftGun/FormAntiAircraftGun.resx
Normal 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>
|
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AntiAircraftGun.DrawningObjects;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
|
||||
namespace AntiAircraftGun.Generics
|
||||
{
|
||||
internal class AntiAircraftGunsGenericCollection<T, U>
|
||||
where T : DrawningAircraftGun
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
// Размер занимаемого объектом места(ширина)
|
||||
private readonly int _placeSizeWidth = 185;
|
||||
// Размер занимаемого объектом места(высота)
|
||||
private readonly int _placeSizeHeight = 128;
|
||||
|
||||
// Набор объектов
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
// Конструктор
|
||||
public AntiAircraftGunsGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
// Перегрузка оператора сложения
|
||||
public static bool operator +(AntiAircraftGunsGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
|
||||
// Перегрузка оператора вычитания
|
||||
public static bool operator -(AntiAircraftGunsGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
collect._collection.Remove(pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Получение объекта IMoveableObject
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
|
||||
// Вывод всего набора объектов
|
||||
public Bitmap ShowAntiAircraftGuns()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
// Метод отрисовки фона
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
// Метод прорисовки объектов
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int i = 0;
|
||||
foreach (var antiaircraftgun in _collection.GetAntiAircraftGuns())
|
||||
{
|
||||
if (antiaircraftgun != null)
|
||||
{
|
||||
antiaircraftgun.SetPosition((i % width) * _placeSizeWidth, (i / height) * _placeSizeHeight);
|
||||
antiaircraftgun.DrawZenitka(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Получение объектов коллекции
|
||||
public IEnumerable<T?> GetAntiAircraftGuns => _collection.GetAntiAircraftGuns();
|
||||
}
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
using AntiAircraftGun.DrawningObjects;
|
||||
|
||||
namespace AntiAircraftGun.Generics
|
||||
{
|
||||
internal class AntiAircraftGunsGenericStorage
|
||||
{
|
||||
// Словарь
|
||||
readonly Dictionary<string, AntiAircraftGunsGenericCollection<DrawningAircraftGun, DrawningObjectAircraftGun>> _aircraftgunStorages;
|
||||
|
||||
// Возвращение списка названий наборов
|
||||
public List<string> Keys => _aircraftgunStorages.Keys.ToList();
|
||||
// Ширина окна отрисовки
|
||||
private readonly int _pictureWidth;
|
||||
// Высота окна отрисовки
|
||||
private readonly int _pictureHeight;
|
||||
// Разделитель для записи ключа и значения элемента словаря
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
// Разделитель для записей коллекции данных в файл
|
||||
private readonly char _separatorRecords = ';';
|
||||
// Разделитель для записи информации по объекту в файл
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
// Конструктор
|
||||
public AntiAircraftGunsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_aircraftgunStorages = new Dictionary<string, AntiAircraftGunsGenericCollection<DrawningAircraftGun, DrawningObjectAircraftGun>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
// Добавление набора
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if(_aircraftgunStorages.ContainsKey(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_aircraftgunStorages[name] = new AntiAircraftGunsGenericCollection<DrawningAircraftGun, DrawningObjectAircraftGun>(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
// Удаление набора
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_aircraftgunStorages.ContainsKey(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_aircraftgunStorages.Remove(name);
|
||||
}
|
||||
|
||||
// Доступ к набору
|
||||
public AntiAircraftGunsGenericCollection<DrawningAircraftGun, DrawningObjectAircraftGun>?this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_aircraftgunStorages.ContainsKey(ind))
|
||||
{
|
||||
return _aircraftgunStorages[ind];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Сохранение информации по зениткам в хранилище в файл
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string, AntiAircraftGunsGenericCollection<DrawningAircraftGun, DrawningObjectAircraftGun>> record in _aircraftgunStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningAircraftGun? elem in record.Value.GetAntiAircraftGuns)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using StreamWriter fs = new StreamWriter(filename);
|
||||
string info = $"AircraftStorage{Environment.NewLine}{data}";
|
||||
fs.Write(info, 0, info.Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Загрузка информации по зениткам в хранилище из файла
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using (StreamReader fs = new StreamReader(filename))
|
||||
{
|
||||
string str = fs.ReadLine();
|
||||
if (!str.StartsWith("AircraftStorage"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_aircraftgunStorages.Clear();
|
||||
while ((str = fs.ReadLine()) != null)
|
||||
{
|
||||
if (str.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
AntiAircraftGunsGenericCollection<DrawningAircraftGun, DrawningObjectAircraftGun> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawningAircraftGun? aircraftgun = elem?.CreateDrawningAircraftGun(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (aircraftgun != null)
|
||||
{
|
||||
if (!(collection + aircraftgun))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_aircraftgunStorages.Add(record[0], collection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
101
AntiAircraftGun/AntiAircraftGun/Generics/SetGeneric.cs
Normal file
101
AntiAircraftGun/AntiAircraftGun/Generics/SetGeneric.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using AntiAircraftGun.DrawningObjects;
|
||||
using AntiAircraftGun.Generics;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.Generics
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
// Список
|
||||
private readonly List<T?> _places;
|
||||
|
||||
// Кол-во объектов в списке
|
||||
public int Count => _places.Count;
|
||||
|
||||
// Максимальное кол-во объектов в списке
|
||||
private readonly int _maxCount;
|
||||
|
||||
// Конструктор
|
||||
public SetGeneric(int Count)
|
||||
{
|
||||
_maxCount = Count;
|
||||
_places = new List<T?>(Count);
|
||||
}
|
||||
|
||||
// Добавление объекта в набор
|
||||
public bool Insert(T antiaircraftgun)
|
||||
{
|
||||
return Insert(antiaircraftgun, 0);
|
||||
}
|
||||
|
||||
// Добавление объекта на конкретную позицию
|
||||
public bool Insert(T antiaircraftgun, int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (Count >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places.Insert(0, antiaircraftgun);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Удаление объекта из набора с конкретной позиции
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Получение объекта из набора по позиции
|
||||
public T? this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places[position] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Проход по списку
|
||||
public IEnumerable<T?> GetAntiAircraftGuns(int? maxAntiAircraftGuns = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; i++)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxAntiAircraftGuns.HasValue && i == maxAntiAircraftGuns.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AntiAircraftGun.DrawningObjects;
|
||||
|
||||
namespace AntiAircraftGun.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
// Перемещаемый объект
|
||||
private IMoveableObject? _moveableObject;
|
||||
|
||||
// Статус перемещения
|
||||
private Status _state = Status.NotInit;
|
||||
|
||||
// Ширина поля
|
||||
protected int FieldWidth { get; private set; }
|
||||
|
||||
// Высота поля
|
||||
protected int FieldHeight { get; private set; }
|
||||
|
||||
// Статус перемещения
|
||||
public Status GetStatus() { return _state; }
|
||||
|
||||
// Установка данных
|
||||
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;
|
||||
}
|
||||
|
||||
// Шаг перемещения
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
// Перемещение влево
|
||||
// результат перемещения(true - удалось, false - не удалось)
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
|
||||
// Перемещение вправо
|
||||
// результат перемещения(true - удалось, false - не удалось)
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
|
||||
// Перемещение вверх
|
||||
// результат перемещения(true - удалось, false - не удалось)
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
|
||||
// Перемещение вниз
|
||||
// результат перемещения(true - удалось, false - не удалось)
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
|
||||
// Параметры объекта
|
||||
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||
|
||||
// Шаг объекта
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
|
||||
// перемещение к цели
|
||||
protected abstract void MoveToTarget();
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
|
||||
// Попытка перемещения в требуемом направлении
|
||||
// Результат попытки(true - удалось, false - не удалось)
|
||||
|
||||
private bool MoveTo(DirectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AntiAircraftGun.DrawningObjects;
|
||||
|
||||
namespace AntiAircraftGun.MovementStrategy
|
||||
{
|
||||
// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
|
||||
|
||||
public class DrawningObjectAircraftGun : IMoveableObject
|
||||
{
|
||||
private readonly DrawningAircraftGun? _drawningAircraftGun = null;
|
||||
|
||||
public DrawningObjectAircraftGun(DrawningAircraftGun drawningAircraftGun)
|
||||
{
|
||||
_drawningAircraftGun = drawningAircraftGun;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningAircraftGun == null || _drawningAircraftGun.EntityAircraftGun == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningAircraftGun.GetPosX, _drawningAircraftGun.GetPosY, _drawningAircraftGun.GetWidth, _drawningAircraftGun.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_drawningAircraftGun?.EntityAircraftGun?.Step ?? 0);
|
||||
|
||||
public bool CheckCanMove(DirectionType direction) => _drawningAircraftGun?.CanMove(direction) ?? false;
|
||||
|
||||
public void MoveObject(DirectionType direction) => _drawningAircraftGun?.MoveTransport(direction);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AntiAircraftGun.DrawningObjects;
|
||||
|
||||
namespace AntiAircraftGun.MovementStrategy
|
||||
{
|
||||
// Интерфейс для работы с перемещаемым объектом
|
||||
public interface IMoveableObject
|
||||
{
|
||||
// Поулчение координаты X объекта
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
|
||||
// Шаг объекта
|
||||
int GetStep { get; }
|
||||
|
||||
// Првоерка, можно ли переместиться по нужному направлению
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
|
||||
// Изменение направления перемещения объекта
|
||||
void MoveObject(DirectionType direction);
|
||||
}
|
||||
}
|
@ -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 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.ObjectMiddleHorizontal - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
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;
|
||||
|
||||
// Левая граница
|
||||
public int LeftBorder => _x;
|
||||
// Верхняя граница
|
||||
public int TopBorder => _y;
|
||||
// Правая граница
|
||||
public int RightBorder => _x + _width;
|
||||
// Нижняя граница
|
||||
public int DownBorder => _y + _height;
|
||||
|
||||
// Середина объекта
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
// Середина объекта
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
|
||||
//Конструктор
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
16
AntiAircraftGun/AntiAircraftGun/MovementStrategy/Status.cs
Normal file
16
AntiAircraftGun/AntiAircraftGun/MovementStrategy/Status.cs
Normal file
@ -0,0 +1,16 @@
|
||||
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
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace AntiAircraftGun
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new FormAircraftGunCollection());
|
||||
}
|
||||
}
|
||||
}
|
103
AntiAircraftGun/AntiAircraftGun/Properties/Resources.Designer.cs
generated
Normal file
103
AntiAircraftGun/AntiAircraftGun/Properties/Resources.Designer.cs
generated
Normal 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 arrowDown {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrowDown", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrowLeft {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrowLeft", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrowRight {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrowRight", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrowUp {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrowUp", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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="arrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
BIN
AntiAircraftGun/AntiAircraftGun/Resources/arrowDown.png
Normal file
BIN
AntiAircraftGun/AntiAircraftGun/Resources/arrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 418 B |
BIN
AntiAircraftGun/AntiAircraftGun/Resources/arrowLeft.png
Normal file
BIN
AntiAircraftGun/AntiAircraftGun/Resources/arrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 362 B |
BIN
AntiAircraftGun/AntiAircraftGun/Resources/arrowRight.png
Normal file
BIN
AntiAircraftGun/AntiAircraftGun/Resources/arrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 428 B |
BIN
AntiAircraftGun/AntiAircraftGun/Resources/arrowUp.png
Normal file
BIN
AntiAircraftGun/AntiAircraftGun/Resources/arrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 412 B |
Loading…
x
Reference in New Issue
Block a user