Compare commits

...

23 Commits

Author SHA1 Message Date
platoff aeeee
538472a1b8 Готовая 5 лаба 2023-12-06 10:31:56 +04:00
platoff aeeee
de5812d86c Готовая 5 лаба 2023-12-05 19:35:57 +04:00
platoff aeeee
d8a1dfa401 правки 5 лаб 2023-11-22 11:02:20 +04:00
platoff aeeee
b2a66c7bc6 Правки 5 лаб 2023-11-22 02:02:29 +04:00
platoff aeeee
431f46b2bb Готовая 4 лаба 2023-11-08 10:58:56 +04:00
platoff aeeee
b906b3f880 Готовая 4 лаба! 2023-11-08 09:24:14 +04:00
platoff aeeee
270c3d7d4f Правки 4 лаб 2023-11-08 00:26:38 +04:00
platoff aeeee
bda0646769 Правки 4 лаба 2023-11-08 00:15:08 +04:00
platoff aeeee
91252d99a9 правки 4 лаб 2023-11-07 16:54:15 +04:00
platoff aeeee
49ee242064 правки 4 лаб 2023-11-07 16:38:25 +04:00
platoff aeeee
e8df20e0eb Готовая 3 лаба 2023-10-25 10:40:17 +04:00
platoff aeeee
28f3d56a17 правки 3 лаба 2023-10-24 23:44:03 +04:00
platoff aeeee
25b4c0cd84 Готовая 2 лаба 2023-10-11 10:55:24 +04:00
platoff aeeee
205635a1f8 Правки2лаб 2023-10-11 10:43:28 +04:00
platoff aeeee
6412d03510 Правки2лаб 2023-10-11 10:41:13 +04:00
platoff aeeee
35ef737015 Правки 2 лабы 2023-10-11 09:18:45 +04:00
platoff aeeee
7293c69407 Правки 2023-10-11 09:18:35 +04:00
platoff aeeee
083ffec901 Правки 2лаб 2023-10-10 23:57:24 +04:00
platoff aeeee
a52eb31b45 Правки лаб2 2023-10-10 23:46:42 +04:00
platoff aeeee
0b3396d17f перенос 2 лабы 2023-10-03 19:51:48 +04:00
platoff aeeee
a7f1fc2910 Готовая 1 лаба 2023-09-27 09:20:00 +04:00
platoff aeeee
02c4fa2ec2 Правки 2023-09-26 23:13:18 +04:00
platoff aeeee
cd60cbbe7f Перенесение проекта 2023-09-26 17:01:06 +04:00
34 changed files with 2671 additions and 50 deletions

17
Tank/Tank/Direction.cs Normal file

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tank
{
/// Направление перемещения
public enum Direction
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

@ -0,0 +1,214 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tank.Entites;
using Tank.MovementStrategy;
namespace Tank.DrawingObjects
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawingArmoredCar
{
public IMoveableObject GetMoveableObject => new DrawingObjectArmoredCar(this);
/// <summary>
/// Класс-сущность
/// </summary>
public EntityArmoredCar? Tank { get; protected set; }
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY => _startPosY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _ArmoredcarWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _ArmoredcarHeight;
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному
/// направлению</returns>
public bool CanMove(Direction direction)
{
if (Tank == null)
{
return false;
}
return direction switch
{
Direction.Left => _startPosX - Tank.Step > 0,
Direction.Up => _startPosY - Tank.Step > 0,
Direction.Right => _startPosX + Tank.Step < _pictureWidth - _ArmoredcarWidth, //вниз
Direction.Down => _startPosY + Tank.Step < _pictureHeight - _ArmoredcarHeight,
_ => false,
};
}
/// <summary>
/// Ширина окна
/// </summary>
public int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
public int _pictureHeight;
/// <summary>
/// Левая координата прорисовки автомобиля
/// </summary>
protected int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки автомобиля
/// </summary>
protected int _startPosY;
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
protected readonly int _ArmoredcarWidth = 150;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
protected readonly int _ArmoredcarHeight = 65;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawingArmoredCar(int speed, double weight, Color bodyColor, int
width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureHeight < _ArmoredcarHeight || _pictureWidth < _ArmoredcarWidth)
{
return;
}
Tank = new EntityArmoredCar(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
/// <param name="carWidth">Ширина прорисовки автомобиля</param>
/// <param name="carHeight">Высота прорисовки автомобиля</param>
protected DrawingArmoredCar(int speed, double weight, Color bodyColor, int
width, int height, int carWidth, int carHeight)
{
_pictureWidth = width;
_pictureHeight = height;
_ArmoredcarWidth = _ArmoredcarWidth;
_ArmoredcarHeight = _ArmoredcarHeight;
if (_pictureHeight < _ArmoredcarHeight || _pictureWidth < _ArmoredcarWidth) {
return;
}
Tank = new EntityArmoredCar(speed, weight, bodyColor);
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
if (x <0 || x > _pictureHeight - _ArmoredcarHeight)
{
x = 0;
}
if (y < 0 || y > _pictureWidth - _ArmoredcarWidth)
{
y = 0;
}
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(Direction direction)
{
if (Tank == null)
{
return;
}
switch (direction)
{
//влево
case Direction.Left:
if (_startPosX - Tank.Step > 0)
{
_startPosX -= (int)Tank.Step;
}
break;
//вверх
case Direction.Up:
if (_startPosY - Tank.Step > 0)
{
_startPosY -= (int)Tank.Step;
}
break;
// вправо
case Direction.Right:
if (_startPosX + Tank.Step + _ArmoredcarWidth < _pictureWidth)
{
_startPosX += (int)Tank.Step;
}
break;
//вниз
case Direction.Down:
if (_startPosY + Tank.Step + _ArmoredcarHeight < _pictureHeight)
{
_startPosY += (int)Tank.Step;
}
break;
}
}
//}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (Tank == null)
{
return;
}
Brush BrushRandom = new SolidBrush(Tank?.BodyColor ?? Color.Black);
//кузов
Brush br = new SolidBrush(Tank.BodyColor);
g.FillRectangle(br, _startPosX + 5, _startPosY + 17, 110, 18);
g.FillRectangle(br, _startPosX + 30, _startPosY + 3, 50, 13);
// колеса
Brush brBlack = new SolidBrush(Color.Black);
g.FillEllipse(brBlack, _startPosX + 95, _startPosY + 35, 20, 20);
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 35, 20, 20);
}
}
}

