diff --git a/WarmlyShip/WarmlyShip/AbstractMap.cs b/WarmlyShip/WarmlyShip/AbstractMap.cs
new file mode 100644
index 0000000..b05b4fd
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/AbstractMap.cs
@@ -0,0 +1,121 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyShip
+{
+ 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();
+ }
+
+ private bool CanMove(Direction direction, (float Left, float Right, float Top, float Bottom) position) //Проверка на возможность шага
+ {
+ for (int i = (int)(position.Top / _size_y); i <= (int)(position.Bottom / _size_y); ++i)
+ {
+ for (int j = (int)(position.Left / _size_x); j <= (int)(position.Right / _size_x); ++j)
+ {
+ if (i >= 0 && j >= 0 && i < _map.GetLength(0) && j < _map.GetLength(1) && _map[i, j] == _barrier) return false;
+ }
+ }
+ return true;
+ }
+
+ public Bitmap MoveObject(Direction direction)
+ {
+ (float Left, float Right, float Top, float Bottom) position = _drawningObject.GetCurrentPosition();
+ if (direction == Direction.Left)
+ {
+ position.Left -= _drawningObject.Step;
+ }
+ else if (direction == Direction.Right)
+ {
+ position.Right += _drawningObject.Step;
+ }
+ else if (direction == Direction.Up)
+ {
+ position.Top -= _drawningObject.Step;
+ }
+ else if (direction == Direction.Down)
+ {
+ position.Bottom += _drawningObject.Step;
+ }
+
+ if (CanMove(direction, position))
+ {
+ _drawningObject.MoveObject(direction);
+ }
+ return DrawMapWithObject();
+ }
+
+ private bool SetObjectOnMap()
+ {
+ if (_drawningObject == null || _map == null)
+ {
+ return false;
+ }
+ int x = _random.Next(0, 10);
+ int y = _random.Next(0, 10);
+ _drawningObject.SetObject(x, y, _width, _height);
+ for (int i = (int)(_drawningObject.GetCurrentPosition().Top / _size_y); i <= (int)(_drawningObject.GetCurrentPosition().Bottom / _size_y); ++i)
+ {
+ for (int j = (int)(_drawningObject.GetCurrentPosition().Left / _size_x); j <= (int)(_drawningObject.GetCurrentPosition().Right / _size_x); ++j)
+ {
+ if (_map[i, j] == _barrier) return false;
+ }
+ }
+ return true;
+ }
+ private Bitmap DrawMapWithObject()
+ {
+ Bitmap bmp = new(_width, _height);
+ if (_drawningObject == null || _map == null)
+ {
+ return bmp;
+ }
+ Graphics gr = Graphics.FromImage(bmp);
+ for (int i = 0; i < _map.GetLength(0); ++i)
+ {
+ for (int j = 0; j < _map.GetLength(1); ++j)
+ {
+ if (_map[i, j] == _freeRoad)
+ {
+ DrawRoadPart(gr, i, j);
+ }
+ else if (_map[i, j] == _barrier)
+ {
+ DrawBarrierPart(gr, i, j);
+ }
+ }
+ }
+ _drawningObject.DrawningObject(gr);
+ return bmp;
+ }
+ protected abstract void GenerateMap();
+ protected abstract void DrawRoadPart(Graphics g, int i, int j);
+ protected abstract void DrawBarrierPart(Graphics g, int i, int j);
+ }
+}
diff --git a/WarmlyShip/WarmlyShip/Direction.cs b/WarmlyShip/WarmlyShip/Direction.cs
index fa7a4e8..09a6267 100644
--- a/WarmlyShip/WarmlyShip/Direction.cs
+++ b/WarmlyShip/WarmlyShip/Direction.cs
@@ -8,6 +8,7 @@ namespace WarmlyShip
{
internal enum Direction //Направление при перемещении
{
+ None = 0,
Left = 1, //Влево
Up = 2, //Вверх
Right = 3, //Вправо
diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs
index b131644..de2d7a2 100644
--- a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs
+++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs
@@ -8,20 +8,27 @@ namespace WarmlyShip
{
internal class DrawingWarmlyShip
{
- public EntityWarmlyShip warmlyShip { private set; get; } //Класс-сущность
+ public EntityWarmlyShip warmlyShip { protected set; get; } //Класс-сущность
public float _startPosX; //Координаты отрисовки по оси x
public float _startPosY; //Координаты отрисовки по оси y
private int? _pictureWidth = null; //Ширина окна
private int? _pictureHeight = null; //Высота окна
- private readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля
- private readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля
+ protected readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля
+ protected readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля
- public void Init(int speed, float weight, Color bodyColor)
+ //Инициализация
+ public DrawingWarmlyShip(int speed, float weight, Color bodyColor)
{
- warmlyShip = new EntityWarmlyShip();
- warmlyShip.Init(speed, weight, bodyColor);
+ warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor);
}
+ protected DrawingWarmlyShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight) : this(speed, weight, bodyColor)
+ {
+ _warmlyShipWidth = warmlyWidth;
+ _warmlyShipHeight = warmlyHeight;
+ }
+
+ //Начальные коордитанты
public void SetPosition(int x, int y, int width, int height)
{
if (width < _warmlyShipWidth || height < _warmlyShipHeight) return;
@@ -32,6 +39,7 @@ namespace WarmlyShip
_pictureHeight = height;
}
+ //Движение транспорта по координатам
public void MoveTransport(Direction direction)
{
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) return;
@@ -52,7 +60,8 @@ namespace WarmlyShip
}
}
- public void DrawTransport(Graphics g)
+ //Отрисовка транспорта
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
@@ -84,6 +93,7 @@ namespace WarmlyShip
g.DrawEllipse(new(Color.Blue, 2), _startPosX + _warmlyShipWidth * 2 / 5 + 2.5f, _startPosY + 25, 20, 20);
}
+ //Изменение границ отрисовки
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
@@ -104,5 +114,10 @@ namespace WarmlyShip
}
}
+
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return (_startPosX, _startPosX + _warmlyShipWidth, _startPosY, _startPosY + _warmlyShipHeight);
+ }
}
}
diff --git a/WarmlyShip/WarmlyShip/DrawningMotorShip.cs b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs
new file mode 100644
index 0000000..0d17867
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyShip
+{
+ internal class DrawningMotorShip : DrawingWarmlyShip
+ {
+ public DrawningMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor, 150, 75)
+ {
+ warmlyShip = new EntityMotorShip(speed, weight, bodyColor, dopColor, tubes , cistern);
+ }
+
+ public override void DrawTransport(Graphics g)
+ {
+ if (warmlyShip is not EntityMotorShip motorShip)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black, 2);
+ Brush dopBrush = new SolidBrush(motorShip.DopColor);
+ if (motorShip.Tubes)
+ {
+ g.FillRectangle(dopBrush, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
+ g.DrawRectangle(pen, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
+ g.FillRectangle(dopBrush, _startPosX + _warmlyShipWidth * 3 / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
+ g.DrawRectangle(pen, _startPosX + _warmlyShipWidth * 3 / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
+ }
+
+ _startPosY += 25;
+ base.DrawTransport(g);
+ _startPosY -= 25;
+
+ if (motorShip.Cistern)
+ {
+ g.FillEllipse(dopBrush, _startPosX, _startPosY + 25, 25, 20);
+ g.DrawEllipse(pen, _startPosX, _startPosY + 25, 25, 20);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/WarmlyShip/WarmlyShip/DrawningObjectShip.cs b/WarmlyShip/WarmlyShip/DrawningObjectShip.cs
new file mode 100644
index 0000000..e9c2b8a
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/DrawningObjectShip.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyShip
+{
+ internal class DrawningObjectShip : IDrawningObject
+ {
+ private DrawingWarmlyShip _warmlyShip = null;
+
+ public DrawningObjectShip(DrawingWarmlyShip warmlyShip)
+ {
+ _warmlyShip = warmlyShip;
+ }
+
+ public float Step => _warmlyShip?.warmlyShip?.Step ?? 0;
+
+ public void DrawningObject(Graphics g)
+ {
+ _warmlyShip?.DrawTransport(g);
+ }
+
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return _warmlyShip?.GetCurrentPosition() ?? default;
+ }
+
+ public void MoveObject(Direction direction)
+ {
+ _warmlyShip?.MoveTransport(direction);
+ }
+
+ public void SetObject(int x, int y, int width, int height)
+ {
+ _warmlyShip?.SetPosition(x, y, width, height);
+ }
+ }
+}
diff --git a/WarmlyShip/WarmlyShip/EntityMotorShip.cs b/WarmlyShip/WarmlyShip/EntityMotorShip.cs
new file mode 100644
index 0000000..55ddeb5
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/EntityMotorShip.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyShip
+{
+ internal class EntityMotorShip : EntityWarmlyShip
+ {
+ public Color DopColor { get; private set; }
+ public bool Tubes { get; private set; }
+ public bool Cistern { get; private set; }
+
+ public EntityMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor)
+ {
+ DopColor = dopColor;
+ Tubes = tubes;
+ Cistern = cistern;
+ }
+
+ }
+}
+
\ No newline at end of file
diff --git a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs
index 29576fb..1da24c8 100644
--- a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs
+++ b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs
@@ -13,7 +13,8 @@ namespace WarmlyShip
public Color BodyColor { get; private set; } //Цвет
public float Step => Speed * 100 / Weight; //Шаг при перемещении
- public void Init(int speed, float weight, Color bodyColor)
+ //Инициализация
+ public EntityWarmlyShip(int speed, float weight, Color bodyColor)
{
Random random = new Random();
Speed = speed <= 0 ? random.Next(50, 150) : speed;
diff --git a/WarmlyShip/WarmlyShip/FormClass.Designer.cs b/WarmlyShip/WarmlyShip/FormClass.Designer.cs
index 26dca06..f23d522 100644
--- a/WarmlyShip/WarmlyShip/FormClass.Designer.cs
+++ b/WarmlyShip/WarmlyShip/FormClass.Designer.cs
@@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.ButtonCreate = new System.Windows.Forms.Button();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@@ -142,11 +143,23 @@
this.ButtonCreate.UseVisualStyleBackColor = true;
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreateModif.Location = new System.Drawing.Point(93, 402);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(100, 23);
+ this.buttonCreateModif.TabIndex = 8;
+ this.buttonCreateModif.Text = "Модификация ";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
// FormClass
//
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.ButtonCreate);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
@@ -176,5 +189,6 @@
private Button buttonLeft;
private Button buttonDown;
private Button ButtonCreate;
+ private Button buttonCreateModif;
}
}
\ No newline at end of file
diff --git a/WarmlyShip/WarmlyShip/FormClass.cs b/WarmlyShip/WarmlyShip/FormClass.cs
index 23e86ce..5d1bf94 100644
--- a/WarmlyShip/WarmlyShip/FormClass.cs
+++ b/WarmlyShip/WarmlyShip/FormClass.cs
@@ -17,15 +17,20 @@ namespace WarmlyShip
pictureBox.Image = bmp;
}
- private void ButtonCreate_Click(object sender, EventArgs e)
- {
+ private void SetData()
+ {
Random random = new Random();
- _warmlyShip = new DrawingWarmlyShip();
- _warmlyShip.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
- _warmlyShip.SetPosition(random.Next(pictureBox.Width - 150, pictureBox.Width - 125), random.Next(pictureBox.Height - 150, pictureBox.Height - 50), pictureBox.Width, pictureBox.Height);
+ _warmlyShip.SetPosition(random.Next(0, 100), random.Next(0, 100), pictureBox.Width, pictureBox.Height);
toolStripStatusSpeed.Text = $": {_warmlyShip.warmlyShip?.Speed}";
toolStripStatusWeight.Text = $": {_warmlyShip.warmlyShip?.Weight}";
toolStripStatusLabelBodyColor.Text = $": {_warmlyShip.warmlyShip?.BodyColor}";
+ }
+
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random random = new Random();
+ _warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
+ SetData();
Draw();
}
@@ -55,5 +60,16 @@ namespace WarmlyShip
_warmlyShip?.ChangeBorders(pictureBox.Width, pictureBox.Height);
Draw();
}
+
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random random = new Random();
+ _warmlyShip = new DrawningMotorShip(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ SetData();
+ Draw();
+ }
}
}
\ No newline at end of file
diff --git a/WarmlyShip/WarmlyShip/FormMap.Designer.cs b/WarmlyShip/WarmlyShip/FormMap.Designer.cs
new file mode 100644
index 0000000..f89a930
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/FormMap.Designer.cs
@@ -0,0 +1,210 @@
+namespace WarmlyShip
+{
+ 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.pictureBox = new System.Windows.Forms.PictureBox();
+ this.statusStrip = new System.Windows.Forms.StatusStrip();
+ this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.ButtonCreate = new System.Windows.Forms.Button();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.statusStrip.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // pictureBox
+ //
+ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBox.Location = new System.Drawing.Point(0, 0);
+ this.pictureBox.Name = "pictureBox";
+ this.pictureBox.Size = new System.Drawing.Size(800, 428);
+ this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBox.TabIndex = 0;
+ this.pictureBox.TabStop = false;
+ //
+ // statusStrip
+ //
+ this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusSpeed,
+ this.toolStripStatusWeight,
+ this.toolStripStatusLabelBodyColor});
+ this.statusStrip.Location = new System.Drawing.Point(0, 428);
+ this.statusStrip.Name = "statusStrip";
+ this.statusStrip.Size = new System.Drawing.Size(800, 22);
+ this.statusStrip.TabIndex = 1;
+ this.statusStrip.Text = "statusStrip1";
+ //
+ // toolStripStatusSpeed
+ //
+ this.toolStripStatusSpeed.Name = "toolStripStatusSpeed";
+ this.toolStripStatusSpeed.Size = new System.Drawing.Size(62, 17);
+ this.toolStripStatusSpeed.Text = "Скорость:";
+ //
+ // toolStripStatusWeight
+ //
+ this.toolStripStatusWeight.Name = "toolStripStatusWeight";
+ this.toolStripStatusWeight.Size = new System.Drawing.Size(29, 17);
+ this.toolStripStatusWeight.Text = "Вес:";
+ //
+ // toolStripStatusLabelBodyColor
+ //
+ this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
+ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
+ this.toolStripStatusLabelBodyColor.Text = "Цвет:";
+ //
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::WarmlyShip.Properties.Resources.toright;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(738, 375);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(50, 50);
+ this.buttonRight.TabIndex = 3;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonUp
+ //
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::WarmlyShip.Properties.Resources.totop;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(682, 319);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(50, 50);
+ this.buttonUp.TabIndex = 4;
+ 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::WarmlyShip.Properties.Resources.toleft;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(626, 375);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(50, 50);
+ this.buttonLeft.TabIndex = 5;
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.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::WarmlyShip.Properties.Resources.todown;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(682, 375);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(50, 50);
+ this.buttonDown.TabIndex = 6;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // 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 = 7;
+ this.ButtonCreate.Text = "Создать";
+ this.ButtonCreate.UseVisualStyleBackColor = true;
+ this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
+ //
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreateModif.Location = new System.Drawing.Point(93, 402);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(100, 23);
+ this.buttonCreateModif.TabIndex = 8;
+ this.buttonCreateModif.Text = "Модификация ";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта",
+ "Вторая карта",
+ "Последняя карта"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
+ this.comboBoxSelectorMap.TabIndex = 9;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.СomboBoxSelectorMap_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.comboBoxSelectorMap);
+ this.Controls.Add(this.buttonCreateModif);
+ this.Controls.Add(this.ButtonCreate);
+ this.Controls.Add(this.buttonDown);
+ this.Controls.Add(this.buttonLeft);
+ this.Controls.Add(this.buttonUp);
+ this.Controls.Add(this.buttonRight);
+ this.Controls.Add(this.pictureBox);
+ this.Controls.Add(this.statusStrip);
+ this.Name = "FormMap";
+ this.Text = "FormMap";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.statusStrip.ResumeLayout(false);
+ this.statusStrip.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private PictureBox pictureBox;
+ private StatusStrip statusStrip;
+ private ToolStripStatusLabel toolStripStatusSpeed;
+ private ToolStripStatusLabel toolStripStatusWeight;
+ private ToolStripStatusLabel toolStripStatusLabelBodyColor;
+ private Button buttonRight;
+ private Button buttonUp;
+ private Button buttonLeft;
+ private Button buttonDown;
+ private Button ButtonCreate;
+ private Button buttonCreateModif;
+ private ComboBox comboBoxSelectorMap;
+ }
+}
\ No newline at end of file
diff --git a/WarmlyShip/WarmlyShip/FormMap.cs b/WarmlyShip/WarmlyShip/FormMap.cs
new file mode 100644
index 0000000..3d6c502
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/FormMap.cs
@@ -0,0 +1,88 @@
+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 WarmlyShip
+{
+ public partial class FormMap : Form
+ {
+ private AbstractMap _abstractMap;
+
+ public FormMap()
+ {
+ InitializeComponent();
+ _abstractMap = new SimpleMap();
+ }
+
+ private void SetData(DrawingWarmlyShip warmlyShip)
+ {
+ toolStripStatusSpeed.Text = $"Скорость: {warmlyShip.warmlyShip?.Speed}";
+ toolStripStatusWeight.Text = $"Вес: {warmlyShip.warmlyShip?.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет: {warmlyShip.warmlyShip?.BodyColor}";
+ pictureBox.Image = _abstractMap.CreateMap(pictureBox.Width, pictureBox.Height, new DrawningObjectShip(warmlyShip));
+ }
+
+
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random random = new Random();
+ var warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
+ SetData(warmlyShip);
+ }
+
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ Direction direction = Direction.None;
+ switch (name)
+ {
+ case "buttonLeft":
+ direction = Direction.Left;
+ break;
+ case "buttonUp":
+ direction = Direction.Up;
+ break;
+ case "buttonRight":
+ direction = Direction.Right;
+ break;
+ case "buttonDown":
+ direction = Direction.Down;
+ break;
+ }
+ pictureBox.Image = _abstractMap?.MoveObject(direction);
+ }
+
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random random = new Random();
+ var warmlyShip = new DrawningMotorShip(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ SetData(warmlyShip);
+ }
+
+ private void СomboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ _abstractMap = new SimpleMap();
+ break;
+ case "Вторая карта":
+ _abstractMap = new SecondMap();
+ break;
+ case "Последняя карта":
+ _abstractMap = new LastMap();
+ break;
+ }
+
+ }
+ }
+}
diff --git a/WarmlyShip/WarmlyShip/FormMap.resx b/WarmlyShip/WarmlyShip/FormMap.resx
new file mode 100644
index 0000000..2c0949d
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/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/WarmlyShip/WarmlyShip/IDrawningObject.cs b/WarmlyShip/WarmlyShip/IDrawningObject.cs
new file mode 100644
index 0000000..a732b2c
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/IDrawningObject.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyShip
+{
+ internal interface IDrawningObject
+ {
+ public float Step { get; }
+ void SetObject(int x, int y, int width, int height);
+ void MoveObject(Direction direction);
+ void DrawningObject(Graphics g);
+ (float Left, float Right, float Top, float Bottom) GetCurrentPosition();
+ }
+}
diff --git a/WarmlyShip/WarmlyShip/LastMap.cs b/WarmlyShip/WarmlyShip/LastMap.cs
new file mode 100644
index 0000000..9cede84
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/LastMap.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyShip
+{
+ internal class LastMap : AbstractMap
+ {
+ private readonly Brush barrierColor = new SolidBrush(Color.Red);
+
+ private readonly Brush roadColor = new SolidBrush(Color.Green);
+
+ protected override void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, j * _size_x, i * _size_y, _size_x, _size_y);
+ }
+ protected override void GenerateMap()
+ {
+ _map = new int[100, 100];
+ _size_x = (float)_width / _map.GetLength(0);
+ _size_y = (float)_height / _map.GetLength(1);
+ int counter = 0;
+ for (int i = 0; i < _map.GetLength(0); ++i)
+ {
+ for (int j = 0; j < _map.GetLength(1); ++j)
+ {
+ _map[i, j] = _freeRoad;
+ }
+ }
+ while (counter < 45)
+ {
+ int x = _random.Next(0, 100);
+ int y = _random.Next(0, 100);
+ if (_map[x, y] == _freeRoad)
+ {
+ _map[x, y] = _barrier;
+ if (x > 0 && y > 0 && x < _map.GetLength(0) - 1 && y < _map.GetLength(1) - 1)
+ {
+ _map[x - 1, y] = _barrier;
+ _map[x + 1, y] = _barrier;
+ _map[x, y - 1] = _barrier;
+ _map[x, y + 1] = _barrier;
+ }
+ counter++;
+ }
+ }
+ }
+ }
+}
diff --git a/WarmlyShip/WarmlyShip/Program.cs b/WarmlyShip/WarmlyShip/Program.cs
index a894d54..9bf5de7 100644
--- a/WarmlyShip/WarmlyShip/Program.cs
+++ b/WarmlyShip/WarmlyShip/Program.cs
@@ -11,7 +11,7 @@ namespace WarmlyShip
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormClass());
+ Application.Run(new FormMap());
}
}
}
\ No newline at end of file
diff --git a/WarmlyShip/WarmlyShip/SecondMap.cs b/WarmlyShip/WarmlyShip/SecondMap.cs
new file mode 100644
index 0000000..e3674f0
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/SecondMap.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyShip
+{
+ internal class SecondMap : AbstractMap
+ {
+ private readonly Brush barrierColor = new SolidBrush(Color.Gold);
+
+ private readonly Brush roadColor = new SolidBrush(Color.Black);
+
+ protected override void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, j * _size_x, i * _size_y, _size_x, _size_y);
+ }
+ protected override void GenerateMap()
+ {
+ _map = new int[100, 100];
+ _size_x = (float)_width / _map.GetLength(0);
+ _size_y = (float)_height / _map.GetLength(1);
+ int counter = 0;
+ for (int i = 0; i < _map.GetLength(0); ++i)
+ {
+ for (int j = 0; j < _map.GetLength(1); ++j)
+ {
+ _map[i, j] = _freeRoad;
+ }
+ }
+ for (int i = 0; i < _map.GetLength(0); ++i)
+ {
+ _map[i, _map.GetLength(1) / 2] = _barrier;
+ _map[i, _map.GetLength(1) - 1] = _barrier;
+ }
+ for (int j = 0; j < _map.GetLength(1); ++j)
+ {
+ _map[_map.GetLength(0) - 1, j] = _barrier;
+ }
+ while (counter < 45)
+ {
+ 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/WarmlyShip/WarmlyShip/SimpleMap.cs b/WarmlyShip/WarmlyShip/SimpleMap.cs
new file mode 100644
index 0000000..88ac895
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/SimpleMap.cs
@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyShip
+{
+ 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, j * _size_x, i * _size_y, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, j * _size_x, i * _size_y, _size_x, _size_y);
+ }
+ protected override void GenerateMap()
+ {
+ _map = new int[100, 100];
+ _size_x = (float)_width / _map.GetLength(0);
+ _size_y = (float)_height / _map.GetLength(1);
+ int counter = 0;
+ for (int i = 0; i < _map.GetLength(0); ++i)
+ {
+ for (int j = 0; j < _map.GetLength(1); ++j)
+ {
+ _map[i, j] = _freeRoad;
+ }
+ }
+ while (counter < 50)
+ {
+ int x = _random.Next(0, 100);
+ int y = _random.Next(0, 100);
+ if (_map[x, y] == _freeRoad)
+ {
+ _map[x, y] = _barrier;
+ counter++;
+ }
+ }
+ }
+ }
+}