diff --git a/Stormtrooper/Stormtrooper/AbstractMap.cs b/Stormtrooper/Stormtrooper/AbstractMap.cs
new file mode 100644
index 0000000..29c10ef
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/AbstractMap.cs
@@ -0,0 +1,135 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Stormtrooper
+{
+ 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;
+
+ private bool CheckEnoughPlace(float x, float y)
+ {
+ int right = Convert.ToInt32((_drawningObject.GetCurrentPosition().Right + x) / _size_x) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Right + x) / _size_x) : 0;
+ int left = Convert.ToInt32((_drawningObject.GetCurrentPosition().Left + x) / _size_x) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Left + x) / _size_x) : 0;
+ int up = Convert.ToInt32((_drawningObject.GetCurrentPosition().Top + y) / _size_y) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Top + y) / _size_y) : 0;
+ int down = Convert.ToInt32((_drawningObject.GetCurrentPosition().Bottom + y) / _size_y) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Bottom + y) / _size_y) : 0;
+ for (int i = left; i <= right; i++)
+ {
+ for (int j = up; j <= down; j++)
+ {
+ if (_map[i, j] == _barrier)
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
+ {
+ _width = width;
+ _height = height;
+ _drawningObject = drawningObject;
+ GenerateMap();
+ while (!SetObjectOnMap())
+ {
+ GenerateMap();
+ }
+ return DrawMapWithObject();
+ }
+ public Bitmap MoveObject(Direction direction)
+ {
+ // TODO проверка, что объект может переместится в требуемом направлении
+ bool place = false;
+ switch (direction)
+ {
+ case Direction.Up:
+ place = CheckEnoughPlace(0, _drawningObject.Step * -1);
+ break;
+ case Direction.Down:
+ place = CheckEnoughPlace(0, _drawningObject.Step);
+ break;
+ case Direction.Left:
+ place = CheckEnoughPlace(_drawningObject.Step * -1, 0);
+ break;
+ case Direction.Right:
+ place = CheckEnoughPlace(_drawningObject.Step, 0);
+ break;
+ }
+ if (place)
+ {
+ _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);
+ // TODO првоерка, что объект не "накладывается" на закрытые участки
+ while (!CheckEnoughPlace(0, 0))
+ {
+ x += 10;
+ if (x >= _width)
+ {
+ if (y <= _height)
+ {
+ y += 10;
+ x = 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ _drawningObject.SetObject(x, y, _width, _height);
+ }
+ 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/Stormtrooper/Stormtrooper/Direction.cs b/Stormtrooper/Stormtrooper/Direction.cs
index 53ade33..ad7316d 100644
--- a/Stormtrooper/Stormtrooper/Direction.cs
+++ b/Stormtrooper/Stormtrooper/Direction.cs
@@ -8,6 +8,7 @@ namespace Stormtrooper
{
internal enum Direction
{
+ None = 0,
Up = 1,
Down = 2,
Left = 3,
diff --git a/Stormtrooper/Stormtrooper/DrawningObject.cs b/Stormtrooper/Stormtrooper/DrawningObject.cs
new file mode 100644
index 0000000..d7ac06d
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/DrawningObject.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Stormtrooper
+{
+ internal class DrawningObjectStormtrooper : IDrawningObject
+ {
+ private DrowningStormtrooper _stormtrooper = null;
+ public DrawningObjectStormtrooper(DrowningStormtrooper stormtrooper)
+ {
+ _stormtrooper = stormtrooper;
+ }
+ public float Step => _stormtrooper?.Stormtrooper?.Step ?? 0;
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return _stormtrooper?.GetCurrentPosition() ?? default;
+ }
+ public void MoveObject(Direction direction)
+ {
+ _stormtrooper?.MoveTransport(direction);
+ }
+ public void SetObject(int x, int y, int width, int height)
+ {
+ _stormtrooper.SetPosition(x, y, width, height);
+ }
+ public void DrawningObject(Graphics g)
+ {
+ _stormtrooper?.DrawTransport(g);
+ }
+
+ }
+}
diff --git a/Stormtrooper/Stormtrooper/DrowningStormtrooper.cs b/Stormtrooper/Stormtrooper/DrowningStormtrooper.cs
index cb21c3f..db9f014 100644
--- a/Stormtrooper/Stormtrooper/DrowningStormtrooper.cs
+++ b/Stormtrooper/Stormtrooper/DrowningStormtrooper.cs
@@ -8,15 +8,18 @@ namespace Stormtrooper
{
internal class DrowningStormtrooper
{
- public EntityStormtrooper Stormtrooper { private set; get; }
+ ///
+ /// Класс-сущность
+ ///
+ public EntityStormtrooper Stormtrooper { protected set; get; }
///
/// Левая координата отрисовки автомобиля
///
- private float _startPosX;
+ protected float _startPosX;
///
/// Верхняя кооридната отрисовки автомобиля
///
- private float _startPosY;
+ protected float _startPosY;
///
/// Ширина окна отрисовки
///
@@ -39,11 +42,17 @@ namespace Stormtrooper
/// Скорость
/// Вес автомобиля
/// Цвет кузова
- public void Init(int speed, float weight, Color bodyColor)
+ public DrowningStormtrooper(int speed, float weight, Color bodyColor)
{
- Stormtrooper = new EntityStormtrooper();
- Stormtrooper.Init(speed, weight, bodyColor);
+ Stormtrooper = new EntityStormtrooper(speed, weight, bodyColor);
}
+ protected DrowningStormtrooper(int speed, float weight, Color bodyColor, int StormtrooperWidth, int StormtrooperHeight) :
+ this(speed, weight, bodyColor)
+ {
+ _stormtrooperWidth = StormtrooperWidth;
+ _stormtrooperHeight = StormtrooperHeight;
+ }
+
///
/// Установка позиции автомобиля
///
@@ -53,7 +62,7 @@ namespace Stormtrooper
/// Высота картинки
public void SetPosition(int x, int y, int width, int height)
{
- if(x > 0 && y > 0 && width >= _stormtrooperWidth && height >= _stormtrooperHeight && x + _stormtrooperWidth < width && y + _stormtrooperHeight < height)
+ if(x >= 0 && y >= 0 && width >= x + _stormtrooperWidth && height >= y + _stormtrooperHeight)
{
_startPosX = x;
_startPosY = y;
@@ -109,7 +118,7 @@ namespace Stormtrooper
/// Отрисовка автомобиля
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@@ -198,22 +207,7 @@ namespace Stormtrooper
g.FillPolygon(Brushes.Black, all_stoormtrooper);
- /*g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20);
- g.DrawEllipse(pen, _startPosX, _startPosY + 30, 20, 20);
- g.DrawEllipse(pen, _startPosX + 70, _startPosY, 20, 20);
- g.DrawEllipse(pen, _startPosX + 70, _startPosY + 30, 20, 20);
- g.DrawRectangle(pen, _startPosX - 1, _startPosY + 10, 10, 30);
- g.DrawRectangle(pen, _startPosX + 80, _startPosY + 10, 10, 30);
- g.DrawRectangle(pen, _startPosX + 10, _startPosY - 1, 70, 52);
- //задние фары
- Brush brRed = new SolidBrush(Color.Red);
- g.FillEllipse(brRed, _startPosX, _startPosY, 20, 20);
- g.FillEllipse(brRed, _startPosX, _startPosY + 30, 20, 20);
- //передние фары
- Brush brYellow = new SolidBrush(Color.Yellow);
- g.FillEllipse(brYellow, _startPosX + 70, _startPosY, 20, 20);
- g.FillEllipse(brYellow, _startPosX + 70, _startPosY + 30, 20, 20);*/
- //кузов
+
Brush br = new SolidBrush(Stormtrooper?.BodyColor ?? Color.Black);
point1 = new PointF(_startPosX + 30, _startPosY + 50);
point2 = new PointF(_startPosX + 40, _startPosY + 10);
@@ -249,19 +243,7 @@ namespace Stormtrooper
g.FillPolygon(Brushes.Brown, cabin);
- /*g.FillRectangle(br, _startPosX, _startPosY + 10, 10, 30);
- g.FillRectangle(br, _startPosX + 80, _startPosY + 10, 10, 30);
- g.FillRectangle(br, _startPosX + 10, _startPosY, 70, 50);
- //стекла
- Brush brBlue = new SolidBrush(Color.LightBlue);
- g.FillRectangle(brBlue, _startPosX + 60, _startPosY + 5, 5, 40);
- g.FillRectangle(brBlue, _startPosX + 20, _startPosY + 5, 5, 40);
- g.FillRectangle(brBlue, _startPosX + 25, _startPosY + 3, 35, 2);
- g.FillRectangle(brBlue, _startPosX + 25, _startPosY + 46, 35, 2);
- //выделяем рамкой крышу
- g.DrawRectangle(pen, _startPosX + 25, _startPosY + 5, 35, 40);
- g.DrawRectangle(pen, _startPosX + 65, _startPosY + 10, 25, 30);
- g.DrawRectangle(pen, _startPosX, _startPosY + 10, 15, 30);*/
+
}
///
/// Смена границ формы отрисовки
@@ -287,6 +269,9 @@ namespace Stormtrooper
_startPosY = _pictureHeight.Value - _stormtrooperHeight;
}
}
-
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return (_startPosX, _startPosY, _startPosX + _stormtrooperWidth, _startPosY + _stormtrooperHeight);
+ }
}
}
diff --git a/Stormtrooper/Stormtrooper/DrowningSuperStormtrooper.cs b/Stormtrooper/Stormtrooper/DrowningSuperStormtrooper.cs
new file mode 100644
index 0000000..dea7073
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/DrowningSuperStormtrooper.cs
@@ -0,0 +1,146 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Stormtrooper
+{
+ internal class DrowningSuperStormtrooper : DrowningStormtrooper
+ {
+ public DrowningSuperStormtrooper(int speed, float weight, Color bodyColor, Color dopColor, bool bombs, bool rockets, bool sportLine) : base(speed, weight, bodyColor, 90, 120)
+ {
+ Stormtrooper = new EntitySuperStormtrooper(speed, weight, bodyColor, dopColor, bombs, rockets, sportLine);
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (Stormtrooper is not EntitySuperStormtrooper superStormtrooper)
+ {
+ return;
+ }
+
+ Brush redBrush = new SolidBrush(Color.Red);
+ Brush dopBrush = new SolidBrush(superStormtrooper.DopColor);
+
+ if (superStormtrooper.Bombs)
+ {
+ g.FillEllipse(dopBrush, _startPosX + 55, _startPosY + 50, 10, 10);
+ g.FillEllipse(dopBrush, _startPosX + 55, _startPosY + 70, 10, 10);
+
+ PointF point1 = new PointF(_startPosX + 45, _startPosY + 50);
+ PointF point2 = new PointF(_startPosX + 40, _startPosY + 50);
+ PointF point3 = new PointF(_startPosX + 35, _startPosY + 45);
+ PointF point4 = new PointF(_startPosX + 30, _startPosY + 45);
+ PointF point5 = new PointF(_startPosX + 35, _startPosY + 50);
+ PointF point6 = new PointF(_startPosX + 35, _startPosY + 55);
+ PointF point7 = new PointF(_startPosX + 40, _startPosY + 55);
+ PointF point8 = new PointF(_startPosX + 45, _startPosY + 50);
+
+ PointF[] first_bomb =
+ {
+ point1,
+ point2,
+ point3,
+ point4,
+ point5,
+ point6,
+ point7,
+ point8,
+ };
+ g.FillPolygon(dopBrush, first_bomb);
+
+ PointF point9 = new PointF(_startPosX + 45, _startPosY + 80);
+ PointF point10 = new PointF(_startPosX + 40, _startPosY + 75);
+ PointF point11 = new PointF(_startPosX + 35, _startPosY + 75);
+ PointF point12 = new PointF(_startPosX + 35, _startPosY + 80);
+ PointF point13 = new PointF(_startPosX + 30, _startPosY + 85);
+ PointF point14 = new PointF(_startPosX + 35, _startPosY + 85);
+ PointF point15 = new PointF(_startPosX + 40, _startPosY + 80);
+ PointF point16 = new PointF(_startPosX + 45, _startPosY + 80);
+ PointF[] second_bomb =
+ {
+ point9,
+ point10,
+ point11,
+ point12,
+ point13,
+ point14,
+ point15,
+ point16,
+ };
+ g.FillPolygon(dopBrush, second_bomb);
+
+ }
+
+
+
+ _startPosX += 10;
+ _startPosY += 5;
+
+ if (superStormtrooper.Rockets)
+ {
+ PointF point1 = new PointF(_startPosX + 20, _startPosY + 20);
+ PointF point2 = new PointF(_startPosX + 30, _startPosY + 20);
+ PointF point3 = new PointF(_startPosX + 33, _startPosY + 22);
+ PointF point4 = new PointF(_startPosX + 55, _startPosY + 22);
+ PointF point5 = new PointF(_startPosX + 60, _startPosY + 25);
+ PointF point6 = new PointF(_startPosX + 55, _startPosY + 28);
+ PointF point7 = new PointF(_startPosX + 33, _startPosY + 28);
+ PointF point8 = new PointF(_startPosX + 30, _startPosY + 30);
+ PointF point9 = new PointF(_startPosX + 20, _startPosY + 30);
+ PointF point10 = new PointF(_startPosX + 25, _startPosY + 25);
+ PointF point11 = new PointF(_startPosX + 20, _startPosY + 20);
+
+ PointF[] first_rocket =
+ {
+ point1,
+ point2,
+ point3,
+ point4,
+ point5,
+ point6,
+ point7,
+ point8,
+ point9,
+ point10,
+ point11
+ };
+ g.FillPolygon(redBrush, first_rocket);
+
+ PointF point12 = new PointF(_startPosX + 20, _startPosY + 90);
+ PointF point13 = new PointF(_startPosX + 30, _startPosY + 90);
+ PointF point14 = new PointF(_startPosX + 33, _startPosY + 92);
+ PointF point15 = new PointF(_startPosX + 55, _startPosY + 92);
+ PointF point16 = new PointF(_startPosX + 60, _startPosY + 95);
+ PointF point17 = new PointF(_startPosX + 55, _startPosY + 98);
+ PointF point18 = new PointF(_startPosX + 33, _startPosY + 98);
+ PointF point19 = new PointF(_startPosX + 30, _startPosY + 100);
+ PointF point20 = new PointF(_startPosX + 20, _startPosY + 100);
+ PointF point21 = new PointF(_startPosX + 25, _startPosY + 95);
+ PointF point22 = new PointF(_startPosX + 20, _startPosY + 90);
+
+ PointF[] second_rocket =
+ {
+ point12,
+ point13,
+ point14,
+ point15,
+ point16,
+ point17,
+ point18,
+ point19,
+ point20,
+ point21,
+ point22
+ };
+ g.FillPolygon(redBrush, second_rocket);
+
+ }
+
+ base.DrawTransport(g);
+ _startPosX -= 10;
+ _startPosY -= 5;
+
+ }
+ }
+}
diff --git a/Stormtrooper/Stormtrooper/EntityStormtrooper.cs b/Stormtrooper/Stormtrooper/EntityStormtrooper.cs
index e60000a..55e8408 100644
--- a/Stormtrooper/Stormtrooper/EntityStormtrooper.cs
+++ b/Stormtrooper/Stormtrooper/EntityStormtrooper.cs
@@ -28,11 +28,11 @@ namespace Stormtrooper
///
///
///
- public void Init(int speed, float weight, Color bodyColor)
+ public EntityStormtrooper(int speed, float weight, Color bodyColor)
{
Random rnd = new();
- Speed = speed <= 0 ? rnd.Next(500, 1500) : speed;
- Weight = weight <= 0 ? rnd.Next(4, 7) : weight;
+ Speed = speed <= 0 ? rnd.Next(5, 30) : speed;
+ Weight = weight <= 0 ? rnd.Next(30, 100) : weight;
BodyColor = bodyColor;
}
diff --git a/Stormtrooper/Stormtrooper/EntitySuperStormtrooper.cs b/Stormtrooper/Stormtrooper/EntitySuperStormtrooper.cs
new file mode 100644
index 0000000..2ed04fe
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/EntitySuperStormtrooper.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Stormtrooper
+{
+ internal class EntitySuperStormtrooper : EntityStormtrooper
+ {
+ public Color DopColor { get; private set; }
+ ///
+ /// Признак наличия обвеса
+ ///
+ public bool Bombs { get; private set; }
+ ///
+ /// Признак наличия антикрыла
+ ///
+ public bool Rockets { get; private set; }
+ ///
+ /// Признак наличия гоночной полосы
+ ///
+ public bool SportLine { get; private set; }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия бомб
+ /// Признак наличия рокет
+ /// Признак наличия гоночной полосы
+
+ public EntitySuperStormtrooper(int speed, float weight, Color bodyColor, Color dopColor, bool bombs, bool rockets, bool sportLine) :
+ base(speed, weight, bodyColor)
+ {
+ DopColor = dopColor;
+ Bombs = bombs;
+ Rockets = rockets;
+ SportLine = sportLine;
+ }
+ }
+}
diff --git a/Stormtrooper/Stormtrooper/FormMap.Designer.cs b/Stormtrooper/Stormtrooper/FormMap.Designer.cs
new file mode 100644
index 0000000..be0ff03
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/FormMap.Designer.cs
@@ -0,0 +1,208 @@
+namespace Stormtrooper
+{
+ 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.pictureBoxStormtrooper = 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.buttonDown = 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.pictureBoxStormtrooper)).BeginInit();
+ this.statusStrip1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // pictureBoxStormtrooper
+ //
+ this.pictureBoxStormtrooper.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxStormtrooper.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxStormtrooper.Name = "pictureBoxStormtrooper";
+ this.pictureBoxStormtrooper.Size = new System.Drawing.Size(800, 424);
+ this.pictureBoxStormtrooper.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBoxStormtrooper.TabIndex = 0;
+ this.pictureBoxStormtrooper.TabStop = false;
+ //
+ // statusStrip1
+ //
+ this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusLabelSpeed,
+ this.toolStripStatusLabelWeight,
+ this.toolStripStatusLabelBodyColor});
+ this.statusStrip1.Location = new System.Drawing.Point(0, 424);
+ this.statusStrip1.Name = "statusStrip1";
+ this.statusStrip1.Size = new System.Drawing.Size(800, 26);
+ this.statusStrip1.TabIndex = 1;
+ this.statusStrip1.Text = "statusStrip1";
+ //
+ // toolStripStatusLabelSpeed
+ //
+ this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
+ this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20);
+ this.toolStripStatusLabelSpeed.Text = "Скорость:";
+ //
+ // toolStripStatusLabelWeight
+ //
+ this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
+ this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20);
+ this.toolStripStatusLabelWeight.Text = "Вес:";
+ //
+ // toolStripStatusLabelBodyColor
+ //
+ this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
+ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20);
+ 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(31, 364);
+ this.buttonCreate.Name = "buttonCreate";
+ this.buttonCreate.Size = new System.Drawing.Size(94, 29);
+ this.buttonCreate.TabIndex = 2;
+ this.buttonCreate.Text = "Create";
+ this.buttonCreate.UseVisualStyleBackColor = true;
+ this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
+ //
+ // buttonUp
+ //
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(713, 328);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 3;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(713, 364);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 4;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.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.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(677, 365);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.TabIndex = 5;
+ 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.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(749, 364);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 6;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+
+ //
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Location = new System.Drawing.Point(150, 364);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(129, 29);
+ this.buttonCreateModif.TabIndex = 7;
+ 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(31, 12);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28);
+ this.comboBoxSelectorMap.TabIndex = 8;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
+
+ //
+ // FormMap
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ 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.buttonRight);
+ this.Controls.Add(this.buttonLeft);
+ this.Controls.Add(this.buttonDown);
+ this.Controls.Add(this.buttonUp);
+ this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.pictureBoxStormtrooper);
+ this.Controls.Add(this.statusStrip1);
+ this.Name = "FormMap";
+ this.Text = "FormMap";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxStormtrooper)).EndInit();
+ this.statusStrip1.ResumeLayout(false);
+ this.statusStrip1.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxStormtrooper;
+ private StatusStrip statusStrip1;
+ private ToolStripStatusLabel toolStripStatusLabelSpeed;
+ private ToolStripStatusLabel toolStripStatusLabelWeight;
+ private ToolStripStatusLabel toolStripStatusLabelBodyColor;
+ private Button buttonCreate;
+ private Button buttonUp;
+ private Button buttonDown;
+ private Button buttonLeft;
+ private Button buttonRight;
+ private Button buttonCreateModif;
+ private ComboBox comboBoxSelectorMap;
+ }
+}
\ No newline at end of file
diff --git a/Stormtrooper/Stormtrooper/FormMap.cs b/Stormtrooper/Stormtrooper/FormMap.cs
new file mode 100644
index 0000000..e1b0d51
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/FormMap.cs
@@ -0,0 +1,106 @@
+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 Stormtrooper
+{
+ public partial class FormMap : Form
+ {
+ private AbstractMap _abstractMap;
+ public FormMap()
+ {
+ InitializeComponent();
+ _abstractMap = new SimpleMap();
+ }
+ ///
+ /// Заполнение информации по объекту
+ ///
+ ///
+ private void SetData(DrowningStormtrooper car)
+ {
+ toolStripStatusLabelSpeed.Text = $"Скорость: {car.Stormtrooper.Speed}";
+ toolStripStatusLabelWeight.Text = $"Вес: {car.Stormtrooper.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет:{ car.Stormtrooper.BodyColor.Name}";
+ pictureBoxStormtrooper.Image = _abstractMap.CreateMap(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height, new DrawningObjectStormtrooper(car));
+ }
+ ///
+ /// Обработка нажатия кнопки "Создать"
+ ///
+ ///
+ ///
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var car = new DrowningStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData(car);
+ }
+ ///
+ /// Изменение размеров формы
+ ///
+ ///
+ ///
+ 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;
+ }
+ pictureBoxStormtrooper.Image = _abstractMap?.MoveObject(dir);
+ }
+ ///
+ /// Обработка нажатия кнопки "Модификация"
+ ///
+ ///
+ ///
+ private void buttonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var car = new DrowningSuperStormtrooper(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 MyMap();
+ break;
+ }
+ }
+
+
+ }
+}
diff --git a/Stormtrooper/Stormtrooper/FormMap.resx b/Stormtrooper/Stormtrooper/FormMap.resx
new file mode 100644
index 0000000..5cb320f
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/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/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs b/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs
index 70930a2..f52744b 100644
--- a/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs
+++ b/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs
@@ -39,6 +39,7 @@
this.buttonDown = 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.pictureBoxStormtrooper)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@@ -72,7 +73,6 @@
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20);
this.toolStripStatusLabelSpeed.Text = "Скорость:";
- this.toolStripStatusLabelSpeed.Click += new System.EventHandler(this.ToolStripStatusLabelSpeed_Click);
//
// toolStripStatusLabelWeight
//
@@ -145,11 +145,22 @@
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Location = new System.Drawing.Point(150, 364);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(129, 29);
+ this.buttonCreateModif.TabIndex = 7;
+ this.buttonCreateModif.Text = "Модификация";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
+ //
// FormStormtrooper
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
@@ -180,5 +191,6 @@
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
+ private Button buttonCreateModif;
}
}
\ No newline at end of file
diff --git a/Stormtrooper/Stormtrooper/FormStormtrooper.cs b/Stormtrooper/Stormtrooper/FormStormtrooper.cs
index 3c7d596..9ffb425 100644
--- a/Stormtrooper/Stormtrooper/FormStormtrooper.cs
+++ b/Stormtrooper/Stormtrooper/FormStormtrooper.cs
@@ -32,11 +32,18 @@ namespace Stormtrooper
pictureBoxStormtrooper.Image = bmp;
}
+ private void SetData(DrowningStormtrooper stormtrooper)
+ {
+ toolStripStatusLabelSpeed.Text = $"Скорость: {stormtrooper.Stormtrooper.Speed}";
+ toolStripStatusLabelWeight.Text = $"Вес: {stormtrooper.Stormtrooper.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет:{ stormtrooper.Stormtrooper.BodyColor.Name}";
+ //pictureBoxCar.Image = _abstractMap.CreateMap(pictureBoxCar.Width, pictureBoxCar.Height, new DrawningObjectCar(car));
+ }
+
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _stormtrooper = new DrowningStormtrooper();
- _stormtrooper.Init(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ _stormtrooper = new DrowningStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_stormtrooper.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
@@ -74,5 +81,15 @@ namespace Stormtrooper
Draw();
}
+ private void buttonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var stormtrooper = new DrowningSuperStormtrooper(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(stormtrooper);
+
+ }
}
}
diff --git a/Stormtrooper/Stormtrooper/IDrawningObject.cs b/Stormtrooper/Stormtrooper/IDrawningObject.cs
new file mode 100644
index 0000000..f921bc5
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/IDrawningObject.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Stormtrooper
+{
+ 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/Stormtrooper/Stormtrooper/MyMap.cs b/Stormtrooper/Stormtrooper/MyMap.cs
new file mode 100644
index 0000000..9d5ddee
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/MyMap.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Stormtrooper
+{
+ internal class MyMap : AbstractMap
+ {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierColor = new SolidBrush(Color.Red);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush roadColor = new SolidBrush(Color.FromArgb(242, 242, 242));
+ 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[150, 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 < 10)
+ {
+ int x = _random.Next(0, _map.GetLength(0));
+ int y = _random.Next(0, _map.GetLength(1));
+ if (_map[x, y] == _freeRoad)
+ {
+ _map[x, y] = _barrier;
+ counter++;
+ }
+ }
+ }
+ }
+}
diff --git a/Stormtrooper/Stormtrooper/Program.cs b/Stormtrooper/Stormtrooper/Program.cs
index f56f0d8..a5278ed 100644
--- a/Stormtrooper/Stormtrooper/Program.cs
+++ b/Stormtrooper/Stormtrooper/Program.cs
@@ -11,7 +11,7 @@ namespace Stormtrooper
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormStormtrooper());
+ Application.Run(new FormMap());
}
}
}
\ No newline at end of file
diff --git a/Stormtrooper/Stormtrooper/SimpleMap.cs b/Stormtrooper/Stormtrooper/SimpleMap.cs
new file mode 100644
index 0000000..c9f67af
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/SimpleMap.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Stormtrooper
+{
+ 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 < 30)
+ {
+ int x = _random.Next(0, 100);
+ int y = _random.Next(0, 100);
+ if (_map[x, y] == _freeRoad)
+ {
+ _map[x, y] = _barrier;
+ counter++;
+ }
+ }
+ }
+ }
+}