@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tank.Entites;
namespace Tank.DrawingObjects
{
public class DrawingTank : DrawingArmoredCar
{
/// Конструктор
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawingTank(int speed, double weight, Color bodyColor, Color additionalColor,
bool bodyKit, bool wing, bool sportLine, int width, int height) :
base(speed, weight, bodyColor, width, height, 110, 60)
{
if (Tank != null)
{
Tank = new EntityTank(speed, weight, bodyColor,
additionalColor, bodyKit, wing, sportLine);
}
}
public override void DrawTransport(Graphics g)
{
if (Tank is not EntityTank ArmoredCar)
{
return;
}
base.DrawTransport(g);
Pen pen = new(Color.Black);
Brush additionalBrush = new
SolidBrush(ArmoredCar.AdditionalColor);
// гусеница
Rectangle Caterpillar = new Rectangle(_startPosX + 2, _startPosY + 35, 16, 22);
float startAngle_Caterpillar = 90;
float sweepAngle_Caterpillar = 180;
g.DrawArc(pen, Caterpillar, startAngle_Caterpillar, sweepAngle_Caterpillar);
Rectangle Caterpillar2 = new Rectangle(_startPosX + 102, _startPosY + 35, 16, 22);
float startAngle_Caterpillar2 = 270;
float sweepAngle_Caterpillar2 = 180;
g.DrawArc(pen, Caterpillar2, startAngle_Caterpillar2, sweepAngle_Caterpillar2);
Point startPoint = new Point(_startPosX + 10, _startPosY + 58);
Point endPoint = new Point(_startPosX + 110, _startPosY + 58);
g.DrawLine(pen, startPoint, endPoint);
// колеса
Brush brBlack = new SolidBrush(Color.Black);
g.FillEllipse(brBlack, _startPosX + 95, _startPosY + 35, 20, 20);
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 35, 20, 20);
// колеса снизу поменьше
g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 47, 10, 10);
g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 47, 10, 10);
g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 47, 10, 10);
g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 47, 10, 10);
// колеса сверху
g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 32, 10, 10);
g.FillEllipse(brBlack, _startPosX + 55, _startPosY + 32, 10, 10);
g.FillEllipse(brBlack, _startPosX + 75, _startPosY + 32, 10, 10);
//кузов
Brush br = new SolidBrush(ArmoredCar.BodyColor);
g.FillRectangle(br, _startPosX + 5, _startPosY + 17, 110, 18);
g.FillRectangle(br, _startPosX + 30, _startPosY, 50, 15);
// пулемет
g.FillRectangle(br, _startPosX + 80, _startPosY + 3, 25, 5);
// зенитный пулемет на башне
g.FillRectangle(br, _startPosX + 40, _startPosY - 10, 20, 5);
g.FillRectangle(brBlack, _startPosX + 50, _startPosY - 5, 5, 5);
g.FillRectangle(brBlack, _startPosX + 55, _startPosY - 10, 5, 10);
g.FillRectangle(brBlack, _startPosX + 52, _startPosY - 7, 3, 2);
//выделяем рамкой весь танк
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 17, 110, 18);
g.DrawRectangle(pen, _startPosX + 30, _startPosY, 50, 15);
g.DrawRectangle(pen, _startPosX + 80, _startPosY + 3, 25, 5);
g.DrawRectangle(pen, _startPosX + 40, _startPosY - 10, 20, 5);
// обвесы
if (ArmoredCar.BodyKit)
{
Brush brAdd = new SolidBrush(ArmoredCar.AdditionalColor);
g.FillRectangle(brAdd, _startPosX + 5, _startPosY + 17, 20, 18);
g.FillRectangle(brAdd, _startPosX + 95, _startPosY + 17, 20, 18);
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 17, 20, 18);
g.DrawRectangle(pen, _startPosX + 95, _startPosY + 17, 20, 18);
g.FillRectangle(brAdd, _startPosX + 100, _startPosY + 4, 5, 4);
}
// линия
if (ArmoredCar.Line)
{
g.FillRectangle(additionalBrush, _startPosX + 75,
_startPosY + 23, 25, 15);
g.FillRectangle(additionalBrush, _startPosX + 35,
_startPosY + 23, 35, 15);
g.FillRectangle(additionalBrush, _startPosX + 10,
_startPosY + 23, 20, 15);
}
// багажник
if (ArmoredCar.Trunk)
{
g.FillRectangle(additionalBrush, _startPosX + 23, _startPosY + 4, 8, 10);
g.DrawRectangle(pen, _startPosX + 23, _startPosY + 4, 8, 10);
}
}
}
}

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tank.Entites
{
/// <summary>
/// Класс-сущность "Бронированная машина"
/// </summary>
public class EntityArmoredCar
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => (double)Speed * 300 / Weight;
/// <summary>
/// Конструктор с параметрами
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityArmoredCar(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
public void setBodyColor(Color color)
{
BodyColor = color;
}
}
}

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tank.Entites;
namespace Tank.Entites
{
public class EntityTank : EntityArmoredCar
{
public int Speed { get; private set; }
public Color AdditionalColor { get; private set; }
// Признак (опция) наличия обвеса
public bool BodyKit { get; private set; }
// Признак (опция) наличия Багажника
public bool Trunk { get; private set; }
// Признак (опция) наличия гоночной полосы
public bool Line { get; private set; }
/// Шаг перемещения танка
/// Инициализация полей объекта-класса спортивного автомобиля
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес Танка</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="trunk">Признак наличия багажника</param>
/// <param name="line">Признак наличия гоночной полосы</param>
public EntityTank(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool trunk, bool line) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
BodyKit = bodyKit;
Trunk = trunk;
Line = line;
}
public void setAdditionalColor(Color color)
{
AdditionalColor = color;
}
}
}

