Compare commits

...

14 Commits

32 changed files with 2236 additions and 50 deletions

View File

@ -0,0 +1,139 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
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)
{
(float leftX, float topY, float rightX, float bottomY) = _drawningObject.GetCurrentPosition();
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
switch (direction)
{
case Direction.Up:
if (_size_y * (j + 1) >= topY - _drawningObject.Step && _size_y * (j + 1) < topY && _size_x * (i + 1) > leftX
&& _size_x * (i + 1) <= rightX)
{
return DrawMapWithObject();
}
break;
case Direction.Down:
if (_size_y * j <= bottomY + _drawningObject.Step && _size_y * j > bottomY && _size_x * (i + 1) > leftX
&& _size_x * (i + 1) <= rightX)
{
return DrawMapWithObject();
}
break;
case Direction.Left:
if (_size_x * (i + 1) >= leftX - _drawningObject.Step && _size_x * (i + 1) < leftX && _size_y * (j + 1) < bottomY
&& _size_y * (j + 1) >= topY)
{
return DrawMapWithObject();
}
break;
case Direction.Right:
if (_size_x * i <= rightX + _drawningObject.Step && _size_x * i > leftX && _size_y * (j + 1) < bottomY
&& _size_y * (j + 1) >= topY)
{
return DrawMapWithObject();
}
break;
}
}
}
}
_drawningObject.MoveObject(direction);
return DrawMapWithObject();
}
private bool SetObjectOnMap()
{
(float leftX, float topY, float rightX, float bottomY) = _drawningObject.GetCurrentPosition();
if (_drawningObject == null || _map == null)
{
return false;
}
float airplaneWidth = rightX - leftX;
float airplaneHeight = bottomY - topY;
int x = _random.Next(0, 10);
int y = _random.Next(0, 10);
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
if (_map[i, j] == _barrier)
{
if (x + airplaneWidth >= _size_x * i && x <= _size_x * i && y + airplaneHeight > _size_y * j && y <= _size_y * j)
{
return false;
}
}
}
}
_drawningObject.SetObject(x, y, _width, _height);
return true;
}
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);
}
}

