From b190f9518e3d73af22663e09203d90c744293c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=80=D1=8C=D1=8F=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Fri, 16 Dec 2022 18:06:25 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningJet.cs | 29 +++++++++++++++++++++-------- AirBomber/AirBomber/EntityJet.cs | 2 +- AirBomber/AirBomber/WarJet.cs | 3 +-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/AirBomber/AirBomber/DrawningJet.cs b/AirBomber/AirBomber/DrawningJet.cs index 23f0567..f96ccb1 100644 --- a/AirBomber/AirBomber/DrawningJet.cs +++ b/AirBomber/AirBomber/DrawningJet.cs @@ -14,15 +14,15 @@ namespace AirBomber /// /// Класс-сущность /// - public EntityJet Jet { get; private set; } + public EntityJet Jet { get; protected set; } /// /// Левая координата отрисовки самолета /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки самолета /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -45,10 +45,16 @@ namespace AirBomber /// Скорость /// Вес самолета /// Цвет самолета - public void Init(int speed, float weight, Color bodyColor) + public DrawningJet(int speed, float weight, Color bodyColor) { - Jet = new EntityJet(); - Jet.Init(speed, weight, bodyColor); + Jet = new EntityJet(speed, weight, bodyColor); + } + + protected DrawningJet(int speed, float weight, Color bodyColor, int jetWidth, int jetHeight) : + this(speed, weight, bodyColor) + { + _jetWidth = jetWidth; + _jetHeight = jetHeight; } /// /// Установка позиции самолета @@ -58,7 +64,7 @@ namespace AirBomber /// Ширина картинки /// Высота картинки - public void SetPosition(int x, int y, int width, int height) + public virtual void SetPosition(int x, int y, int width, int height) { if (x < 0 || y < 0 || width < x + _jetWidth || height < y + _jetHeight) { @@ -122,7 +128,7 @@ namespace AirBomber /// Отрисовка самолета /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) @@ -202,5 +208,12 @@ namespace AirBomber _startPosY = _pictureHeight.Value - _jetHeight; } } + /// + /// Получение текущей позиции + /// + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _jetWidth, _startPosY + _jetHeight); + } } } diff --git a/AirBomber/AirBomber/EntityJet.cs b/AirBomber/AirBomber/EntityJet.cs index 02dd8b6..f713d10 100644 --- a/AirBomber/AirBomber/EntityJet.cs +++ b/AirBomber/AirBomber/EntityJet.cs @@ -35,7 +35,7 @@ namespace AirBomber /// /// - public void Init(int speed, float weight, Color bodyColor) + public EntityJet(int speed, float weight, Color bodyColor) { Random rnd = new Random(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed; diff --git a/AirBomber/AirBomber/WarJet.cs b/AirBomber/AirBomber/WarJet.cs index ca69f50..9f2fd7d 100644 --- a/AirBomber/AirBomber/WarJet.cs +++ b/AirBomber/AirBomber/WarJet.cs @@ -57,8 +57,7 @@ namespace AirBomber private void buttonCreate_Click(object sender, EventArgs e) { Random rnd = new Random(); - _jet = new DrawningJet(); - _jet.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _jet = new DrawningJet(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _jet.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height); toolStripStatusLabelSpeed.Text = $": {_jet.Jet.Speed}"; toolStripStatusLabelWeight.Text = $": {_jet.Jet.Weight}"; -- 2.25.1 From 6f9ccc81d433bcb0461ecd7675ccb114153a871c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=80=D1=8C=D1=8F=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Fri, 16 Dec 2022 18:46:39 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=D1=82=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningSportJet.cs | 81 +++++++++++++++++++++++++ AirBomber/AirBomber/EntitySportJet.cs | 46 ++++++++++++++ AirBomber/AirBomber/WarJet.Designer.cs | 41 ++++++++----- AirBomber/AirBomber/WarJet.cs | 35 ++++++++--- 4 files changed, 181 insertions(+), 22 deletions(-) create mode 100644 AirBomber/AirBomber/DrawningSportJet.cs create mode 100644 AirBomber/AirBomber/EntitySportJet.cs diff --git a/AirBomber/AirBomber/DrawningSportJet.cs b/AirBomber/AirBomber/DrawningSportJet.cs new file mode 100644 index 0000000..840e102 --- /dev/null +++ b/AirBomber/AirBomber/DrawningSportJet.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + + internal class DrawningSportJet : DrawningJet + { + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Цвет + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// + public DrawningSportJet(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : + base(speed, weight, bodyColor, 110, 60) + { + Jet = new EntitySportJet(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); + } + + public override void DrawTransport(Graphics g) + { + if (Jet is not EntitySportJet sportJet) + { + return; + } + + Pen pen = new Pen(Color.Black); + Brush dopBrush = new SolidBrush(sportJet.DopColor); + int x = Convert.ToInt32(_startPosX); + int y = Convert.ToInt32(_startPosY); + + if (sportJet.Wing) + { + GraphicsPath path1 = new GraphicsPath(); + Point pt1 = new Point(x + 100, y + 10); + Point pt2 = new Point(x + 100, y + 40); + Rectangle rect1 = new Rectangle(x + 80, y + 10, 30, 30); + + path1.AddLine(pt1, pt2); + path1.AddArc(rect1, 90, 180); + g.DrawPath(pen, path1); + g.FillPath(dopBrush, path1); + + GraphicsPath path2 = new GraphicsPath(); + Point pt3 = new Point(x + 100, y + 80); + Point pt4 = new Point(x + 100, y + 110); + Rectangle rect2 = new Rectangle(x + 80, y + 80, 30, 30); + + path2.AddLine(pt3, pt4); + path2.AddArc(rect2, 90, 180); + g.DrawPath(pen, path2); + g.FillPath(dopBrush, path2); + } + if (sportJet.SportLine) { } + + _startPosX += 10; + _startPosY += 5; + base.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 5; + + if (sportJet.BodyKit) + { + Rectangle rect = new Rectangle(x + 146, y + 45, 10, 40); + g.DrawRectangle(pen, rect); + g.FillRectangle(dopBrush, rect); + Point pt5 = new Point(x + 30, y + 65); + Point pt6 = new Point(x + 145, y + 65); + g.DrawLine(pen, pt5, pt6); + } + } + } +} diff --git a/AirBomber/AirBomber/EntitySportJet.cs b/AirBomber/AirBomber/EntitySportJet.cs new file mode 100644 index 0000000..6127a16 --- /dev/null +++ b/AirBomber/AirBomber/EntitySportJet.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class EntitySportJet : EntityJet + { + /// + ///Класс-сущность "Спортивный автомобиль" + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия обвеса + /// + public bool BodyKit { get; private set; } + /// + /// Признак наличия антикрыла + /// + public bool Wing { get; private set; } + /// + /// Признак наличия гоночной полосы + /// + public bool SportLine { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public EntitySportJet(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + BodyKit = bodyKit; + Wing = wing; + SportLine = sportLine; + } + } +} diff --git a/AirBomber/AirBomber/WarJet.Designer.cs b/AirBomber/AirBomber/WarJet.Designer.cs index e07e3da..d476ade 100644 --- a/AirBomber/AirBomber/WarJet.Designer.cs +++ b/AirBomber/AirBomber/WarJet.Designer.cs @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - this.pictureBoxCar = new System.Windows.Forms.PictureBox(); + this.pictureBoxJet = new System.Windows.Forms.PictureBox(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); @@ -38,20 +38,21 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit(); + this.buttonCreateModif = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxJet)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // - // pictureBoxCar + // pictureBoxJet // - this.pictureBoxCar.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxCar.Location = new System.Drawing.Point(0, 0); - this.pictureBoxCar.Name = "pictureBoxCar"; - this.pictureBoxCar.Size = new System.Drawing.Size(800, 428); - this.pictureBoxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxCar.TabIndex = 0; - this.pictureBoxCar.TabStop = false; - this.pictureBoxCar.Click += new System.EventHandler(this.PictureBoxCar_Resize); + this.pictureBoxJet.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxJet.Location = new System.Drawing.Point(0, 0); + this.pictureBoxJet.Name = "pictureBoxJet"; + this.pictureBoxJet.Size = new System.Drawing.Size(800, 450); + this.pictureBoxJet.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxJet.TabIndex = 0; + this.pictureBoxJet.TabStop = false; + this.pictureBoxJet.Click += new System.EventHandler(this.PictureBoxCar_Resize); // // statusStrip1 // @@ -142,21 +143,32 @@ this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(93, 402); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(107, 23); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); + // // WarJet // 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.buttonCreateModif); 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.pictureBoxCar); this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.pictureBoxJet); this.Name = "WarJet"; this.Text = "Военный самолет"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxJet)).EndInit(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); this.ResumeLayout(false); @@ -166,7 +178,7 @@ #endregion - private PictureBox pictureBoxCar; + private PictureBox pictureBoxJet; private StatusStrip statusStrip1; private ToolStripStatusLabel toolStripStatusLabelSpeed; private ToolStripStatusLabel toolStripStatusLabelWeight; @@ -176,5 +188,6 @@ private Button buttonLeft; private Button buttonRight; private Button buttonDown; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/WarJet.cs b/AirBomber/AirBomber/WarJet.cs index 9f2fd7d..a0d81b4 100644 --- a/AirBomber/AirBomber/WarJet.cs +++ b/AirBomber/AirBomber/WarJet.cs @@ -12,12 +12,22 @@ namespace AirBomber /// private void Draw() { - Bitmap bmp = new Bitmap(pictureBoxCar.Width, pictureBoxCar.Height); + Bitmap bmp = new Bitmap(pictureBoxJet.Width, pictureBoxJet.Height); Graphics gr = Graphics.FromImage(bmp); _jet?.DrawTransport(gr); - pictureBoxCar.Image = bmp; + pictureBoxJet.Image = bmp; + } + /// + /// + /// + private void SetData() + { + Random rnd = new Random(); + _jet.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxJet.Width, pictureBoxJet.Height); + toolStripStatusLabelSpeed.Text = $": {_jet.Jet.Speed}"; + toolStripStatusLabelWeight.Text = $": {_jet.Jet.Weight}"; + toolStripStatusLabelBodyColor.Text = $": {_jet.Jet.BodyColor.Name}"; } - private void buttonMove_Click(object sender, EventArgs e) { // @@ -46,7 +56,7 @@ namespace AirBomber /// private void PictureBoxCar_Resize(object sender, EventArgs e) { - _jet?.ChangeBorders(pictureBoxCar.Width, pictureBoxCar.Height); + _jet?.ChangeBorders(pictureBoxJet.Width, pictureBoxJet.Height); Draw(); } /// @@ -58,10 +68,19 @@ namespace AirBomber { Random rnd = new Random(); _jet = new DrawningJet(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _jet.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height); - toolStripStatusLabelSpeed.Text = $": {_jet.Jet.Speed}"; - toolStripStatusLabelWeight.Text = $": {_jet.Jet.Weight}"; - toolStripStatusLabelBodyColor.Text = $": {_jet.Jet.BodyColor.Name}"; + _jet.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxJet.Width, pictureBoxJet.Height); + SetData(); + Draw(); + } + + private void buttonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new Random(); + var jet = new DrawningSportJet(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)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(); Draw(); } } -- 2.25.1 From 07fe09f7e17ff543799bcf8bde9ad14fffe9e0aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=80=D1=8C=D1=8F=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Fri, 16 Dec 2022 19:53:19 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=90=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA?= =?UTF-8?q?=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 --- AirBomber/AirBomber/AbstractMap.cs | 152 +++++++++++++++++ AirBomber/AirBomber/Direction.cs | 1 + AirBomber/AirBomber/DrawningObjectJet.cs | 35 ++++ AirBomber/AirBomber/FormMap.Designer.cs | 208 +++++++++++++++++++++++ AirBomber/AirBomber/FormMap.cs | 92 ++++++++++ AirBomber/AirBomber/FormMap.resx | 63 +++++++ AirBomber/AirBomber/IDrawningObject.cs | 39 +++++ AirBomber/AirBomber/Program.cs | 2 +- AirBomber/AirBomber/SimpleMap.cs | 52 ++++++ AirBomber/AirBomber/SkyMap.cs | 52 ++++++ 10 files changed, 695 insertions(+), 1 deletion(-) create mode 100644 AirBomber/AirBomber/AbstractMap.cs create mode 100644 AirBomber/AirBomber/DrawningObjectJet.cs create mode 100644 AirBomber/AirBomber/FormMap.Designer.cs create mode 100644 AirBomber/AirBomber/FormMap.cs create mode 100644 AirBomber/AirBomber/FormMap.resx create mode 100644 AirBomber/AirBomber/IDrawningObject.cs create mode 100644 AirBomber/AirBomber/SimpleMap.cs create mode 100644 AirBomber/AirBomber/SkyMap.cs diff --git a/AirBomber/AirBomber/AbstractMap.cs b/AirBomber/AirBomber/AbstractMap.cs new file mode 100644 index 0000000..8cb258b --- /dev/null +++ b/AirBomber/AirBomber/AbstractMap.cs @@ -0,0 +1,152 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal abstract class AbstractMap + { + private IDrawningObject _drawningObject = null; + protected int[,] _map = null; + protected int _width; + protected int _height; + protected float _size_x; + protected float _size_y; + protected readonly Random _random = new(); + protected readonly int _freeRoad = 0; + protected readonly int _barrier = 1; + public Bitmap CreateMap(int width, int height, IDrawningObject + drawningObject) + { + _width = width; + _height = height; + _drawningObject = drawningObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + public bool CheckAround(float Left, float Right, float Top, float Bottom) + { + int startX = (int)(Left / _size_x); + int startY = (int)(Right / _size_y); + int endX = (int)(Top / _size_x); + if (endX > 100) + { + endX = 100; + } + int endY = (int)(Bottom / _size_y); + if (endY > 100) + { + endY = 100; + } + for (int i = startX; i <= endX; i++) + { + for (int j = startY; j <= endY; j++) + { + if (_map[i, j] == _barrier) + { + return true; + } + } + } + return false; + } + public Bitmap MoveObject(Direction direction) + { + // TODO проверка, что объект может переместится в требуемом направлении + _drawningObject.MoveObject(direction); + (float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition(); + + if (CheckAround(Left, Right, Top, Bottom)) + { + _drawningObject.MoveObject(MoveObjectBack(direction)); + } + return DrawMapWithObject(); + } + private Direction MoveObjectBack(Direction direction) + { + switch (direction) + { + case Direction.Up: + return Direction.Down; + case Direction.Down: + return Direction.Up; + case Direction.Left: + return Direction.Right; + case Direction.Right: + return Direction.Left; + } + return Direction.None; + } + private bool SetObjectOnMap() + { + if (_drawningObject == null || _map == null) + { + return false; + } + int x = _random.Next(0, 10); + int y = _random.Next(0, 10); + _drawningObject.SetObject(x, y, _width, _height); + // TODO првоерка, что объект не "накладывается" на закрытые участки + (float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition(); + if (!CheckAround(Left, Right, Top, Bottom)) return true; + float startX = Left; + float startY = Right; + float lengthX = Top - Left; + float lengthY = Bottom - Right; + while (CheckAround(startX, startY, startX + lengthX, startY + lengthY)) + { + bool result; + do + { + result = CheckAround(startX, startY, startX + lengthX, startY + lengthY); + if (!result) + { + _drawningObject.SetObject((int)startX, (int)startY, _width, _height); + return true; + } + else + { + startX += _size_x; + } + } while (result); + startX = x; + startY += _size_y; + } + return false; + } + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + if (_drawningObject == null || _map == null) + { + return bmp; + } + Graphics gr = Graphics.FromImage(bmp); + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + if (_map[i, j] == _freeRoad) + { + DrawRoadPart(gr, i, j); + } + else if (_map[i, j] == _barrier) + { + DrawBarrierPart(gr, i, j); + } + } + } + _drawningObject.DrawningObject(gr); + return bmp; + } + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + } +} diff --git a/AirBomber/AirBomber/Direction.cs b/AirBomber/AirBomber/Direction.cs index 306144d..5f01285 100644 --- a/AirBomber/AirBomber/Direction.cs +++ b/AirBomber/AirBomber/Direction.cs @@ -8,6 +8,7 @@ namespace AirBomber { internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/AirBomber/AirBomber/DrawningObjectJet.cs b/AirBomber/AirBomber/DrawningObjectJet.cs new file mode 100644 index 0000000..273fd65 --- /dev/null +++ b/AirBomber/AirBomber/DrawningObjectJet.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class DrawningObjectJet : IDrawningObject + { + private DrawningJet _jet = null; + public DrawningObjectJet(DrawningJet jet) + { + _jet = jet; + } + public float Step => _jet?.Jet?.Step ?? 0; + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _jet?.GetCurrentPosition() ?? default; + } + public void MoveObject(Direction direction) + { + _jet?.MoveTransport(direction); + } + public void SetObject(int x, int y, int width, int height) + { + _jet.SetPosition(x, y, width, height); + } + + void IDrawningObject.DrawningObject(Graphics g) + { + _jet.DrawTransport(g); + } + } +} diff --git a/AirBomber/AirBomber/FormMap.Designer.cs b/AirBomber/AirBomber/FormMap.Designer.cs new file mode 100644 index 0000000..f0fab3b --- /dev/null +++ b/AirBomber/AirBomber/FormMap.Designer.cs @@ -0,0 +1,208 @@ +namespace AirBomber +{ + 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.pictureBoxJet = new System.Windows.Forms.PictureBox(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.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.buttonCreateModif = new System.Windows.Forms.Button(); + this.comboBoxCelectorMap1 = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxJet)).BeginInit(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxJet + // + this.pictureBoxJet.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxJet.Location = new System.Drawing.Point(0, 0); + this.pictureBoxJet.Name = "pictureBoxJet"; + this.pictureBoxJet.Size = new System.Drawing.Size(800, 450); + this.pictureBoxJet.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxJet.TabIndex = 0; + this.pictureBoxJet.TabStop = false; + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor}); + this.statusStrip1.Location = new System.Drawing.Point(0, 428); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(800, 22); + this.statusStrip1.TabIndex = 1; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17); + this.toolStripStatusLabelSpeed.Text = "Скорость:"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17); + this.toolStripStatusLabelWeight.Text = "Вес:"; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusLabelBodyColor.Text = "Цвет:"; + // + // 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, 402); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Создать"; + 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::AirBomber.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(702, 331); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(40, 40); + 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::AirBomber.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(656, 377); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(40, 40); + 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::AirBomber.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(748, 377); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(40, 40); + 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::AirBomber.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(702, 377); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(40, 40); + this.buttonDown.TabIndex = 6; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(93, 402); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(107, 23); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); + // + // comboBoxCelectorMap1 + // + this.comboBoxCelectorMap1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxCelectorMap1.FormattingEnabled = true; + this.comboBoxCelectorMap1.Items.AddRange(new object[] { + "Простоя карта", + "Небо"}); + this.comboBoxCelectorMap1.Location = new System.Drawing.Point(12, 12); + this.comboBoxCelectorMap1.Name = "comboBoxCelectorMap1"; + this.comboBoxCelectorMap1.Size = new System.Drawing.Size(121, 23); + this.comboBoxCelectorMap1.TabIndex = 8; + this.comboBoxCelectorMap1.SelectedIndexChanged += new System.EventHandler(this.comboBoxCelectorMap1_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.comboBoxCelectorMap1); + this.Controls.Add(this.buttonCreateModif); + 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.statusStrip1); + this.Controls.Add(this.pictureBoxJet); + this.Name = "FormMap"; + this.Text = "FormMap"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxJet)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxJet; + private StatusStrip statusStrip1; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private Button buttonCreate; + private Button buttonUp; + private Button buttonLeft; + private Button buttonRight; + private Button buttonDown; + private Button buttonCreateModif; + private ComboBox comboBoxCelectorMap1; + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/FormMap.cs b/AirBomber/AirBomber/FormMap.cs new file mode 100644 index 0000000..23fa207 --- /dev/null +++ b/AirBomber/AirBomber/FormMap.cs @@ -0,0 +1,92 @@ +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 AirBomber +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + public FormMap() + { + InitializeComponent(); + _abstractMap = new SimpleMap(); + } + /// + /// Заполнение информации по объекту + /// + private void SetData(DrawningJet jet) + { + toolStripStatusLabelSpeed.Text = $"Скорость: {jet.Jet.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {jet.Jet.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {jet.Jet.BodyColor.Name}"; + pictureBoxJet.Image = _abstractMap.CreateMap(pictureBoxJet.Width, pictureBoxJet.Height, new DrawningObjectJet(jet)); + } + /// + /// Обработка нажатия кнопки "Создать" + /// + /// + /// + private void buttonCreate_Click(object sender, EventArgs e) + { + Random rnd = new Random(); + var jet = new DrawningJet(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(jet); + } + 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; + } + pictureBoxJet.Image = _abstractMap?.MoveObject(dir); + } + + private void buttonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new Random(); + var jet = new DrawningSportJet(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)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(jet); + } + /// + /// Смена карты + /// + /// + /// + private void comboBoxCelectorMap1_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxCelectorMap1.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + case "Небо": + _abstractMap = new SkyMap(); + break; + } + } + } +} diff --git a/AirBomber/AirBomber/FormMap.resx b/AirBomber/AirBomber/FormMap.resx new file mode 100644 index 0000000..5cb320f --- /dev/null +++ b/AirBomber/AirBomber/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/AirBomber/AirBomber/IDrawningObject.cs b/AirBomber/AirBomber/IDrawningObject.cs new file mode 100644 index 0000000..acaf82d --- /dev/null +++ b/AirBomber/AirBomber/IDrawningObject.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal interface IDrawningObject + { + /// + /// Шаг перемещения объекта + /// + public float Step { get; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + void SetObject(int x, int y, int width, int height); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + void MoveObject(Direction direction); + /// + /// Отрисовка объекта + /// + /// + void DrawningObject(Graphics g); + /// + /// Получение текущей позиции объекта + /// + /// + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } +} diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index 05d9610..e462fb5 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -11,7 +11,7 @@ namespace AirBomber // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new WarJet()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/AirBomber/AirBomber/SimpleMap.cs b/AirBomber/AirBomber/SimpleMap.cs new file mode 100644 index 0000000..00b0dca --- /dev/null +++ b/AirBomber/AirBomber/SimpleMap.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class SimpleMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// + /// Цвет участка открытого + /// + private readonly 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) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 25) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +} diff --git a/AirBomber/AirBomber/SkyMap.cs b/AirBomber/AirBomber/SkyMap.cs new file mode 100644 index 0000000..bd76e8f --- /dev/null +++ b/AirBomber/AirBomber/SkyMap.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class SkyMap : AbstractMap + { + private readonly Brush barrierColor = new SolidBrush(Color.White); + private readonly Brush roadColor = new SolidBrush(Color.DeepSkyBlue); + 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)); + 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) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 20) + { + int x = _random.Next(0, 95); + int y = _random.Next(0, 95); + if (_map[x, y] == _freeRoad) + { + _map[x, y + 1] = _barrier; + _map[x, y + 2] = _barrier; + _map[x + 1, y + 1] = _barrier; + _map[x + 2, y + 1] = _barrier; + _map[x + 1, y] = _barrier; + _map[x + 2, y] = _barrier; + counter++; + } + } + } + } +} -- 2.25.1