@ -1,39 +0,0 @@
namespace Tank
{
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 Tank
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

@ -0,0 +1,188 @@
namespace Tank
{
partial class FormArmoredCarCollection
{
/// <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.groupBox2 = new System.Windows.Forms.GroupBox();
this.textBoxStorageName = new System.Windows.Forms.TextBox();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.ButtonDelObject = new System.Windows.Forms.Button();
this.ButtonAddObject = new System.Windows.Forms.Button();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
this.ButtonRemoveArmoredCar = new System.Windows.Forms.Button();
this.ButtonAddArmoredCar = new System.Windows.Forms.Button();
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
this.groupBox1.Controls.Add(this.ButtonRefreshCollection);
this.groupBox1.Controls.Add(this.ButtonRemoveArmoredCar);
this.groupBox1.Controls.Add(this.ButtonAddArmoredCar);
this.groupBox1.Location = new System.Drawing.Point(579, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 426);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.textBoxStorageName);
this.groupBox2.Controls.Add(this.listBoxStorages);
this.groupBox2.Controls.Add(this.ButtonDelObject);
this.groupBox2.Controls.Add(this.ButtonAddObject);
this.groupBox2.Location = new System.Drawing.Point(13, 22);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(181, 219);
this.groupBox2.TabIndex = 8;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Наборы";
//
// textBoxStorageName
//
this.textBoxStorageName.Location = new System.Drawing.Point(27, 18);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(129, 23);
this.textBoxStorageName.TabIndex = 7;
//
// listBoxStorages
//
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 15;
this.listBoxStorages.Location = new System.Drawing.Point(27, 76);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(129, 94);
this.listBoxStorages.TabIndex = 6;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged);
//
// ButtonDelObject
//
this.ButtonDelObject.Location = new System.Drawing.Point(12, 176);
this.ButtonDelObject.Name = "ButtonDelObject";
this.ButtonDelObject.Size = new System.Drawing.Size(154, 23);
this.ButtonDelObject.TabIndex = 5;
this.ButtonDelObject.Text = "Удалить набор";
this.ButtonDelObject.UseVisualStyleBackColor = true;
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
//
// ButtonAddObject
//
this.ButtonAddObject.Location = new System.Drawing.Point(12, 47);
this.ButtonAddObject.Name = "ButtonAddObject";
this.ButtonAddObject.Size = new System.Drawing.Size(154, 23);
this.ButtonAddObject.TabIndex = 4;
this.ButtonAddObject.Text = "Добавить набор";
this.ButtonAddObject.UseVisualStyleBackColor = true;
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
//
// maskedTextBoxNumber
//
this.maskedTextBoxNumber.Location = new System.Drawing.Point(40, 295);
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(129, 23);
this.maskedTextBoxNumber.TabIndex = 3;
//
// ButtonRefreshCollection
//
this.ButtonRefreshCollection.Location = new System.Drawing.Point(13, 389);
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
this.ButtonRefreshCollection.Size = new System.Drawing.Size(187, 31);
this.ButtonRefreshCollection.TabIndex = 2;
this.ButtonRefreshCollection.Text = "Обновить коллекцию";
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// ButtonRemoveArmoredCar
//
this.ButtonRemoveArmoredCar.Location = new System.Drawing.Point(13, 324);
this.ButtonRemoveArmoredCar.Name = "ButtonRemoveArmoredCar";
this.ButtonRemoveArmoredCar.Size = new System.Drawing.Size(181, 40);
this.ButtonRemoveArmoredCar.TabIndex = 1;
this.ButtonRemoveArmoredCar.Text = "Удалить бронированную машину";
this.ButtonRemoveArmoredCar.UseVisualStyleBackColor = true;
this.ButtonRemoveArmoredCar.Click += new System.EventHandler(this.ButtonRemoveArmoredCar_Click);
//
// ButtonAddArmoredCar
//
this.ButtonAddArmoredCar.Location = new System.Drawing.Point(13, 247);
this.ButtonAddArmoredCar.Name = "ButtonAddArmoredCar";
this.ButtonAddArmoredCar.Size = new System.Drawing.Size(181, 42);
this.ButtonAddArmoredCar.TabIndex = 0;
this.ButtonAddArmoredCar.Text = "Добавить бронированную машину";
this.ButtonAddArmoredCar.UseVisualStyleBackColor = true;
this.ButtonAddArmoredCar.Click += new System.EventHandler(this.ButtonAddArmoredCar_Click);
//
// pictureBoxCollection
//
this.pictureBoxCollection.Location = new System.Drawing.Point(1, 0);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(572, 438);
this.pictureBoxCollection.TabIndex = 1;
this.pictureBoxCollection.TabStop = false;
//
// FormArmoredCarCollection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.pictureBoxCollection);
this.Controls.Add(this.groupBox1);
this.Name = "FormArmoredCarCollection";
this.Text = "Набор бронированных машин";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private Button ButtonRefreshCollection;
private Button ButtonRemoveArmoredCar;
private Button ButtonAddArmoredCar;
private PictureBox pictureBoxCollection;
private MaskedTextBox maskedTextBoxNumber;
private ListBox listBoxStorages;
private Button ButtonDelObject;
private Button ButtonAddObject;
private GroupBox groupBox2;
private TextBox textBoxStorageName;
}
}