View File

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

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
public enum Direction
{
None = 0,
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
public class DrawningAirplane
{
public EntityAirplane Airplane { get; protected set; }
protected float _startPosX;
protected float _startPosY;
private int? _pictureWidth = null;
private int? _pictureHeight = null;
private readonly int _airplaneWidth = 50;
private readonly int _airplaneHeight = 27;
public DrawningAirplane(int speed, float weight, Color bodyColor)
{
Airplane = new EntityAirplane(speed, weight, bodyColor);
}
protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) :
this(speed, weight, bodyColor)
{
_airplaneWidth = airplaneWidth;
_airplaneHeight = airplaneHeight;
}
public void SetPosition(int x, int y, int width, int height)
{
if (x + _airplaneWidth <= width && y + _airplaneHeight <= height && x >= 0 && y >= 0)
{
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
}
public void MoveTransport(Direction direction)
{
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
{
return;
}
switch (direction)
{
// вправо
case Direction.Right:
if (_startPosX + _airplaneWidth + Airplane.Step < _pictureWidth)
{
_startPosX += Airplane.Step;
}
break;
//влево
case Direction.Left:
if (_startPosX - Airplane.Step > 0)
{
_startPosX -= Airplane.Step;
}
break;
//вверх
case Direction.Up:
if (_startPosY - Airplane.Step > 0)
{
_startPosY -= Airplane.Step;
}
break;
//вниз
case Direction.Down:
if (_startPosY + _airplaneHeight + Airplane.Step + 30 < _pictureHeight)
{
_startPosY += Airplane.Step;
}
break;
}
}
public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
Pen pen = new(Color.Black);
// Корпус
g.DrawRectangle(pen, _startPosX, _startPosY + 10, 40, 10);
Brush darkBrush = new SolidBrush(Airplane?.BodyColor ?? Color.Black);
g.FillRectangle(darkBrush, _startPosX + 1, _startPosY + 11, 39, 9);
// Окно
darkBrush = new SolidBrush(Color.Black);
g.FillRectangle(darkBrush, _startPosX + 12, _startPosY + 13, 20, 2);
// Хвост
darkBrush = new SolidBrush(Color.Black);
g.DrawLine(pen, _startPosX, _startPosY + 12, _startPosX, _startPosY);
g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 10, _startPosY + 10);
// Заднее шасси
g.FillRectangle(darkBrush, _startPosX + 10, _startPosY + 21, 2, 2);
g.FillRectangle(darkBrush, _startPosX + 13, _startPosY + 23, 4, 4);
g.FillRectangle(darkBrush, _startPosX + 8, _startPosY + 23, 2, 4);
// Переднее шасси
g.FillRectangle(darkBrush, _startPosX + 35, _startPosY + 21, 2, 2);
g.FillRectangle(darkBrush, _startPosX + 35, _startPosY + 23, 4, 4);
// Нос
g.DrawLine(pen, _startPosX + 40, _startPosY + 10, _startPosX + 47, _startPosY + 15);
g.DrawLine(pen, _startPosX + 40, _startPosY + 20, _startPosX + 50, _startPosY + 15);
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _airplaneWidth || _pictureHeight <= _airplaneHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _airplaneWidth > _pictureWidth)
{
_startPosX = _pictureWidth.Value - _airplaneWidth;
}
if (_startPosY + _airplaneHeight > _pictureHeight)
{
_startPosY = _pictureHeight.Value - _airplaneHeight;
}
}
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _airplaneWidth, _startPosY + _airplaneHeight);
}
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
internal class DrawningAirplaneWithRadar : DrawningAirplane
{
public DrawningAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool ladder, bool window) :
base(speed, weight, bodyColor, 50, 27)
{
Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, ladder, window);
}
public override void DrawTransport(Graphics g)
{
if (Airplane is not EntityAirplaneWithRadar airplaneWithRadar)
{
return;
}
Pen pen = new(Color.Black, 2);
Brush dopBrush = new SolidBrush(airplaneWithRadar.DopColor);
base.DrawTransport(g);
if (airplaneWithRadar.Radar)
{
g.DrawEllipse(new Pen(Color.Black), _startPosX + 18, _startPosY + 3, 9, 4);
g.DrawRectangle(new Pen(Color.Black), _startPosX + 20, _startPosY + 6, 5, 4);
}
if (airplaneWithRadar.Window)
{
g.FillEllipse(dopBrush, _startPosX + 40, _startPosY + 13, 5, 5);
}
if (airplaneWithRadar.Ladder)
{
g.DrawLine(new Pen(Color.Black), _startPosX + 3, _startPosY + 18, _startPosX + 3, _startPosY + 12);
g.DrawLine(new Pen(Color.Black), _startPosX + 7, _startPosY + 18, _startPosX + 7, _startPosY + 12);
g.DrawLine(new Pen(Color.Black), _startPosX + 3, _startPosY + 16, _startPosX + 7, _startPosY + 16);
g.DrawLine(new Pen(Color.Black), _startPosX + 3, _startPosY + 13, _startPosX + 7, _startPosY + 13);
}
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
internal class DrawningObjectAirplane : IDrawningObject
{
private DrawningAirplane _airplane = null;
public DrawningObjectAirplane(DrawningAirplane airplane)
{
_airplane = airplane;
}
public float Step => _airplane?.Airplane?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _airplane?.GetCurrentPosition() ?? default;
}
public void MoveObject(Direction direction)
{
_airplane?.MoveTransport(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_airplane.SetPosition(x, y, width, height);
}
void IDrawningObject.DrawningObject(Graphics g)
{
_airplane.DrawTransport(g);
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
public class EntityAirplane
{
public int Speed { get; private set; }
public float Weight { get; private set; }
public Color BodyColor { get; private set; }
public float Step => Speed * 100 / Weight;
public EntityAirplane(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor;
}
}
}

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
internal class EntityAirplaneWithRadar : EntityAirplane
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; private set; }
/// <summary>
/// Признак наличия радара
/// </summary>
public bool Radar { get; private set; }
/// <summary>
/// Признак наличия лестницы
/// </summary>
public bool Ladder { get; private set; }
/// <summary>
/// Признак наличия окон
/// </summary>
public bool Window { get; private set; }
public EntityAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool ladder, bool window) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
Radar = radar;
Ladder = ladder;
Window = window;
}
}
}

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
internal class FoggySkyMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Blue);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.DarkGray);
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 < 12)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
if (y + 5 < 100 && x + 3 < 100)
{
_map[x, y] = _barrier;
_map[x + 1, y + 1] = _barrier;
_map[x + 2, y + 2] = _barrier;
_map[x + 1, y + 3] = _barrier;
_map[x + 2, y + 4] = _barrier;
_map[x + 3 , y + 5] = _barrier;
counter++;
}
}
}
}
}
}

