Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
87c41fd6a7 | |||
692995dcae | |||
08e95fbcec | |||
6189e9012a | |||
eb98000ec2 | |||
57503df640 | |||
0039840d33 | |||
2db962f860 | |||
fb0f6def7c | |||
9a87009db1 | |||
8127c1cc38 | |||
36d0e53168 | |||
9e57fd3aeb | |||
10a75c38fc | |||
c63c420f7e | |||
f07e0ddd9e |
107
WarPlanes/WarPlanes/AbstractMap.cs
Normal file
107
WarPlanes/WarPlanes/AbstractMap.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
{
|
||||
private IDrawningObject _drawningObject = null;
|
||||
protected int[,] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected readonly Random _random = new();
|
||||
protected readonly int _freeRoad = 0;
|
||||
protected readonly int _barrier = 1;
|
||||
|
||||
public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawningObject = drawningObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
RectangleF rectObject = _drawningObject.GetCurrentPosition();
|
||||
|
||||
if (direction == Direction.Up) rectObject.Y -= _drawningObject.Step;
|
||||
else if (direction == Direction.Down) rectObject.Y += _drawningObject.Step;
|
||||
else if (direction == Direction.Left) rectObject.X -= _drawningObject.Step;
|
||||
else if (direction == Direction.Right) rectObject.X += _drawningObject.Step;
|
||||
|
||||
if(rectObject.X < 0 || rectObject.Right >= _width || rectObject.Y < 0 || rectObject.Bottom >= _height)
|
||||
{
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
if (isCollision(rectObject))
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private bool isCollision (RectangleF rectObject)
|
||||
{
|
||||
for (int i = (int) Math.Clamp((rectObject.Left / _size_x),0, _width); i < MathF.Ceiling(rectObject.Right / _size_x); i++)
|
||||
{
|
||||
for (int j = (int)Math.Clamp((rectObject.Top / _size_y),0,_height); j < MathF.Ceiling(rectObject.Bottom / _size_y); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
return isCollision(_drawningObject.GetCurrentPosition());
|
||||
}
|
||||
private Bitmap DrawMapWithObject()
|
||||
{
|
||||
Bitmap bmp = new(_width, _height);
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i, j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i, j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawningObject.DrawningObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
||||
}
|
@ -3,8 +3,9 @@
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
|
73
WarPlanes/WarPlanes/DrawningFighter.cs
Normal file
73
WarPlanes/WarPlanes/DrawningFighter.cs
Normal file
@ -0,0 +1,73 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class DrawningFighter : DrawningWarPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолёта</param>
|
||||
/// <param name="bodyColor">Цвет самолёта</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="rocket">Признак наличия ракет</param>
|
||||
/// <param name="wing">Признак наличия дополнительных крыльев</param>
|
||||
public DrawningFighter(int speed, float weight, Color bodyColor, Color dopColor, bool rocket, bool wing) :
|
||||
base(speed, weight, bodyColor, 110, 60)
|
||||
{
|
||||
WarPlane = new EntityFighter(speed, weight, bodyColor, dopColor, rocket, wing);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (WarPlane is not EntityFighter Fighter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(Fighter.DopColor);
|
||||
|
||||
if (Fighter.Rocket)
|
||||
{
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
PointF[] point = new PointF[3];
|
||||
//нижняя ракета
|
||||
point[0] = new PointF(_startPosX + _warplaneWidth / 2, _startPosY + _warplaneHeight);
|
||||
point[1] = new PointF(_startPosX + _warplaneWidth / 2, _startPosY + _warplaneHeight + _warplaneHeight / 15);
|
||||
point[2] = new PointF(_startPosX + _warplaneWidth / 2 - 5, _startPosY + _warplaneHeight + _warplaneHeight / 30);
|
||||
g.FillPolygon(dopBrush, point);
|
||||
point[0] = new PointF(_startPosX + _warplaneWidth*3 / 4-2 , _startPosY + _warplaneHeight -4);
|
||||
point[1] = new PointF(_startPosX + _warplaneWidth*3 / 4-2, _startPosY + _warplaneHeight + _warplaneHeight / 15 + 4);
|
||||
point[2] = new PointF(_startPosX + _warplaneWidth * 3 / 4 - 8, _startPosY + _warplaneHeight + _warplaneHeight / 30);
|
||||
g.FillPolygon(dopBrush, point);
|
||||
g.FillRectangle(dopBrush, _startPosX + _warplaneWidth / 2, _startPosY + _warplaneHeight, _warplaneWidth/4, _warplaneHeight/15);
|
||||
|
||||
//верхняя ракета
|
||||
point[0] = new PointF(_startPosX + _warplaneWidth / 2, _startPosY + _warplaneHeight / 15 + 1);
|
||||
point[1] = new PointF(_startPosX + _warplaneWidth / 2, _startPosY + _warplaneHeight / 7.5F + 1);
|
||||
point[2] = new PointF(_startPosX + _warplaneWidth / 2 - 5, _startPosY + _warplaneHeight / 11.25F +1);
|
||||
g.FillPolygon(dopBrush, point);
|
||||
point[0] = new PointF(_startPosX + _warplaneWidth * 3 / 4 - 2, _startPosY + _warplaneHeight / 15 -3);
|
||||
point[1] = new PointF(_startPosX + _warplaneWidth * 3 / 4 - 2, _startPosY + _warplaneHeight / 7.5F + 5);
|
||||
point[2] = new PointF(_startPosX + _warplaneWidth * 3 / 4 - 8, _startPosY + _warplaneHeight / 11.25F + 1 + _warplaneHeight / 30);
|
||||
g.FillPolygon(dopBrush, point);
|
||||
g.FillRectangle(dopBrush, _startPosX + _warplaneWidth / 2, _startPosY+ _warplaneHeight / 15+1, _warplaneWidth / 4, _warplaneHeight / 15);
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
if (Fighter.Wing)
|
||||
{
|
||||
//Задние Крьлья
|
||||
PointF[] point = new PointF[5];
|
||||
point[0] = new PointF(_startPosX + _warplaneWidth / 3, _startPosY + _warplaneHeight / 4);
|
||||
point[1] = new PointF(_startPosX + _warplaneWidth / 3 + 5, _startPosY + _warplaneHeight / 4 );
|
||||
point[2] = new PointF(_startPosX + _warplaneWidth / 3 + 10, _startPosY + _warplaneHeight / 2);
|
||||
point[3] = new PointF(_startPosX + _warplaneWidth / 3 + 5, _startPosY + _warplaneHeight - _warplaneHeight / 4);
|
||||
point[4] = new PointF(_startPosX + _warplaneWidth / 3, _startPosY + _warplaneHeight - _warplaneHeight / 4);
|
||||
g.FillPolygon(dopBrush, point);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
34
WarPlanes/WarPlanes/DrawningObjectWarPlane.cs
Normal file
34
WarPlanes/WarPlanes/DrawningObjectWarPlane.cs
Normal file
@ -0,0 +1,34 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class DrawningObjectWarPlane : IDrawningObject
|
||||
{
|
||||
private DrawningWarPlane _warplane = null;
|
||||
|
||||
public DrawningObjectWarPlane(DrawningWarPlane warplane)
|
||||
{
|
||||
_warplane = warplane;
|
||||
}
|
||||
|
||||
public float Step => _warplane?.WarPlane?.Step ?? 0;
|
||||
|
||||
public RectangleF GetCurrentPosition()
|
||||
{
|
||||
return _warplane?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_warplane?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_warplane.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
void IDrawningObject.DrawningObject(Graphics g)
|
||||
{
|
||||
_warplane.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,46 +3,59 @@
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
internal class DrawningWarPlane
|
||||
public class DrawningWarPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityWarPlane WarPlane { get; private set; }
|
||||
public EntityWarPlane WarPlane { get; protected set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки Военного самолёта
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки Военного самолёта
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private int? _pictureWidth = null;
|
||||
protected int? _pictureWidth = null;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private int? _pictureHeight = null;
|
||||
protected int? _pictureHeight = null;
|
||||
/// <summary>
|
||||
/// Ширина отрисовки Военного самолёта
|
||||
/// </summary>
|
||||
private readonly int _warplaneWidth = 80;
|
||||
protected readonly int _warplaneWidth = 80;
|
||||
/// <summary>
|
||||
/// Высота отрисовки Военного самолёта
|
||||
/// </summary>
|
||||
private readonly int _warplaneHeight = 50;
|
||||
protected readonly int _warplaneHeight = 50;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес Военного самолёта</param>
|
||||
/// <param name="bodyColor">Цвет Военного самолёта</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawningWarPlane(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
WarPlane = new EntityWarPlane();
|
||||
WarPlane.Init(speed, weight, bodyColor);
|
||||
WarPlane = new EntityWarPlane(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолёта</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="warplaneWidth">Ширина отрисовки самолёта</param>
|
||||
/// <param name="warplaneHeight">Высота отрисовки самолёта</param>
|
||||
protected DrawningWarPlane(int speed, float weight, Color bodyColor, int warplaneWidth, int warplaneHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_warplaneWidth = warplaneWidth;
|
||||
_warplaneHeight = warplaneHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции Военного самолёта
|
||||
@ -110,7 +123,7 @@
|
||||
/// Отрисовка самолёта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
@ -175,5 +188,13 @@
|
||||
_startPosY = _pictureHeight.Value - _warplaneHeight;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public RectangleF GetCurrentPosition()
|
||||
{
|
||||
return new RectangleF(_startPosX, _startPosY, _warplaneWidth, _warplaneHeight);
|
||||
}
|
||||
}
|
||||
}
|
37
WarPlanes/WarPlanes/EntityFighter.cs
Normal file
37
WarPlanes/WarPlanes/EntityFighter.cs
Normal file
@ -0,0 +1,37 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Истрибитель"
|
||||
/// </summary>
|
||||
internal class EntityFighter : EntityWarPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия рокет
|
||||
/// </summary>
|
||||
public bool Rocket { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак дополнительных крыльев
|
||||
/// </summary>
|
||||
public bool Wing { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолёта</param>
|
||||
/// <param name="bodyColor">Цвет самолёта</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="rocket">Признак наличия ракет</param>
|
||||
/// <param name="wing">Признак наличия дополнительных крыльев</param>
|
||||
public EntityFighter(int speed, float weight, Color bodyColor, Color dopColor, bool rocket, bool wing) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Rocket = rocket;
|
||||
Wing = wing;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Класс-сущность "Военный самолёт"
|
||||
/// </summary>
|
||||
internal class EntityWarPlane
|
||||
public class EntityWarPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -28,7 +28,7 @@
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityWarPlane(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
|
217
WarPlanes/WarPlanes/FormMapWithSetWarPlanes.Designer.cs
generated
Normal file
217
WarPlanes/WarPlanes/FormMapWithSetWarPlanes.Designer.cs
generated
Normal file
@ -0,0 +1,217 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
partial class FormMapWithSetWarPlanes
|
||||
{
|
||||
/// <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.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRemoveWarPlane = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonAddWarPlane = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRemoveWarPlane);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddWarPlane);
|
||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(204, 554);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
||||
this.maskedTextBoxPosition.TabIndex = 2;
|
||||
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRemoveWarPlane
|
||||
//
|
||||
this.buttonRemoveWarPlane.Location = new System.Drawing.Point(17, 195);
|
||||
this.buttonRemoveWarPlane.Name = "buttonRemoveWarPlane";
|
||||
this.buttonRemoveWarPlane.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonRemoveWarPlane.TabIndex = 3;
|
||||
this.buttonRemoveWarPlane.Text = "Удалить самолёт";
|
||||
this.buttonRemoveWarPlane.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveWarPlane.Click += new System.EventHandler(this.ButtonRemoveWarPlane_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(17, 287);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(91, 504);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 10;
|
||||
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::AirFighter.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(127, 504);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 9;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.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::AirFighter.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(55, 504);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 8;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(91, 468);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 7;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// buttonAddWarPlane
|
||||
//
|
||||
this.buttonAddWarPlane.Location = new System.Drawing.Point(17, 106);
|
||||
this.buttonAddWarPlane.Name = "buttonAddWarPlane";
|
||||
this.buttonAddWarPlane.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonAddWarPlane.TabIndex = 1;
|
||||
this.buttonAddWarPlane.Text = "Добавить самолёт";
|
||||
this.buttonAddWarPlane.UseVisualStyleBackColor = true;
|
||||
this.buttonAddWarPlane.Click += new System.EventHandler(this.ButtonAddWarPlane_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Закрытая карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// 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(811, 554);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetWarPlanes
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1015, 554);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Name = "FormMapWithSetWarPlanes";
|
||||
this.Text = "Карта с набором объектов";
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
this.groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private PictureBox pictureBox;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private Button buttonShowOnMap;
|
||||
private Button buttonAddWarPlane;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonRemoveWarPlane;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
}
|
||||
}
|
153
WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs
Normal file
153
WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs
Normal file
@ -0,0 +1,153 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
public partial class FormMapWithSetWarPlanes : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// </summary>
|
||||
private MapWithSetWarPlanesGeneric<DrawningObjectWarPlane, AbstractMap> _mapWarPlanesCollectionGeneric;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMapWithSetWarPlanes()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Закрытая карта":
|
||||
map = new CloseMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapWarPlanesCollectionGeneric = new MapWithSetWarPlanesGeneric<DrawningObjectWarPlane, AbstractMap>(
|
||||
pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapWarPlanesCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddWarPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if(_mapWarPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormWarPlane form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawningObjectWarPlane warplane = new(form.SelectedWarPlane);
|
||||
if (form.SelectedWarPlane == null || (_mapWarPlanesCollectionGeneric + warplane) == -1)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveWarPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapWarPlanesCollectionGeneric - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapWarPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapWarPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapWarPlanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapWarPlanesCollectionGeneric.MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
60
WarPlanes/WarPlanes/FormMapWithSetWarPlanes.resx
Normal file
60
WarPlanes/WarPlanes/FormMapWithSetWarPlanes.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>
|
27
WarPlanes/WarPlanes/FormWarPlane.Designer.cs
generated
27
WarPlanes/WarPlanes/FormWarPlane.Designer.cs
generated
@ -38,6 +38,8 @@
|
||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.buttonSelectCar = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarPlane)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -141,11 +143,34 @@
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(104, 390);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(110, 23);
|
||||
this.buttonCreateModif.TabIndex = 14;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// buttonSelectCar
|
||||
//
|
||||
this.buttonSelectCar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonSelectCar.Location = new System.Drawing.Point(569, 390);
|
||||
this.buttonSelectCar.Name = "buttonSelectCar";
|
||||
this.buttonSelectCar.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonSelectCar.TabIndex = 15;
|
||||
this.buttonSelectCar.Text = "Выбрать";
|
||||
this.buttonSelectCar.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectCar.Click += new System.EventHandler(this.ButtonSelectWarPlane_Click);
|
||||
//
|
||||
// FormWarPlane
|
||||
//
|
||||
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.buttonSelectCar);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
@ -175,5 +200,7 @@
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private Button buttonCreateModif;
|
||||
private Button buttonSelectCar;
|
||||
}
|
||||
}
|
@ -3,6 +3,10 @@ namespace AirFighter
|
||||
public partial class FormWarPlane : Form
|
||||
{
|
||||
private DrawningWarPlane _warplane;
|
||||
/// <summary>
|
||||
/// Âűáđŕííűé îáúĺęň
|
||||
/// </summary>
|
||||
public DrawningWarPlane SelectedWarPlane { get; private set; }
|
||||
|
||||
public FormWarPlane()
|
||||
{
|
||||
@ -19,6 +23,17 @@ namespace AirFighter
|
||||
pictureBoxWarPlane.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ěĺňîä óńňŕíîâęč äŕííűő
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_warplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarPlane.Width, pictureBoxWarPlane.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ńęîđîńňü: {_warplane.WarPlane.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âĺń: {_warplane.WarPlane.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâĺň: {_warplane.WarPlane.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
@ -26,12 +41,14 @@ namespace AirFighter
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_warplane = new DrawningWarPlane();
|
||||
_warplane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_warplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarPlane.Width, pictureBoxWarPlane.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_warplane.WarPlane.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_warplane.WarPlane.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_warplane.WarPlane.BodyColor.Name}";
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_warplane = new DrawningWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -70,5 +87,37 @@ namespace AirFighter
|
||||
_warplane?.ChangeBorders(pictureBoxWarPlane.Width, pictureBoxWarPlane.Height);
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáđŕáîňęŕ íŕćŕňč˙ ęíîďęč "Ěîäčôčęŕöč˙"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialogDop = new();
|
||||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialogDop.Color;
|
||||
}
|
||||
_warplane = new DrawningFighter(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonSelectWarPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedWarPlane = _warplane;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
34
WarPlanes/WarPlanes/IDrawningObject.cs
Normal file
34
WarPlanes/WarPlanes/IDrawningObject.cs
Normal file
@ -0,0 +1,34 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
internal interface IDrawningObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
/// </summary>
|
||||
public float Step { get; }
|
||||
/// <summary>
|
||||
/// Установка позиции объекта
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина полотна</param>
|
||||
/// <param name="height">Высота полотна</param>
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns></returns>
|
||||
void MoveObject(Direction direction);
|
||||
/// <summary>
|
||||
/// Отрисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
void DrawningObject(Graphics g);
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
RectangleF GetCurrentPosition();
|
||||
}
|
||||
}
|
178
WarPlanes/WarPlanes/MapWithSetWarPlanesGeneric.cs
Normal file
178
WarPlanes/WarPlanes/MapWithSetWarPlanesGeneric.cs
Normal file
@ -0,0 +1,178 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Карта с набром объектов под нее
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class MapWithSetWarPlanesGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetWarPlanesGeneric<T> _setWarPlanes;
|
||||
/// <summary>
|
||||
/// Карта
|
||||
/// </summary>
|
||||
private readonly U _map;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="map"></param>
|
||||
public MapWithSetWarPlanesGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setWarPlanes = new SetWarPlanesGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="warplane"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(MapWithSetWarPlanesGeneric<T, U> map, T warplane)
|
||||
{
|
||||
return map._setWarPlanes.Insert(warplane);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public static T operator -(MapWithSetWarPlanesGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setWarPlanes.Remove(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawWarPlanes(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Просмотр объекта на карте
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setWarPlanes.Count; i++)
|
||||
{
|
||||
var warplane = _setWarPlanes.Get(i);
|
||||
if (warplane != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, warplane);
|
||||
}
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение объекта по крате
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||
/// </summary>
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setWarPlanes.Count - 1;
|
||||
for (int i = 0; i < _setWarPlanes.Count; i++)
|
||||
{
|
||||
if (_setWarPlanes.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var warplane = _setWarPlanes.Get(j);
|
||||
if (warplane != null)
|
||||
{
|
||||
_setWarPlanes.Insert(warplane, i);
|
||||
_setWarPlanes.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void DrawHangar(Graphics g, int x, int y, int width, int height)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
g.DrawLine(pen, x, y, x + width, y);
|
||||
g.DrawLine(pen, x, y, x, y+height);
|
||||
g.DrawLine(pen, x, y + height, x+ width, y + height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
DrawHangar(g, i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth*3/4, _placeSizeHeight-10);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawWarPlanes(Graphics g)
|
||||
{
|
||||
int countInLine = _pictureWidth / _placeSizeWidth;
|
||||
int maxLeft = (countInLine - 1) * _placeSizeWidth;
|
||||
for (int i = 0; i < _setWarPlanes.Count; i++)
|
||||
{
|
||||
var warplane = _setWarPlanes.Get(i);
|
||||
warplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth +10, _pictureHeight - _placeSizeHeight - i / countInLine * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
warplane?.DrawningObject(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace AirFighter
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormWarPlane());
|
||||
Application.Run(new FormMapWithSetWarPlanes());
|
||||
}
|
||||
}
|
||||
}
|
87
WarPlanes/WarPlanes/SetWarPlanesGeneric.cs
Normal file
87
WarPlanes/WarPlanes/SetWarPlanesGeneric.cs
Normal file
@ -0,0 +1,87 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetWarPlanesGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetWarPlanesGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="warplane">Добавляемый самолёт</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T warplane)
|
||||
{
|
||||
return Insert(warplane, 0);
|
||||
}
|
||||
private bool isCorrectPosition(int position)
|
||||
{
|
||||
return 0 <= position && position < Count;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="warplane">Добавляемый военный самолёт</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T warplane, int position)
|
||||
{
|
||||
int positionNullElement = position;
|
||||
while (Get(positionNullElement) != null)
|
||||
{
|
||||
positionNullElement++;
|
||||
}
|
||||
if (!isCorrectPosition(positionNullElement))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
while (positionNullElement != position) // Смещение вправо
|
||||
{
|
||||
_places[positionNullElement] = _places[positionNullElement - 1];
|
||||
positionNullElement--;
|
||||
}
|
||||
_places[position] = warplane;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (!isCorrectPosition(position)) return null;
|
||||
var result = _places[position];
|
||||
_places[position] = null;
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
if (isCorrectPosition(position)) { return _places[position]; }
|
||||
else { return null; }
|
||||
}
|
||||
}
|
||||
}
|
50
WarPlanes/WarPlanes/SimpleMap.cs
Normal file
50
WarPlanes/WarPlanes/SimpleMap.cs
Normal file
@ -0,0 +1,50 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Простая реализация абсрактного класса AbstractMap
|
||||
/// </summary>
|
||||
internal class SimpleMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
43
WarPlanes/WarPlanes/СloseMap.cs
Normal file
43
WarPlanes/WarPlanes/СloseMap.cs
Normal file
@ -0,0 +1,43 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Простая реализация абсрактного класса AbstractMap
|
||||
/// </summary>
|
||||
internal class CloseMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Red);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.WhiteSmoke);
|
||||
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (i == 0 || j == 0 || i == _map.GetLength(0) - 1 || j == _map.GetLength(1) - 1)
|
||||
_map[i, j] = _barrier;
|
||||
else
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user