@ -0,0 +1,158 @@
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 Tank.DrawingObjects;
using Tank.MovementStrategy;
using Tank.Generics;
namespace Tank
{
public partial class FormArmoredCarCollection : Form
{
private readonly TanksGenericStorage _storage;
public FormArmoredCarCollection()
{
InitializeComponent();
_storage = new TanksGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
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;
}
}
public void AddArmoredCar(DrawingArmoredCar tank)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
if ((obj + tank) != false)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowTanks();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
private void ButtonAddArmoredCar_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
FormTankConfig form = new FormTankConfig();
form.Show();
form.AddEvent(AddArmoredCar);
}
private void ButtonRemoveArmoredCar_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.ShowTanks();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
public void RefreshCollection()
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowTanks();
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
RefreshCollection();
}
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 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 listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTanks();
RefreshCollection();
}
}
}

@ -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>

188
Tank/Tank/FormTank.Designer.cs generated Normal file

@ -0,0 +1,188 @@
namespace Tank
{
partial class FormTank
{
/// <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.pictureBoxTank = new System.Windows.Forms.PictureBox();
this.buttonCreate = new System.Windows.Forms.Button();
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.buttonCreateArmoredCar = new System.Windows.Forms.Button();
this.buttonStep = new System.Windows.Forms.Button();
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.ButtonSelectTank = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTank)).BeginInit();
this.SuspendLayout();
//
// pictureBoxTank
//
this.pictureBoxTank.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxTank.Location = new System.Drawing.Point(0, 0);
this.pictureBoxTank.Name = "pictureBoxTank";
this.pictureBoxTank.Size = new System.Drawing.Size(884, 461);
this.pictureBoxTank.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxTank.TabIndex = 0;
this.pictureBoxTank.TabStop = false;
this.pictureBoxTank.Click += new System.EventHandler(this.pictureBox1_Click);
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(26, 417);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(97, 23);
this.buttonCreate.TabIndex = 1;
this.buttonCreate.Text = "Создать Танк";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Tank.Properties.Resources.upper_arrow;
this.buttonUp.Location = new System.Drawing.Point(772, 374);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 2;
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::Tank.Properties.Resources.left_arrow;
this.buttonLeft.Location = new System.Drawing.Point(736, 410);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 3;
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::Tank.Properties.Resources.down_arrow;
this.buttonDown.Location = new System.Drawing.Point(772, 410);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 4;
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::Tank.Properties.Resources.right_arrow;
this.buttonRight.Location = new System.Drawing.Point(808, 410);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonCreateArmoredCar
//
this.buttonCreateArmoredCar.Location = new System.Drawing.Point(129, 417);
this.buttonCreateArmoredCar.Name = "buttonCreateArmoredCar";
this.buttonCreateArmoredCar.Size = new System.Drawing.Size(210, 23);
this.buttonCreateArmoredCar.TabIndex = 7;
this.buttonCreateArmoredCar.Text = "Создать Бронированную машину\r\n";
this.buttonCreateArmoredCar.UseVisualStyleBackColor = true;
this.buttonCreateArmoredCar.Click += new System.EventHandler(this.buttonCreateArmoredCar_Click);
//
// buttonStep
//
this.buttonStep.Location = new System.Drawing.Point(753, 70);
this.buttonStep.Name = "buttonStep";
this.buttonStep.Size = new System.Drawing.Size(75, 23);
this.buttonStep.TabIndex = 9;
this.buttonStep.Text = "Шаг";
this.buttonStep.UseVisualStyleBackColor = true;
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
//
// comboBoxStrategy
//
this.comboBoxStrategy.FormattingEnabled = true;
this.comboBoxStrategy.Items.AddRange(new object[] {
"0",
"1"});
this.comboBoxStrategy.Location = new System.Drawing.Point(733, 41);
this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
this.comboBoxStrategy.TabIndex = 10;
//
// ButtonSelectTank
//
this.ButtonSelectTank.Location = new System.Drawing.Point(737, 113);
this.ButtonSelectTank.Name = "ButtonSelectTank";
this.ButtonSelectTank.Size = new System.Drawing.Size(117, 23);
this.ButtonSelectTank.TabIndex = 11;
this.ButtonSelectTank.Text = "Выбор машины";
this.ButtonSelectTank.UseVisualStyleBackColor = true;
this.ButtonSelectTank.Click += new System.EventHandler(this.ButtonSelectTank_Click);
//
// FormTank
//
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.ButtonSelectTank);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.buttonCreateArmoredCar);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxTank);
this.Name = "FormTank";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Tank";
this.Load += new System.EventHandler(this.FormTank_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTank)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxTank;
private Button buttonCreate;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonCreateArmoredCar;
private Button buttonStep;
private ComboBox comboBoxStrategy;
private Button ButtonSelectTank;
}
}