View File

@ -1,39 +0,0 @@
namespace AirplaneWithRadar
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

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

View File

@ -0,0 +1,207 @@
namespace AirplaneWithRadar
{
partial class FormAirplane
{
/// <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.pictureBoxAirplane = new System.Windows.Forms.PictureBox();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = 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.buttonUp = new System.Windows.Forms.Button();
this.buttonCreateModify = new System.Windows.Forms.Button();
this.buttonSelectCar = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxAirplane
//
this.pictureBoxAirplane.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.pictureBoxAirplane.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxAirplane.Location = new System.Drawing.Point(0, 0);
this.pictureBoxAirplane.Name = "pictureBoxAirplane";
this.pictureBoxAirplane.Size = new System.Drawing.Size(800, 451);
this.pictureBoxAirplane.TabIndex = 0;
this.pictureBoxAirplane.TabStop = false;
this.pictureBoxAirplane.Click += new System.EventHandler(this.ButtonMove_Click);
//
// statusStrip1
//
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip1.Location = new System.Drawing.Point(0, 425);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(800, 26);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20);
this.toolStripStatusLabelSpeed.Text = "Скорость:";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20);
this.toolStripStatusLabelWeight.Text = "Вес:";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20);
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(11, 391);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(677, 391);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 29);
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::AirplaneWithRadar.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(712, 391);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 29);
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::AirplaneWithRadar.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(747, 392);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 29);
this.buttonRight.TabIndex = 5;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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::AirplaneWithRadar.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(712, 355);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 29);
this.buttonUp.TabIndex = 6;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonCreateModify
//
this.buttonCreateModify.Location = new System.Drawing.Point(111, 391);
this.buttonCreateModify.Name = "buttonCreateModify";
this.buttonCreateModify.Size = new System.Drawing.Size(133, 29);
this.buttonCreateModify.TabIndex = 7;
this.buttonCreateModify.Text = "Модификация";
this.buttonCreateModify.UseVisualStyleBackColor = true;
this.buttonCreateModify.Click += new System.EventHandler(this.buttonCreateModify_Click);
//
// buttonSelectCar
//
this.buttonSelectCar.Location = new System.Drawing.Point(560, 391);
this.buttonSelectCar.Name = "buttonSelectCar";
this.buttonSelectCar.Size = new System.Drawing.Size(94, 29);
this.buttonSelectCar.TabIndex = 8;
this.buttonSelectCar.Text = "Выбрать";
this.buttonSelectCar.UseVisualStyleBackColor = true;
this.buttonSelectCar.Click += new System.EventHandler(this.buttonSelectCar_Click);
//
// FormAirplane
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 451);
this.Controls.Add(this.buttonSelectCar);
this.Controls.Add(this.buttonCreateModify);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.pictureBoxAirplane);
this.Name = "FormAirplane";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxAirplane;
private StatusStrip statusStrip1;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
private Button buttonCreateModify;
private Button buttonSelectCar;
}
}

View File

