Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
ba37ae1d9b | |||
|
3290b58955 | ||
|
d60f81c6f7 | ||
|
94a05eba86 | ||
|
7fb3ca88c9 | ||
|
1af264335c | ||
|
d3f412720d | ||
|
7a919fc4d0 | ||
|
41000f3cc5 | ||
|
91d21e3081 |
158
AirFighter/AirFighter/AbstractMap.cs
Normal file
158
AirFighter/AirFighter/AbstractMap.cs
Normal file
@ -0,0 +1,158 @@
|
||||
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)
|
||||
{
|
||||
// Проверка коллизии
|
||||
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Right:
|
||||
if (Right + _drawningObject.Step < _width)
|
||||
{
|
||||
Left += _drawningObject.Step;
|
||||
Right += _drawningObject.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.Left:
|
||||
if (Left - _drawningObject.Step >= 0)
|
||||
{
|
||||
Left -= _drawningObject.Step;
|
||||
Right -= _drawningObject.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.Up:
|
||||
if (Top - _drawningObject.Step >= 0)
|
||||
{
|
||||
Top -= _drawningObject.Step;
|
||||
Bottom -= _drawningObject.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.Down:
|
||||
if (Bottom + _drawningObject.Step < _height)
|
||||
{
|
||||
Top += _drawningObject.Step;
|
||||
Bottom += _drawningObject.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (CheckBarrier((int)Right, (int)Left, (int)Top, (int)Bottom) == 1)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private int CheckBarrier(int Right, int Left, int Top, int Bottom)
|
||||
{
|
||||
if(Left < 0 || Top < 0 || Right > _width || Bottom > _height)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
for (int i = (int)(Top / _size_y); i <= (int)(Bottom / _size_y); i++)
|
||||
{
|
||||
for (int j = (int)(Left / _size_x); j <= (int)(Right / _size_x); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.Next(0, 10);
|
||||
int y = _random.Next(0, 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
// Првоерка, что объект не "накладывается" на закрытые участки
|
||||
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
|
||||
float tempBottom = Bottom;
|
||||
float tempTop = Top;
|
||||
while (CheckBarrier((int)Right, (int)Left, (int)Top, (int)Bottom) == 0)
|
||||
{
|
||||
int flag = 0;
|
||||
while (flag == 0)
|
||||
{
|
||||
|
||||
y += (int)_size_y;
|
||||
Top += (int)_size_y;
|
||||
Bottom += (int)_size_y;
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
flag = CheckBarrier((int)Right, (int)Left, (int)Top, (int)Bottom);
|
||||
}
|
||||
if (flag == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
x += (int)_size_x;
|
||||
Left += (int)_size_x;
|
||||
Right += (int)_size_x;
|
||||
y = (int)tempTop;
|
||||
Top = (int)tempTop;
|
||||
Bottom = (int)tempBottom;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
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, j, i);
|
||||
}
|
||||
else if (_map[i, j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
_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);
|
||||
}
|
||||
}
|
@ -9,8 +9,9 @@ namespace AirFighter
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
|
@ -9,20 +9,20 @@ namespace AirFighter
|
||||
/// <summary>
|
||||
/// Класс отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
internal class DrawningAirFighter
|
||||
public class DrawningAirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirFighter AirFighter { private set; get; }
|
||||
public EntityAirFighter AirFighter { protected set; get; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки самолета
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки самолета
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -45,10 +45,15 @@ namespace AirFighter
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawningAirFighter(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
AirFighter = new EntityAirFighter();
|
||||
AirFighter.Init(speed, weight, bodyColor);
|
||||
AirFighter = new EntityAirFighter(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawningAirFighter(int speed, float weight, Color bodyColor, int airFighterWight, int airFighterHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_airFighterWidth = airFighterWight;
|
||||
_airFighterHeight = airFighterHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции самолета
|
||||
@ -124,7 +129,7 @@ namespace AirFighter
|
||||
/// <summary>
|
||||
/// Отрисовка самолета
|
||||
/// </summary>
|
||||
public void DrawAirFighter(Graphics g)
|
||||
public virtual void DrawAirFighter(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
@ -183,5 +188,13 @@ namespace AirFighter
|
||||
_startPosY = _pictureHeight.Value - _airFighterHeight;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosX + _airFighterWidth, _startPosY, _startPosY + _airFighterHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
AirFighter/AirFighter/DrawningObjectAirFighter.cs
Normal file
38
AirFighter/AirFighter/DrawningObjectAirFighter.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class DrawningObjectAirFighter : IDrawningObject
|
||||
{
|
||||
private DrawningAirFighter _airFighter = null;
|
||||
public float Step => _airFighter?.AirFighter.Step ?? 0;
|
||||
public DrawningObjectAirFighter(DrawningAirFighter airFighter)
|
||||
{
|
||||
_airFighter = airFighter;
|
||||
}
|
||||
|
||||
void IDrawningObject.DrawningObject(Graphics g)
|
||||
{
|
||||
_airFighter.DrawAirFighter(g);
|
||||
}
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _airFighter?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_airFighter?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_airFighter?.SetPosition(x, y, width, height);
|
||||
}
|
||||
}
|
||||
}
|
99
AirFighter/AirFighter/DrawningUpgradeAirFighter.cs
Normal file
99
AirFighter/AirFighter/DrawningUpgradeAirFighter.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class DrawningUpgradeAirFighter : DrawningAirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <param name="dopColor"></param>
|
||||
/// <param name="dopWing"></param>
|
||||
/// <param name="rocket"></param>
|
||||
public DrawningUpgradeAirFighter(int speed, float weight, Color bodyColor, Color dopColor, bool dopWing, bool rocket) :
|
||||
base(speed, weight, bodyColor, 85, 80)
|
||||
{
|
||||
AirFighter = new EntityUpgradeAirFighter(speed, weight, bodyColor, dopColor, dopWing, rocket);
|
||||
}
|
||||
public override void DrawAirFighter(Graphics g)
|
||||
{
|
||||
if(AirFighter is not EntityUpgradeAirFighter upgradeAirFighter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(upgradeAirFighter.DopColor);
|
||||
|
||||
_startPosX += 5;
|
||||
_startPosY += 5;
|
||||
base.DrawAirFighter(g);
|
||||
_startPosX -= 5;
|
||||
_startPosY -= 5;
|
||||
|
||||
if (upgradeAirFighter.DopWing)
|
||||
{
|
||||
PointF[] _pointBackWing =
|
||||
{
|
||||
new PointF(_startPosX, _startPosY + 35),
|
||||
new PointF(_startPosX, _startPosY + 45),
|
||||
new PointF(_startPosX + 10, _startPosY + 40)
|
||||
};
|
||||
PointF[] _pointLeftWing =
|
||||
{
|
||||
new PointF(_startPosX + 50, _startPosY + 35),
|
||||
new PointF(_startPosX + 55, _startPosY + 30),
|
||||
new PointF(_startPosX + 65, _startPosY + 35)
|
||||
};
|
||||
PointF[] _pointRightWing =
|
||||
{
|
||||
new PointF(_startPosX + 50, _startPosY + 45),
|
||||
new PointF(_startPosX + 55, _startPosY + 50),
|
||||
new PointF(_startPosX + 65, _startPosY + 45)
|
||||
};
|
||||
|
||||
g.FillPolygon(dopBrush, _pointBackWing);
|
||||
g.FillPolygon(dopBrush, _pointLeftWing);
|
||||
g.FillPolygon(dopBrush, _pointRightWing);
|
||||
|
||||
g.DrawPolygon(pen, _pointBackWing);
|
||||
g.DrawPolygon(pen, _pointLeftWing);
|
||||
g.DrawPolygon(pen, _pointRightWing);
|
||||
}
|
||||
|
||||
if (upgradeAirFighter.Rocket)
|
||||
{
|
||||
PointF[] _pointLeftRocket =
|
||||
{
|
||||
new PointF(_startPosX + 35, _startPosY),
|
||||
new PointF(_startPosX + 45, _startPosY),
|
||||
new PointF(_startPosX + 50, _startPosY + 3),
|
||||
new PointF(_startPosX + 45, _startPosY + 5),
|
||||
new PointF(_startPosX + 35, _startPosY + 5)
|
||||
};
|
||||
PointF[] _pointRightRocket =
|
||||
{
|
||||
new PointF(_startPosX + 35, _startPosY + 75),
|
||||
new PointF(_startPosX + 45, _startPosY + 75),
|
||||
new PointF(_startPosX + 50, _startPosY + 77),
|
||||
new PointF(_startPosX + 45, _startPosY + 80),
|
||||
new PointF(_startPosX + 35, _startPosY + 80)
|
||||
};
|
||||
|
||||
g.FillPolygon(dopBrush, _pointLeftRocket);
|
||||
g.FillPolygon(dopBrush, _pointRightRocket);
|
||||
|
||||
g.DrawPolygon(pen, _pointLeftRocket);
|
||||
g.DrawPolygon(pen, _pointRightRocket);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ namespace AirFighter
|
||||
/// <summary>
|
||||
/// Класс-сущность "Военный самолет"
|
||||
/// </summary>
|
||||
internal class EntityAirFighter
|
||||
public class EntityAirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -34,7 +34,7 @@ namespace AirFighter
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityAirFighter(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
|
43
AirFighter/AirFighter/EntityUpgradeAirFighter.cs
Normal file
43
AirFighter/AirFighter/EntityUpgradeAirFighter.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность самолет разведчик
|
||||
/// </summary>
|
||||
internal class EntityUpgradeAirFighter : EntityAirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия дополнительных крыльев
|
||||
/// </summary>
|
||||
public bool DopWing { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия ракет
|
||||
/// </summary>
|
||||
public bool Rocket { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <param name="dopColor"></param>
|
||||
/// <param name="dopWing"></param>
|
||||
/// <param name="rocket"></param>
|
||||
public EntityUpgradeAirFighter(int speed, float weight, Color bodyColor, Color dopColor, bool dopWing, bool rocket) :
|
||||
base(speed,weight,bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
DopWing = dopWing;
|
||||
Rocket = rocket;
|
||||
}
|
||||
}
|
||||
}
|
27
AirFighter/AirFighter/FormAirFighter.Designer.cs
generated
27
AirFighter/AirFighter/FormAirFighter.Designer.cs
generated
@ -38,6 +38,8 @@
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonUpgrade = new System.Windows.Forms.Button();
|
||||
this.buttonSelectAirFighter = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -142,11 +144,34 @@
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUpgrade
|
||||
//
|
||||
this.buttonUpgrade.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonUpgrade.Location = new System.Drawing.Point(148, 379);
|
||||
this.buttonUpgrade.Name = "buttonUpgrade";
|
||||
this.buttonUpgrade.Size = new System.Drawing.Size(127, 29);
|
||||
this.buttonUpgrade.TabIndex = 7;
|
||||
this.buttonUpgrade.Text = "Модификация";
|
||||
this.buttonUpgrade.UseVisualStyleBackColor = true;
|
||||
this.buttonUpgrade.Click += new System.EventHandler(this.ButtonUpgrade_Click);
|
||||
//
|
||||
// buttonSelectAirFighter
|
||||
//
|
||||
this.buttonSelectAirFighter.Location = new System.Drawing.Point(565, 379);
|
||||
this.buttonSelectAirFighter.Name = "buttonSelectAirFighter";
|
||||
this.buttonSelectAirFighter.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonSelectAirFighter.TabIndex = 8;
|
||||
this.buttonSelectAirFighter.Text = "Выбрать";
|
||||
this.buttonSelectAirFighter.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectAirFighter.Click += new System.EventHandler(this.ButtonSelectAirFighter_Click);
|
||||
//
|
||||
// FormAirFighter
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonSelectAirFighter);
|
||||
this.Controls.Add(this.buttonUpgrade);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
@ -176,5 +201,7 @@
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonUpgrade;
|
||||
private Button buttonSelectAirFighter;
|
||||
}
|
||||
}
|
@ -3,6 +3,10 @@ namespace AirFighter
|
||||
public partial class FormAirFighter : Form
|
||||
{
|
||||
private DrawningAirFighter _airFighter;
|
||||
/// <summary>
|
||||
/// Âûáðàííûé îáúåêò
|
||||
/// </summary>
|
||||
public DrawningAirFighter SelectedAirFighter { get ; private set; }
|
||||
public FormAirFighter()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -18,19 +22,32 @@ namespace AirFighter
|
||||
pictureBoxAirFighter.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter?.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter?.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airFighter.AirFighter?.BodyColor}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
_airFighter = new DrawningAirFighter();
|
||||
Random rnd = new Random();
|
||||
_airFighter.Init(rnd.Next(200, 500), rnd.Next(2000, 5000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter?.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter?.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airFighter.AirFighter?.BodyColor}";
|
||||
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;
|
||||
}
|
||||
_airFighter = new DrawningAirFighter(rnd.Next(200, 500), rnd.Next(2000, 5000), color);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -68,5 +85,36 @@ namespace AirFighter
|
||||
_airFighter?.ChangeBorders(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonUpgrade_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;
|
||||
}
|
||||
_airFighter = new DrawningUpgradeAirFighter(rnd.Next(300, 600), rnd.Next(2000, 5000), color,
|
||||
dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonSelectAirFighter_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedAirFighter = _airFighter;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
212
AirFighter/AirFighter/FormMapWithSetAirFighters.Designer.cs
generated
Normal file
212
AirFighter/AirFighter/FormMapWithSetAirFighters.Designer.cs
generated
Normal file
@ -0,0 +1,212 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
partial class FormMapWithSetAirFighters
|
||||
{
|
||||
/// <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.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonRemoveAirFighter = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonAddAirFighter = 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.buttonUp);
|
||||
this.groupBox.Controls.Add(this.buttonDown);
|
||||
this.groupBox.Controls.Add(this.buttonLeft);
|
||||
this.groupBox.Controls.Add(this.buttonRight);
|
||||
this.groupBox.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBox.Controls.Add(this.buttonShowStorage);
|
||||
this.groupBox.Controls.Add(this.buttonRemoveAirFighter);
|
||||
this.groupBox.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBox.Controls.Add(this.buttonAddAirFighter);
|
||||
this.groupBox.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox.Location = new System.Drawing.Point(550, 0);
|
||||
this.groupBox.Name = "groupBox";
|
||||
this.groupBox.Size = new System.Drawing.Size(250, 450);
|
||||
this.groupBox.TabIndex = 0;
|
||||
this.groupBox.TabStop = false;
|
||||
this.groupBox.Text = "Инструменты";
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.Up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(135, 370);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 2;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.Down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(135, 408);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 3;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.Left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(99, 408);
|
||||
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);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.Right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(171, 408);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 5;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(28, 296);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(210, 29);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(28, 252);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(210, 29);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// buttonRemoveAirFighter
|
||||
//
|
||||
this.buttonRemoveAirFighter.Location = new System.Drawing.Point(28, 194);
|
||||
this.buttonRemoveAirFighter.Name = "buttonRemoveAirFighter";
|
||||
this.buttonRemoveAirFighter.Size = new System.Drawing.Size(210, 29);
|
||||
this.buttonRemoveAirFighter.TabIndex = 3;
|
||||
this.buttonRemoveAirFighter.Text = "Удалить самолет";
|
||||
this.buttonRemoveAirFighter.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveAirFighter.Click += new System.EventHandler(this.ButtonRemoveAirFighter_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(28, 145);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27);
|
||||
this.maskedTextBoxPosition.TabIndex = 2;
|
||||
//
|
||||
// buttonAddAirFighter
|
||||
//
|
||||
this.buttonAddAirFighter.Location = new System.Drawing.Point(28, 96);
|
||||
this.buttonAddAirFighter.Name = "buttonAddAirFighter";
|
||||
this.buttonAddAirFighter.Size = new System.Drawing.Size(210, 29);
|
||||
this.buttonAddAirFighter.TabIndex = 1;
|
||||
this.buttonAddAirFighter.Text = "Добавить самолет";
|
||||
this.buttonAddAirFighter.UseVisualStyleBackColor = true;
|
||||
this.buttonAddAirFighter.Click += new System.EventHandler(this.ButtonAddAirFighter_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(28, 45);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(210, 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.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(550, 450);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetAirFighters
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox);
|
||||
this.Name = "FormMapWithSetAirFighters";
|
||||
this.Text = "FormMapWithSetAirFighters";
|
||||
this.groupBox.ResumeLayout(false);
|
||||
this.groupBox.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox;
|
||||
private Button buttonShowOnMap;
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonRemoveAirFighter;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonAddAirFighter;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
}
|
||||
}
|
166
AirFighter/AirFighter/FormMapWithSetAirFighters.cs
Normal file
166
AirFighter/AirFighter/FormMapWithSetAirFighters.cs
Normal file
@ -0,0 +1,166 @@
|
||||
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 AirFighter
|
||||
{
|
||||
public partial class FormMapWithSetAirFighters : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// </summary>
|
||||
private MapWithSetAirFightersGeneric<DrawningObjectAirFighter, AbstractMap> _mapAirFightersCollectionGeneric;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
public FormMapWithSetAirFighters()
|
||||
{
|
||||
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 StormMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapAirFightersCollectionGeneric = new
|
||||
MapWithSetAirFightersGeneric<DrawningObjectAirFighter, AbstractMap>(
|
||||
pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapAirFightersCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddAirFighter_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirFightersCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormAirFighter form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawningObjectAirFighter airFighter = new(form.SelectedAirFighter);
|
||||
if ((_mapAirFightersCollectionGeneric + airFighter) == 0)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveAirFighter_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 ((_mapAirFightersCollectionGeneric - pos) != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirFightersCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirFightersCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirFightersCollectionGeneric == 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 = _mapAirFightersCollectionGeneric.MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
60
AirFighter/AirFighter/FormMapWithSetAirFighters.resx
Normal file
60
AirFighter/AirFighter/FormMapWithSetAirFighters.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>
|
44
AirFighter/AirFighter/IDrawningObject.cs
Normal file
44
AirFighter/AirFighter/IDrawningObject.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||
/// </summary>
|
||||
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>
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
203
AirFighter/AirFighter/MapWithSetAirFightersGeneric.cs
Normal file
203
AirFighter/AirFighter/MapWithSetAirFightersGeneric.cs
Normal file
@ -0,0 +1,203 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Карта с набром объектов под нее
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class MapWithSetAirFightersGeneric<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 SetAirFightersGeneric<T> _setAirFighters;
|
||||
/// <summary>
|
||||
/// Карта
|
||||
/// </summary>
|
||||
private readonly U _map;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="map"></param>
|
||||
public MapWithSetAirFightersGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setAirFighters = new SetAirFightersGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="car"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(MapWithSetAirFightersGeneric<T, U> map, T airFighter)
|
||||
{
|
||||
return map._setAirFighters.Insert(airFighter);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public static T operator -(MapWithSetAirFightersGeneric<T, U> map, int
|
||||
position)
|
||||
{
|
||||
return map._setAirFighters.Remove(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawAirFighters(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Просмотр объекта на карте
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setAirFighters.Count; i++)
|
||||
{
|
||||
var airFighter = _setAirFighters.Get(i);
|
||||
if (airFighter != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, airFighter);
|
||||
}
|
||||
}
|
||||
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 = _setAirFighters.Count - 1;
|
||||
for (int i = 0; i < _setAirFighters.Count; i++)
|
||||
{
|
||||
if (_setAirFighters.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var airFighter = _setAirFighters.Get(j);
|
||||
if (airFighter != null)
|
||||
{
|
||||
_setAirFighters.Insert(airFighter, i);
|
||||
_setAirFighters.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i *
|
||||
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
|
||||
g.FillPolygon(new SolidBrush(Color.Gray), new PointF[]
|
||||
{
|
||||
new Point(i * _placeSizeWidth + _placeSizeWidth / 5, j * _placeSizeHeight + _placeSizeHeight / 10),
|
||||
new Point((i + 1) * _placeSizeWidth - _placeSizeWidth / 5, j * _placeSizeHeight + _placeSizeHeight / 10),
|
||||
new Point((i + 1) * _placeSizeWidth - _placeSizeWidth / 5, (j + 1) * _placeSizeHeight - _placeSizeHeight / 10),
|
||||
new Point(i * _placeSizeWidth + _placeSizeWidth / 5, (j + 1) * _placeSizeHeight - _placeSizeHeight / 10),
|
||||
});
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawAirFighters(Graphics g)
|
||||
{
|
||||
int currentWidth = _pictureWidth / _placeSizeWidth - 1;
|
||||
int currentHeight = _pictureHeight / _placeSizeHeight - 1;
|
||||
|
||||
for (int i = 0; i < _setAirFighters.Count; i++)
|
||||
{
|
||||
_setAirFighters.Get(i)?.SetObject(currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
_setAirFighters.Get(i)?.DrawningObject(g);
|
||||
|
||||
if(currentWidth > 0)
|
||||
{
|
||||
currentWidth -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(currentHeight > 0)
|
||||
{
|
||||
currentHeight -= 1;
|
||||
currentWidth = _pictureWidth / _placeSizeWidth - 1;
|
||||
}else return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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 FormAirFighter());
|
||||
Application.Run(new FormMapWithSetAirFighters());
|
||||
}
|
||||
}
|
||||
}
|
136
AirFighter/AirFighter/SetAirFightersGeneric.cs
Normal file
136
AirFighter/AirFighter/SetAirFightersGeneric.cs
Normal file
@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetAirFightersGeneric<T>
|
||||
where T: class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetAirFightersGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка на наличие пустых мест
|
||||
/// </summary>
|
||||
/// <param name="firstIndex"></param>
|
||||
/// <returns></returns>
|
||||
private bool CheckNullPosition(int firstIndex)
|
||||
{
|
||||
if(firstIndex >= _places.Length && firstIndex < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for(int i = firstIndex; i < _places.Length; i++)
|
||||
{
|
||||
if(_places[i] == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="airFighter">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T airFighter)
|
||||
{
|
||||
return Insert(airFighter, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="airFighter">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T airFighter, int position)
|
||||
{
|
||||
if(airFighter == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = airFighter;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(CheckNullPosition(position + 1))
|
||||
{
|
||||
T tempMain = airFighter;
|
||||
for (int i = position; i < _places.Length; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
_places[i] = tempMain;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
T temp2 = _places[i];
|
||||
_places[i] = tempMain;
|
||||
tempMain = temp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= 0 && position < _places.Length && _places[position] != null)
|
||||
{
|
||||
T temp = _places[position];
|
||||
_places[position] = null;
|
||||
return temp;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
if (_places[position] != null)
|
||||
{
|
||||
return _places[position];
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
53
AirFighter/AirFighter/SimpleMap.cs
Normal file
53
AirFighter/AirFighter/SimpleMap.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class SimpleMap : 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, (i + 1) * _size_x, (j + 1) * _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
66
AirFighter/AirFighter/StormMap.cs
Normal file
66
AirFighter/AirFighter/StormMap.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class StormMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.FromArgb(168, 168, 168));
|
||||
/// <summary>
|
||||
/// Дополнительный цвет открытого участка
|
||||
/// </summary>
|
||||
private readonly Brush dopRoadColor = new SolidBrush(Color.LightGray);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _size_y);
|
||||
}
|
||||
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
Random random = new Random();
|
||||
if (random.Next(0, 2) == 1)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _size_y);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.FillRectangle(dopRoadColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user