170
Tank/Tank/FormTank.cs Normal file

@ -0,0 +1,170 @@
using Tank.DrawingObjects;
using Tank.MovementStrategy;
namespace Tank
{
/// <summary>
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Ñïîðòèâíûé àâòîìîáèëü"
/// </summary>
public partial class FormTank : Form
{
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
private DrawingArmoredCar? _Tank;
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
private AbstractStrategy? _abstractStrategy;
public DrawingArmoredCar? SelectedTank { get; private set; }
public FormTank()
{
InitializeComponent();
_abstractStrategy = null;
SelectedTank = null;
}
/// Ìåòîä ïðîðèñîâêè ìàøèíû
private void Draw()
{
if (_Tank == null)
{
return;
}
Bitmap bmp = new(pictureBoxTank.Width,
pictureBoxTank.Height);
Graphics gr = Graphics.FromImage(bmp);
_Tank?.DrawTransport(gr);
pictureBoxTank.Image = bmp;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
// Ñîçäàíèå Tank
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));
// âûáîð äîïîëíèòåëüíîãî öâåòà
ColorDialog dialog2 = new();
if (dialog2.ShowDialog() == DialogResult.OK)
{
dopColor = dialog2.Color;
}
_Tank = new DrawingTank(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)),
pictureBoxTank.Width, pictureBoxTank.Height);
_Tank.SetPosition(random.Next(10, 100),
random.Next(10, 100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_Tank == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_Tank.MoveTransport(Direction.Up);
break;
case "buttonDown":
_Tank.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_Tank.MoveTransport(Direction.Left);
break;
case "buttonRight":
_Tank.MoveTransport(Direction.Right);
break;
}
Draw();
}
// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü Áðîíèðîâàííóþ ìàøèíó"
private void buttonCreateArmoredCar_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;
}
_Tank = new DrawingArmoredCar(random.Next(100, 300), random.Next(1000, 3000), color,
pictureBoxTank.Width, pictureBoxTank.Height);
_Tank.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
private void buttonStep_Click(object sender, EventArgs e)
{
if (_Tank == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawingObjectArmoredCar(_Tank), pictureBoxTank.Width,
pictureBoxTank.Height);
}
if (_abstractStrategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
private void FormTank_Load(object sender, EventArgs e)
{
}
private void ButtonSelectTank_Click(object sender, EventArgs e)
{
SelectedTank = _Tank;
DialogResult = DialogResult.OK;
}
}
}

60
Tank/Tank/FormTank.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>

418
Tank/Tank/FormTankConfig.Designer.cs generated Normal file

