Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
d9ecf70478 | |||
f114eaf924 | |||
7a0e613b8f | |||
046d6fa073 | |||
dbfce5a591 | |||
23a70fbf75 | |||
7a6735b1a2 | |||
e769920644 | |||
e362903c4d | |||
cd1bc62668 | |||
3b037b5de0 | |||
21d89cec7b | |||
49c93d0ada | |||
bc45f4ef20 | |||
cc0c33e907 | |||
7ad72d90a7 | |||
70102bcf7d | |||
f8dfa86e69 | |||
4dab796efa | |||
8efe9be84a | |||
cda44e6ec9 | |||
3cc8122f19 | |||
e71ced4b54 | |||
23dfac6957 | |||
5adf2864ae | |||
fd3b420d31 | |||
517fc78f0c | |||
80197437fa | |||
ea89147e87 | |||
ee062b561c | |||
88725c4703 | |||
6c1da36415 | |||
ee5a000d55 |
206
AirFighter/AbstractMap.cs
Normal file
206
AirFighter/AbstractMap.cs
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal abstract class AbstractMap
|
||||||
|
{
|
||||||
|
private IDrawingObject _drawingObject = 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 drawingObject)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawingObject = drawingObject;
|
||||||
|
GenerateMap();
|
||||||
|
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
int CollisionFlag = 0;
|
||||||
|
|
||||||
|
Size objSize1 = new Size(100,100);
|
||||||
|
|
||||||
|
//COLLISION CHECK
|
||||||
|
if (direction == Direction.Up)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
Point LeftTop = new Point((int)_drawingObject.GetCurrentPosition().Left, (int)(_drawingObject.GetCurrentPosition().Top - _drawingObject.Step));
|
||||||
|
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
|
||||||
|
|
||||||
|
if (objectRect.IntersectsWith(rectBarrier))
|
||||||
|
{
|
||||||
|
CollisionFlag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (direction == Direction.Down)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
Point LeftTop = new Point((int)_drawingObject.GetCurrentPosition().Left, (int)(_drawingObject.GetCurrentPosition().Top + _drawingObject.Step));
|
||||||
|
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
|
||||||
|
|
||||||
|
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y),(int) _size_x,(int) _size_y);
|
||||||
|
|
||||||
|
if (objectRect.IntersectsWith(rectBarrier))
|
||||||
|
{
|
||||||
|
CollisionFlag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (direction == Direction.Left)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
|
||||||
|
Point LeftTop = new Point((int)(_drawingObject.GetCurrentPosition().Left - _drawingObject.Step), (int)_drawingObject.GetCurrentPosition().Top);
|
||||||
|
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
|
||||||
|
|
||||||
|
|
||||||
|
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
|
||||||
|
|
||||||
|
if (objectRect.IntersectsWith(rectBarrier))
|
||||||
|
{
|
||||||
|
CollisionFlag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (direction == Direction.Right)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
Point LeftTop = new Point((int)(_drawingObject.GetCurrentPosition().Left + _drawingObject.Step), (int)_drawingObject.GetCurrentPosition().Top);
|
||||||
|
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
|
||||||
|
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
|
||||||
|
if (objectRect.IntersectsWith(rectBarrier))
|
||||||
|
{
|
||||||
|
CollisionFlag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CollisionFlag != 1)
|
||||||
|
{
|
||||||
|
_drawingObject.MoveObject(direction);
|
||||||
|
_drawingObject.DoSomething();
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool SetObjectOnMap()
|
||||||
|
{
|
||||||
|
if (_drawingObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int x = _random.Next(0, 10);
|
||||||
|
int y = _random.Next(0,10);
|
||||||
|
_drawingObject.SetObject(x, y, _width, _height);
|
||||||
|
|
||||||
|
Rectangle rectObject = new Rectangle(x, y, 100, 100);
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier)
|
||||||
|
{
|
||||||
|
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
|
||||||
|
if (rectObject.IntersectsWith(rectBarrier))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Bitmap DrawMapWithObject()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_width, _height);
|
||||||
|
if (_drawingObject == 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_drawingObject.DrawingObject(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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
26
AirFighter/AirFighterForm.Designer.cs
generated
26
AirFighter/AirFighterForm.Designer.cs
generated
@ -38,6 +38,8 @@
|
|||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCreateModification = new System.Windows.Forms.Button();
|
||||||
|
this.SelectButton = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
|
||||||
this.statusStripAircraft.SuspendLayout();
|
this.statusStripAircraft.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -141,11 +143,33 @@
|
|||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||||
//
|
//
|
||||||
|
// buttonCreateModification
|
||||||
|
//
|
||||||
|
this.buttonCreateModification.Location = new System.Drawing.Point(103, 389);
|
||||||
|
this.buttonCreateModification.Name = "buttonCreateModification";
|
||||||
|
this.buttonCreateModification.Size = new System.Drawing.Size(110, 23);
|
||||||
|
this.buttonCreateModification.TabIndex = 7;
|
||||||
|
this.buttonCreateModification.Text = "Modification";
|
||||||
|
this.buttonCreateModification.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModification.Click += new System.EventHandler(this.buttonCreateModification_Click);
|
||||||
|
//
|
||||||
|
// SelectButton
|
||||||
|
//
|
||||||
|
this.SelectButton.Location = new System.Drawing.Point(551, 390);
|
||||||
|
this.SelectButton.Name = "SelectButton";
|
||||||
|
this.SelectButton.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.SelectButton.TabIndex = 8;
|
||||||
|
this.SelectButton.Text = "Select";
|
||||||
|
this.SelectButton.UseVisualStyleBackColor = true;
|
||||||
|
this.SelectButton.Click += new System.EventHandler(this.SelectButton_Click);
|
||||||
|
//
|
||||||
// AirFighterForm
|
// AirFighterForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.SelectButton);
|
||||||
|
this.Controls.Add(this.buttonCreateModification);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
@ -175,5 +199,7 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
|
private Button buttonCreateModification;
|
||||||
|
private Button SelectButton;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,8 @@ namespace AirFighter
|
|||||||
{
|
{
|
||||||
private DrawingAircraft _aircraft;
|
private DrawingAircraft _aircraft;
|
||||||
|
|
||||||
|
public DrawingAircraft SelectedAircraft { get; private set; }
|
||||||
|
|
||||||
public AirFighterForm()
|
public AirFighterForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -17,18 +19,31 @@ namespace AirFighter
|
|||||||
pictureBoxAirFighter.Image = bmp;
|
pictureBoxAirFighter.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetData()
|
||||||
|
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
_aircraft = new DrawingAircraft();
|
|
||||||
_aircraft.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
_aircraft.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||||
_aircraft.SetPosition(rnd.Next(10,100),rnd.Next(10,100),pictureBoxAirFighter.Width,pictureBoxAirFighter.Height);
|
|
||||||
toolStripStatusSpeed.Text = $"Speed: {_aircraft.Plane.Speed}";
|
toolStripStatusSpeed.Text = $"Speed: {_aircraft.Plane.Speed}";
|
||||||
toolStripStatusWeight.Text = $"Weight: {_aircraft.Plane.Weight}";
|
toolStripStatusWeight.Text = $"Weight: {_aircraft.Plane.Weight}";
|
||||||
toolStripStatusBodyColor.Text = $"BodyColor: {_aircraft.Plane.BodyColor.Name}";
|
toolStripStatusBodyColor.Text = $"BodyColor: {_aircraft.Plane.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonCreate_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;
|
||||||
|
}
|
||||||
|
_aircraft = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
color);
|
||||||
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
@ -65,5 +80,37 @@ namespace AirFighter
|
|||||||
_aircraft?.ChangeBorders(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
_aircraft?.ChangeBorders(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonCreateModification_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;
|
||||||
|
}
|
||||||
|
_aircraft = new DrawingMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
color, dopColor,
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,
|
||||||
|
2)));
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedAircraft = _aircraft;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,8 +6,9 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AirFighter
|
namespace AirFighter
|
||||||
{
|
{
|
||||||
internal enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
|
None = 0,
|
||||||
Up =1,
|
Up =1,
|
||||||
Down = 2,
|
Down = 2,
|
||||||
Left = 3,
|
Left = 3,
|
||||||
|
@ -9,24 +9,30 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AirFighter
|
namespace AirFighter
|
||||||
{
|
{
|
||||||
internal class DrawingAircraft
|
public class DrawingAircraft
|
||||||
{
|
{
|
||||||
public EntityAircraft Plane { get; private set; }
|
public EntityAircraft Plane { get; protected set; }
|
||||||
|
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
|
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
|
|
||||||
private int? _pictureWidth = null;
|
private int? _pictureWidth = null;
|
||||||
private int? _pictureHeight = null;
|
private int? _pictureHeight = null;
|
||||||
|
|
||||||
protected readonly int _aircraftWidth = 100;
|
private readonly int _aircraftWidth = 100;
|
||||||
protected readonly int _aircraftHeight = 100;
|
private readonly int _aircraftHeight = 100;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public DrawingAircraft(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Plane = new EntityAircraft();
|
Plane = new EntityAircraft(speed, weight, bodyColor);
|
||||||
Plane.Init(speed, weight, bodyColor);
|
}
|
||||||
|
|
||||||
|
protected DrawingAircraft(int speed, float weight, Color bodyColor, int aircraftWidth, int aircraftHeight) : this(speed, weight,bodyColor)
|
||||||
|
{
|
||||||
|
|
||||||
|
_aircraftHeight = aircraftHeight;
|
||||||
|
_aircraftWidth = aircraftWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
@ -127,15 +133,13 @@ namespace AirFighter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Aircraft Body
|
//Aircraft Body
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush brWhite = new SolidBrush(Plane.BodyColor);
|
Brush brWhite = new SolidBrush(Plane.BodyColor);
|
||||||
@ -144,7 +148,6 @@ namespace AirFighter
|
|||||||
g.DrawRectangle(pen,_startPosX + 20, _startPosY + 45, 80, 14);
|
g.DrawRectangle(pen,_startPosX + 20, _startPosY + 45, 80, 14);
|
||||||
|
|
||||||
//Wings
|
//Wings
|
||||||
|
|
||||||
GraphicsPath pathWing1 = new GraphicsPath();
|
GraphicsPath pathWing1 = new GraphicsPath();
|
||||||
|
|
||||||
Point point1B = new Point((int)(_startPosX + 50), (int)(_startPosY + 45));
|
Point point1B = new Point((int)(_startPosX + 50), (int)(_startPosY + 45));
|
||||||
@ -157,7 +160,6 @@ namespace AirFighter
|
|||||||
g.DrawPath(pen, pathWing1);
|
g.DrawPath(pen, pathWing1);
|
||||||
g.FillPath(brWhite, pathWing1);
|
g.FillPath(brWhite, pathWing1);
|
||||||
|
|
||||||
|
|
||||||
GraphicsPath pathWing2 = new GraphicsPath();
|
GraphicsPath pathWing2 = new GraphicsPath();
|
||||||
|
|
||||||
Point point1B2 = new Point((int)(_startPosX + 50), (int)(_startPosY + 60));
|
Point point1B2 = new Point((int)(_startPosX + 50), (int)(_startPosY + 60));
|
||||||
@ -235,5 +237,10 @@ namespace AirFighter
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return (_startPosX, _startPosY, _startPosX + _aircraftWidth - 1, _startPosY + _aircraftHeight - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
89
AirFighter/DrawingMilitaryAircraft.cs
Normal file
89
AirFighter/DrawingMilitaryAircraft.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class DrawingMilitaryAircraft : DrawingAircraft
|
||||||
|
{
|
||||||
|
public DrawingMilitaryAircraft(int speed, float weight, Color bodyColor, Color extraColor, bool rockets, bool extraWings) : base(speed,weight,bodyColor, 100, 100)
|
||||||
|
{
|
||||||
|
Plane = new EntityMilitaryAircraft(speed, weight, bodyColor, extraColor, rockets, extraWings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Plane is not EntityMilitaryAircraft militaryAircraft)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush extraBrush = new SolidBrush(militaryAircraft.ExtraColor);
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
if (militaryAircraft.ExtraWings)
|
||||||
|
{
|
||||||
|
GraphicsPath pathExtraWing1 = new GraphicsPath();
|
||||||
|
|
||||||
|
Point point1W1 = new Point((int)(_startPosX + 30), (int)(_startPosY + 45));
|
||||||
|
Point point2W1 = new Point(point1W1.X , point1W1.Y - 40);
|
||||||
|
Point point3W1 = new Point(point2W1.X + 10,point1W1.Y);
|
||||||
|
|
||||||
|
Point[] pointsExtraWing1 = new Point[] { point1W1,point2W1,point3W1};
|
||||||
|
|
||||||
|
pathExtraWing1.AddLines(pointsExtraWing1);
|
||||||
|
g.DrawPath(pen, pathExtraWing1);
|
||||||
|
g.FillPath(extraBrush, pathExtraWing1);
|
||||||
|
|
||||||
|
GraphicsPath pathExtraWing2 = new GraphicsPath();
|
||||||
|
|
||||||
|
Point point1W2 = new Point((int)(_startPosX + 30),(int)(_startPosY + 60));
|
||||||
|
Point point2W2 = new Point(point1W2.X , point1W2.Y + 40);
|
||||||
|
Point point3W3 = new Point(point2W2.X + 10,point1W2.Y);
|
||||||
|
|
||||||
|
Point[] pointsExtraWing2 = new Point[] {point1W2,point2W2,point3W3};
|
||||||
|
pathExtraWing2.AddLines(pointsExtraWing2);
|
||||||
|
g.DrawPath(pen, pathExtraWing2);
|
||||||
|
g.FillPath(extraBrush, pathExtraWing2);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (militaryAircraft.Rockets)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 30,17,4);
|
||||||
|
|
||||||
|
GraphicsPath pathRocketHead1 = new GraphicsPath();
|
||||||
|
|
||||||
|
Point point1R1 = new Point((int)(_startPosX + 50),(int)(_startPosY + 30));
|
||||||
|
Point point2R1 = new Point(point1R1.X - 5,point1R1.Y + 2);
|
||||||
|
Point point3R1 = new Point(point1R1.X , point1R1.Y + 4);
|
||||||
|
|
||||||
|
Point[] pointsExtraRocketHead1 = new Point[] { point1R1, point2R1, point3R1 };
|
||||||
|
pathRocketHead1.AddLines(pointsExtraRocketHead1);
|
||||||
|
g.DrawPath(pen, pathRocketHead1);
|
||||||
|
g.FillPath(extraBrush, pathRocketHead1);
|
||||||
|
|
||||||
|
|
||||||
|
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 70, 17, 4);
|
||||||
|
|
||||||
|
GraphicsPath pathRocketHead2 = new GraphicsPath();
|
||||||
|
|
||||||
|
Point point1R2 = new Point((int)(_startPosX + 50),(int)(_startPosY + 70));
|
||||||
|
Point point2R2 = new Point(point1R2.X - 5,point1R2.Y + 2);
|
||||||
|
Point point3R2 = new Point(point1R2.X, point1R2.Y + 4);
|
||||||
|
|
||||||
|
Point[] pointsExtraRocketHead2 = new Point[] { point1R2, point2R2, point3R2 };
|
||||||
|
pathRocketHead2.AddLines(pointsExtraRocketHead2);
|
||||||
|
g.DrawPath(pen, pathRocketHead2);
|
||||||
|
g.FillPath(extraBrush, pathRocketHead2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
48
AirFighter/DrawingObjectAircraft.cs
Normal file
48
AirFighter/DrawingObjectAircraft.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class DrawingObjectAircraft : IDrawingObject
|
||||||
|
{
|
||||||
|
private DrawingAircraft _aircraft = null;
|
||||||
|
|
||||||
|
public DrawingObjectAircraft(DrawingAircraft aircraft)
|
||||||
|
{
|
||||||
|
_aircraft = aircraft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Step => _aircraft.Plane?.Step ?? 0;
|
||||||
|
|
||||||
|
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return _aircraft?.GetCurrentPosition() ?? default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_aircraft.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetObject(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_aircraft.SetPosition(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDrawingObject.DrawingObject(Graphics g)
|
||||||
|
{
|
||||||
|
_aircraft.DrawTransport(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void DoSomething()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
int x = rnd.Next(0, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AirFighter
|
namespace AirFighter
|
||||||
{
|
{
|
||||||
internal class EntityAircraft
|
public class EntityAircraft
|
||||||
{
|
{
|
||||||
public int Speed
|
public int Speed
|
||||||
{
|
{
|
||||||
@ -29,8 +29,7 @@ namespace AirFighter
|
|||||||
//=> оператор подобный return
|
//=> оператор подобный return
|
||||||
public float Step => Speed * 100 / Weight;
|
public float Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
|
public EntityAircraft(int speed, float weight, Color bodyColor)
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
|
24
AirFighter/EntityMilitaryAircraft.cs
Normal file
24
AirFighter/EntityMilitaryAircraft.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class EntityMilitaryAircraft : EntityAircraft
|
||||||
|
{
|
||||||
|
public Color ExtraColor { get; private set; }
|
||||||
|
|
||||||
|
public bool Rockets { get; private set; }
|
||||||
|
|
||||||
|
public bool ExtraWings { get; private set; }
|
||||||
|
|
||||||
|
public EntityMilitaryAircraft(int speed, float weight, Color bodyColor, Color extraColor, bool rockets, bool extraWings) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
ExtraColor = extraColor;
|
||||||
|
Rockets = rockets;
|
||||||
|
ExtraWings = extraWings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
279
AirFighter/FormMapWithSetAircrafts.Designer.cs
generated
Normal file
279
AirFighter/FormMapWithSetAircrafts.Designer.cs
generated
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
partial class FormMapWithSetAircrafts
|
||||||
|
{
|
||||||
|
/// <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.PanelGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
|
this.MapsGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
|
this.DeleteMapButton = new System.Windows.Forms.Button();
|
||||||
|
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||||
|
this.AddMapButton = new System.Windows.Forms.Button();
|
||||||
|
this.newMapTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxMapSelection = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
|
this.ShowMapButton = new System.Windows.Forms.Button();
|
||||||
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
|
this.ShowHangarButton = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
|
this.DeleteAircraftButton = new System.Windows.Forms.Button();
|
||||||
|
this.maskedTextBoxPostion = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.AddAircraftButton = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.PanelGroupBox.SuspendLayout();
|
||||||
|
this.MapsGroupBox.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// PanelGroupBox
|
||||||
|
//
|
||||||
|
this.PanelGroupBox.Controls.Add(this.MapsGroupBox);
|
||||||
|
this.PanelGroupBox.Controls.Add(this.buttonDown);
|
||||||
|
this.PanelGroupBox.Controls.Add(this.buttonRight);
|
||||||
|
this.PanelGroupBox.Controls.Add(this.ShowMapButton);
|
||||||
|
this.PanelGroupBox.Controls.Add(this.buttonLeft);
|
||||||
|
this.PanelGroupBox.Controls.Add(this.ShowHangarButton);
|
||||||
|
this.PanelGroupBox.Controls.Add(this.buttonUp);
|
||||||
|
this.PanelGroupBox.Controls.Add(this.DeleteAircraftButton);
|
||||||
|
this.PanelGroupBox.Controls.Add(this.maskedTextBoxPostion);
|
||||||
|
this.PanelGroupBox.Controls.Add(this.AddAircraftButton);
|
||||||
|
this.PanelGroupBox.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
|
this.PanelGroupBox.Location = new System.Drawing.Point(672, 0);
|
||||||
|
this.PanelGroupBox.Name = "PanelGroupBox";
|
||||||
|
this.PanelGroupBox.Size = new System.Drawing.Size(218, 623);
|
||||||
|
this.PanelGroupBox.TabIndex = 0;
|
||||||
|
this.PanelGroupBox.TabStop = false;
|
||||||
|
this.PanelGroupBox.Text = "Function panel";
|
||||||
|
//
|
||||||
|
// MapsGroupBox
|
||||||
|
//
|
||||||
|
this.MapsGroupBox.Controls.Add(this.DeleteMapButton);
|
||||||
|
this.MapsGroupBox.Controls.Add(this.listBoxMaps);
|
||||||
|
this.MapsGroupBox.Controls.Add(this.AddMapButton);
|
||||||
|
this.MapsGroupBox.Controls.Add(this.newMapTextBox);
|
||||||
|
this.MapsGroupBox.Controls.Add(this.comboBoxMapSelection);
|
||||||
|
this.MapsGroupBox.Location = new System.Drawing.Point(6, 22);
|
||||||
|
this.MapsGroupBox.Name = "MapsGroupBox";
|
||||||
|
this.MapsGroupBox.Size = new System.Drawing.Size(188, 260);
|
||||||
|
this.MapsGroupBox.TabIndex = 15;
|
||||||
|
this.MapsGroupBox.TabStop = false;
|
||||||
|
this.MapsGroupBox.Text = "Maps";
|
||||||
|
//
|
||||||
|
// DeleteMapButton
|
||||||
|
//
|
||||||
|
this.DeleteMapButton.Location = new System.Drawing.Point(6, 222);
|
||||||
|
this.DeleteMapButton.Name = "DeleteMapButton";
|
||||||
|
this.DeleteMapButton.Size = new System.Drawing.Size(176, 32);
|
||||||
|
this.DeleteMapButton.TabIndex = 13;
|
||||||
|
this.DeleteMapButton.Text = "Delete map";
|
||||||
|
this.DeleteMapButton.UseVisualStyleBackColor = true;
|
||||||
|
this.DeleteMapButton.Click += new System.EventHandler(this.DeleteMapButton_Click);
|
||||||
|
//
|
||||||
|
// listBoxMaps
|
||||||
|
//
|
||||||
|
this.listBoxMaps.FormattingEnabled = true;
|
||||||
|
this.listBoxMaps.ItemHeight = 15;
|
||||||
|
this.listBoxMaps.Location = new System.Drawing.Point(8, 122);
|
||||||
|
this.listBoxMaps.Name = "listBoxMaps";
|
||||||
|
this.listBoxMaps.Size = new System.Drawing.Size(174, 94);
|
||||||
|
this.listBoxMaps.TabIndex = 12;
|
||||||
|
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// AddMapButton
|
||||||
|
//
|
||||||
|
this.AddMapButton.Location = new System.Drawing.Point(6, 81);
|
||||||
|
this.AddMapButton.Name = "AddMapButton";
|
||||||
|
this.AddMapButton.Size = new System.Drawing.Size(176, 35);
|
||||||
|
this.AddMapButton.TabIndex = 11;
|
||||||
|
this.AddMapButton.Text = "Add map";
|
||||||
|
this.AddMapButton.UseVisualStyleBackColor = true;
|
||||||
|
this.AddMapButton.Click += new System.EventHandler(this.AddMapButton_Click);
|
||||||
|
//
|
||||||
|
// newMapTextBox
|
||||||
|
//
|
||||||
|
this.newMapTextBox.Location = new System.Drawing.Point(6, 22);
|
||||||
|
this.newMapTextBox.Name = "newMapTextBox";
|
||||||
|
this.newMapTextBox.Size = new System.Drawing.Size(176, 23);
|
||||||
|
this.newMapTextBox.TabIndex = 10;
|
||||||
|
//
|
||||||
|
// comboBoxMapSelection
|
||||||
|
//
|
||||||
|
this.comboBoxMapSelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxMapSelection.FormattingEnabled = true;
|
||||||
|
this.comboBoxMapSelection.Items.AddRange(new object[] {
|
||||||
|
"1. Simple map",
|
||||||
|
"2. NightSky map"});
|
||||||
|
this.comboBoxMapSelection.Location = new System.Drawing.Point(6, 51);
|
||||||
|
this.comboBoxMapSelection.Name = "comboBoxMapSelection";
|
||||||
|
this.comboBoxMapSelection.Size = new System.Drawing.Size(176, 23);
|
||||||
|
this.comboBoxMapSelection.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.ArrowDown;
|
||||||
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonDown.Location = new System.Drawing.Point(99, 581);
|
||||||
|
this.buttonDown.Name = "buttonDown";
|
||||||
|
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonDown.TabIndex = 11;
|
||||||
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.ArrowRight;
|
||||||
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonRight.Location = new System.Drawing.Point(135, 581);
|
||||||
|
this.buttonRight.Name = "buttonRight";
|
||||||
|
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonRight.TabIndex = 10;
|
||||||
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// ShowMapButton
|
||||||
|
//
|
||||||
|
this.ShowMapButton.Location = new System.Drawing.Point(6, 483);
|
||||||
|
this.ShowMapButton.Name = "ShowMapButton";
|
||||||
|
this.ShowMapButton.Size = new System.Drawing.Size(182, 36);
|
||||||
|
this.ShowMapButton.TabIndex = 14;
|
||||||
|
this.ShowMapButton.Text = "Show map";
|
||||||
|
this.ShowMapButton.UseVisualStyleBackColor = true;
|
||||||
|
this.ShowMapButton.Click += new System.EventHandler(this.ShowMapButton_Click);
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.ArrowLeft;
|
||||||
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonLeft.Location = new System.Drawing.Point(63, 581);
|
||||||
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
|
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonLeft.TabIndex = 9;
|
||||||
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// ShowHangarButton
|
||||||
|
//
|
||||||
|
this.ShowHangarButton.Location = new System.Drawing.Point(6, 447);
|
||||||
|
this.ShowHangarButton.Name = "ShowHangarButton";
|
||||||
|
this.ShowHangarButton.Size = new System.Drawing.Size(182, 30);
|
||||||
|
this.ShowHangarButton.TabIndex = 13;
|
||||||
|
this.ShowHangarButton.Text = "Show hangar";
|
||||||
|
this.ShowHangarButton.UseVisualStyleBackColor = true;
|
||||||
|
this.ShowHangarButton.Click += new System.EventHandler(this.ShowHangarButton_Click);
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.ArrowUp;
|
||||||
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
|
this.buttonUp.Location = new System.Drawing.Point(99, 545);
|
||||||
|
this.buttonUp.Name = "buttonUp";
|
||||||
|
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||||
|
this.buttonUp.TabIndex = 8;
|
||||||
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
|
//
|
||||||
|
// DeleteAircraftButton
|
||||||
|
//
|
||||||
|
this.DeleteAircraftButton.Location = new System.Drawing.Point(6, 405);
|
||||||
|
this.DeleteAircraftButton.Name = "DeleteAircraftButton";
|
||||||
|
this.DeleteAircraftButton.Size = new System.Drawing.Size(182, 36);
|
||||||
|
this.DeleteAircraftButton.TabIndex = 12;
|
||||||
|
this.DeleteAircraftButton.Text = "Delete aircraft";
|
||||||
|
this.DeleteAircraftButton.UseVisualStyleBackColor = true;
|
||||||
|
this.DeleteAircraftButton.Click += new System.EventHandler(this.DeleteAircraftButton_Click);
|
||||||
|
//
|
||||||
|
// maskedTextBoxPostion
|
||||||
|
//
|
||||||
|
this.maskedTextBoxPostion.Location = new System.Drawing.Point(6, 358);
|
||||||
|
this.maskedTextBoxPostion.Mask = "00";
|
||||||
|
this.maskedTextBoxPostion.Name = "maskedTextBoxPostion";
|
||||||
|
this.maskedTextBoxPostion.Size = new System.Drawing.Size(182, 23);
|
||||||
|
this.maskedTextBoxPostion.TabIndex = 11;
|
||||||
|
//
|
||||||
|
// AddAircraftButton
|
||||||
|
//
|
||||||
|
this.AddAircraftButton.Location = new System.Drawing.Point(6, 317);
|
||||||
|
this.AddAircraftButton.Name = "AddAircraftButton";
|
||||||
|
this.AddAircraftButton.Size = new System.Drawing.Size(182, 35);
|
||||||
|
this.AddAircraftButton.TabIndex = 10;
|
||||||
|
this.AddAircraftButton.Text = "Add aircraft";
|
||||||
|
this.AddAircraftButton.UseVisualStyleBackColor = true;
|
||||||
|
this.AddAircraftButton.Click += new System.EventHandler(this.AddAircraftButton_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(672, 623);
|
||||||
|
this.pictureBox.TabIndex = 1;
|
||||||
|
this.pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormMapWithSetAircrafts
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(890, 623);
|
||||||
|
this.Controls.Add(this.pictureBox);
|
||||||
|
this.Controls.Add(this.PanelGroupBox);
|
||||||
|
this.Name = "FormMapWithSetAircrafts";
|
||||||
|
this.Text = "MapWithSelectedAircrafts";
|
||||||
|
this.PanelGroupBox.ResumeLayout(false);
|
||||||
|
this.PanelGroupBox.PerformLayout();
|
||||||
|
this.MapsGroupBox.ResumeLayout(false);
|
||||||
|
this.MapsGroupBox.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox PanelGroupBox;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private ComboBox comboBoxMapSelection;
|
||||||
|
private Button ShowMapButton;
|
||||||
|
private Button ShowHangarButton;
|
||||||
|
private Button DeleteAircraftButton;
|
||||||
|
private MaskedTextBox maskedTextBoxPostion;
|
||||||
|
private Button AddAircraftButton;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonUp;
|
||||||
|
private GroupBox MapsGroupBox;
|
||||||
|
private Button DeleteMapButton;
|
||||||
|
private ListBox listBoxMaps;
|
||||||
|
private Button AddMapButton;
|
||||||
|
private TextBox newMapTextBox;
|
||||||
|
}
|
||||||
|
}
|
193
AirFighter/FormMapWithSetAircrafts.cs
Normal file
193
AirFighter/FormMapWithSetAircrafts.cs
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
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 FormMapWithSetAircrafts : Form
|
||||||
|
{
|
||||||
|
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||||
|
{
|
||||||
|
{ "Simple map", new SimpleMap() },
|
||||||
|
|
||||||
|
{"Nightsky map", new NightSkyMap()}
|
||||||
|
};
|
||||||
|
|
||||||
|
private readonly MapsCollection _mapsCollection;
|
||||||
|
|
||||||
|
public FormMapWithSetAircrafts()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||||
|
comboBoxMapSelection.Items.Clear();
|
||||||
|
foreach (var elem in _mapsDict)
|
||||||
|
{
|
||||||
|
comboBoxMapSelection.Items.Add(elem.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshMaps()
|
||||||
|
{
|
||||||
|
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 ShowMapButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddAircraftButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AirFighterForm form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
DrawingObjectAircraft aircraft = new(form.SelectedAircraft);
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + aircraft != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Object is added");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Unable to add object");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteAircraftButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBoxPostion.Text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Delete object?", "Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxPostion.Text);
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Object is deleted");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Unable to delete object");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowHangarButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 "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 = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddMapButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxMapSelection.SelectedIndex == -1 || string.IsNullOrEmpty(newMapTextBox.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Not all data is filled", " Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_mapsDict.ContainsKey(comboBoxMapSelection.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("There is no such map","Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection.AddMap(newMapTextBox.Text, _mapsDict[comboBoxMapSelection.Text]);
|
||||||
|
RefreshMaps();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteMapButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?", "Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_mapsCollection.DeleteMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
|
RefreshMaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
AirFighter/FormMapWithSetAircrafts.resx
Normal file
60
AirFighter/FormMapWithSetAircrafts.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>
|
23
AirFighter/IDrawingObject.cs
Normal file
23
AirFighter/IDrawingObject.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
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 DrawingObject(Graphics g);
|
||||||
|
|
||||||
|
void DoSomething();
|
||||||
|
|
||||||
|
(float Left, float Top, float Right, float Bottom) GetCurrentPosition();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
145
AirFighter/MapWithSetAircraftsGeneric.cs
Normal file
145
AirFighter/MapWithSetAircraftsGeneric.cs
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class MapWithSetAircraftsGeneric<T, U>
|
||||||
|
where T : class, IDrawingObject
|
||||||
|
where U : AbstractMap
|
||||||
|
{
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
private readonly int _placeSizeWidth = 145;
|
||||||
|
|
||||||
|
private readonly int _placeSizeHeight = 145;
|
||||||
|
|
||||||
|
private readonly SetAircraftsGeneric<T> _setAircrafts;
|
||||||
|
|
||||||
|
private readonly U _map;
|
||||||
|
|
||||||
|
public MapWithSetAircraftsGeneric(int picWidth, int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setAircrafts = new SetAircraftsGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int operator +(MapWithSetAircraftsGeneric<T, U> map, T aircraft)
|
||||||
|
{
|
||||||
|
return map._setAircrafts.Insert(aircraft);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T operator -(MapWithSetAircraftsGeneric<T, U> map, int position)
|
||||||
|
{
|
||||||
|
return map._setAircrafts.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Bitmap ShowSet()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawAircrafts(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
|
||||||
|
foreach (var aircraft in _setAircrafts.GetAircrafts())
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, aircraft);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
return _map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setAircrafts.Count - 1;
|
||||||
|
for (int i = 0; i < _setAircrafts.Count; i++)
|
||||||
|
{
|
||||||
|
if (_setAircrafts[i] == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var aircraft = _setAircrafts[j];
|
||||||
|
if (aircraft != null)
|
||||||
|
{
|
||||||
|
_setAircrafts.Insert(aircraft, i);
|
||||||
|
_setAircrafts.Remove(j);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 2);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth + 1; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 135, _placeSizeWidth - 80, j * _placeSizeHeight + 135);
|
||||||
|
if(i * _placeSizeWidth + _placeSizeWidth + 20 < _pictureWidth - 10)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 60, i * _placeSizeWidth + _placeSizeWidth / 2 + 20, j * _placeSizeHeight + 45);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth / 2 + 20, j * _placeSizeHeight + 45, i * _placeSizeWidth + _placeSizeWidth + 20 , j * _placeSizeHeight + 60);
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 135, i * _placeSizeWidth + 20, j * _placeSizeHeight + 60);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawAircrafts(Graphics g)
|
||||||
|
{
|
||||||
|
int curX = _pictureWidth / _placeSizeWidth - 1;
|
||||||
|
int curY = _pictureHeight / _placeSizeHeight - 1;
|
||||||
|
|
||||||
|
foreach (var aircraft in _setAircrafts.GetAircrafts())
|
||||||
|
{
|
||||||
|
aircraft.SetObject(curX * _placeSizeWidth + 30, curY * _placeSizeHeight + 40, _pictureWidth, _pictureHeight);
|
||||||
|
aircraft.DrawingObject(g);
|
||||||
|
|
||||||
|
if (curX <= 0)
|
||||||
|
{
|
||||||
|
curX = _pictureWidth / _placeSizeWidth - 1;
|
||||||
|
curY--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curX--;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
AirFighter/MapsCollection.cs
Normal file
56
AirFighter/MapsCollection.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class MapsCollection
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>> _mapsVault;
|
||||||
|
|
||||||
|
public List<string> Keys => _mapsVault.Keys.ToList();
|
||||||
|
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
private bool flag = false;
|
||||||
|
|
||||||
|
|
||||||
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
_mapsVault = new Dictionary<string, MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddMap(string name, AbstractMap map)
|
||||||
|
{
|
||||||
|
if (!Keys.Contains(name))
|
||||||
|
{
|
||||||
|
_mapsVault.Add(name, new MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteMap(string name)
|
||||||
|
{
|
||||||
|
if (Keys.Contains(name))
|
||||||
|
{
|
||||||
|
_mapsVault.Remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap> this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _mapsVault.ContainsKey(ind) ? _mapsVault[ind] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
AirFighter/NightSkyMap.cs
Normal file
60
AirFighter/NightSkyMap.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class NightSkyMap : AbstractMap
|
||||||
|
{
|
||||||
|
Brush ThundercloudColor = new SolidBrush(Color.FromArgb(0, 0, 139));
|
||||||
|
|
||||||
|
Brush NightSkyColor = new SolidBrush(Color.Black);
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(ThundercloudColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(NightSkyColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (counter < 20)
|
||||||
|
{
|
||||||
|
int x = _random.Next(10,90);
|
||||||
|
int y = _random.Next(10,90);
|
||||||
|
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
_map[x-1,y] = _barrier;
|
||||||
|
_map[x + 1, y] = _barrier;
|
||||||
|
_map[x,y - 1] = _barrier;
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,7 +11,7 @@ namespace AirFighter
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new AirFighterForm());
|
Application.Run(new FormMapWithSetAircrafts());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
102
AirFighter/SetAircraftsGeneric.cs
Normal file
102
AirFighter/SetAircraftsGeneric.cs
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class SetAircraftsGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
private readonly List<T> _places;
|
||||||
|
|
||||||
|
public int Count => _places.Count;
|
||||||
|
|
||||||
|
private readonly int _maxCount;
|
||||||
|
|
||||||
|
public SetAircraftsGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new List<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T aircraft)
|
||||||
|
{
|
||||||
|
return Insert(aircraft, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T aircraft, int position)
|
||||||
|
{
|
||||||
|
if (position > Count || position < 0 || Count == _maxCount)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
_places.Insert(position, aircraft);
|
||||||
|
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < Count && position >= 0)
|
||||||
|
{
|
||||||
|
if (_places.ElementAt(position) != null)
|
||||||
|
{
|
||||||
|
T result = _places.ElementAt(position);
|
||||||
|
|
||||||
|
_places.RemoveAt(position);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public T this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position < _maxCount && position >= 0)
|
||||||
|
{
|
||||||
|
return _places.ElementAt(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < _maxCount && position >= 0)
|
||||||
|
{
|
||||||
|
Insert(value,position);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T> GetAircrafts()
|
||||||
|
{
|
||||||
|
foreach (var aircraft in _places)
|
||||||
|
{
|
||||||
|
if (aircraft != null)
|
||||||
|
{
|
||||||
|
yield return aircraft;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
50
AirFighter/SimpleMap.cs
Normal file
50
AirFighter/SimpleMap.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirFighter
|
||||||
|
{
|
||||||
|
internal class SimpleMap : AbstractMap
|
||||||
|
{
|
||||||
|
Brush barrierColor = new SolidBrush(Color.Black);
|
||||||
|
|
||||||
|
Brush roadColor = new SolidBrush(Color.Gray);
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void GenerateMap()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
_map = new int[100, 100];
|
||||||
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_random.Next(0, 90) == 5)
|
||||||
|
{
|
||||||
|
_map[i, j] = _barrier;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_map[i, j] = _freeRoad;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user