diff --git a/Trolleybus/Trolleybus/AbstractMap.cs b/Trolleybus/Trolleybus/AbstractMap.cs
new file mode 100644
index 0000000..671d37b
--- /dev/null
+++ b/Trolleybus/Trolleybus/AbstractMap.cs
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Drawing;
+
+namespace Trolleybus
+{
+ 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 Random();
+ protected readonly int _freeRoad = 0;
+ protected readonly int _barrier = 1;
+
+ public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
+ {
+ _width = width;
+ _height = height;
+ _drawningObject = drawningObject;
+ GenerateMap();
+ while (!SetObjectOnMap())
+ {
+ GenerateMap();
+ }
+ return DrawMapWithObject();
+ }
+ public Bitmap MoveObject(Direction direction)
+ {
+ // TODO проверка, что объект может переместится в требуемом направлении
+ if (true)
+ {
+ _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 првоерка, что объект не "накладывается" на закрытые участки
+ return true;
+ }
+ private Bitmap DrawMapWithObject()
+ {
+ Bitmap bmp = new Bitmap(_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/Trolleybus/Trolleybus/Direction.cs b/Trolleybus/Trolleybus/Direction.cs
index 68bfa63..7a92de3 100644
--- a/Trolleybus/Trolleybus/Direction.cs
+++ b/Trolleybus/Trolleybus/Direction.cs
@@ -11,6 +11,7 @@ namespace Trolleybus
///
internal enum Direction
{
+ None = 0,
Up = 1,
Down = 2,
Left = 3,
diff --git a/Trolleybus/Trolleybus/DrawingSmallTrolleybus.cs b/Trolleybus/Trolleybus/DrawingSmallTrolleybus.cs
new file mode 100644
index 0000000..0033ac2
--- /dev/null
+++ b/Trolleybus/Trolleybus/DrawingSmallTrolleybus.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Drawing;
+
+namespace Trolleybus
+{
+ internal class DrawningSmallTrolleybus : DrawingTrolleybus
+ {
+ public DrawningSmallTrolleybus(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) :
+ base(speed, weight, bodyColor, 110, 60)
+ {
+ Trolleybus = new EntitySmallTrolleybus(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
+ }
+
+ public override void DrawTransport(Graphics g)
+ {
+ if (Trolleybus is not EntitySmallTrolleybus smallTrolleybus)
+ {
+ return;
+ }
+
+ Pen pen = new Pen(Color.Black);
+ Brush dopBrush = new SolidBrush(smallTrolleybus.DopColor);
+
+ if (smallTrolleybus.BodyKit)
+ {
+ g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20);
+ g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20, 20);
+ g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10, 20, 40);
+ g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, 15);
+ g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45, 15, 15);
+
+ g.FillEllipse(dopBrush, _startPosX + 90, _startPosY, 20, 20);
+ g.FillEllipse(dopBrush, _startPosX + 90, _startPosY + 40, 20, 20);
+ g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 10, 20, 40);
+ g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 1, 15, 15);
+ g.FillRectangle(dopBrush, _startPosX + 90, _startPosY + 45, 15, 15);
+
+ g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20);
+ g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20);
+ g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20, 40);
+ g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14, 15);
+ g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45, 14, 15);
+
+ g.FillEllipse(dopBrush, _startPosX, _startPosY, 20, 20);
+ g.FillEllipse(dopBrush, _startPosX, _startPosY + 40, 20, 20);
+ g.FillRectangle(dopBrush, _startPosX + 1, _startPosY + 10, 25, 40);
+ g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 1, 15, 15);
+ g.FillRectangle(dopBrush, _startPosX + 5, _startPosY + 45, 15, 15);
+
+ g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39, 15);
+ g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45, 39, 15);
+
+ g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 1, 40, 15);
+ g.FillRectangle(dopBrush, _startPosX + 35, _startPosY + 45, 40, 15);
+ }
+
+ _startPosX += 10;
+ _startPosY += 5;
+ base.DrawTransport(g);
+ _startPosX -= 10;
+ _startPosY -= 5;
+
+ if (smallTrolleybus.SportLine)
+ {
+ g.FillRectangle(dopBrush, _startPosX + 76, _startPosY + 23, 24, 15);
+ g.FillRectangle(dopBrush, _startPosX + 36, _startPosY + 23, 34, 15);
+ g.FillRectangle(dopBrush, _startPosX + 11, _startPosY + 23, 14, 15);
+ }
+
+ if (smallTrolleybus.Wing)
+ {
+ g.FillRectangle(dopBrush, _startPosX, _startPosY + 5, 10, 50);
+ g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10, 50);
+ }
+ }
+ }
+}
diff --git a/Trolleybus/Trolleybus/DrawingTrolleybus.cs b/Trolleybus/Trolleybus/DrawingTrolleybus.cs
index d963d78..e135e93 100644
--- a/Trolleybus/Trolleybus/DrawingTrolleybus.cs
+++ b/Trolleybus/Trolleybus/DrawingTrolleybus.cs
@@ -13,23 +13,23 @@ namespace Trolleybus
///
internal class DrawingTrolleybus
{
- public EntityTrolleybus Trolleybus { get; private set; }
+ public EntityTrolleybus Trolleybus { get; protected set; }
///
/// левая координата отрисовки
///
- private float _startPosX;
+ public float _startPosX;
///
/// верхняя координата отрисовки
///
- private float _startPosY;
+ public float _startPosY;
///
/// левая координата начала отрисовки
///
- private float _startX;
+ public float _startX;
///
/// Верхняя координата начала отрисовки
///
- private float _startY;
+ public float _startY;
///
/// Ширина окна отрисовки
///
@@ -52,10 +52,15 @@ namespace Trolleybus
/// Скорость
/// Вес автомобиля
/// Цвет кузова
- public void Init(int speed, float weight, Color bodyColor)
+ public DrawingTrolleybus(int speed, float weight, Color bodyColor)
{
- Trolleybus = new EntityTrolleybus();
- Trolleybus.Init(speed, weight, bodyColor);
+ Trolleybus = new EntityTrolleybus(speed, weight, bodyColor);
+ }
+ protected DrawingTrolleybus(int speed, float weight, Color bodyColor, int trolleybusWidth, int trolleybusHeight)
+ {
+ Trolleybus = new EntityTrolleybus(speed, weight, bodyColor);
+ _trolleybusWidth = trolleybusWidth;
+ _trolleybusHeight = trolleybusHeight;
}
///
/// Установка позиции
@@ -65,12 +70,12 @@ namespace Trolleybus
/// Ширина картинки
/// Высота картинки
// public void SetPosition(int x, int y, int startX, int startY, int width, int height)
- public void SetPosition(int x, int y, int startX, int startY, int width, int height)
+ public void SetPosition(int x, int y, int width, int height)
{
_startPosX = x;
_startPosY = y;
- _startX = startX;
- _startY = startY;
+// _startX = startX;
+// _startY = startY;
_pictureWidth = width;
_pictureHeight = height;
}
@@ -95,14 +100,16 @@ namespace Trolleybus
break;
//влево
case Direction.Left:
- if (_startPosX > _startX)
- {
- _startPosX -= Trolleybus.Step;
+// if (_startPosX > _startX)
+ if (_startPosX > 12)
+ {
+ _startPosX -= Trolleybus.Step;
}
break;
//вверх
case Direction.Up:
- if (_startPosY > _startY)
+// if (_startPosY > _startY)
+ if (_startPosY > 12)
{
_startPosY -= Trolleybus.Step;
}
@@ -120,7 +127,7 @@ namespace Trolleybus
/// Отрисовка троллейбуса
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@@ -177,5 +184,10 @@ namespace Trolleybus
_startPosY = _pictureHeight.Value - _trolleybusHeight;
}
}
+
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return (_startPosX, _startPosY, _startPosX + _trolleybusWidth, _startPosY + _trolleybusHeight);
+ }
}
}
diff --git a/Trolleybus/Trolleybus/DrawningObject.cs b/Trolleybus/Trolleybus/DrawningObject.cs
new file mode 100644
index 0000000..b35f8e6
--- /dev/null
+++ b/Trolleybus/Trolleybus/DrawningObject.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using static System.Windows.Forms.AxHost;
+
+namespace Trolleybus
+{
+ internal class DrawningObject : IDrawningObject
+ {
+ private DrawingTrolleybus _trolleybus = null;
+
+ public DrawningObject(DrawingTrolleybus car)
+ {
+ _trolleybus = car;
+ }
+
+ public float Step => _trolleybus?.Trolleybus?.Step ?? 0;
+
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return _trolleybus?.GetCurrentPosition() ?? default;
+ }
+
+ public void MoveObject(Direction direction)
+ {
+ _trolleybus?.MoveTransport(direction);
+ }
+
+ public void SetObject(int x, int y, int width, int height)
+ {
+// _trolleybus.SetPosition(x, y, startX, startY, width, height);
+ _trolleybus.SetPosition(x, y, width, height);
+ }
+
+ void IDrawningObject.DrawningObject(Graphics g)
+ {
+ // TODO
+ }
+ }
+}
diff --git a/Trolleybus/Trolleybus/EntitySmallTrolleybus.cs b/Trolleybus/Trolleybus/EntitySmallTrolleybus.cs
new file mode 100644
index 0000000..f65843c
--- /dev/null
+++ b/Trolleybus/Trolleybus/EntitySmallTrolleybus.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Drawing;
+
+namespace Trolleybus
+{
+ class EntitySmallTrolleybus : EntityTrolleybus
+ {
+ ///
+ /// Дополнительный цвет
+ ///
+ public Color DopColor { get; private set; }
+ ///
+ /// Признак наличия обвеса
+ ///
+ public bool BodyKit { get; private set; }
+ ///
+ /// Признак наличия антикрыла
+ ///
+ public bool Wing { get; private set; }
+ ///
+ /// Признак наличия гоночной полосы
+ ///
+ public bool SportLine { get; private set; }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия обвеса
+ /// Признак наличия антикрыла
+ /// Признак наличия гоночной полосы
+ public EntitySmallTrolleybus(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) :
+ base(speed, weight, bodyColor)
+ {
+ DopColor = dopColor;
+ BodyKit = bodyKit;
+ Wing = wing;
+ SportLine = sportLine;
+ }
+ }
+}
diff --git a/Trolleybus/Trolleybus/EntityTrolleybus.cs b/Trolleybus/Trolleybus/EntityTrolleybus.cs
index 686b943..7d8e2ad 100644
--- a/Trolleybus/Trolleybus/EntityTrolleybus.cs
+++ b/Trolleybus/Trolleybus/EntityTrolleybus.cs
@@ -35,12 +35,12 @@ namespace Trolleybus
///
///
///
- public void Init(int speed, float weight, Color bodyColor)
+ public EntityTrolleybus(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0? rnd.Next(50, 150): speed;
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
- bodyColor = bodyColor;
+ BodyColor = bodyColor;
}
}
-}
+}
\ No newline at end of file
diff --git a/Trolleybus/Trolleybus/Form1.Designer.cs b/Trolleybus/Trolleybus/Form1.Designer.cs
index 7160c1d..5b64bee 100644
--- a/Trolleybus/Trolleybus/Form1.Designer.cs
+++ b/Trolleybus/Trolleybus/Form1.Designer.cs
@@ -39,6 +39,7 @@ namespace Trolleybus
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.pictureBoxTrolleybus = new System.Windows.Forms.PictureBox();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTrolleybus)).BeginInit();
this.SuspendLayout();
@@ -135,11 +136,22 @@ namespace Trolleybus
this.pictureBoxTrolleybus.TabIndex = 0;
this.pictureBoxTrolleybus.TabStop = false;
//
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Location = new System.Drawing.Point(94, 389);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(86, 23);
+ this.buttonCreateModif.TabIndex = 7;
+ this.buttonCreateModif.Text = "Модификация";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
+ //
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
@@ -169,6 +181,7 @@ namespace Trolleybus
private System.Windows.Forms.Button buttonLeft;
private System.Windows.Forms.Button buttonRight;
private System.Windows.Forms.Button buttonUp;
+ private System.Windows.Forms.Button buttonCreateModif;
}
}
diff --git a/Trolleybus/Trolleybus/Form1.cs b/Trolleybus/Trolleybus/Form1.cs
index 07959cc..bc42fbf 100644
--- a/Trolleybus/Trolleybus/Form1.cs
+++ b/Trolleybus/Trolleybus/Form1.cs
@@ -29,6 +29,14 @@ namespace Trolleybus
pictureBoxTrolleybus.Image = bmp;
}
+ private void SetData()
+ {
+ Bitmap bmp = new Bitmap(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _trolleybus?.DrawTransport(gr);
+ pictureBoxTrolleybus.Image = bmp;
+ }
+
///
/// Обработка нажатия "Создать"
///
@@ -38,10 +46,9 @@ namespace Trolleybus
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
- _trolleybus = new DrawingTrolleybus();
- _trolleybus.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- _trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), Location.X, Location.Y, pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
-// _trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
+ _trolleybus = new DrawingTrolleybus(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+// _trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), Location.X, Location.Y, pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
+ _trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_trolleybus.Trolleybus.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_trolleybus.Trolleybus.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {_trolleybus.Trolleybus.BodyColor.Name}";
@@ -74,5 +81,16 @@ namespace Trolleybus
_trolleybus?.ChangeBorders(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
Draw();
}
+
+ private void buttonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new Random();
+ _trolleybus = new DrawningSmallTrolleybus(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();
+ }
}
}
diff --git a/Trolleybus/Trolleybus/FormMap.Designer.cs b/Trolleybus/Trolleybus/FormMap.Designer.cs
new file mode 100644
index 0000000..97c3940
--- /dev/null
+++ b/Trolleybus/Trolleybus/FormMap.Designer.cs
@@ -0,0 +1,199 @@
+namespace Trolleybus
+{
+ 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.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.buttonCreateModif = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.pictureBoxTrolleybus = new System.Windows.Forms.PictureBox();
+ this.statusStrip1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTrolleybus)).BeginInit();
+ this.SuspendLayout();
+ //
+ // statusStrip1
+ //
+ this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusLabelSpeed,
+ this.toolStripStatusLabelWeight,
+ this.toolStripStatusLabelBodyColor});
+ this.statusStrip1.Location = new System.Drawing.Point(0, 428);
+ this.statusStrip1.Name = "statusStrip1";
+ this.statusStrip1.Size = new System.Drawing.Size(800, 22);
+ this.statusStrip1.TabIndex = 1;
+ this.statusStrip1.Text = "statusStrip1";
+ //
+ // toolStripStatusLabelSpeed
+ //
+ this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
+ this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(59, 17);
+ this.toolStripStatusLabelSpeed.Text = "Скорость";
+ //
+ // toolStripStatusLabelWeight
+ //
+ this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
+ this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(26, 17);
+ this.toolStripStatusLabelWeight.Text = "Вес";
+ //
+ // toolStripStatusLabelBodyColor
+ //
+ this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
+ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(33, 17);
+ this.toolStripStatusLabelBodyColor.Text = "Цвет";
+ //
+ // buttonCreate
+ //
+ this.buttonCreate.Location = new System.Drawing.Point(12, 390);
+ this.buttonCreate.Name = "buttonCreate";
+ this.buttonCreate.Size = new System.Drawing.Size(75, 23);
+ this.buttonCreate.TabIndex = 2;
+ this.buttonCreate.Text = "Создать";
+ this.buttonCreate.UseVisualStyleBackColor = true;
+ this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
+ //
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Location = new System.Drawing.Point(94, 389);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(86, 23);
+ 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(12, 12);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 21);
+ this.comboBoxSelectorMap.TabIndex = 8;
+ //
+ // buttonUp
+ //
+ this.buttonUp.BackgroundImage = global::Trolleybus.Properties.Resources.up30;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(722, 353);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 6;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonRight
+ //
+ this.buttonRight.BackgroundImage = global::Trolleybus.Properties.Resources.right30;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(758, 389);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 5;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonLeft
+ //
+ this.buttonLeft.BackgroundImage = global::Trolleybus.Properties.Resources.left30;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(686, 389);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.TabIndex = 4;
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonDown
+ //
+ this.buttonDown.BackgroundImage = global::Trolleybus.Properties.Resources.down30;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(722, 389);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 3;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // pictureBoxTrolleybus
+ //
+ this.pictureBoxTrolleybus.Location = new System.Drawing.Point(12, 12);
+ this.pictureBoxTrolleybus.Name = "pictureBoxTrolleybus";
+ this.pictureBoxTrolleybus.Size = new System.Drawing.Size(776, 413);
+ this.pictureBoxTrolleybus.TabIndex = 0;
+ this.pictureBoxTrolleybus.TabStop = false;
+ //
+ // FormMap
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ 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.buttonUp);
+ this.Controls.Add(this.buttonRight);
+ this.Controls.Add(this.buttonLeft);
+ this.Controls.Add(this.buttonDown);
+ this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.statusStrip1);
+ this.Controls.Add(this.pictureBoxTrolleybus);
+ this.Name = "FormMap";
+ this.Text = "Карта";
+ this.statusStrip1.ResumeLayout(false);
+ this.statusStrip1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTrolleybus)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.PictureBox pictureBoxTrolleybus;
+ private System.Windows.Forms.StatusStrip statusStrip1;
+ private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpeed;
+ private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelWeight;
+ private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelBodyColor;
+ private System.Windows.Forms.Button buttonCreate;
+ private System.Windows.Forms.Button buttonDown;
+ private System.Windows.Forms.Button buttonLeft;
+ private System.Windows.Forms.Button buttonRight;
+ private System.Windows.Forms.Button buttonUp;
+ private System.Windows.Forms.Button buttonCreateModif;
+ private System.Windows.Forms.ComboBox comboBoxSelectorMap;
+ }
+}
\ No newline at end of file
diff --git a/Trolleybus/Trolleybus/FormMap.cs b/Trolleybus/Trolleybus/FormMap.cs
new file mode 100644
index 0000000..565216d
--- /dev/null
+++ b/Trolleybus/Trolleybus/FormMap.cs
@@ -0,0 +1,102 @@
+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 Trolleybus
+{
+ public partial class FormMap : Form
+ {
+ private AbstractMap _abstractMap;
+
+ public FormMap()
+ {
+ InitializeComponent();
+ _abstractMap = new SimpleMap();
+ }
+ ///
+ /// Заполнение информации по объекту
+ ///
+ ///
+ private void SetData(DrawingTrolleybus trolleybus)
+ {
+ toolStripStatusLabelSpeed.Text = $"Скорость: {trolleybus.Trolleybus.Speed}";
+ toolStripStatusLabelWeight.Text = $"Вес: {trolleybus.Trolleybus.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет: {trolleybus.Trolleybus.BodyColor.Name}";
+ pictureBoxTrolleybus.Image = _abstractMap.CreateMap(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height,
+ new DrawningObject(trolleybus));
+ }
+ ///
+ /// Обработка нажатия кнопки "Создать"
+ ///
+ ///
+ ///
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new Random();
+ var trolleybus = new DrawingTrolleybus(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData(trolleybus);
+ }
+ ///
+ /// Изменение размеров формы
+ ///
+ ///
+ ///
+ 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;
+ }
+ pictureBoxTrolleybus.Image = _abstractMap?.MoveObject(dir);
+ }
+ ///
+ /// Обработка нажатия кнопки "Модификация"
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new Random();
+ var trolleybus = new DrawningSmallTrolleybus(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(trolleybus);
+ }
+ ///
+ /// Смена карты
+ ///
+ ///
+ ///
+ private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ _abstractMap = new SimpleMap();
+ break;
+ }
+ }
+ }
+}
diff --git a/Trolleybus/Trolleybus/FormMap.resx b/Trolleybus/Trolleybus/FormMap.resx
new file mode 100644
index 0000000..174ebc7
--- /dev/null
+++ b/Trolleybus/Trolleybus/FormMap.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/Trolleybus/Trolleybus/IDrawingObject.cs b/Trolleybus/Trolleybus/IDrawingObject.cs
new file mode 100644
index 0000000..5659b86
--- /dev/null
+++ b/Trolleybus/Trolleybus/IDrawingObject.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Drawing;
+
+namespace Trolleybus
+{
+ internal interface IDrawningObject
+ {
+ ///
+ /// Шаг перемещения объекта
+ ///
+ 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/Trolleybus/Trolleybus/Program.cs b/Trolleybus/Trolleybus/Program.cs
index 3a773ae..be48583 100644
--- a/Trolleybus/Trolleybus/Program.cs
+++ b/Trolleybus/Trolleybus/Program.cs
@@ -16,7 +16,7 @@ namespace Trolleybus
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
+ Application.Run(new FormMap());
}
}
}
diff --git a/Trolleybus/Trolleybus/SimpleMap.cs b/Trolleybus/Trolleybus/SimpleMap.cs
new file mode 100644
index 0000000..0f8af7f
--- /dev/null
+++ b/Trolleybus/Trolleybus/SimpleMap.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Drawing;
+
+namespace Trolleybus
+{
+ 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 < 50)
+ {
+ 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/Trolleybus/Trolleybus/Trolleybus.csproj b/Trolleybus/Trolleybus/Trolleybus.csproj
index ce41cd2..7b4d071 100644
--- a/Trolleybus/Trolleybus/Trolleybus.csproj
+++ b/Trolleybus/Trolleybus/Trolleybus.csproj
@@ -11,6 +11,7 @@
v4.7.2
512
true
+ 9.0
true
@@ -46,8 +47,12 @@
+
+
+
+
Form
@@ -55,11 +60,22 @@
Form1.cs
+
+ Form
+
+
+ FormMap.cs
+
+
+
Form1.cs
+
+ FormMap.cs
+
ResXFileCodeGenerator
Resources.Designer.cs
diff --git a/Trolleybus/Trolleybus/save/Trolleybus.csproj b/Trolleybus/Trolleybus/save/Trolleybus.csproj
new file mode 100644
index 0000000..af2fa34
--- /dev/null
+++ b/Trolleybus/Trolleybus/save/Trolleybus.csproj
@@ -0,0 +1,114 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {07E18270-5508-4D1A-A699-8B170C1E8502}
+ WinExe
+ Trolleybus
+ Trolleybus
+ v4.7.2
+ 512
+ true
+ true
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ Form1.cs
+
+
+ Form
+
+
+ FormMap.cs
+
+
+
+
+
+
+ Form1.cs
+
+
+ FormMap.cs
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Designer
+
+
+ True
+ Resources.resx
+ True
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+ True
+ Settings.settings
+ True
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file