@ -0,0 +1,418 @@
namespace Tank
{
partial class FormTankConfig
{
/// <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.groupBoxParameters = new System.Windows.Forms.GroupBox();
this.labelComplexObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelSilver = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelBlack = 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.checkBoxLine = new System.Windows.Forms.CheckBox();
this.checkBoxBodyKit = new System.Windows.Forms.CheckBox();
this.checkBoxTrunk = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelWeigth = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label();
this.button_Cancel = new System.Windows.Forms.Button();
this.button_Add = new System.Windows.Forms.Button();
this.PanelObject = new System.Windows.Forms.Panel();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.panelColor = new System.Windows.Forms.Panel();
this.label_Additional_Color = new System.Windows.Forms.Label();
this.label_Color = new System.Windows.Forms.Label();
this.groupBoxParameters.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.PanelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.panelColor.SuspendLayout();
this.SuspendLayout();
//
// groupBoxParameters
//
this.groupBoxParameters.Controls.Add(this.labelComplexObject);
this.groupBoxParameters.Controls.Add(this.labelSimpleObject);
this.groupBoxParameters.Controls.Add(this.groupBoxColors);
this.groupBoxParameters.Controls.Add(this.checkBoxLine);
this.groupBoxParameters.Controls.Add(this.checkBoxBodyKit);
this.groupBoxParameters.Controls.Add(this.checkBoxTrunk);
this.groupBoxParameters.Controls.Add(this.numericUpDownWeight);
this.groupBoxParameters.Controls.Add(this.numericUpDownSpeed);
this.groupBoxParameters.Controls.Add(this.labelWeigth);
this.groupBoxParameters.Controls.Add(this.labelSpeed);
this.groupBoxParameters.Location = new System.Drawing.Point(12, 12);
this.groupBoxParameters.Name = "groupBoxParameters";
this.groupBoxParameters.Size = new System.Drawing.Size(476, 213);
this.groupBoxParameters.TabIndex = 0;
this.groupBoxParameters.TabStop = false;
this.groupBoxParameters.Text = "Параметры";
//
// labelComplexObject
//
this.labelComplexObject.AllowDrop = true;
this.labelComplexObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelComplexObject.Location = new System.Drawing.Point(346, 164);
this.labelComplexObject.Name = "labelComplexObject";
this.labelComplexObject.Size = new System.Drawing.Size(109, 34);
this.labelComplexObject.TabIndex = 9;
this.labelComplexObject.Text = "Продвинутый";
this.labelComplexObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelComplexObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.AllowDrop = true;
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(222, 164);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(109, 34);
this.labelSimpleObject.TabIndex = 8;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.panelWhite);
this.groupBoxColors.Controls.Add(this.panelSilver);
this.groupBoxColors.Controls.Add(this.panelGray);
this.groupBoxColors.Controls.Add(this.panelBlack);
this.groupBoxColors.Controls.Add(this.panelYellow);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Location = new System.Drawing.Point(222, 22);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(233, 136);
this.groupBoxColors.TabIndex = 7;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
//
// panelWhite
//
this.panelWhite.AllowDrop = true;
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(178, 63);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(48, 35);
this.panelWhite.TabIndex = 1;
//
// panelSilver
//
this.panelSilver.BackColor = System.Drawing.Color.Silver;
this.panelSilver.Location = new System.Drawing.Point(124, 63);
this.panelSilver.Name = "panelSilver";
this.panelSilver.Size = new System.Drawing.Size(48, 35);
this.panelSilver.TabIndex = 1;
//
// panelGray
//
this.panelGray.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.panelGray.Location = new System.Drawing.Point(70, 63);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(48, 35);
this.panelGray.TabIndex = 1;
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(16, 63);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(48, 35);
this.panelBlack.TabIndex = 1;
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(178, 22);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(48, 35);
this.panelYellow.TabIndex = 1;
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(124, 22);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(48, 35);
this.panelBlue.TabIndex = 1;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(70, 22);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(48, 35);
this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(16, 22);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(48, 35);
this.panelRed.TabIndex = 0;
this.panelRed.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelRed.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// checkBoxLine
//
this.checkBoxLine.AutoSize = true;
this.checkBoxLine.Location = new System.Drawing.Point(37, 164);
this.checkBoxLine.Name = "checkBoxLine";
this.checkBoxLine.Size = new System.Drawing.Size(121, 19);
this.checkBoxLine.TabIndex = 6;
this.checkBoxLine.Text = "Наличие полосы";
this.checkBoxLine.UseVisualStyleBackColor = true;
//
// checkBoxBodyKit
//
this.checkBoxBodyKit.AutoSize = true;
this.checkBoxBodyKit.Location = new System.Drawing.Point(37, 139);
this.checkBoxBodyKit.Name = "checkBoxBodyKit";
this.checkBoxBodyKit.Size = new System.Drawing.Size(116, 19);
this.checkBoxBodyKit.TabIndex = 5;
this.checkBoxBodyKit.Text = "Наличие обвеса";
this.checkBoxBodyKit.UseVisualStyleBackColor = true;
//
// checkBoxTrunk
//
this.checkBoxTrunk.AutoSize = true;
this.checkBoxTrunk.Location = new System.Drawing.Point(37, 114);
this.checkBoxTrunk.Name = "checkBoxTrunk";
this.checkBoxTrunk.Size = new System.Drawing.Size(137, 19);
this.checkBoxTrunk.TabIndex = 4;
this.checkBoxTrunk.Text = "Наличие багажника";
this.checkBoxTrunk.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(115, 72);
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(77, 23);
this.numericUpDownWeight.TabIndex = 3;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(115, 40);
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(77, 23);
this.numericUpDownSpeed.TabIndex = 2;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelWeigth
//
this.labelWeigth.AutoSize = true;
this.labelWeigth.Location = new System.Drawing.Point(37, 74);
this.labelWeigth.Name = "labelWeigth";
this.labelWeigth.Size = new System.Drawing.Size(26, 15);
this.labelWeigth.TabIndex = 1;
this.labelWeigth.Text = "Вес";
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(37, 40);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(59, 15);
this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = "Скорость";
//
// button_Cancel
//
this.button_Cancel.Location = new System.Drawing.Point(625, 12);
this.button_Cancel.Name = "button_Cancel";
this.button_Cancel.Size = new System.Drawing.Size(105, 32);
this.button_Cancel.TabIndex = 15;
this.button_Cancel.Text = "Отмена";
this.button_Cancel.UseVisualStyleBackColor = true;
//
// button_Add
//
this.button_Add.Location = new System.Drawing.Point(514, 12);
this.button_Add.Name = "button_Add";
this.button_Add.Size = new System.Drawing.Size(105, 32);
this.button_Add.TabIndex = 14;
this.button_Add.Text = "Добавить";
this.button_Add.UseVisualStyleBackColor = true;
this.button_Add.Click += new System.EventHandler(this.button_Add_Click);
//
// PanelObject
//
this.PanelObject.AllowDrop = true;
this.PanelObject.Controls.Add(this.pictureBoxObject);
this.PanelObject.Location = new System.Drawing.Point(494, 137);
this.PanelObject.Name = "PanelObject";
this.PanelObject.Size = new System.Drawing.Size(294, 190);
this.PanelObject.TabIndex = 11;
this.PanelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.PanelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(6, 14);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(270, 157);
this.pictureBoxObject.TabIndex = 10;
this.pictureBoxObject.TabStop = false;
//
// panelColor
//
this.panelColor.AllowDrop = true;
this.panelColor.Controls.Add(this.label_Additional_Color);
this.panelColor.Controls.Add(this.label_Color);
this.panelColor.Location = new System.Drawing.Point(500, 52);
this.panelColor.Name = "panelColor";
this.panelColor.Size = new System.Drawing.Size(288, 65);
this.panelColor.TabIndex = 11;
this.panelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// label_Additional_Color
//
this.label_Additional_Color.AllowDrop = true;
this.label_Additional_Color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_Additional_Color.Location = new System.Drawing.Point(151, 4);
this.label_Additional_Color.Name = "label_Additional_Color";
this.label_Additional_Color.Size = new System.Drawing.Size(111, 47);
this.label_Additional_Color.TabIndex = 13;
this.label_Additional_Color.Text = "Доп.цвет";
this.label_Additional_Color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_Additional_Color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
this.label_Additional_Color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_dragEnter);
//
// label_Color
//
this.label_Color.AllowDrop = true;
this.label_Color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_Color.Location = new System.Drawing.Point(14, 4);
this.label_Color.Name = "label_Color";
this.label_Color.Size = new System.Drawing.Size(115, 47);
this.label_Color.TabIndex = 12;
this.label_Color.Text = "Цвет";
this.label_Color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_Color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
this.label_Color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_dragEnter);
//
// FormTankConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.button_Add);
this.Controls.Add(this.panelColor);
this.Controls.Add(this.button_Cancel);
this.Controls.Add(this.PanelObject);
this.Controls.Add(this.groupBoxParameters);
this.Name = "FormTankConfig";
this.Text = "FormTankConfig";
this.groupBoxParameters.ResumeLayout(false);
this.groupBoxParameters.PerformLayout();
this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.PanelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.panelColor.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxParameters;
private CheckBox checkBoxLine;
private CheckBox checkBoxBodyKit;
private CheckBox checkBoxTrunk;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelWeigth;
private Label labelSpeed;
private GroupBox groupBoxColors;
private Panel panelWhite;
private Panel panelSilver;
private Panel panelGray;
private Panel panelBlack;
private Panel panelYellow;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelRed;
private Label labelComplexObject;
private Label labelSimpleObject;
private PictureBox pictureBoxObject;
private Button button_Cancel;
private Button button_Add;
private Label label_Color;
private Panel PanelObject;
private Panel panelColor;
private Label label_Additional_Color;
}
}