@ -0,0 +1,103 @@
namespace AirplaneWithRadar
{
public partial class FormAirplane : Form
{
private DrawningAirplane _airplane;
/// <summary>
/// Âűáđŕííűé îáúĺęň
/// </summary>
public DrawningAirplane SelectedAirplane { get; private set; }
public FormAirplane()
{
InitializeComponent();
}
private void Draw()
{
Bitmap bmp = new(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
Graphics gr = Graphics.FromImage(bmp);
_airplane?.DrawTransport(gr);
pictureBoxAirplane.Image = bmp;
}
/// <summary>
/// Ěĺňîä óńňŕíîâęč äŕííűő
/// </summary>
private void SetData()
{
Random rnd = new();
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
toolStripStatusLabelSpeed.Text = $"Ńęîđîńňü: {_airplane.Airplane.Speed}";
toolStripStatusLabelWeight.Text = $"Âĺń: {_airplane.Airplane.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâĺň: {_airplane.Airplane.BodyColor.Name}";
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new();
Color myColor = new Color();
ColorDialog MyDialog = new ColorDialog();
if (MyDialog.ShowDialog() == DialogResult.OK)
{
myColor = MyDialog.Color;
}
_airplane = new DrawningAirplane(random.Next(30, 50), random.Next(1000, 2000), myColor);
SetData();
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
//ďîëó÷ŕĺě čě˙ ęíîďęč
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_airplane?.MoveTransport(Direction.Up);
break;
case "buttonDown":
_airplane?.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_airplane?.MoveTransport(Direction.Left);
break;
case "buttonRight":
_airplane?.MoveTransport(Direction.Right);
break;
}
Draw();
}
private void PictureBoxAirplane_Resize(object sender, EventArgs e)
{
_airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
Draw();
}
/// <summary>
/// Îáđŕáîňęŕ íŕćŕňč˙ ęíîďęč "Ěîäčôčęŕöč˙"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateModify_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;
}
_airplane = new DrawningAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
private void buttonSelectCar_Click(object sender, EventArgs e)
{
SelectedAirplane = _airplane;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -0,0 +1,63 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,209 @@
namespace AirplaneWithRadar
{
partial class FormMap
{
/// <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.pictureBoxAirplane = new System.Windows.Forms.PictureBox();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
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.buttonCreateModify = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxAirplane
//
this.pictureBoxAirplane.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxAirplane.Location = new System.Drawing.Point(0, 0);
this.pictureBoxAirplane.Name = "pictureBoxAirplane";
this.pictureBoxAirplane.Size = new System.Drawing.Size(800, 450);
this.pictureBoxAirplane.TabIndex = 0;
this.pictureBoxAirplane.TabStop = false;
//
// statusStrip1
//
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip1.Location = new System.Drawing.Point(0, 428);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(800, 22);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "Скорость";
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(59, 17);
this.toolStripStatusLabelSpeed.Text = "Скорость";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(26, 17);
this.toolStripStatusLabelWeight.Text = "Вес";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(33, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет";
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(12, 402);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 2;
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::AirplaneWithRadar.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(687, 357);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(651, 395);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4;
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::AirplaneWithRadar.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(687, 395);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(723, 395);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 6;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonCreateModify
//
this.buttonCreateModify.Location = new System.Drawing.Point(93, 402);
this.buttonCreateModify.Name = "buttonCreateModify";
this.buttonCreateModify.Size = new System.Drawing.Size(108, 23);
this.buttonCreateModify.TabIndex = 7;
this.buttonCreateModify.Text = "Модификация";
this.buttonCreateModify.UseVisualStyleBackColor = true;
this.buttonCreateModify.Click += new System.EventHandler(this.buttonCreateModify_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(12, 12);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
this.comboBoxSelectorMap.TabIndex = 8;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// FormMap
//
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.comboBoxSelectorMap);
this.Controls.Add(this.buttonCreateModify);
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.statusStrip1);
this.Controls.Add(this.pictureBoxAirplane);
this.Name = "FormMap";
this.Text = "FormMap";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxAirplane;
private StatusStrip statusStrip1;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonCreateModify;
private ComboBox comboBoxSelectorMap;
}
}

View File

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AirplaneWithRadar
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
/// <summary>
/// Заполнение информации по объекту
/// </summary>
/// <param name="aiplane"></param>
private void SetData(DrawningAirplane airplane)
{
toolStripStatusLabelSpeed.Text = $"Скорость: {airplane.Airplane.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {airplane.Airplane.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {airplane.Airplane.BodyColor.Name}";
pictureBoxAirplane.Image = _abstractMap.CreateMap(pictureBoxAirplane.Width, pictureBoxAirplane.Height,
new DrawningObjectAirplane(airplane));
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
var ship = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetData(ship);
}
/// <summary>
/// Изменение размеров формы
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
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;
}
pictureBoxAirplane.Image = _abstractMap?.MoveObject(dir);
}
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateModify_Click(object sender, EventArgs e)
{
Random rnd = new();
var ship = new DrawningAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(ship);
}
/// <summary>
/// Смена карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Карта неба с облаками":
_abstractMap = new SkyMap();
break;
case "Карта туманного неба с грозой":
_abstractMap = new FoggySkyMap();
break;
}
}
}
}

