diff --git a/AirFighter/AbstractMap.cs b/AirFighter/AbstractMap.cs
new file mode 100644
index 0000000..73fab23
--- /dev/null
+++ b/AirFighter/AbstractMap.cs
@@ -0,0 +1,221 @@
+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);
+
+
+ }
+}
diff --git a/AirFighter/AirFighterForm.Designer.cs b/AirFighter/AirFighterForm.Designer.cs
index 0c48d17..693134d 100644
--- a/AirFighter/AirFighterForm.Designer.cs
+++ b/AirFighter/AirFighterForm.Designer.cs
@@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
+ this.buttonCreateModification = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
this.statusStripAircraft.SuspendLayout();
this.SuspendLayout();
@@ -141,11 +142,22 @@
this.buttonDown.UseVisualStyleBackColor = true;
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);
+ //
// AirFighterForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.buttonCreateModification);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
@@ -175,5 +187,6 @@
private Button buttonLeft;
private Button buttonRight;
private Button buttonDown;
+ private Button buttonCreateModification;
}
}
\ No newline at end of file
diff --git a/AirFighter/AirFighterForm.cs b/AirFighter/AirFighterForm.cs
index 960f866..d08ae99 100644
--- a/AirFighter/AirFighterForm.cs
+++ b/AirFighter/AirFighterForm.cs
@@ -17,17 +17,24 @@ namespace AirFighter
pictureBoxAirFighter.Image = bmp;
}
-
+
+ private void SetData()
+ {
+ Random rnd = new Random();
+
+ _aircraft.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
+ toolStripStatusSpeed.Text = $"Speed: {_aircraft.Plane.Speed}";
+ toolStripStatusWeight.Text = $"Weight: {_aircraft.Plane.Weight}";
+ toolStripStatusBodyColor.Text = $"BodyColor: {_aircraft.Plane.BodyColor.Name}";
+ }
+
+
private void buttonCreate_Click(object sender, EventArgs e)
{
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);
- toolStripStatusSpeed.Text = $"Speed: {_aircraft.Plane.Speed}";
- toolStripStatusWeight.Text = $"Weight: {_aircraft.Plane.Weight}";
- toolStripStatusBodyColor.Text = $"BodyColor: {_aircraft.Plane.BodyColor.Name}";
+ _aircraft = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData();
Draw();
}
@@ -65,5 +72,17 @@ namespace AirFighter
_aircraft?.ChangeBorders(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
Draw();
}
+
+ private void buttonCreateModification_Click(object sender, EventArgs e)
+ {
+ Random rnd = new Random();
+ _aircraft = new DrawingMilitaryAircraft(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();
+ Draw();
+ }
}
}
\ No newline at end of file
diff --git a/AirFighter/Direction.cs b/AirFighter/Direction.cs
index 59ed9e2..fc2586d 100644
--- a/AirFighter/Direction.cs
+++ b/AirFighter/Direction.cs
@@ -8,6 +8,7 @@ namespace AirFighter
{
internal enum Direction
{
+ None = 0,
Up =1,
Down = 2,
Left = 3,
diff --git a/AirFighter/DrawingAircraft.cs b/AirFighter/DrawingAircraft.cs
index 97b7e5d..a54c275 100644
--- a/AirFighter/DrawingAircraft.cs
+++ b/AirFighter/DrawingAircraft.cs
@@ -11,22 +11,28 @@ namespace AirFighter
{
internal 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? _pictureHeight = null;
- protected readonly int _aircraftWidth = 100;
- protected readonly int _aircraftHeight = 100;
+ private readonly int _aircraftWidth = 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.Init(speed, weight, bodyColor);
+ Plane = new EntityAircraft(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)
@@ -127,7 +133,7 @@ namespace AirFighter
}
}
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
@@ -235,5 +241,10 @@ namespace AirFighter
}
}
+
+ public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
+ {
+ return (_startPosX, _startPosY, _startPosX + _aircraftWidth - 1, _startPosY + _aircraftHeight - 1);
+ }
}
}
diff --git a/AirFighter/DrawingMilitaryAircraft.cs b/AirFighter/DrawingMilitaryAircraft.cs
new file mode 100644
index 0000000..0528f9b
--- /dev/null
+++ b/AirFighter/DrawingMilitaryAircraft.cs
@@ -0,0 +1,98 @@
+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);
+
+
+
+
+ }
+ }
+
+ }
+}
diff --git a/AirFighter/DrawingObjectAircraft.cs b/AirFighter/DrawingObjectAircraft.cs
new file mode 100644
index 0000000..618b1e0
--- /dev/null
+++ b/AirFighter/DrawingObjectAircraft.cs
@@ -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);
+ }
+ }
+
+}
diff --git a/AirFighter/EntityAircraft.cs b/AirFighter/EntityAircraft.cs
index f37a30e..8da76b3 100644
--- a/AirFighter/EntityAircraft.cs
+++ b/AirFighter/EntityAircraft.cs
@@ -30,7 +30,7 @@ namespace AirFighter
public float Step => Speed * 100 / Weight;
- public void Init(int speed, float weight, Color bodyColor)
+ public EntityAircraft(int speed, float weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
diff --git a/AirFighter/EntityMilitaryAircraft.cs b/AirFighter/EntityMilitaryAircraft.cs
new file mode 100644
index 0000000..5e7ad6b
--- /dev/null
+++ b/AirFighter/EntityMilitaryAircraft.cs
@@ -0,0 +1,26 @@
+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;
+ }
+ }
+}
diff --git a/AirFighter/FormMap.Designer.cs b/AirFighter/FormMap.Designer.cs
new file mode 100644
index 0000000..ac71830
--- /dev/null
+++ b/AirFighter/FormMap.Designer.cs
@@ -0,0 +1,207 @@
+namespace AirFighter
+{
+ partial class FormMap
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.pictureBoxAirFighter = new System.Windows.Forms.PictureBox();
+ this.statusStripAircraft = new System.Windows.Forms.StatusStrip();
+ this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
+ this.buttonCreate = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.buttonCreateModification = new System.Windows.Forms.Button();
+ this.comboBoxMapSelection = new System.Windows.Forms.ComboBox();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
+ this.statusStripAircraft.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // pictureBoxAirFighter
+ //
+ this.pictureBoxAirFighter.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxAirFighter.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxAirFighter.Name = "pictureBoxAirFighter";
+ this.pictureBoxAirFighter.Size = new System.Drawing.Size(800, 428);
+ this.pictureBoxAirFighter.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBoxAirFighter.TabIndex = 0;
+ this.pictureBoxAirFighter.TabStop = false;
+ //
+ // statusStripAircraft
+ //
+ this.statusStripAircraft.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusSpeed,
+ this.toolStripStatusWeight,
+ this.toolStripStatusBodyColor});
+ this.statusStripAircraft.Location = new System.Drawing.Point(0, 428);
+ this.statusStripAircraft.Name = "statusStripAircraft";
+ this.statusStripAircraft.Size = new System.Drawing.Size(800, 22);
+ this.statusStripAircraft.TabIndex = 1;
+ //
+ // toolStripStatusSpeed
+ //
+ this.toolStripStatusSpeed.Name = "toolStripStatusSpeed";
+ this.toolStripStatusSpeed.Size = new System.Drawing.Size(42, 17);
+ this.toolStripStatusSpeed.Text = "Speed:";
+ //
+ // toolStripStatusWeight
+ //
+ this.toolStripStatusWeight.Name = "toolStripStatusWeight";
+ this.toolStripStatusWeight.Size = new System.Drawing.Size(48, 17);
+ this.toolStripStatusWeight.Text = "Weight:";
+ //
+ // toolStripStatusBodyColor
+ //
+ this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor";
+ this.toolStripStatusBodyColor.Size = new System.Drawing.Size(66, 17);
+ this.toolStripStatusBodyColor.Text = "BodyColor:";
+ //
+ // buttonCreate
+ //
+ this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreate.Location = new System.Drawing.Point(12, 389);
+ this.buttonCreate.Name = "buttonCreate";
+ this.buttonCreate.Size = new System.Drawing.Size(75, 23);
+ this.buttonCreate.TabIndex = 2;
+ this.buttonCreate.Text = "Create";
+ this.buttonCreate.UseVisualStyleBackColor = true;
+ this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
+ //
+ // buttonUp
+ //
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.ArrowUp;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(702, 346);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 3;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
+ //
+ // buttonLeft
+ //
+ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.ArrowLeft;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(666, 382);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.TabIndex = 4;
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
+ //
+ // buttonRight
+ //
+ this.buttonRight.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(738, 382);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 5;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
+ //
+ // 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(702, 382);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 6;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ 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);
+ //
+ // 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(12, 12);
+ this.comboBoxMapSelection.Name = "comboBoxMapSelection";
+ this.comboBoxMapSelection.Size = new System.Drawing.Size(121, 23);
+ this.comboBoxMapSelection.TabIndex = 8;
+ this.comboBoxMapSelection.SelectedIndexChanged += new System.EventHandler(this.comboBoxMapSelection_SelectedIndexChanged);
+ //
+ // FormMap
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.comboBoxMapSelection);
+ this.Controls.Add(this.buttonCreateModification);
+ this.Controls.Add(this.buttonDown);
+ this.Controls.Add(this.buttonRight);
+ this.Controls.Add(this.buttonLeft);
+ this.Controls.Add(this.buttonUp);
+ this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.pictureBoxAirFighter);
+ this.Controls.Add(this.statusStripAircraft);
+ this.Name = "FormMap";
+ this.Text = "Map";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).EndInit();
+ this.statusStripAircraft.ResumeLayout(false);
+ this.statusStripAircraft.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxAirFighter;
+ private StatusStrip statusStripAircraft;
+ private ToolStripStatusLabel toolStripStatusSpeed;
+ private ToolStripStatusLabel toolStripStatusWeight;
+ private ToolStripStatusLabel toolStripStatusBodyColor;
+ private Button buttonCreate;
+ private Button buttonUp;
+ private Button buttonLeft;
+ private Button buttonRight;
+ private Button buttonDown;
+ private Button buttonCreateModification;
+ private ComboBox comboBoxMapSelection;
+ }
+}
\ No newline at end of file
diff --git a/AirFighter/FormMap.cs b/AirFighter/FormMap.cs
new file mode 100644
index 0000000..301897d
--- /dev/null
+++ b/AirFighter/FormMap.cs
@@ -0,0 +1,102 @@
+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 AbstractMap _abstractMap;
+ public FormMap()
+ {
+ InitializeComponent();
+ _abstractMap = new SimpleMap();
+ }
+
+ private void SetData(DrawingAircraft plane)
+ {
+ toolStripStatusSpeed.Text = $"Speed: {plane.Plane.Speed}";
+ toolStripStatusWeight.Text = $"Weight: {plane.Plane.Weight}";
+ toolStripStatusBodyColor.Text = $"BodyColor: {plane.Plane.BodyColor.Name}";
+ pictureBoxAirFighter.Image = _abstractMap.CreateMap(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height, new DrawingObjectAircraft(plane) );
+ }
+
+
+ private void buttonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new Random();
+ var plane = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData(plane);
+
+ }
+
+ private void buttonMove_Click(object sender, EventArgs e)
+ {
+ string name = ((Button)sender)?.Name ?? string.Empty;
+
+ Direction dir = Direction.None;
+ switch (name)
+ {
+ case "buttonUp":
+ {
+ dir = Direction.Up;
+ }
+ break;
+ case "buttonDown":
+ {
+ dir = Direction.Down;
+ }
+ break;
+ case "buttonLeft":
+ {
+ dir = Direction.Left;
+ }
+ break;
+ case "buttonRight":
+ {
+ dir = Direction.Right;
+ }
+ break;
+ }
+ pictureBoxAirFighter.Image = _abstractMap?.MoveObject(dir);
+
+ }
+
+
+
+ private void buttonCreateModification_Click(object sender, EventArgs e)
+ {
+ Random rnd = new Random();
+ var plane = new DrawingMilitaryAircraft(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(plane);
+
+ }
+
+ private void comboBoxMapSelection_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxMapSelection.Text)
+ {
+ case "1. Simple map":
+ {
+ _abstractMap = new SimpleMap();
+ }
+ break;
+ case "2. NightSky map":
+ {
+ _abstractMap = new NightSkyMap();
+ }
+ break;
+ }
+ }
+ }
+}
diff --git a/AirFighter/FormMap.resx b/AirFighter/FormMap.resx
new file mode 100644
index 0000000..12a7f01
--- /dev/null
+++ b/AirFighter/FormMap.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/AirFighter/IDrawingObject.cs b/AirFighter/IDrawingObject.cs
new file mode 100644
index 0000000..63d7e8f
--- /dev/null
+++ b/AirFighter/IDrawingObject.cs
@@ -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();
+
+ }
+}
diff --git a/AirFighter/NightSkyMap.cs b/AirFighter/NightSkyMap.cs
new file mode 100644
index 0000000..afa6610
--- /dev/null
+++ b/AirFighter/NightSkyMap.cs
@@ -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++;
+ }
+ }
+ }
+
+}
diff --git a/AirFighter/Program.cs b/AirFighter/Program.cs
index 2eb2d18..b613151 100644
--- a/AirFighter/Program.cs
+++ b/AirFighter/Program.cs
@@ -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 AirFighterForm());
+ Application.Run(new FormMap());
}
}
}
\ No newline at end of file
diff --git a/AirFighter/SimpleMap.cs b/AirFighter/SimpleMap.cs
new file mode 100644
index 0000000..f920cff
--- /dev/null
+++ b/AirFighter/SimpleMap.cs
@@ -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;
+ }
+
+ }
+ }
+ }
+ }
+}