135
Tank/Tank/FormTankConfig.cs Normal file

@ -0,0 +1,135 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tank.DrawingObjects;
using Tank.Entites;
namespace Tank
{
public partial class FormTankConfig : Form
{
DrawingArmoredCar? _Tank = null;
private event Action<DrawingArmoredCar> EventAddTank;
public FormTankConfig()
{
InitializeComponent();
panelRed.MouseDown += panelColor_MouseDown;
panelGreen.MouseDown += panelColor_MouseDown;
panelBlue.MouseDown += panelColor_MouseDown;
panelYellow.MouseDown += panelColor_MouseDown;
panelBlack.MouseDown += panelColor_MouseDown;
panelGray.MouseDown += panelColor_MouseDown;
panelSilver.MouseDown += panelColor_MouseDown;
panelWhite.MouseDown += panelColor_MouseDown;
button_Cancel.Click += (s, e) => Close();
}
private void DrawTank()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_Tank?.SetPosition(5, 5);
_Tank?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
internal void AddEvent(Action<DrawingArmoredCar> eventAdd)
{
if (EventAddTank == null)
{
EventAddTank = eventAdd;
}
else
{
EventAddTank += eventAdd;
}
}
private void panelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void labelColor_dragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void labelColor_DragDrop(object sender, DragEventArgs e)
{
if (_Tank == null)
{
return;
}
switch (((Label)sender).Name)
{
case "label_Color":
_Tank.Tank.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "label_Additional_Color":
if (!(_Tank is DrawingTank))
return;
(_Tank.Tank as EntityTank).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
break;
}
DrawTank();
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name, 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":
_Tank = new DrawingArmoredCar((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelComplexObject":
_Tank = new DrawingTank((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxTrunk.Checked,
checkBoxBodyKit.Checked, checkBoxLine.Checked, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
}
DrawTank();
}
private void button_Add_Click(object sender, EventArgs e)
{
EventAddTank?.Invoke(_Tank);
Close();
}
}
}

@ -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,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tank.Generics
{
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T"></typeparam>
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?>(_maxCount);
}
public bool Insert(T tank)
{
return Insert(tank, 0);
}
public bool Insert(T tank, int position)
{
if (position < 0 || position > _maxCount)
return false;
if (Count >= _maxCount)
return false;
_places.Insert(0, tank);
return true;
}
public bool Remove(int position)
{
if (position < 0 || position > _maxCount)
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?> GetTanks(int? maxTanks = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxTanks.HasValue && i == maxTanks.Value)
{
yield break;
}
}
}
}
}