View File

@ -0,0 +1,63 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,239 @@
namespace AirplaneWithRadar
{
partial class FormMapWithSetAirplane
{
/// <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.groupBox = new System.Windows.Forms.GroupBox();
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.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveAirplane = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddAirplane = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBox
//
this.groupBox.Controls.Add(this.buttonDown);
this.groupBox.Controls.Add(this.buttonRight);
this.groupBox.Controls.Add(this.buttonLeft);
this.groupBox.Controls.Add(this.buttonUp);
this.groupBox.Controls.Add(this.buttonShowOnMap);
this.groupBox.Controls.Add(this.buttonShowStorage);
this.groupBox.Controls.Add(this.buttonRemoveAirplane);
this.groupBox.Controls.Add(this.maskedTextBoxPosition);
this.groupBox.Controls.Add(this.buttonAddAirplane);
this.groupBox.Controls.Add(this.comboBoxSelectorMap);
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox.Location = new System.Drawing.Point(685, 0);
this.groupBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox.Name = "groupBox";
this.groupBox.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox.Size = new System.Drawing.Size(229, 600);
this.groupBox.TabIndex = 0;
this.groupBox.TabStop = false;
this.groupBox.Text = "Инструменты";
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(99, 537);
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(34, 40);
this.buttonDown.TabIndex = 9;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(141, 537);
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(34, 40);
this.buttonRight.TabIndex = 8;
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::AirplaneWithRadar.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(58, 537);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(34, 40);
this.buttonLeft.TabIndex = 7;
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::AirplaneWithRadar.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(99, 489);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(34, 40);
this.buttonUp.TabIndex = 6;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonShowOnMap.Location = new System.Drawing.Point(22, 416);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(193, 40);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonShowStorage.Location = new System.Drawing.Point(22, 311);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(193, 40);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonRemoveAirplane
//
this.buttonRemoveAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRemoveAirplane.Location = new System.Drawing.Point(22, 228);
this.buttonRemoveAirplane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
this.buttonRemoveAirplane.Size = new System.Drawing.Size(193, 40);
this.buttonRemoveAirplane.TabIndex = 3;
this.buttonRemoveAirplane.Text = "Удалить самолет";
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
this.buttonRemoveAirplane.Click += new System.EventHandler(this.ButtonRemoveAirplane_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.maskedTextBoxPosition.Location = new System.Drawing.Point(22, 189);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(193, 27);
this.maskedTextBoxPosition.TabIndex = 2;
//
// buttonAddAirplane
//
this.buttonAddAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAddAirplane.Location = new System.Drawing.Point(22, 120);
this.buttonAddAirplane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddAirplane.Name = "buttonAddAirplane";
this.buttonAddAirplane.Size = new System.Drawing.Size(193, 40);
this.buttonAddAirplane.TabIndex = 1;
this.buttonAddAirplane.Text = "Добавить самолет";
this.buttonAddAirplane.UseVisualStyleBackColor = true;
this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
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(22, 44);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(193, 28);
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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(685, 600);
this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetAirplane
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(914, 600);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMapWithSetAirplane";
this.Text = "FormMapWithSetAirplane";
this.groupBox.ResumeLayout(false);
this.groupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private GroupBox groupBox;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private Button buttonUp;
private Button buttonShowOnMap;
private Button buttonShowStorage;
private Button buttonRemoveAirplane;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddAirplane;
private ComboBox comboBoxSelectorMap;
private PictureBox pictureBox;
}
}

View File

@ -0,0 +1,164 @@
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 static System.Windows.Forms.DataFormats;
namespace AirplaneWithRadar
{
public partial class FormMapWithSetAirplane : Form
{
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetAirplaneGeneric<DrawningObjectAirplane, AbstractMap> _mapAirplaneCollectionGeneric;
public FormMapWithSetAirplane()
{
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 SkyMap();
break;
case "Карта туманного неба с грозой":
map = new FoggySkyMap();
break;
}
if (map != null)
{
_mapAirplaneCollectionGeneric = new MapWithSetAirplaneGeneric<DrawningObjectAirplane, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapAirplaneCollectionGeneric = null;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddAirplane_Click(object sender, EventArgs e)
{
if (_mapAirplaneCollectionGeneric == null)
{
return;
}
FormAirplane form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectAirplane airplane = new(form.SelectedAirplane);
if (_mapAirplaneCollectionGeneric + airplane != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveAirplane_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 (_mapAirplaneCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapAirplaneCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapAirplaneCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapAirplaneCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapAirplaneCollectionGeneric == 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 = _mapAirplaneCollectionGeneric.MoveObject(dir);
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
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>
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
}
}

View File

@ -0,0 +1,142 @@
namespace AirplaneWithRadar
{
// Карта с набром объектов под нее
internal class MapWithSetAirplaneGeneric<T, U>
where T : class, IDrawningObject
where U : AbstractMap
{
// Ширина окна отрисовки
private readonly int _pictureWidth;
// Высота окна отрисовки
private readonly int _pictureHeight;
// Размер занимаемого объектом места (ширина)
private readonly int _placeSizeWidth = 180;
// Размер занимаемого объектом места (высота)
private readonly int _placeSizeHeight = 90;
// Набор объектов
private readonly SetAirplaneGeneric<T> _setAirplane;
// Карта
private readonly U _map;
// Конструктор
public MapWithSetAirplaneGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setAirplane = new SetAirplaneGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
// Перегрузка оператора сложения
public static int operator +(MapWithSetAirplaneGeneric<T, U> map, T airplane)
{
return map._setAirplane.Insert(airplane);
}
// Перегрузка оператора вычитания
public static T operator -(MapWithSetAirplaneGeneric<T, U> map, int position)
{
return map._setAirplane.Remove(position);
}
// Вывод всего набора объектов
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawAirplane(gr);
return bmp;
}
// Просмотр объекта на карте
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setAirplane.Count; i++)
{
var airplane = _setAirplane.Get(i);
if (airplane != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, airplane);
}
}
return new(_pictureWidth, _pictureHeight);
}
// Перемещение объекта по карте
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new(_pictureWidth, _pictureHeight);
}
// "Взбалтываем" набор, чтобы все элементы оказались в начале
private void Shaking()
{
int j = _setAirplane.Count - 1;
for (int i = 0; i < _setAirplane.Count; i++)
{
if (_setAirplane.Get(i) == null)
{
for (; j > i; j--)
{
var airplane = _setAirplane.Get(j);
if (airplane != null)
{
_setAirplane.Insert(airplane, i);
_setAirplane.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
// Метод отрисовки фона
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
Brush brush = new SolidBrush(Color.FromArgb(147, 146, 151));
g.FillRectangle(brush, 0, 0, _pictureWidth, _pictureHeight);
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, j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight + 10, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + 10);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
// Метод прорисовки объектов
private void DrawAirplane(Graphics g)
{
int widthEl = _pictureWidth / _placeSizeWidth;
int heightEl = _pictureHeight / _placeSizeHeight;
int curWidth = 0;
int curHeight = 0;
for (int i = _setAirplane.Count; i >= 0; i--)
{
_setAirplane.Get(i)?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 80,
curHeight * _placeSizeHeight + 30, _pictureWidth, _pictureHeight);
_setAirplane.Get(i)?.DrawningObject(g);
if (curWidth < widthEl)
curWidth++;
else
{
curWidth = 1;
curHeight++;
}
if (curHeight > heightEl)
{
return;
}
}
}
}
}

View File

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

View File

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

View File

@ -117,4 +117,17 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="arrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowDown.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowLeft.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowRight.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="arrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\arrowUp.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -0,0 +1,75 @@
namespace AirplaneWithRadar
{
// Параметризованный набор объектов
internal class SetAirplaneGeneric<T>
where T : class
{
// Массив объектов, которые храним
private readonly T[] _places;
// Количество объектов в массиве
public int Count => _places.Length;
// Конструктор
public SetAirplaneGeneric(int count)
{
_places = new T[count];
}
// Добавление объекта в набор
public int Insert(T airplane)
{
// вставка в начало набора
return Insert(airplane, 0);
}
// Добавление объекта в набор на конкретную позицию
public int Insert(T airplane, int position)
{
// проверка позиции
if (position >= _places.Length || position < 0)
return -1;
//проверка, что элемент массива по этой позиции пустой, если нет, то
if (_places[position] == null)
{
_places[position] = airplane;
return position;
}
//проверка, что после вставляемого элемента в массиве есть пустой элемент
int findEmptyPos = -1;
for (int i = position + 1; i < Count; i++)
{
if (_places[i] == null)
{
findEmptyPos = i;
break;
}
}
if (findEmptyPos < 0) return -1;
//сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
for (int i = findEmptyPos; i > position; i--)
{
_places[i] = _places[i - 1];
}
// вставка по позиции
_places[position] = airplane;
return position;
}
// Удаление объекта из набора с конкретной позиции
public T Remove(int position)
{
// проверка позиции
if (position >= _places.Length || position < 0) return null;
// удаление объекта из массива, присовив элементу массива значение null
T temp = _places[position];
_places[position] = null;
return temp;
}
// Получение объекта из набора по позиции
public T Get(int position)
{
// проверка позиции
if (position >= _places.Length || position < 0)
return null;
return _places[position];
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
/// <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, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
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++;
}
}
}
}
}

View File

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirplaneWithRadar
{
/// <summary>
/// Простая реализация абсрактного класса AbstractMap
/// </summary>
internal class SkyMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Gray);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.LightBlue);
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 < 10)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (x - 2 >=0 && y + 4 < 100 && x + 2 < 100)
{
if (_map[x, y] == _freeRoad && _map[x + 1, y + 1] == _freeRoad && _map[x - 1, y + 1] == _freeRoad && _map[x, y + 2] == _freeRoad && _map[x, y + 1] == _freeRoad
&& _map[x + 2, y + 2] == _freeRoad && _map[x - 2, y + 2] == _freeRoad && _map[x + 1, y + 3] == _freeRoad && _map[x - 1, y + 3] == _freeRoad
&& _map[x, y + 3] == _freeRoad && _map[x, y + 4] == _freeRoad && _map[x + 1, y + 2] == _freeRoad && _map[x - 1, y + 2] == _freeRoad)
{
_map[x, y] = _barrier;
_map[x + 1, y + 1] = _barrier;
_map[x - 1, y + 1] = _barrier;
_map[x + 2, y + 2] = _barrier;
_map[x - 2, y + 2] = _barrier;
_map[x, y + 2] = _barrier;
_map[x, y + 1] = _barrier;
_map[x + 1, y + 3] = _barrier;
_map[x - 1, y + 3] = _barrier;
_map[x, y + 3] = _barrier;
_map[x, y + 4] = _barrier;
_map[x + 1, y + 2] = _barrier;
_map[x - 1, y + 2] = _barrier;
counter++;
}
}
}
}
}
}