diff --git a/AircraftCarrier/AircraftCarrier/AbstractMap.cs b/AircraftCarrier/AircraftCarrier/AbstractMap.cs
new file mode 100644
index 0000000..667881f
--- /dev/null
+++ b/AircraftCarrier/AircraftCarrier/AbstractMap.cs
@@ -0,0 +1,155 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftCarrier
+{
+ 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 drawningObject)
+ {
+ _width = width;
+ _height = height;
+ _drawingObject = drawningObject;
+ GenerateMap();
+ while (!SetObjectOnMap())
+ {
+ GenerateMap();
+ }
+ return DrawMapWithObject();
+ }
+ public Bitmap MoveObject(Direction direction)
+ {
+ if (true)
+ {
+ _drawingObject.MoveObject(direction);
+ }
+ (float Left, float Right, float Top, float Bottom) = _drawingObject.GetCurrentPosition();
+
+ if (Check(Left, Right, Top, Bottom) != 0)
+ {
+ _drawingObject.MoveObject(GetOpositDirection(direction));
+ }
+ return DrawMapWithObject();
+ }
+
+ private Direction GetOpositDirection(Direction dir)
+ {
+ switch (dir)
+ {
+ case Direction.None:
+ return Direction.None;
+ 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 (_drawingObject == null || _map == null)
+ {
+ return false;
+ }
+ int x = _random.Next(0, 10);
+ int y = _random.Next(0, 10);
+ _drawingObject.SetObject(x, y, _width, _height);
+ (float Left, float Right, float Top, float Bottom) = _drawingObject.GetCurrentPosition();
+ float nowX = Left;
+ float nowY = Right;
+ float lenX = Top - Left;
+ float lenY = Bottom - Right;
+ while (Check(nowX, nowY, nowX + lenX, nowY + lenY) != 2)
+ {
+ int result;
+ do
+ {
+ result = Check(nowX, nowY, nowX + lenX, nowY + lenY);
+ if (result == 0)
+ {
+ _drawingObject.SetObject((int)nowX, (int)nowY, _width, _height);
+ return true;
+ }
+ else
+ {
+ nowX += _size_x;
+ }
+ } while (result != 2);
+ nowX = x;
+ nowY += _size_y;
+ }
+ return false;
+ }
+
+ private int Check(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);
+ int endY = (int)(Bottom / _size_y);
+ if (startX < 0 || startY < 0 || endX >= _map.GetLength(0) || endY >= _map.GetLength(0))
+ {
+ return 2;
+ }
+ for (int i = startX; i <= endX; i++)
+ {
+ for (int j = startY; j <= endY; j++)
+ {
+ if (_map[i, j] == _barrier)
+ {
+ return 1;
+ }
+ }
+ }
+ return 0;
+ }
+
+ 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.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/AircraftCarrier/AircraftCarrier/Direction.cs b/AircraftCarrier/AircraftCarrier/Direction.cs
index ec2abc9..0f48c8f 100644
--- a/AircraftCarrier/AircraftCarrier/Direction.cs
+++ b/AircraftCarrier/AircraftCarrier/Direction.cs
@@ -11,6 +11,7 @@ namespace AircraftCarrier
///
internal enum Direction
{
+ None = 0,
Up = 1,
Down = 2,
Left = 3,
diff --git a/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs
new file mode 100644
index 0000000..cea3477
--- /dev/null
+++ b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs
@@ -0,0 +1,100 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftCarrier
+{
+ internal class DrawingAircraftCarrier : DrawingWarship
+ {
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес военного корабля
+ /// Цвет основной палубы
+ /// Дополнительный цвет
+ /// Признак наличия боковой площадки
+ /// Признак наличия рубки
+ /// Признак наличия усиленного двигателя
+ public DrawingAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool сabin, bool superEngine) :
+ base(speed, weight, bodyColor, 114, 40)
+ {
+ Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, сabin, superEngine);
+ }
+
+ public override void DrawTransport(Graphics g)
+ {
+ if(Warship is not EntityAircraftCarrier aircraftCarrier)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush dopBrush = new SolidBrush(aircraftCarrier.DopColor);
+ Brush brGray = new SolidBrush(Color.Gray);
+ Brush brRed = new SolidBrush(Color.Red);
+ Brush br = new SolidBrush(Warship?.BodyColor ?? Color.White);
+
+ if (aircraftCarrier.BodyKit)
+ {
+ //боковая площадка
+ PointF pointAircraftCarrier1 = new PointF(_startPosX + 94, _startPosY + 40);
+ PointF pointAircraftCarrier2 = new PointF(_startPosX + 74, _startPosY + 60);
+ PointF pointAircraftCarrier3 = new PointF(_startPosX + 24, _startPosY + 60);
+ PointF pointAircraftCarrier4 = new PointF(_startPosX + 4, _startPosY + 40);
+
+ PointF[] PointsAircraftCarrier =
+ {
+ pointAircraftCarrier1, pointAircraftCarrier2, pointAircraftCarrier3, pointAircraftCarrier4
+ };
+ g.FillPolygon(br, PointsAircraftCarrier);
+ g.DrawPolygon(pen, PointsAircraftCarrier);
+
+ //полоса
+ PointF pontStartLine1 = new PointF(_startPosX + 4, _startPosY);
+ PointF pontStartLine2 = new PointF(_startPosX + 15, _startPosY);
+ PointF pontStartLine3 = new PointF(_startPosX + 74, _startPosY + 60);
+ PointF pontStartLine4 = new PointF(_startPosX + 59, _startPosY + 60);
+
+ PointF[] PointsStartLine =
+ {
+ pontStartLine1, pontStartLine2, pontStartLine3, pontStartLine4
+ };
+ g.FillPolygon(brGray, PointsStartLine);
+ g.DrawPolygon(pen, PointsStartLine);
+ }
+
+ if (aircraftCarrier.SuperEngine)
+ {
+ g.FillEllipse(brRed, _startPosX, _startPosY, 10, 10);
+ g.DrawEllipse(pen, _startPosX, _startPosY, 10, 10);
+
+ g.FillEllipse(brRed, _startPosX, _startPosY + 10, 10, 10);
+ g.DrawEllipse(pen, _startPosX, _startPosY + 10, 10, 10);
+
+ g.FillEllipse(brRed, _startPosX, _startPosY + 18, 10, 10);
+ g.DrawEllipse(pen, _startPosX, _startPosY + 18, 10, 10);
+
+ g.FillEllipse(brRed, _startPosX, _startPosY + 30, 10, 10);
+ g.DrawEllipse(pen, _startPosX, _startPosY + 30, 10, 10);
+ }
+
+ base.DrawTransport(g);
+
+ if (aircraftCarrier.Сabin)
+ {
+ g.FillEllipse(brGray, _startPosX + 10, _startPosY + 15, 10, 10);
+ g.DrawEllipse(pen, _startPosX + 10, _startPosY + 15, 10, 10);
+
+ g.FillEllipse(brGray, _startPosX + 20, _startPosY + 15, 10, 10);
+ g.DrawEllipse(pen, _startPosX + 20, _startPosY + 15, 10, 10);
+
+ g.FillRectangle(brGray, _startPosX + 15, _startPosY + 15, 10, 10);
+ g.DrawRectangle(pen, _startPosX + 15, _startPosY + 15, 10, 10);
+ }
+ }
+ }
+
+}
diff --git a/AircraftCarrier/AircraftCarrier/DrawingObjectWarship.cs b/AircraftCarrier/AircraftCarrier/DrawingObjectWarship.cs
new file mode 100644
index 0000000..104b2e0
--- /dev/null
+++ b/AircraftCarrier/AircraftCarrier/DrawingObjectWarship.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftCarrier
+{
+ internal class DrawingObjectWarship : IDrawingObject
+ {
+ private DrawingWarship _warship = null;
+
+ public DrawingObjectWarship(DrawingWarship warship)
+ {
+ _warship = warship;
+ }
+ public float Step => _warship?.Warship?.Step ?? 0;
+
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return _warship?.GetCurrentPosition() ?? default;
+ }
+
+ public void MoveObject(Direction direction)
+ {
+ _warship?.MoveTransport(direction);
+ }
+
+ public void SetObject(int x, int y, int width, int height)
+ {
+ _warship.SetPosition(x, y, width, height);
+ }
+
+ void IDrawingObject.DrawningObject(Graphics g)
+ {
+ _warship.DrawTransport(g);
+ }
+ }
+}
diff --git a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs
index e5fdddb..0cf2699 100644
--- a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs
+++ b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs
@@ -14,15 +14,15 @@ namespace AircraftCarrier
///
/// Класс-сущность
///
- public EntityWarship Warship { get; private set; }
+ public EntityWarship Warship { get; protected set; }
///
/// Левая координата отрисовки военного корабля
///
- private float _startPosX;
+ protected float _startPosX;
///
/// Верхняя кооридната отрисовки военного корабля
///
- private float _startPosY;
+ protected float _startPosY;
///
/// Ширина окна отрисовки
///
@@ -34,7 +34,7 @@ namespace AircraftCarrier
///
/// Ширина отрисовки военного корабля
///
- private readonly int _warshipWidth = 94;
+ private readonly int _warshipWidth = 114;
///
/// Высота отрисовки военного корабля
///
@@ -45,10 +45,24 @@ namespace AircraftCarrier
/// Скорость
/// Вес военного корабля
/// Цвет главной палубы
- public void Init(int speed, float weight, Color bodyColor)
+ public DrawingWarship(int speed, float weight, Color bodyColor)
{
- Warship = new EntityWarship();
- Warship.Init(speed, weight, bodyColor);
+ Warship = new EntityWarship(speed, weight, bodyColor);
+ }
+
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес военного корабля
+ /// Цвет главной палубы
+ /// Ширина отрисовки автомобиля
+ /// Высота отрисовки автомобиля
+ protected DrawingWarship(int speed, float weight, Color bodyColor, int warshipWidth, int warshipHeight) :
+ this(speed, weight, bodyColor)
+ {
+ _warshipWidth = warshipWidth;
+ _warshipHeight = warshipHeight;
}
///
/// Установка позиции военного корабля
@@ -59,27 +73,14 @@ namespace AircraftCarrier
///
public void SetPosition(int x, int y, int width, int height)
{
- _startPosX = x;
- _startPosY = y;
- _pictureWidth = width;
- _pictureHeight = height;
-
- if (width < _warshipWidth)
+ if (width >= x + _warshipWidth && height >= y + _warshipHeight && x >= 0 && y >= 0)
{
- width = _warshipWidth;
- }
- if (height < _warshipHeight)
- {
- height = _warshipHeight;
- }
- if(x + _warshipWidth > width)
- {
- _startPosX -= x + _warshipWidth - width;
- }
- if (y + _warshipHeight > height)
- {
- _pictureHeight -= y + _warshipHeight - height;
+ _startPosX = x;
+ _startPosY = y;
+ _pictureWidth = width;
+ _pictureHeight = height;
}
+ else return;
}
///
/// Изменение направления пермещения
@@ -102,14 +103,14 @@ namespace AircraftCarrier
break;
//влево
case Direction.Left:
- if(_startPosX - Warship.Step > 0)
+ if(_startPosX - Warship.Step >= 0)
{
_startPosX -= Warship.Step;
}
break;
//вверх
case Direction.Up:
- if (_startPosY - Warship.Step > 0)
+ if (_startPosY - Warship.Step >= 0)
{
_startPosY -= Warship.Step;
}
@@ -128,7 +129,7 @@ namespace AircraftCarrier
/// Отрисовка военного корабля
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@@ -136,38 +137,37 @@ namespace AircraftCarrier
return;
}
Pen pen = new(Color.Black);
-
- //границы военного корабля
- PointF point1 = new PointF(_startPosX, _startPosY);
- PointF point2 = new PointF(_startPosX + 74, _startPosY);
- PointF point3 = new PointF(_startPosX + 94, _startPosY + 20);
- PointF point4 = new PointF(_startPosX + 74, _startPosY + 40);
- PointF point5 = new PointF(_startPosX, _startPosY + 40);
-
- PointF[] curvePoints =
- {
- point1, point2, point3, point4, point5
- };
- g.DrawPolygon(pen, curvePoints);
+ Brush brOrange = new SolidBrush(Color.Orange);
+ Brush brPurple = new SolidBrush(Color.RebeccaPurple);
//главная палуба
Brush br = new SolidBrush(Warship?.BodyColor ?? Color.White);
- g.FillPolygon(br, curvePoints);
+ PointF pointWarship1 = new PointF(_startPosX + 4, _startPosY);
+ PointF pointWarship2 = new PointF(_startPosX + 94, _startPosY);
+ PointF pointWarship3 = new PointF(_startPosX + 114, _startPosY + 20);
+ PointF pointWarship4 = new PointF(_startPosX + 94, _startPosY + 40);
+ PointF pointWarship5 = new PointF(_startPosX + 4, _startPosY + 40);
- //мачта
- Brush brWhite = new SolidBrush(Color.White);
- g.FillEllipse(brWhite, _startPosX + 59, _startPosY + 13, 15, 15);
+ PointF[] PointsWarship =
+ {
+ pointWarship1, pointWarship2, pointWarship3, pointWarship4, pointWarship5
+ };
+ g.FillPolygon(br, PointsWarship);
+ g.DrawPolygon(pen, PointsWarship);
+
+ //мачта
+ g.FillEllipse(brOrange, _startPosX + 79, _startPosY + 13, 15, 15);
//границы мачты
- g.DrawEllipse(pen, _startPosX + 59, _startPosY + 13, 15, 15);
+ g.DrawEllipse(pen, _startPosX + 79, _startPosY + 13, 15, 15);
- //палуба
- g.FillRectangle(brWhite, _startPosX + 44, _startPosY + 10, 10, 20);
- g.FillRectangle(brWhite, _startPosX + 24, _startPosY + 15, 20, 10);
+ //палуба
+ g.FillRectangle(brPurple, _startPosX + 64, _startPosY + 10, 10, 20);
+ g.FillRectangle(brPurple, _startPosX + 44, _startPosY + 15, 20, 10);
//границы палуба
- g.DrawRectangle(pen, _startPosX + 44, _startPosY + 10, 10, 20);
- g.DrawRectangle(pen, _startPosX + 24, _startPosY + 15, 20, 10);
+ g.DrawRectangle(pen, _startPosX + 64, _startPosY + 10, 10, 20);
+ g.DrawRectangle(pen, _startPosX + 44, _startPosY + 15, 20, 10);
//двигатели
Brush brBlack = new SolidBrush(Color.Black);
@@ -199,6 +199,13 @@ namespace AircraftCarrier
_startPosY = _pictureHeight.Value - _warshipHeight;
}
}
-
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return (_startPosX, _startPosY, _startPosX + _warshipWidth, _startPosY + _warshipHeight);
+ }
}
}
diff --git a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs
new file mode 100644
index 0000000..6f75160
--- /dev/null
+++ b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftCarrier
+{
+ internal class EntityAircraftCarrier : EntityWarship
+ {
+ ///
+ /// Дополнительный цвет
+ ///
+ public Color DopColor { get; private set; }
+ ///
+ /// Признак наличия боковой площадки
+ ///
+ public bool BodyKit { get; private set; }
+ ///
+ /// Признак наличия рубки
+ ///
+ public bool Сabin { get; private set; }
+ ///
+ /// Признак наличия усиленного двигателя
+ ///
+ public bool SuperEngine { get; private set; }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес военного корабля
+ /// Цвет основной палубы
+ /// Дополнительный цвет
+ /// Признак наличия боковой площадки
+ /// Признак наличия рубки
+ /// Признак наличия усиленного двигателя
+ public EntityAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool сabin, bool superEngine) :
+ base(speed, weight, bodyColor)
+ {
+ DopColor = dopColor;
+ BodyKit = bodyKit;
+ Сabin = сabin;
+ SuperEngine = superEngine;
+ }
+ }
+}
diff --git a/AircraftCarrier/AircraftCarrier/EntityWarship.cs b/AircraftCarrier/AircraftCarrier/EntityWarship.cs
index 2c0f4f5..b5d037c 100644
--- a/AircraftCarrier/AircraftCarrier/EntityWarship.cs
+++ b/AircraftCarrier/AircraftCarrier/EntityWarship.cs
@@ -33,14 +33,12 @@ namespace AircraftCarrier
///
///
///
- public void Init(int speed, float weight, Color bodyColor)
+ public EntityWarship(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor;
}
-
-
}
}
diff --git a/AircraftCarrier/AircraftCarrier/FormMap.Designer.cs b/AircraftCarrier/AircraftCarrier/FormMap.Designer.cs
new file mode 100644
index 0000000..ee9bc8b
--- /dev/null
+++ b/AircraftCarrier/AircraftCarrier/FormMap.Designer.cs
@@ -0,0 +1,211 @@
+namespace AircraftCarrier
+{
+ 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.pictureBoxWarship = new System.Windows.Forms.PictureBox();
+ this.statusStrip = 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.buttonDown = 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.buttonCreateModif = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit();
+ this.statusStrip.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // pictureBoxWarship
+ //
+ this.pictureBoxWarship.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxWarship.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxWarship.Name = "pictureBoxWarship";
+ this.pictureBoxWarship.Size = new System.Drawing.Size(768, 426);
+ this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBoxWarship.TabIndex = 0;
+ this.pictureBoxWarship.TabStop = false;
+ //
+ // statusStrip
+ //
+ this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusLabelSpeed,
+ this.toolStripStatusLabelWeight,
+ this.toolStripStatusLabelBodyColor});
+ this.statusStrip.Location = new System.Drawing.Point(0, 426);
+ this.statusStrip.Name = "statusStrip";
+ this.statusStrip.Size = new System.Drawing.Size(768, 22);
+ this.statusStrip.TabIndex = 1;
+ //
+ // toolStripStatusLabelSpeed
+ //
+ this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
+ this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(39, 17);
+ this.toolStripStatusLabelSpeed.Text = "Speed";
+ //
+ // toolStripStatusLabelWeight
+ //
+ this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
+ this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(45, 17);
+ this.toolStripStatusLabelWeight.Text = "Weight";
+ //
+ // toolStripStatusLabelBodyColor
+ //
+ this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
+ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
+ this.toolStripStatusLabelBodyColor.Text = "Color";
+ //
+ // 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, 393);
+ 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);
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowDown;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(686, 386);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 3;
+ this.buttonDown.Text = " ";
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.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::AircraftCarrier.Properties.Resources.ArrowUp;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(686, 350);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 4;
+ this.buttonUp.Text = " ";
+ 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::AircraftCarrier.Properties.Resources.ArrowLeft;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(650, 386);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.TabIndex = 5;
+ this.buttonLeft.Text = " ";
+ 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::AircraftCarrier.Properties.Resources.ArrowRight;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(722, 386);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 6;
+ this.buttonRight.Text = " ";
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Location = new System.Drawing.Point(93, 393);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(92, 23);
+ this.buttonCreateModif.TabIndex = 7;
+ this.buttonCreateModif.Text = "Modification";
+ 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 = 8;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged);
+ //
+ // FormMap
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(768, 448);
+ this.Controls.Add(this.comboBoxSelectorMap);
+ this.Controls.Add(this.buttonCreateModif);
+ this.Controls.Add(this.buttonRight);
+ this.Controls.Add(this.buttonLeft);
+ this.Controls.Add(this.buttonUp);
+ this.Controls.Add(this.buttonDown);
+ this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.pictureBoxWarship);
+ this.Controls.Add(this.statusStrip);
+ this.Name = "FormMap";
+ this.Text = "Карта";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).EndInit();
+ this.statusStrip.ResumeLayout(false);
+ this.statusStrip.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxWarship;
+ private StatusStrip statusStrip;
+ private ToolStripStatusLabel toolStripStatusLabelSpeed;
+ private ToolStripStatusLabel toolStripStatusLabelWeight;
+ private ToolStripStatusLabel toolStripStatusLabelBodyColor;
+ private Button buttonCreate;
+ private Button buttonDown;
+ private Button buttonUp;
+ private Button buttonLeft;
+ private Button buttonRight;
+ private Button buttonCreateModif;
+ private ComboBox comboBoxSelectorMap;
+ }
+}
\ No newline at end of file
diff --git a/AircraftCarrier/AircraftCarrier/FormMap.cs b/AircraftCarrier/AircraftCarrier/FormMap.cs
new file mode 100644
index 0000000..acd3cfe
--- /dev/null
+++ b/AircraftCarrier/AircraftCarrier/FormMap.cs
@@ -0,0 +1,104 @@
+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 AircraftCarrier
+{
+ public partial class FormMap : Form
+ {
+ private AbstractMap _abstractMap;
+ public FormMap()
+ {
+ InitializeComponent();
+ _abstractMap = new SimpleMap();
+ }
+ ///
+ /// Заполнение информации по объекту
+ ///
+ ///
+ private void SetData(DrawingWarship warship)
+ {
+ toolStripStatusLabelSpeed.Text = $"Скорость: {warship.Warship.Speed}";
+ toolStripStatusLabelWeight.Text = $"Вес: {warship.Warship.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет: {warship.Warship.BodyColor.Name}";
+ pictureBoxWarship.Image = _abstractMap.CreateMap(pictureBoxWarship.Width, pictureBoxWarship.Height,
+ new DrawingObjectWarship(warship));
+ }
+ ///
+ /// Обработка нажатия кнопки "Create"
+ ///
+ ///
+ ///
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var warship = new DrawingWarship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData(warship);
+ }
+ ///
+ /// Обработка нажатия стрелочек
+ ///
+ ///
+ ///
+ 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;
+ }
+ pictureBoxWarship.Image = _abstractMap?.MoveObject(dir);
+ }
+
+ ///
+ /// Обработка нажатия кнопки "Modification"
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var car = new DrawingAircraftCarrier(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(car);
+ }
+ ///
+ /// Смена карты
+ ///
+ ///
+ ///
+ private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ _abstractMap = new SimpleMap();
+ break;
+ case "Преграды-линии":
+ _abstractMap = new LineMap();
+ break;
+ }
+ }
+ }
+}
diff --git a/AircraftCarrier/AircraftCarrier/FormMap.resx b/AircraftCarrier/AircraftCarrier/FormMap.resx
new file mode 100644
index 0000000..2c0949d
--- /dev/null
+++ b/AircraftCarrier/AircraftCarrier/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/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs b/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs
index 4e7f9f8..854abe8 100644
--- a/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs
+++ b/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs
@@ -38,6 +38,7 @@
this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@@ -47,7 +48,7 @@
this.pictureBoxWarship.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxWarship.Location = new System.Drawing.Point(0, 0);
this.pictureBoxWarship.Name = "pictureBoxWarship";
- this.pictureBoxWarship.Size = new System.Drawing.Size(510, 426);
+ this.pictureBoxWarship.Size = new System.Drawing.Size(768, 426);
this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxWarship.TabIndex = 0;
this.pictureBoxWarship.TabStop = false;
@@ -61,7 +62,7 @@
this.toolStripStatusLabelBodyColor});
this.statusStrip.Location = new System.Drawing.Point(0, 426);
this.statusStrip.Name = "statusStrip";
- this.statusStrip.Size = new System.Drawing.Size(510, 22);
+ this.statusStrip.Size = new System.Drawing.Size(768, 22);
this.statusStrip.TabIndex = 1;
//
// toolStripStatusLabelSpeed
@@ -98,7 +99,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(428, 386);
+ this.buttonDown.Location = new System.Drawing.Point(686, 386);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 3;
@@ -111,7 +112,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(428, 350);
+ this.buttonUp.Location = new System.Drawing.Point(686, 350);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 4;
@@ -124,7 +125,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(392, 386);
+ this.buttonLeft.Location = new System.Drawing.Point(650, 386);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 5;
@@ -137,7 +138,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(464, 386);
+ this.buttonRight.Location = new System.Drawing.Point(722, 386);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 6;
@@ -145,11 +146,22 @@
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Location = new System.Drawing.Point(93, 393);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(92, 23);
+ this.buttonCreateModif.TabIndex = 7;
+ this.buttonCreateModif.Text = "Modification";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
// FormWarship
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(510, 448);
+ this.ClientSize = new System.Drawing.Size(768, 448);
+ this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
@@ -179,5 +191,6 @@
private Button buttonUp;
private Button buttonLeft;
private Button buttonRight;
+ private Button buttonCreateModif;
}
}
\ No newline at end of file
diff --git a/AircraftCarrier/AircraftCarrier/FormWarship.cs b/AircraftCarrier/AircraftCarrier/FormWarship.cs
index 3866bc7..1d0e4a3 100644
--- a/AircraftCarrier/AircraftCarrier/FormWarship.cs
+++ b/AircraftCarrier/AircraftCarrier/FormWarship.cs
@@ -18,6 +18,17 @@ namespace AircraftCarrier
pictureBoxWarship.Image = bmp;
}
///
+ ///
+ ///
+ private void SetData()
+ {
+ Random rnd = new();
+ _warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height);
+ toolStripStatusLabelSpeed.Text = $": {_warship.Warship.Speed}";
+ toolStripStatusLabelWeight.Text = $": {_warship.Warship.Weight}";
+ toolStripStatusLabelBodyColor.Text = $": {_warship.Warship.BodyColor.Name}";
+ }
+ ///
/// "Create"
///
///
@@ -25,15 +36,15 @@ namespace AircraftCarrier
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _warship = new DrawingWarship();
- _warship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- _warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height);
- toolStripStatusLabelSpeed.Text = $": {_warship.Warship.Speed}";
- toolStripStatusLabelWeight.Text = $": {_warship.Warship.Weight}";
- toolStripStatusLabelBodyColor.Text = $": {_warship.Warship.BodyColor.Name}";
+ _warship = new DrawingWarship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData();
Draw();
}
-
+ ///
+ ///
+ ///
+ ///
+ ///
private void ButtonMove_Click(object sender, EventArgs e)
{
string name = ((Button)sender)?.Name ?? string.Empty;
@@ -64,5 +75,21 @@ namespace AircraftCarrier
_warship?.ChangeBorders(pictureBoxWarship.Width,pictureBoxWarship.Height);
Draw();
}
+ ///
+ /// "Modification"
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _warship = new DrawingAircraftCarrier(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();
+
+ }
}
}
\ No newline at end of file
diff --git a/AircraftCarrier/AircraftCarrier/IDrawingObject.cs b/AircraftCarrier/AircraftCarrier/IDrawingObject.cs
new file mode 100644
index 0000000..c22daf9
--- /dev/null
+++ b/AircraftCarrier/AircraftCarrier/IDrawingObject.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftCarrier
+{
+ ///
+ /// Интерфейс для работы с объектом, прорисовываемым на форме
+ ///
+ internal interface IDrawingObject
+ {
+ ///
+ /// Шаг перемещения объекта
+ ///
+ 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/AircraftCarrier/AircraftCarrier/LineMap.cs b/AircraftCarrier/AircraftCarrier/LineMap.cs
new file mode 100644
index 0000000..2853b76
--- /dev/null
+++ b/AircraftCarrier/AircraftCarrier/LineMap.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace AircraftCarrier
+{
+ internal class LineMap : AbstractMap
+ {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierColor = new SolidBrush(Color.Brown);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush waterColor = new SolidBrush(Color.Blue);
+ protected override void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(waterColor, i * _size_x, j * _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;
+ }
+ }
+ bool flag = true;
+ while (counter < 20)
+ {
+ int lineX = _random.Next(11, 89);
+ int lineY = _random.Next(11, 89);
+
+ if (flag)
+ {
+ for (int i = lineY; i <= lineY + 10; i++)
+ _map[lineX, i] = _barrier;
+ flag = false;
+ }
+ else
+ {
+ for (int i = lineX; i <= lineX + 10; i++)
+ _map[i, lineY] = _barrier;
+ flag = true;
+ }
+ counter++;
+ }
+ }
+ }
+}
diff --git a/AircraftCarrier/AircraftCarrier/Program.cs b/AircraftCarrier/AircraftCarrier/Program.cs
index 8b302c0..4080ebd 100644
--- a/AircraftCarrier/AircraftCarrier/Program.cs
+++ b/AircraftCarrier/AircraftCarrier/Program.cs
@@ -11,7 +11,7 @@ namespace AircraftCarrier
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormWarship());
+ Application.Run(new FormMap());
}
}
}
\ No newline at end of file
diff --git a/AircraftCarrier/AircraftCarrier/SimpleMap.cs b/AircraftCarrier/AircraftCarrier/SimpleMap.cs
new file mode 100644
index 0000000..190d99f
--- /dev/null
+++ b/AircraftCarrier/AircraftCarrier/SimpleMap.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftCarrier
+{
+ ///
+ /// Простая реализация абсрактного класса AbstractMap
+ ///
+ internal class SimpleMap : AbstractMap
+ {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierColor = new SolidBrush(Color.Brown);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush waterColor = new SolidBrush(Color.Blue);
+
+ 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(waterColor, 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 < 50)
+ {
+ int x = _random.Next(0, 100);
+ int y = _random.Next(0, 100);
+ if (_map[x, y] == _freeRoad)
+ {
+ _map[x, y] = _barrier;
+ counter++;
+ }
+ }
+ }
+ }
+}