From ee5a000d55e7f9cb4d73d032e1f1f59f97c4ed8f Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Mon, 26 Sep 2022 18:37:10 +0400 Subject: [PATCH 01/11] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BE=D0=B2=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/AirFighterForm.cs | 3 +-- AirFighter/DrawingAircraft.cs | 5 ++--- AirFighter/EntityAircraft.cs | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/AirFighter/AirFighterForm.cs b/AirFighter/AirFighterForm.cs index 960f866..efac4b9 100644 --- a/AirFighter/AirFighterForm.cs +++ b/AirFighter/AirFighterForm.cs @@ -22,8 +22,7 @@ namespace AirFighter 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 = new DrawingAircraft(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}"; diff --git a/AirFighter/DrawingAircraft.cs b/AirFighter/DrawingAircraft.cs index 97b7e5d..2672989 100644 --- a/AirFighter/DrawingAircraft.cs +++ b/AirFighter/DrawingAircraft.cs @@ -23,10 +23,9 @@ namespace AirFighter protected readonly int _aircraftWidth = 100; protected 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); } public void SetPosition(int x, int y, int width, int height) 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; -- 2.25.1 From 6c1da36415e84507470237b81eb85de0a118d334 Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Mon, 26 Sep 2022 21:06:20 +0400 Subject: [PATCH 02/11] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD=D1=83?= =?UTF-8?q?=D1=82=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?=20=D0=B8=20=D0=B5=D0=B3=D0=BE=20=D0=BE=D1=82=D1=80=D0=B8=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/AirFighterForm.Designer.cs | 13 ++++ AirFighter/AirFighterForm.cs | 30 +++++++-- AirFighter/DrawingAircraft.cs | 19 ++++-- AirFighter/DrawingMilitaryAircraft.cs | 96 +++++++++++++++++++++++++++ AirFighter/EntityMilitaryAircraft.cs | 26 ++++++++ 5 files changed, 173 insertions(+), 11 deletions(-) create mode 100644 AirFighter/DrawingMilitaryAircraft.cs create mode 100644 AirFighter/EntityMilitaryAircraft.cs 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 efac4b9..d08ae99 100644 --- a/AirFighter/AirFighterForm.cs +++ b/AirFighter/AirFighterForm.cs @@ -17,16 +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(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}"; + SetData(); Draw(); } @@ -64,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/DrawingAircraft.cs b/AirFighter/DrawingAircraft.cs index 2672989..8647957 100644 --- a/AirFighter/DrawingAircraft.cs +++ b/AirFighter/DrawingAircraft.cs @@ -11,23 +11,30 @@ 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 DrawingAircraft(int speed, float weight, Color 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) { @@ -126,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) { diff --git a/AirFighter/DrawingMilitaryAircraft.cs b/AirFighter/DrawingMilitaryAircraft.cs new file mode 100644 index 0000000..92bd59d --- /dev/null +++ b/AirFighter/DrawingMilitaryAircraft.cs @@ -0,0 +1,96 @@ +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/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; + } + } +} -- 2.25.1 From 88725c47034985075d4464f88940b1c9f77b67da Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Mon, 26 Sep 2022 21:28:41 +0400 Subject: [PATCH 03/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/DrawingAircraft.cs | 5 ++++ AirFighter/DrawingObjectAircraft.cs | 42 +++++++++++++++++++++++++++++ AirFighter/IDrawingObject.cs | 21 +++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 AirFighter/DrawingObjectAircraft.cs create mode 100644 AirFighter/IDrawingObject.cs diff --git a/AirFighter/DrawingAircraft.cs b/AirFighter/DrawingAircraft.cs index 8647957..a73856d 100644 --- a/AirFighter/DrawingAircraft.cs +++ b/AirFighter/DrawingAircraft.cs @@ -241,5 +241,10 @@ namespace AirFighter } } + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _aircraftWidth, _startPosY + _aircraftHeight); + } } } diff --git a/AirFighter/DrawingObjectAircraft.cs b/AirFighter/DrawingObjectAircraft.cs new file mode 100644 index 0000000..9f745a5 --- /dev/null +++ b/AirFighter/DrawingObjectAircraft.cs @@ -0,0 +1,42 @@ +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 Right, float Top, 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); + } + + } + +} diff --git a/AirFighter/IDrawingObject.cs b/AirFighter/IDrawingObject.cs new file mode 100644 index 0000000..c6a9e72 --- /dev/null +++ b/AirFighter/IDrawingObject.cs @@ -0,0 +1,21 @@ +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); + + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + + } +} -- 2.25.1 From ee062b561cd9a0d7c050626f32df1185d16886bd Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Mon, 26 Sep 2022 23:17:44 +0400 Subject: [PATCH 04/11] =?UTF-8?q?=D0=90=D0=B1=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BA=D1=82=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/AbstractMap.cs | 93 +++++++++++++++ AirFighter/Direction.cs | 1 + AirFighter/FormMap.Designer.cs | 206 +++++++++++++++++++++++++++++++++ AirFighter/FormMap.cs | 96 +++++++++++++++ AirFighter/FormMap.resx | 63 ++++++++++ AirFighter/Program.cs | 2 +- AirFighter/SimpleMap.cs | 50 ++++++++ 7 files changed, 510 insertions(+), 1 deletion(-) create mode 100644 AirFighter/AbstractMap.cs create mode 100644 AirFighter/FormMap.Designer.cs create mode 100644 AirFighter/FormMap.cs create mode 100644 AirFighter/FormMap.resx create mode 100644 AirFighter/SimpleMap.cs diff --git a/AirFighter/AbstractMap.cs b/AirFighter/AbstractMap.cs new file mode 100644 index 0000000..afee4e8 --- /dev/null +++ b/AirFighter/AbstractMap.cs @@ -0,0 +1,93 @@ +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) + { + //ПРОВЕРКА НА СТОЛКНОВЕНИЕ + if (true) + { + _drawingObject.MoveObject(direction); + } + 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); + //ПРОВЕРКА ЕСТЬ ЛИ УЖЕ НА ЭТОМ МЕСТЕ ОБЪЕКТ + 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/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/FormMap.Designer.cs b/AirFighter/FormMap.Designer.cs new file mode 100644 index 0000000..6d27600 --- /dev/null +++ b/AirFighter/FormMap.Designer.cs @@ -0,0 +1,206 @@ +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"}); + 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..82901a8 --- /dev/null +++ b/AirFighter/FormMap.cs @@ -0,0 +1,96 @@ +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; + } + + } + + + + 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; + } + } + } +} 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/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..c2283cc --- /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, 50) == 5) + { + _map[i, j] = _barrier; + } + else + { + _map[i, j] = _freeRoad; + } + + } + } + } + } +} -- 2.25.1 From ea89147e87102b9e7352351ab1e12fc55eeb6607 Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Mon, 26 Sep 2022 23:21:02 +0400 Subject: [PATCH 05/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D1=80=D0=B8?= =?UTF-8?q?=D1=81=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/FormMap.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/AirFighter/FormMap.cs b/AirFighter/FormMap.cs index 82901a8..637b89f 100644 --- a/AirFighter/FormMap.cs +++ b/AirFighter/FormMap.cs @@ -64,6 +64,7 @@ namespace AirFighter } break; } + pictureBoxAirFighter.Image = _abstractMap?.MoveObject(dir); } -- 2.25.1 From 80197437fa2f4e162f3f249ed33749fd90c625a1 Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Tue, 27 Sep 2022 04:01:32 +0400 Subject: [PATCH 06/11] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BE=D0=BB=D0=BB=D0=B8=D0=B7=D0=B8=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/AbstractMap.cs | 106 ++++++++++++++++++++++++++++++++- AirFighter/DrawingAircraft.cs | 2 +- AirFighter/FormMap.Designer.cs | 3 +- AirFighter/FormMap.cs | 5 ++ AirFighter/NightSkyMap.cs | 60 +++++++++++++++++++ AirFighter/SimpleMap.cs | 2 +- 6 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 AirFighter/NightSkyMap.cs diff --git a/AirFighter/AbstractMap.cs b/AirFighter/AbstractMap.cs index afee4e8..8d6ce0d 100644 --- a/AirFighter/AbstractMap.cs +++ b/AirFighter/AbstractMap.cs @@ -34,8 +34,108 @@ namespace AirFighter public Bitmap MoveObject(Direction direction) { - //ПРОВЕРКА НА СТОЛКНОВЕНИЕ - if (true) + 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.Contains(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 + 1), (int)(_size_y + 1)); + + if (objectRect.Contains(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 + 1), (int)(_size_y + 1)); + + + if (objectRect.Contains(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 + 1), (int)(_size_y + 1)); + + if (objectRect.Contains(rectBarrier)) + { + CollisionFlag = 1; + } + } + } + } + } + + if (CollisionFlag != 1) { _drawingObject.MoveObject(direction); } @@ -53,7 +153,7 @@ namespace AirFighter int x = _random.Next(0, 10); int y = _random.Next(0,10); _drawingObject.SetObject(x, y, _width, _height); - //ПРОВЕРКА ЕСТЬ ЛИ УЖЕ НА ЭТОМ МЕСТЕ ОБЪЕКТ + //CHECK IF BARRIER IS ALREADY SPAWANED ON OBJECT SPAWN return true; } diff --git a/AirFighter/DrawingAircraft.cs b/AirFighter/DrawingAircraft.cs index a73856d..c0222ef 100644 --- a/AirFighter/DrawingAircraft.cs +++ b/AirFighter/DrawingAircraft.cs @@ -242,7 +242,7 @@ namespace AirFighter } - public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + public (float Left, float Top, float Right, float Bottom) GetCurrentPosition() { return (_startPosX, _startPosY, _startPosX + _aircraftWidth, _startPosY + _aircraftHeight); } diff --git a/AirFighter/FormMap.Designer.cs b/AirFighter/FormMap.Designer.cs index 6d27600..ac71830 100644 --- a/AirFighter/FormMap.Designer.cs +++ b/AirFighter/FormMap.Designer.cs @@ -157,7 +157,8 @@ this.comboBoxMapSelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxMapSelection.FormattingEnabled = true; this.comboBoxMapSelection.Items.AddRange(new object[] { - "1. Simple map"}); + "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); diff --git a/AirFighter/FormMap.cs b/AirFighter/FormMap.cs index 637b89f..301897d 100644 --- a/AirFighter/FormMap.cs +++ b/AirFighter/FormMap.cs @@ -91,6 +91,11 @@ namespace AirFighter _abstractMap = new SimpleMap(); } break; + case "2. NightSky map": + { + _abstractMap = new NightSkyMap(); + } + break; } } } 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/SimpleMap.cs b/AirFighter/SimpleMap.cs index c2283cc..f920cff 100644 --- a/AirFighter/SimpleMap.cs +++ b/AirFighter/SimpleMap.cs @@ -34,7 +34,7 @@ namespace AirFighter { for (int j = 0; j < _map.GetLength(1); j++) { - if (_random.Next(0, 50) == 5) + if (_random.Next(0, 90) == 5) { _map[i, j] = _barrier; } -- 2.25.1 From 517fc78f0ce453705311d61f0defc4803ca62f42 Mon Sep 17 00:00:00 2001 From: 1yuee Date: Tue, 27 Sep 2022 16:04:47 +0400 Subject: [PATCH 07/11] Collision and SetObject checks. --- AirFighter/AbstractMap.cs | 50 ++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/AirFighter/AbstractMap.cs b/AirFighter/AbstractMap.cs index 8d6ce0d..73fab23 100644 --- a/AirFighter/AbstractMap.cs +++ b/AirFighter/AbstractMap.cs @@ -24,6 +24,7 @@ namespace AirFighter _height = height; _drawingObject = drawingObject; GenerateMap(); + while (!SetObjectOnMap()) { GenerateMap(); @@ -37,7 +38,7 @@ namespace AirFighter int CollisionFlag = 0; - + Size objSize1 = new Size(100,100); @@ -56,9 +57,10 @@ namespace AirFighter 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.Contains(rectBarrier)) + Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y); + + if (objectRect.IntersectsWith(rectBarrier)) { CollisionFlag = 1; } @@ -78,9 +80,9 @@ namespace AirFighter 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 + 1), (int)(_size_y + 1)); + Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y),(int) _size_x,(int) _size_y); - if (objectRect.Contains(rectBarrier)) + if (objectRect.IntersectsWith(rectBarrier)) { CollisionFlag = 1; } @@ -101,10 +103,9 @@ namespace AirFighter Rectangle objectRect = new Rectangle(LeftTop, objSize1); - Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x + 1), (int)(_size_y + 1)); + Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y); - - if (objectRect.Contains(rectBarrier)) + if (objectRect.IntersectsWith(rectBarrier)) { CollisionFlag = 1; } @@ -124,9 +125,11 @@ namespace AirFighter Rectangle objectRect = new Rectangle(LeftTop, objSize1); - Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x + 1), (int)(_size_y + 1)); - if (objectRect.Contains(rectBarrier)) + Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y); + + + if (objectRect.IntersectsWith(rectBarrier)) { CollisionFlag = 1; } @@ -138,6 +141,7 @@ namespace AirFighter if (CollisionFlag != 1) { _drawingObject.MoveObject(direction); + _drawingObject.DoSomething(); } return DrawMapWithObject(); } @@ -153,7 +157,27 @@ namespace AirFighter int x = _random.Next(0, 10); int y = _random.Next(0,10); _drawingObject.SetObject(x, y, _width, _height); - //CHECK IF BARRIER IS ALREADY SPAWANED ON OBJECT SPAWN + + 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; } @@ -184,10 +208,14 @@ namespace AirFighter 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); + + } } -- 2.25.1 From fd3b420d31f6386d70dc5736f024fd31c185150a Mon Sep 17 00:00:00 2001 From: 1yuee Date: Tue, 27 Sep 2022 16:06:42 +0400 Subject: [PATCH 08/11] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20GetCurrentPosi?= =?UTF-8?q?tion.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/DrawingAircraft.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AirFighter/DrawingAircraft.cs b/AirFighter/DrawingAircraft.cs index c0222ef..a54c275 100644 --- a/AirFighter/DrawingAircraft.cs +++ b/AirFighter/DrawingAircraft.cs @@ -244,7 +244,7 @@ namespace AirFighter public (float Left, float Top, float Right, float Bottom) GetCurrentPosition() { - return (_startPosX, _startPosY, _startPosX + _aircraftWidth, _startPosY + _aircraftHeight); + return (_startPosX, _startPosY, _startPosX + _aircraftWidth - 1, _startPosY + _aircraftHeight - 1); } } } -- 2.25.1 From 5adf2864ae636f4f823c5c6f1e5105d96235b601 Mon Sep 17 00:00:00 2001 From: 1yuee Date: Tue, 27 Sep 2022 16:07:42 +0400 Subject: [PATCH 09/11] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BE=D1=82?= =?UTF-8?q?=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/DrawingMilitaryAircraft.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AirFighter/DrawingMilitaryAircraft.cs b/AirFighter/DrawingMilitaryAircraft.cs index 92bd59d..0528f9b 100644 --- a/AirFighter/DrawingMilitaryAircraft.cs +++ b/AirFighter/DrawingMilitaryAircraft.cs @@ -26,6 +26,8 @@ namespace AirFighter base.DrawTransport(g); + + if (militaryAircraft.ExtraWings) { -- 2.25.1 From 23dfac69575c8016856e1929114692582e0a37f5 Mon Sep 17 00:00:00 2001 From: 1yuee Date: Tue, 27 Sep 2022 16:08:32 +0400 Subject: [PATCH 10/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=BE=D0=BF.=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/DrawingObjectAircraft.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AirFighter/DrawingObjectAircraft.cs b/AirFighter/DrawingObjectAircraft.cs index 9f745a5..618b1e0 100644 --- a/AirFighter/DrawingObjectAircraft.cs +++ b/AirFighter/DrawingObjectAircraft.cs @@ -17,7 +17,7 @@ namespace AirFighter public float Step => _aircraft.Plane?.Step ?? 0; - public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + public (float Left, float Top, float Right, float Bottom) GetCurrentPosition() { return _aircraft?.GetCurrentPosition() ?? default; } @@ -37,6 +37,12 @@ namespace AirFighter _aircraft.DrawTransport(g); } + + public void DoSomething() + { + Random rnd = new Random(); + int x = rnd.Next(0, 10); + } } } -- 2.25.1 From e71ced4b545227b45d60829820eb44730600a784 Mon Sep 17 00:00:00 2001 From: 1yuee Date: Tue, 27 Sep 2022 16:09:20 +0400 Subject: [PATCH 11/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=BE=D0=BF.=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/IDrawingObject.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AirFighter/IDrawingObject.cs b/AirFighter/IDrawingObject.cs index c6a9e72..63d7e8f 100644 --- a/AirFighter/IDrawingObject.cs +++ b/AirFighter/IDrawingObject.cs @@ -15,7 +15,9 @@ namespace AirFighter void DrawingObject(Graphics g); - (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + void DoSomething(); + + (float Left, float Top, float Right, float Bottom) GetCurrentPosition(); } } -- 2.25.1