Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
077a99d63a | |||
|
cb2fd7ac9f | ||
|
eda0bc77d9 |
@ -1,198 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
{
|
||||
private IDrawingObject _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, IDrawingObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawningObject = drawningObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private (int mapI, int mapJ) checkBarrier((float Left, float Right, float Top, float Bottom) rect)
|
||||
{
|
||||
return checkBarrier(rect, false, false, true, false);
|
||||
}
|
||||
private (int mapI, int mapJ) checkBarrier((float Left, float Right, float Top, float Bottom) rect, bool minLeft, bool maxLeft, bool isTop, bool isBottom)
|
||||
{
|
||||
(int mapI, int mapJ) res = (-1, -1);
|
||||
|
||||
for (int i = (int)(rect.Top / _size_y); i <= (int)(rect.Bottom / _size_y) && i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = (int)(rect.Left / _size_x); j <= (int)(rect.Right / _size_x) && j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (j < 0) j = 0;
|
||||
if (i < 0) i = 0;
|
||||
if (_map[i, j] != _barrier) continue;
|
||||
|
||||
if (res.mapI == -1) res = (i, j);
|
||||
if (minLeft && res.mapJ > j) res = (i, j);
|
||||
if (maxLeft && res.mapJ < j) res = (i, j);
|
||||
if(isBottom) res = (i, j);
|
||||
if (isTop) return (i, j);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
// TODO проверка, что объект может переместится в требуемом
|
||||
|
||||
var position = _drawningObject.GetCurrentPosition();
|
||||
|
||||
float drawningWidth = position.Right - position.Left;
|
||||
float drawningHeight = position.Bottom - position.Top;
|
||||
|
||||
bool minLeft = false;
|
||||
bool maxLeft = false;
|
||||
bool isTop = false;
|
||||
bool isBottom = false;
|
||||
|
||||
if (direction == Direction.Left)
|
||||
{
|
||||
position.Left -= _drawningObject.Step;
|
||||
maxLeft = true;
|
||||
}
|
||||
if (direction == Direction.Right)
|
||||
{
|
||||
position.Left += _drawningObject.Step;
|
||||
minLeft = true;
|
||||
}
|
||||
if (direction == Direction.Up) {
|
||||
position.Top -= _drawningObject.Step;
|
||||
isTop = true;
|
||||
}
|
||||
if (direction == Direction.Down)
|
||||
{
|
||||
position.Top += _drawningObject.Step;
|
||||
isBottom = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
position.Right = position.Left + drawningWidth;
|
||||
position.Bottom = position.Top + drawningHeight;
|
||||
|
||||
var currentBarrier = checkBarrier(position, minLeft, maxLeft, isTop, isBottom);
|
||||
|
||||
if (currentBarrier.mapI == -1)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
|
||||
else if (direction == Direction.Left)
|
||||
position.Left = (currentBarrier.mapJ + 1) * _size_x + 1;
|
||||
|
||||
else if (direction == Direction.Right)
|
||||
position.Left = currentBarrier.mapJ * _size_x - drawningWidth - 1;
|
||||
|
||||
else if (direction == Direction.Up)
|
||||
position.Top = (currentBarrier.mapI + 1) * _size_y + 1;
|
||||
|
||||
else if (direction == Direction.Down)
|
||||
position.Top = currentBarrier.mapI * _size_y - drawningHeight - 1;
|
||||
|
||||
if (currentBarrier.mapI != -1)
|
||||
_drawningObject.SetObject((int)position.Left, (int)position.Top, _width, _height);
|
||||
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
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);
|
||||
// TODO првоерка, что объект не "накладывается" на закрытые участки
|
||||
|
||||
var position = _drawningObject.GetCurrentPosition();
|
||||
float drawningWidth = position.Right - position.Left;
|
||||
float drawningHeight = position.Bottom - position.Top;
|
||||
|
||||
var currentBarrier = checkBarrier(position);
|
||||
int minRowIndex = _map.GetLength(0);
|
||||
|
||||
while(currentBarrier.mapI != -1)
|
||||
{
|
||||
minRowIndex = currentBarrier.mapI < minRowIndex ? currentBarrier.mapI : minRowIndex;
|
||||
|
||||
position.Left = (currentBarrier.mapJ + 1) * _size_x + 1;
|
||||
position.Right = position.Left + drawningWidth;
|
||||
|
||||
if(position.Right > _width)
|
||||
{
|
||||
position.Top = (minRowIndex + 1) * _size_y + 1;
|
||||
position.Bottom = position.Top + drawningHeight;
|
||||
|
||||
position.Left = 0;
|
||||
position.Right = drawningWidth;
|
||||
|
||||
minRowIndex = _map.GetLength(0);
|
||||
}
|
||||
|
||||
if (position.Bottom > _height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
currentBarrier = checkBarrier(position);
|
||||
}
|
||||
|
||||
_drawningObject.SetObject((int)position.Left, (int)position.Top, _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);
|
||||
}
|
||||
}
|
@ -6,9 +6,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
public enum Direction
|
||||
internal enum Direction
|
||||
{
|
||||
None,
|
||||
Up,
|
||||
Right,
|
||||
Left,
|
||||
|
@ -6,12 +6,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
public class DrawingAirFighter
|
||||
internal class DrawingAirFighter
|
||||
{
|
||||
public EntityAirFighter AirFighter { get; protected set; }
|
||||
public EntityAirFighter AirFighter { get; private set; }
|
||||
|
||||
protected float _startPosX;
|
||||
protected float _startPosY;
|
||||
private float _startPosX;
|
||||
private float _startPosY;
|
||||
|
||||
private int? _pictureWidth = null;
|
||||
private int? _pictureHeight = null;
|
||||
@ -19,15 +19,10 @@ namespace AirFighter
|
||||
private readonly int _airFighterWidth = 195;
|
||||
private readonly int _airFighterHeight = 166;
|
||||
|
||||
public DrawingAirFighter(int speed, float weight, Color bodyColor)
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
AirFighter = new EntityAirFighter(speed, weight, bodyColor);
|
||||
}
|
||||
public DrawingAirFighter(int speed, float weight, Color bodyColor, int airFighterWidth, int airFighterHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_airFighterWidth = airFighterWidth;
|
||||
_airFighterHeight = airFighterHeight;
|
||||
AirFighter = new EntityAirFighter();
|
||||
AirFighter.Init(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
@ -82,26 +77,20 @@ namespace AirFighter
|
||||
|
||||
}
|
||||
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return ( _startPosX, _startPosX + _airFighterWidth, _startPosY, _startPosY + _airFighterHeight );
|
||||
}
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||||
{
|
||||
MessageBox.Show("test");
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(AirFighter.BodyColor, 2);
|
||||
Pen pen = new(AirFighter.BodyColor);
|
||||
Brush brushBlack = new SolidBrush(AirFighter.BodyColor);
|
||||
|
||||
PointF[] front = {
|
||||
new(_startPosX + 160, _startPosY + 69),
|
||||
new(_startPosX + 160, _startPosY + 70),
|
||||
new(_startPosX + 195, _startPosY + 83),
|
||||
new(_startPosX + 160, _startPosY + 97)
|
||||
new(_startPosX + 160, _startPosY + 96)
|
||||
};
|
||||
|
||||
PointF[] tailTop = {
|
||||
@ -135,12 +124,12 @@ namespace AirFighter
|
||||
new(_startPosX + 75, _startPosY + 96),
|
||||
};
|
||||
|
||||
g.FillPolygon(brushBlack, front);
|
||||
g.DrawPolygon(pen, tailTop);
|
||||
g.DrawPolygon(pen, tailBottom);
|
||||
g.DrawPolygon(pen, wingTop);
|
||||
g.DrawPolygon(pen, wingBottom);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 70, 160, 26);
|
||||
g.FillPolygon(brushBlack, front);
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
|
@ -1,99 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class DrawingModernAirFighter : DrawingAirFighter
|
||||
{
|
||||
public DrawingModernAirFighter(int speed, float weight, Color bodyColor, Color dopColor, bool dopWings, bool rockets) :
|
||||
base(speed, weight, bodyColor, 195, 166)
|
||||
{
|
||||
AirFighter = new EntityModernAirFighter(speed, weight, bodyColor, dopColor, dopWings, rockets);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (AirFighter is not EntityModernAirFighter modernAirFighter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(modernAirFighter.DopColor);
|
||||
Brush dopBrush = new SolidBrush(modernAirFighter.DopColor);
|
||||
|
||||
if (modernAirFighter.DopWings)
|
||||
{
|
||||
|
||||
|
||||
PointF[] topDopWing =
|
||||
{
|
||||
new(_startPosX + 78, _startPosY + 56),
|
||||
new(_startPosX + 75, _startPosY + 70),
|
||||
new(_startPosX + 55, _startPosY + 50),
|
||||
new(_startPosX + 60, _startPosY + 45),
|
||||
};
|
||||
|
||||
PointF[] bottomDopWing =
|
||||
{
|
||||
new(_startPosX + 78, _startPosY + 110),
|
||||
new(_startPosX + 75, _startPosY + 96),
|
||||
new(_startPosX + 55, _startPosY + 116),
|
||||
new(_startPosX + 60, _startPosY + 121),
|
||||
};
|
||||
|
||||
g.FillPolygon(dopBrush, topDopWing);
|
||||
g.FillPolygon(dopBrush, bottomDopWing);
|
||||
}
|
||||
|
||||
if (modernAirFighter.Rockets)
|
||||
{
|
||||
PointF[] topRocket1 =
|
||||
{
|
||||
new(_startPosX + 100, _startPosY + 20),
|
||||
new(_startPosX + 100, _startPosY + 30),
|
||||
new(_startPosX + 112, _startPosY + 30),
|
||||
new(_startPosX + 120, _startPosY + 25),
|
||||
new(_startPosX + 112, _startPosY + 20)
|
||||
};
|
||||
|
||||
PointF[] topRocket2 =
|
||||
{
|
||||
new(_startPosX + 100, _startPosY + 35),
|
||||
new(_startPosX + 100, _startPosY + 45),
|
||||
new(_startPosX + 112, _startPosY + 45),
|
||||
new(_startPosX + 120, _startPosY + 40),
|
||||
new(_startPosX + 112, _startPosY + 35)
|
||||
};
|
||||
|
||||
PointF[] bottomRocket1 =
|
||||
{
|
||||
new(_startPosX + 100, _startPosY + 146),
|
||||
new(_startPosX + 100, _startPosY + 136),
|
||||
new(_startPosX + 112, _startPosY + 136),
|
||||
new(_startPosX + 120, _startPosY + 141),
|
||||
new(_startPosX + 112, _startPosY + 146)
|
||||
};
|
||||
|
||||
PointF[] bottomRocket2 =
|
||||
{
|
||||
new(_startPosX + 100, _startPosY + 131),
|
||||
new(_startPosX + 100, _startPosY + 121),
|
||||
new(_startPosX + 112, _startPosY + 121),
|
||||
new(_startPosX + 120, _startPosY + 126),
|
||||
new(_startPosX + 112, _startPosY + 131)
|
||||
};
|
||||
|
||||
g.FillPolygon(dopBrush, topRocket1);
|
||||
g.FillPolygon(dopBrush, topRocket2);
|
||||
g.FillPolygon(dopBrush, bottomRocket1);
|
||||
g.FillPolygon(dopBrush, bottomRocket2);
|
||||
}
|
||||
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class DrawingObjectAirFighter : IDrawingObject
|
||||
{
|
||||
private DrawingAirFighter _airFighter = null;
|
||||
public DrawingObjectAirFighter(DrawingAirFighter airFighter)
|
||||
{
|
||||
_airFighter = airFighter;
|
||||
}
|
||||
public float Step => _airFighter?.AirFighter?.Step ?? 0;
|
||||
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);
|
||||
}
|
||||
public void DrawningObject(Graphics g)
|
||||
{
|
||||
// TODO
|
||||
_airFighter.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
public class EntityAirFighter
|
||||
internal class EntityAirFighter
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public float Weight { get; private set; }
|
||||
@ -14,7 +14,7 @@ namespace AirFighter
|
||||
|
||||
public float Step => Speed * 100 / Weight;
|
||||
|
||||
public EntityAirFighter(int speed, float weight, Color bodyColor)
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
|
||||
|
@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
// EntityModernAirFighter
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class EntityModernAirFighter : EntityAirFighter
|
||||
{
|
||||
public Color DopColor { get; private set; }
|
||||
public bool DopWings { get; private set; }
|
||||
public bool Rockets { get; private set; }
|
||||
|
||||
|
||||
public EntityModernAirFighter(int speed, float weight, Color bodyColor, Color
|
||||
dopColor, bool dopWings, bool rockets) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
DopWings = dopWings;
|
||||
Rockets = rockets;
|
||||
}
|
||||
}
|
||||
}
|
30
AirFighter/AirFighter/FormAirFighter.Designer.cs
generated
30
AirFighter/AirFighter/FormAirFighter.Designer.cs
generated
@ -38,8 +38,6 @@
|
||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.buttonSelect = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -51,7 +49,7 @@
|
||||
this.CreateButton.Name = "CreateButton";
|
||||
this.CreateButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.CreateButton.TabIndex = 0;
|
||||
this.CreateButton.Text = "создание";
|
||||
this.CreateButton.Text = "создать";
|
||||
this.CreateButton.UseVisualStyleBackColor = true;
|
||||
this.CreateButton.Click += new System.EventHandler(this.CreateButton_Click);
|
||||
//
|
||||
@ -149,35 +147,11 @@
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(43, 20);
|
||||
this.toolStripStatusLabelBodyColor.Text = "цвет:";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.button1.Location = new System.Drawing.Point(121, 389);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(148, 29);
|
||||
this.button1.TabIndex = 7;
|
||||
this.button1.Text = "модификация";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.CreateModernButton_Click);
|
||||
//
|
||||
// buttonSelect
|
||||
//
|
||||
this.buttonSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonSelect.Location = new System.Drawing.Point(558, 389);
|
||||
this.buttonSelect.Name = "buttonSelect";
|
||||
this.buttonSelect.Size = new System.Drawing.Size(115, 29);
|
||||
this.buttonSelect.TabIndex = 8;
|
||||
this.buttonSelect.Text = "выбрать";
|
||||
this.buttonSelect.UseVisualStyleBackColor = true;
|
||||
this.buttonSelect.Click += new System.EventHandler(this.ButtonSelect_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.buttonSelect);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Controls.Add(this.RightButton);
|
||||
this.Controls.Add(this.LeftButton);
|
||||
@ -207,7 +181,5 @@
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private Button button1;
|
||||
private Button buttonSelect;
|
||||
}
|
||||
}
|
@ -4,60 +4,26 @@ namespace AirFighter
|
||||
{
|
||||
private DrawingAirFighter _airFighter;
|
||||
|
||||
public DrawingAirFighter SelectedAirFighter { get; private set; }
|
||||
|
||||
public FormAirFighter()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void SetData(DrawingAirFighter airFighter)
|
||||
{
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: { _airFighter.AirFighter.BodyColor.Name}";
|
||||
}
|
||||
|
||||
private void CreateButton_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;
|
||||
}
|
||||
_airFighter = new DrawingAirFighter(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||
|
||||
_airFighter = new DrawingAirFighter();
|
||||
|
||||
_airFighter.Init(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
|
||||
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height);
|
||||
|
||||
SetData(_airFighter);
|
||||
Draw();
|
||||
}
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: { _airFighter.AirFighter.BodyColor.Name}";
|
||||
|
||||
private void CreateModernButton_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 DrawingModernAirFighter(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
color, dopColor,
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,2)));
|
||||
|
||||
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height);
|
||||
|
||||
SetData(_airFighter);
|
||||
Draw();
|
||||
}
|
||||
|
||||
@ -93,11 +59,6 @@ namespace AirFighter
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonSelect_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedAirFighter = _airFighter;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
|
215
AirFighter/AirFighter/FormMap.Designer.cs
generated
215
AirFighter/AirFighter/FormMap.Designer.cs
generated
@ -1,215 +0,0 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
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.CreateButton = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.DownButton = new System.Windows.Forms.Button();
|
||||
this.UpButton = new System.Windows.Forms.Button();
|
||||
this.LeftButton = new System.Windows.Forms.Button();
|
||||
this.RightButton = new System.Windows.Forms.Button();
|
||||
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.button1 = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// CreateButton
|
||||
//
|
||||
this.CreateButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.CreateButton.Location = new System.Drawing.Point(12, 390);
|
||||
this.CreateButton.Name = "CreateButton";
|
||||
this.CreateButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.CreateButton.TabIndex = 0;
|
||||
this.CreateButton.Text = "создание";
|
||||
this.CreateButton.UseVisualStyleBackColor = true;
|
||||
this.CreateButton.Click += new System.EventHandler(this.CreateButton_Click);
|
||||
//
|
||||
// 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(800, 450);
|
||||
this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
this.pictureBox.Resize += new System.EventHandler(this.PictureBox_Resize);
|
||||
//
|
||||
// DownButton
|
||||
//
|
||||
this.DownButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.DownButton.BackgroundImage = global::AirFighter.Properties.Resources.down;
|
||||
this.DownButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.DownButton.Location = new System.Drawing.Point(727, 389);
|
||||
this.DownButton.Name = "DownButton";
|
||||
this.DownButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.DownButton.Size = new System.Drawing.Size(30, 30);
|
||||
this.DownButton.TabIndex = 2;
|
||||
this.DownButton.UseVisualStyleBackColor = true;
|
||||
this.DownButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// UpButton
|
||||
//
|
||||
this.UpButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.UpButton.BackgroundImage = global::AirFighter.Properties.Resources.up;
|
||||
this.UpButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.UpButton.Location = new System.Drawing.Point(727, 354);
|
||||
this.UpButton.Name = "UpButton";
|
||||
this.UpButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.UpButton.Size = new System.Drawing.Size(30, 30);
|
||||
this.UpButton.TabIndex = 3;
|
||||
this.UpButton.UseVisualStyleBackColor = true;
|
||||
this.UpButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// LeftButton
|
||||
//
|
||||
this.LeftButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.LeftButton.BackgroundImage = global::AirFighter.Properties.Resources.left;
|
||||
this.LeftButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.LeftButton.Location = new System.Drawing.Point(691, 389);
|
||||
this.LeftButton.Name = "LeftButton";
|
||||
this.LeftButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.LeftButton.Size = new System.Drawing.Size(30, 30);
|
||||
this.LeftButton.TabIndex = 4;
|
||||
this.LeftButton.UseVisualStyleBackColor = true;
|
||||
this.LeftButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// RightButton
|
||||
//
|
||||
this.RightButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.RightButton.BackgroundImage = global::AirFighter.Properties.Resources.right;
|
||||
this.RightButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.RightButton.Location = new System.Drawing.Point(763, 389);
|
||||
this.RightButton.Name = "RightButton";
|
||||
this.RightButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.RightButton.Size = new System.Drawing.Size(30, 30);
|
||||
this.RightButton.TabIndex = 5;
|
||||
this.RightButton.UseVisualStyleBackColor = true;
|
||||
this.RightButton.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, 424);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Size = new System.Drawing.Size(800, 26);
|
||||
this.statusStrip1.TabIndex = 6;
|
||||
this.statusStrip1.Text = "statusStrip1";
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(74, 20);
|
||||
this.toolStripStatusLabelSpeed.Text = "скорость:";
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(35, 20);
|
||||
this.toolStripStatusLabelWeight.Text = "вес:";
|
||||
//
|
||||
// toolStripStatusLabelBodyColor
|
||||
//
|
||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(43, 20);
|
||||
this.toolStripStatusLabelBodyColor.Text = "цвет:";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.button1.Location = new System.Drawing.Point(121, 389);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(148, 29);
|
||||
this.button1.TabIndex = 7;
|
||||
this.button1.Text = "модификация";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.CreateModernButton_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(150, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 8;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// FormMap
|
||||
//
|
||||
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.comboBoxSelectorMap);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Controls.Add(this.RightButton);
|
||||
this.Controls.Add(this.LeftButton);
|
||||
this.Controls.Add(this.UpButton);
|
||||
this.Controls.Add(this.DownButton);
|
||||
this.Controls.Add(this.CreateButton);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Name = "FormMap";
|
||||
this.Text = "Form1";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.statusStrip1.ResumeLayout(false);
|
||||
this.statusStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button CreateButton;
|
||||
private PictureBox pictureBox;
|
||||
private Button DownButton;
|
||||
private Button UpButton;
|
||||
private Button LeftButton;
|
||||
private Button RightButton;
|
||||
private StatusStrip statusStrip1;
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private Button button1;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
}
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
public partial class FormMap : Form
|
||||
{
|
||||
private DrawingAirFighter _airFighter;
|
||||
private AbstractMap _abstractMap;
|
||||
|
||||
public FormMap()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
|
||||
|
||||
private void SetData(DrawingAirFighter airFighter)
|
||||
{
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_airFighter.AirFighter.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_airFighter.AirFighter.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет: { _airFighter.AirFighter.BodyColor.Name}";
|
||||
|
||||
pictureBox.Image = _abstractMap.CreateMap(pictureBox.Width, pictureBox.Height, new DrawingObjectAirFighter(_airFighter));
|
||||
}
|
||||
|
||||
private void CreateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
|
||||
_airFighter = new DrawingAirFighter(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
|
||||
SetData(_airFighter);
|
||||
}
|
||||
|
||||
private void CreateModernButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
|
||||
_airFighter = new DrawingModernAirFighter(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)));
|
||||
|
||||
|
||||
SetData(_airFighter);
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "UpButton":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "DownButton":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "LeftButton":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "RightButton":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _abstractMap?.MoveObject(dir);
|
||||
|
||||
}
|
||||
|
||||
private void PictureBox_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_airFighter?.ChangeBorders(pictureBox.Width, pictureBox.Height);
|
||||
}
|
||||
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (pictureBox.Width == 0 || pictureBox.Height == 0) return;
|
||||
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_airFighter?.DrawTransport(gr);
|
||||
pictureBox.Image = bmp;
|
||||
}
|
||||
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
{
|
||||
case "простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "моя карта":
|
||||
_abstractMap = new MyMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
<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>
|
283
AirFighter/AirFighter/FormMapWithSetCars.Designer.cs
generated
283
AirFighter/AirFighter/FormMapWithSetCars.Designer.cs
generated
@ -1,283 +0,0 @@
|
||||
namespace AirFighter
|
||||
{
|
||||
partial class FormMapWithSetCars
|
||||
{
|
||||
/// <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.tools = new System.Windows.Forms.GroupBox();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||
this.RightButton = new System.Windows.Forms.Button();
|
||||
this.LeftButton = new System.Windows.Forms.Button();
|
||||
this.UpButton = new System.Windows.Forms.Button();
|
||||
this.DownButton = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRemove = new System.Windows.Forms.Button();
|
||||
this.ButtonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.ButtonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.tools.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// tools
|
||||
//
|
||||
this.tools.Controls.Add(this.groupBox1);
|
||||
this.tools.Controls.Add(this.RightButton);
|
||||
this.tools.Controls.Add(this.LeftButton);
|
||||
this.tools.Controls.Add(this.UpButton);
|
||||
this.tools.Controls.Add(this.DownButton);
|
||||
this.tools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.tools.Controls.Add(this.buttonRemove);
|
||||
this.tools.Controls.Add(this.ButtonShowOnMap);
|
||||
this.tools.Controls.Add(this.ButtonShowStorage);
|
||||
this.tools.Controls.Add(this.buttonAdd);
|
||||
this.tools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.tools.Location = new System.Drawing.Point(940, 0);
|
||||
this.tools.Name = "tools";
|
||||
this.tools.Size = new System.Drawing.Size(250, 725);
|
||||
this.tools.TabIndex = 0;
|
||||
this.tools.TabStop = false;
|
||||
this.tools.Text = "Инструменты";
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.buttonDeleteMap);
|
||||
this.groupBox1.Controls.Add(this.listBoxMaps);
|
||||
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBox1.Controls.Add(this.buttonAddMap);
|
||||
this.groupBox1.Controls.Add(this.textBoxNewMapName);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 33);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(226, 286);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "карты";
|
||||
//
|
||||
// buttonDeleteMap
|
||||
//
|
||||
this.buttonDeleteMap.Location = new System.Drawing.Point(12, 243);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(196, 29);
|
||||
this.buttonDeleteMap.TabIndex = 13;
|
||||
this.buttonDeleteMap.Text = "Удалить карту";
|
||||
this.buttonDeleteMap.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.ItemHeight = 20;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(12, 133);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(196, 104);
|
||||
this.listBoxMaps.TabIndex = 12;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// 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, 59);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(196, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
//
|
||||
// buttonAddMap
|
||||
//
|
||||
this.buttonAddMap.Location = new System.Drawing.Point(12, 93);
|
||||
this.buttonAddMap.Name = "buttonAddMap";
|
||||
this.buttonAddMap.Size = new System.Drawing.Size(196, 29);
|
||||
this.buttonAddMap.TabIndex = 11;
|
||||
this.buttonAddMap.Text = "Добавить карту";
|
||||
this.buttonAddMap.UseVisualStyleBackColor = true;
|
||||
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(12, 26);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(196, 27);
|
||||
this.textBoxNewMapName.TabIndex = 0;
|
||||
//
|
||||
// RightButton
|
||||
//
|
||||
this.RightButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.RightButton.BackgroundImage = global::AirFighter.Properties.Resources.right;
|
||||
this.RightButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.RightButton.Location = new System.Drawing.Point(148, 683);
|
||||
this.RightButton.Name = "RightButton";
|
||||
this.RightButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.RightButton.Size = new System.Drawing.Size(30, 30);
|
||||
this.RightButton.TabIndex = 9;
|
||||
this.RightButton.UseVisualStyleBackColor = true;
|
||||
this.RightButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// LeftButton
|
||||
//
|
||||
this.LeftButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.LeftButton.BackgroundImage = global::AirFighter.Properties.Resources.left;
|
||||
this.LeftButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.LeftButton.Location = new System.Drawing.Point(76, 683);
|
||||
this.LeftButton.Name = "LeftButton";
|
||||
this.LeftButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.LeftButton.Size = new System.Drawing.Size(30, 30);
|
||||
this.LeftButton.TabIndex = 8;
|
||||
this.LeftButton.UseVisualStyleBackColor = true;
|
||||
this.LeftButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// UpButton
|
||||
//
|
||||
this.UpButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.UpButton.BackgroundImage = global::AirFighter.Properties.Resources.up;
|
||||
this.UpButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.UpButton.Location = new System.Drawing.Point(112, 648);
|
||||
this.UpButton.Name = "UpButton";
|
||||
this.UpButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.UpButton.Size = new System.Drawing.Size(30, 30);
|
||||
this.UpButton.TabIndex = 7;
|
||||
this.UpButton.UseVisualStyleBackColor = true;
|
||||
this.UpButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// DownButton
|
||||
//
|
||||
this.DownButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.DownButton.BackgroundImage = global::AirFighter.Properties.Resources.down;
|
||||
this.DownButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.DownButton.Location = new System.Drawing.Point(112, 683);
|
||||
this.DownButton.Name = "DownButton";
|
||||
this.DownButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.DownButton.Size = new System.Drawing.Size(30, 30);
|
||||
this.DownButton.TabIndex = 6;
|
||||
this.DownButton.UseVisualStyleBackColor = true;
|
||||
this.DownButton.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(24, 392);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(196, 27);
|
||||
this.maskedTextBoxPosition.TabIndex = 5;
|
||||
//
|
||||
// buttonRemove
|
||||
//
|
||||
this.buttonRemove.Location = new System.Drawing.Point(24, 425);
|
||||
this.buttonRemove.Name = "buttonRemove";
|
||||
this.buttonRemove.Size = new System.Drawing.Size(196, 29);
|
||||
this.buttonRemove.TabIndex = 4;
|
||||
this.buttonRemove.Text = "Удалить";
|
||||
this.buttonRemove.UseVisualStyleBackColor = true;
|
||||
this.buttonRemove.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
|
||||
//
|
||||
// ButtonShowOnMap
|
||||
//
|
||||
this.ButtonShowOnMap.Location = new System.Drawing.Point(24, 520);
|
||||
this.ButtonShowOnMap.Name = "ButtonShowOnMap";
|
||||
this.ButtonShowOnMap.Size = new System.Drawing.Size(196, 29);
|
||||
this.ButtonShowOnMap.TabIndex = 3;
|
||||
this.ButtonShowOnMap.Text = "Посмотреть карту";
|
||||
this.ButtonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.ButtonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// ButtonShowStorage
|
||||
//
|
||||
this.ButtonShowStorage.Location = new System.Drawing.Point(24, 472);
|
||||
this.ButtonShowStorage.Name = "ButtonShowStorage";
|
||||
this.ButtonShowStorage.Size = new System.Drawing.Size(196, 29);
|
||||
this.ButtonShowStorage.TabIndex = 2;
|
||||
this.ButtonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.ButtonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.ButtonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(24, 357);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(196, 29);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.ButtonAddCar_Click);
|
||||
//
|
||||
// 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(940, 725);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetCars
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1190, 725);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.tools);
|
||||
this.Name = "FormMapWithSetCars";
|
||||
this.Text = "FormMapWithSetCars";
|
||||
this.tools.ResumeLayout(false);
|
||||
this.tools.PerformLayout();
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox tools;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonRemove;
|
||||
private Button ButtonShowOnMap;
|
||||
private Button ButtonShowStorage;
|
||||
private Button buttonAdd;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private PictureBox pictureBox;
|
||||
private Button RightButton;
|
||||
private Button LeftButton;
|
||||
private Button UpButton;
|
||||
private Button DownButton;
|
||||
private GroupBox groupBox1;
|
||||
private Button buttonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private Button buttonAddMap;
|
||||
private TextBox textBoxNewMapName;
|
||||
}
|
||||
}
|
@ -1,224 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
public partial class FormMapWithSetCars : Form
|
||||
{
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Простая карта", new SimpleMap() },
|
||||
{ "Моя карта", new MyMap() }
|
||||
};
|
||||
/// <summary>
|
||||
/// Объект от коллекции карт
|
||||
/// </summary>
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMapWithSetCars()
|
||||
{
|
||||
InitializeComponent();
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width,
|
||||
pictureBox.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
foreach (var elem in _mapsDict)
|
||||
{
|
||||
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
///
|
||||
|
||||
private void ReloadMaps()
|
||||
{
|
||||
int index = listBoxMaps.SelectedIndex;
|
||||
listBoxMaps.Items.Clear();
|
||||
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||
{
|
||||
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||
}
|
||||
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||
{
|
||||
listBoxMaps.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||
{
|
||||
listBoxMaps.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAddMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||
{
|
||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.Text,
|
||||
_mapsDict[comboBoxSelectorMap.Text]);
|
||||
ReloadMaps();
|
||||
}
|
||||
|
||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void ButtonDeleteMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ??
|
||||
string.Empty);
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ButtonAddCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormAirFighter form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawingObjectAirFighter car = new(form.SelectedAirFighter);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + car != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image =
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image =
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image =_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "UpButton":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "DownButton":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "LeftButton":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "RightButton":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<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>
|
@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal interface IDrawingObject
|
||||
{
|
||||
public float Step { get; }
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
void MoveObject(Direction direction);
|
||||
void DrawningObject(Graphics g);
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
}
|
||||
|
||||
}
|
@ -1,195 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class MapWithSetCarsGeneric<T, U>
|
||||
where T : class, IDrawingObject
|
||||
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 = 170;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetCarsGeneric<T> _setCars;
|
||||
/// <summary>
|
||||
/// Карта
|
||||
/// </summary>
|
||||
private readonly U _map;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="map"></param>
|
||||
public MapWithSetCarsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setCars = new SetCarsGeneric<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 +(MapWithSetCarsGeneric<T, U> map, T car)
|
||||
{
|
||||
return map._setCars.Insert(car);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public static T operator -(MapWithSetCarsGeneric<T, U> map, int
|
||||
position)
|
||||
{
|
||||
return map._setCars.Remove(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawCars(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Просмотр объекта на карте
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
|
||||
foreach(var car in _setCars.GetCars())
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
||||
}
|
||||
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 = _setCars.Count - 1;
|
||||
for (int i = 0; i < _setCars.Count; i++)
|
||||
{
|
||||
if (_setCars[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setCars[j];
|
||||
if (car != null)
|
||||
{
|
||||
_setCars.Insert(car, i);
|
||||
_setCars.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
Brush brownBrush = new SolidBrush(Color.FromArgb(255, 211, 136, 84));
|
||||
Brush greyBrush = new SolidBrush(Color.FromArgb(255, 160, 160, 160));
|
||||
|
||||
Point[] angar =
|
||||
{
|
||||
new(0, _pictureHeight ),
|
||||
new(0, _pictureHeight / 4 ),
|
||||
new(_pictureWidth / 2 , 9),
|
||||
new(_pictureWidth, _pictureHeight / 4 ),
|
||||
new(_pictureWidth, _pictureHeight ),
|
||||
};
|
||||
|
||||
g.FillPolygon(brownBrush, angar);
|
||||
g.FillRectangle(greyBrush, _pictureWidth / 6, (_pictureHeight * 5) / 12, (_pictureWidth * 2) / 3, (_pictureHeight * 7) / 12);
|
||||
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i *
|
||||
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawCars(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int i = 0;
|
||||
|
||||
foreach(var car in _setCars.GetCars())
|
||||
{
|
||||
int x = i % width;
|
||||
int y = i / width;
|
||||
|
||||
car.SetObject((width - x - 1) * _placeSizeWidth, (height - y - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
car.DrawningObject(g);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetCarsGeneric<DrawingObjectAirFighter, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string,
|
||||
MapWithSetCarsGeneric<DrawingObjectAirFighter, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
// TODO Прописать логику для добавления
|
||||
bool check = _mapStorages.TryGetValue(name, out var value);
|
||||
if (check) return;
|
||||
|
||||
_mapStorages[name] = new(_pictureWidth, _pictureHeight, map);
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к парковке
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetCarsGeneric<DrawingObjectAirFighter, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения объекта
|
||||
bool check = _mapStorages.TryGetValue(ind, out var mapWithSet);
|
||||
return mapWithSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class MyMap : 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, j * _size_x, i * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, j * _size_x, i * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < 20; ++i)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
|
||||
GenerateMap(x, y, _random.Next(13, 23));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void GenerateMap(int x, int y, int depth)
|
||||
{
|
||||
if (depth <= 0) return;
|
||||
bool check = false;
|
||||
|
||||
while (!check)
|
||||
{
|
||||
int deltaX = _random.Next(-1, 2);
|
||||
int deltaY = _random.Next(-1, 2);
|
||||
|
||||
if (x + deltaX < 0 || x + deltaX >= 100) continue;
|
||||
if (y + deltaY < 0 || y + deltaY >= 100) continue;
|
||||
|
||||
if (_map[y + deltaY, x + deltaX] == _barrier) depth--;
|
||||
x += deltaX;
|
||||
y += deltaY;
|
||||
|
||||
_map[y, x] = _barrier;
|
||||
|
||||
check = true;
|
||||
}
|
||||
|
||||
GenerateMap(x, y, depth - 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 FormMapWithSetCars());
|
||||
Application.Run(new FormAirFighter());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirFighter
|
||||
{
|
||||
internal class SetCarsGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в списке
|
||||
/// </summary>
|
||||
public int Count => _places.Count;
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetCarsGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
public int Insert(T car)
|
||||
{
|
||||
// TODO вставка в начало набора
|
||||
if (_places.Count == _maxCount) return -1;
|
||||
_places.Insert(0, car);
|
||||
return 0;
|
||||
}
|
||||
public int Insert(T car, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
if (_places.Count == _maxCount) return -1;
|
||||
_places.Insert(position, car);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присовив элементу массива значение null
|
||||
T res = _places[position];
|
||||
_places.Remove(res);
|
||||
return res;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if(position < 0) return null;
|
||||
if(position >= _places.Count) return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0) return;
|
||||
if (position >= _places.Count) return;
|
||||
// TODO вставка в список по позиции
|
||||
Insert(value, position);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetCars()
|
||||
{
|
||||
foreach (var car in _places)
|
||||
{
|
||||
if (car != null)
|
||||
{
|
||||
yield return car;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
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.Black);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, j * _size_x, i * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user