@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tank.MovementStrategy;
using Tank.DrawingObjects;
using Tank.MovementStrategy;
namespace Tank.Generics
{
/// <summary>
/// Параметризованный класс для набора объектов DrawningCar
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class TanksGenericCollection<T, U>
where T : DrawingArmoredCar
where U : IMoveableObject
{
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 160;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 65;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public TanksGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(TanksGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return false;
}
return (bool)collect?._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(TanksGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowTanks()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
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 + 40, j * _placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
int i = 0;
foreach (var tank in _collection.GetTanks())
{
if (tank != null)
{
tank._pictureWidth = _pictureWidth;
tank._pictureHeight = _pictureHeight;
tank.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth,
(i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
tank.DrawTransport(g);
}
i++;
}
}
}
}

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tank.Generics;
using Tank.DrawingObjects;
using Tank.MovementStrategy;
using System.Globalization;
namespace Tank.Generics
{
/// <summary>
/// Класс для хранения коллекции
/// </summary>
internal class TanksGenericStorage
{
/// <summary>
/// Словарь (хранилище)
/// </summary>
readonly Dictionary<string, TanksGenericCollection<DrawingArmoredCar, DrawingObjectArmoredCar>> _tankStorages;
/// <summary>
/// Возвращение списка названий наборов
/// </summary>
public List<string> Keys => _tankStorages.Keys.ToList();
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
public TanksGenericStorage(int pictureWidth, int pictureHeight)
{
_tankStorages = new Dictionary<string,TanksGenericCollection<DrawingArmoredCar, DrawingObjectArmoredCar>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление набора
/// </summary>
/// <param name="name">Название набора</param>
public void AddSet(string name)
{
if (_tankStorages.ContainsKey(name))
{
return;
}
else
{
_tankStorages[name] = new TanksGenericCollection<DrawingArmoredCar, DrawingObjectArmoredCar>(_pictureWidth, _pictureHeight);
}
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="name">Название набора</param>
public void DelSet(string name)
{
if (_tankStorages.ContainsKey(name))
{
_tankStorages.Remove(name);
}
else
{
return;
}
}
/// <summary>
/// Доступ к набору
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public TanksGenericCollection<DrawingArmoredCar, DrawingObjectArmoredCar>?
this[string ind]
{
get
{
if (_tankStorages.ContainsKey(ind))
{
return _tankStorages[ind];
}
return null;
}
}
}
}

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tank.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;
FieldHeight = height;
FieldWidth = width;
}
public void MakeStep()
{
if (_state != Status.InProgress)
return;
if (IsTargetDestination())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(Direction.Left);
protected bool MoveRight() => MoveTo(Direction.Right);
protected bool MoveUp() => MoveTo(Direction.Up);
protected bool MoveDown() => MoveTo(Direction.Down);
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectParameters;
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestination();
private bool MoveTo(Direction direction)
{
if (_state != Status.InProgress)
return false;
if (_moveableObject?.CheckCanMove(direction) ?? false)
{
_moveableObject.MoveObject(direction);
return true;
}
return false;
}
}
}

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tank.DrawingObjects;
namespace Tank.MovementStrategy
{
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
public class DrawingObjectArmoredCar : IMoveableObject
{
private readonly DrawingArmoredCar? _drawingArmoredCar = null;
public DrawingObjectArmoredCar(DrawingArmoredCar drawingArmoredCar)
{
_drawingArmoredCar = drawingArmoredCar;
}
public ObjectParameters? GetObjectParameters
{
get
{
if (_drawingArmoredCar == null || _drawingArmoredCar.Tank ==
null)
{
return null;
}
return new ObjectParameters(_drawingArmoredCar.GetPosX,
_drawingArmoredCar.GetPosY, _drawingArmoredCar.GetWidth, _drawingArmoredCar.GetHeight);
}
}
public int GetStep => (int)(_drawingArmoredCar?.Tank?.Step ?? 0);
public bool CheckCanMove(Direction direction) =>
_drawingArmoredCar?.CanMove(direction) ?? false;
public void MoveObject(Direction direction) =>
_drawingArmoredCar?.MoveTransport(direction);
}
}

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

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

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

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

@ -11,7 +11,7 @@ namespace Tank
// 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 FormArmoredCarCollection());
}
}
}

103
Tank/Tank/Properties/Resources.Designer.cs generated Normal file

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Tank.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("Tank.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 down_arrow {
get {
object obj = ResourceManager.GetObject("down-arrow", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap left_arrow {
get {
object obj = ResourceManager.GetObject("left-arrow", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap right_arrow {
get {
object obj = ResourceManager.GetObject("right-arrow", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap upper_arrow {
get {
object obj = ResourceManager.GetObject("upper-arrow", 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="down-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\down-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="left-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\left-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="right-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\right-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="upper-arrow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\upper-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

(image error) Size: 281 B

Binary file not shown.

After

(image error) Size: 265 B

Binary file not shown.

After

(image error) Size: 224 B

Binary file not shown.

After

(image error) Size: 264 B

@ -8,4 +8,24 @@
<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>
<ItemGroup>
<Folder Include="Drawings\" />
<Folder Include="MovementStrategy\" />
</ItemGroup>
</Project>