Compare commits

...

14 Commits

25 changed files with 2086 additions and 34 deletions

View File

@ -0,0 +1,140 @@
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)
{
(float leftX, float topY, float rightX, float bottomY) = _drawningObject.GetCurrentPosition();
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
switch (direction)
{
case Direction.Up:
if (_size_y * (j + 1) >= topY - _drawningObject.Step && _size_y * (j + 1) < topY && _size_x * (i + 1) > leftX
&& _size_x * (i + 1) <= rightX)
{
return DrawMapWithObject();
}
break;
case Direction.Down:
if (_size_y * j <= bottomY + _drawningObject.Step && _size_y * j > bottomY && _size_x * (i + 1) > leftX
&& _size_x * (i + 1) <= rightX)
{
return DrawMapWithObject();
}
break;
case Direction.Left:
if (_size_x * (i + 1) >= leftX - _drawningObject.Step && _size_x * (i + 1) < leftX && _size_y * (j + 1) < bottomY
&& _size_y * (j + 1) >= topY)
{
return DrawMapWithObject();
}
break;
case Direction.Right:
if (_size_x * i <= rightX + _drawningObject.Step && _size_x * i > leftX && _size_y * (j + 1) < bottomY
&& _size_y * (j + 1) >= topY)
{
return DrawMapWithObject();
}
break;
}
}
}
}
_drawningObject.MoveObject(direction);
return DrawMapWithObject();
}
private bool SetObjectOnMap()
{
(float leftX, float topY, float rightX, float bottomY) = _drawningObject.GetCurrentPosition();
if (_drawningObject == null || _map == null)
{
return false;
}
float airplaneWidth = rightX - leftX;
float airplaneHeight = bottomY - topY;
int x = _random.Next(0, 10);
int y = _random.Next(0, 10);
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
if (_map[i, j] == _barrier)
{
if (x + airplaneWidth >= _size_x * i && x <= _size_x * i && y + airplaneHeight > _size_y * j && y <= _size_y * j)
{
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);
}
}

View File

@ -0,0 +1,30 @@
using System.Threading;
using Trolleybus;
namespace Trolleybus
{
internal class AutoStopMap : SimpleMap
{
protected override void GenerateMap()
{
_map = new int[100, 100];
_size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1);
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
_map[i, j] = _freeRoad;
}
}
for (int i = 0; i < 50; i++)
{
for (int j = 0; j < 50; j++)
{
_map[i, j] = _barrier;
}
}
}
}
}

View File

@ -9,8 +9,9 @@ namespace Trolleybus
/// <summary>
/// Направление перемещения
/// </summary>
internal enum Direction
public enum Direction
{
None = 0,
Up = 1,
Down = 2,
Left = 3,

View File

@ -0,0 +1,71 @@
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 horns, bool battary) :
base(speed, weight, bodyColor, 110, 60)
{
Trolleybus = new EntitySmallTrolleybus(speed, weight, bodyColor, dopColor,bodyKit, horns, battary);
}
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);
Brush brBlue = new SolidBrush(Color.LightBlue);
Brush dBlue = new SolidBrush(Color.DarkBlue);
Brush bWhite = new SolidBrush(Color.White);
Pen WinBlue = new Pen(Color.Blue);
base.DrawTransport(g);
if (smallTrolleybus.BodyKit)
{
g.DrawRectangle(pen, _startPosX, _startPosY, 200, 50);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 20, 40);
g.FillEllipse(brBlue, _startPosX, _startPosY + 5, 20, 25);
g.DrawEllipse(WinBlue, _startPosX, _startPosY + 5, 20, 25);
g.FillEllipse(brBlue, _startPosX + 25, _startPosY + 5, 20, 25);
g.DrawEllipse(WinBlue, _startPosX + 25, _startPosY + 5, 20, 25);
g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 5, 20, 25);
g.DrawEllipse(WinBlue, _startPosX + 50, _startPosY + 5, 20, 25);
g.FillEllipse(brBlue, _startPosX + 75, _startPosY + 5, 20, 25);
g.DrawEllipse(WinBlue, _startPosX + 75, _startPosY + 5, 20, 25);
g.FillEllipse(brBlue, _startPosX + 120, _startPosY + 5, 20, 25);
g.DrawEllipse(WinBlue, _startPosX + 120, _startPosY + 5, 20, 25);
g.FillEllipse(brBlue, _startPosX + 145, _startPosY + 5, 20, 25);
g.DrawEllipse(WinBlue, _startPosX + 145, _startPosY + 5, 20, 25);
g.FillEllipse(brBlue, _startPosX + 170, _startPosY + 5, 20, 25);
g.DrawEllipse(WinBlue, _startPosX + 170, _startPosY + 5, 20, 25);
g.FillEllipse(bWhite, _startPosX, _startPosY + 40, 30, 30);
g.DrawEllipse(pen, _startPosX, _startPosY + 40, 30, 30);
g.FillEllipse(bWhite, _startPosX + 170, _startPosY + 40, 30, 30);
g.DrawEllipse(pen, _startPosX + 170, _startPosY + 40, 30, 30);
}
if (smallTrolleybus.Horns)
{
g.DrawLine(pen, _startPosX + 100, _startPosY - 10, _startPosX + 150, _startPosY - 20);
g.DrawLine(pen, _startPosX + 150, _startPosY - 20, _startPosX, _startPosY - 30);
g.DrawRectangle(pen, _startPosX + 50, _startPosY - 10, 100, 10);
}
if (smallTrolleybus.Battary)
{
g.DrawRectangle(pen, _startPosX + 100, _startPosY, 10, 10);
}
}
}
}

View File

@ -11,25 +11,25 @@ namespace Trolleybus
/// <summary>
/// Класс прорисовки и перемещения объекта
/// </summary>
internal class DrawingTrolleybus
public class DrawingTrolleybus
{
public EntityTrolleybus Trolleybus { get; private set; }
public EntityTrolleybus Trolleybus { get; protected set; }
/// <summary>
/// левая координата отрисовки
/// </summary>
private float _startPosX;
public float _startPosX;
/// <summary>
/// верхняя координата отрисовки
/// </summary>
private float _startPosY;
public float _startPosY;
/// <summary>
/// левая координата начала отрисовки
/// </summary>
private float _startX;
public float _startX;
/// <summary>
/// Верхняя координата начала отрисовки
/// </summary>
private float _startY;
public float _startY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -52,10 +52,15 @@ namespace Trolleybus
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
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;
}
/// <summary>
/// Установка позиции
@ -65,12 +70,12 @@ namespace Trolleybus
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
// 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 - Trolleybus.Step > 0)
{
_startPosX -= Trolleybus.Step;
}
break;
//вверх
case Direction.Up:
if (_startPosY > _startY)
// if (_startPosY > _startY)
if (_startPosY - Trolleybus.Step > 0)
{
_startPosY -= Trolleybus.Step;
}
@ -120,7 +127,7 @@ namespace Trolleybus
/// Отрисовка троллейбуса
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@ -129,8 +136,9 @@ namespace Trolleybus
}
Pen pen = new Pen(Color.Black);
Brush brBlue = new SolidBrush(Color.LightBlue);
Brush dBlue = new SolidBrush(Color.DarkBlue);
Brush bWhite = new SolidBrush(Color.White);
Brush br = new SolidBrush(Trolleybus?.BodyColor ?? Color.Black);
g.FillRectangle(br, _startPosX, _startPosY, 200, 50);
g.DrawRectangle(pen, _startPosX, _startPosY, 200, 50);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 20, 40);
Pen WinBlue = new Pen(Color.Blue);
@ -177,5 +185,10 @@ namespace Trolleybus
_startPosY = _pictureHeight.Value - _trolleybusHeight;
}
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _trolleybusWidth, _startPosY + _trolleybusHeight);
}
}
}

View File

@ -0,0 +1,47 @@
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 nothing()
{
throw new NotImplementedException();
}
public void SetObject(int x, int y, int width, int height)
{
_trolleybus.SetPosition(x, y, width, height);
}
void IDrawningObject.DrawningObject(Graphics g)
{
// TODO
}
}
}

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace Trolleybus
{
internal class DrawningObjectTrolleybus : IDrawningObject
{
private DrawingTrolleybus _trolleybus = null;
public DrawningObjectTrolleybus(DrawingTrolleybus trolleybus)
{
_trolleybus = trolleybus;
}
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 nothing()
{
throw new NotImplementedException();
}
public void SetObject(int x, int y, int width, int height)
{
_trolleybus.SetPosition(x, y, width, height);
}
void IDrawningObject.DrawningObject(Graphics g)
{
_trolleybus.DrawTransport(g);
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace Trolleybus
{
class EntitySmallTrolleybus : EntityTrolleybus
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; private set; }
/// <summary>
/// Признак наличия обвеса
/// </summary>
public bool BodyKit { get; private set; }
/// <summary>
/// Признак наличия гоночной полосы
/// </summary>
public bool Horns { get; private set; }
public bool Battary { get; private set; }
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="horns">Признак наличия гоночной полосы</param>
/// /// <param name="battary">Признак наличия гоночной полосы</param>
public EntitySmallTrolleybus(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool horns, bool battary) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
BodyKit = bodyKit;
Horns = horns;
Battary = battary;
}
}
}

View File

@ -10,7 +10,7 @@ namespace Trolleybus
/// <summary>
/// Класс-сущность "Троллейбус"
/// </summary>
internal class EntityTrolleybus
public class EntityTrolleybus
{
/// <summary>
/// Скорость
@ -35,12 +35,12 @@ namespace Trolleybus
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <returns></returns>
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;
}
}
}
}

View File

@ -39,6 +39,8 @@ 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.buttonSelectTrolleybus = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTrolleybus)).BeginInit();
this.SuspendLayout();
@ -129,17 +131,39 @@ namespace Trolleybus
//
// pictureBoxTrolleybus
//
this.pictureBoxTrolleybus.Location = new System.Drawing.Point(12, 12);
this.pictureBoxTrolleybus.Location = new System.Drawing.Point(0, 0);
this.pictureBoxTrolleybus.Name = "pictureBoxTrolleybus";
this.pictureBoxTrolleybus.Size = new System.Drawing.Size(776, 413);
this.pictureBoxTrolleybus.Size = new System.Drawing.Size(800, 450);
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);
//
// buttonSelectTrolleybus
//
this.buttonSelectTrolleybus.Location = new System.Drawing.Point(578, 390);
this.buttonSelectTrolleybus.Name = "buttonSelectTrolleybus";
this.buttonSelectTrolleybus.Size = new System.Drawing.Size(75, 23);
this.buttonSelectTrolleybus.TabIndex = 8;
this.buttonSelectTrolleybus.Text = "Выбрать";
this.buttonSelectTrolleybus.UseVisualStyleBackColor = true;
this.buttonSelectTrolleybus.Click += new System.EventHandler(this.buttonSelectTrolleybus_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.buttonSelectTrolleybus);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
@ -169,6 +193,8 @@ 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;
private System.Windows.Forms.Button buttonSelectTrolleybus;
}
}

View File

@ -13,6 +13,7 @@ namespace Trolleybus
public partial class Form1 : Form
{
private DrawingTrolleybus _trolleybus;
public DrawingTrolleybus SelectedTrolleybus { get; private set; }
public Form1()
{
InitializeComponent();
@ -29,6 +30,15 @@ namespace Trolleybus
pictureBoxTrolleybus.Image = bmp;
}
private void SetData()
{
Random rnd = new Random();
_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}";
}
/// <summary>
/// Обработка нажатия "Создать"
/// </summary>
@ -37,14 +47,14 @@ 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);
toolStripStatusLabelSpeed.Text = $"Скорость: {_trolleybus.Trolleybus.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_trolleybus.Trolleybus.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {_trolleybus.Trolleybus.BodyColor.Name}";
Random random = new();
Color myColor = new Color();
ColorDialog MyDialog = new ColorDialog();
if (MyDialog.ShowDialog() == DialogResult.OK)
myColor = MyDialog.Color;
_trolleybus = new DrawingTrolleybus(random.Next(30, 50), random.Next(1000, 2000),
myColor);
SetData();
Draw();
}
@ -74,5 +84,31 @@ namespace Trolleybus
_trolleybus?.ChangeBorders(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
Draw();
}
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random random = new();
Color firstColor = new Color();
Color secondColor = new Color();
ColorDialog MyDialog = new ColorDialog();
if (MyDialog.ShowDialog() == DialogResult.OK)
firstColor = MyDialog.Color;
MyDialog = new ColorDialog();
if (MyDialog.ShowDialog() == DialogResult.OK)
secondColor = MyDialog.Color;
_trolleybus = new DrawningSmallTrolleybus(random.Next(100, 300), random.Next(1000, 2000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
SetData();
Draw();
}
private void buttonSelectTrolleybus_Click(object sender, EventArgs e)
{
SelectedTrolleybus = _trolleybus;
DialogResult = DialogResult.OK;
}
}
}

199
Trolleybus/Trolleybus/FormMap.Designer.cs generated Normal file
View File

@ -0,0 +1,199 @@
namespace Trolleybus
{
partial class FormMap
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Numerics;
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();
}
/// <summary>
/// Заполнение информации по объекту
/// </summary>
/// <param name="trolleybus"></param>
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 DrawningObjectTrolleybus(trolleybus));
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
/// <summary>
/// Изменение размеров формы
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
/// <summary>
/// Смена карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
}
}
}
}

View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,272 @@
namespace Trolleybus
{
partial class FormMapWithSetTrolleybus
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveTrolleybus = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddTrolleybus = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.buttonLeft);
this.groupBox1.Controls.Add(this.buttonRight);
this.groupBox1.Controls.Add(this.buttonDown);
this.groupBox1.Controls.Add(this.buttonUp);
this.groupBox1.Controls.Add(this.buttonShowOnMap);
this.groupBox1.Controls.Add(this.buttonShowStorage);
this.groupBox1.Controls.Add(this.buttonRemoveTrolleybus);
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonAddTrolleybus);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(600, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 648);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.buttonDeleteMap);
this.groupBox2.Controls.Add(this.listBoxMaps);
this.groupBox2.Controls.Add(this.buttonAddMap);
this.groupBox2.Controls.Add(this.textBoxNewMapName);
this.groupBox2.Controls.Add(this.comboBoxSelectorMap);
this.groupBox2.Location = new System.Drawing.Point(6, 19);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(181, 287);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Карты";
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(7, 204);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(168, 23);
this.buttonDeleteMap.TabIndex = 4;
this.buttonDeleteMap.Text = "Удалить Карту";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.Location = new System.Drawing.Point(7, 102);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(168, 95);
this.listBoxMaps.TabIndex = 3;
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(7, 72);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(168, 23);
this.buttonAddMap.TabIndex = 2;
this.buttonAddMap.Text = "Добавить Карту";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(7, 18);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(168, 20);
this.textBoxNewMapName.TabIndex = 1;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Сложная карта"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 44);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(169, 21);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// buttonLeft
//
this.buttonLeft.BackgroundImage = global::Trolleybus.Properties.Resources.left30;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(80, 605);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(32, 31);
this.buttonLeft.TabIndex = 9;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.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(156, 605);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(32, 31);
this.buttonRight.TabIndex = 8;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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(118, 605);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(32, 31);
this.buttonDown.TabIndex = 7;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUp
//
this.buttonUp.BackgroundImage = global::Trolleybus.Properties.Resources.up30;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(118, 568);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(32, 31);
this.buttonUp.TabIndex = 6;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 511);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(181, 23);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(7, 471);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(181, 23);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonRemoveTrolleybus
//
this.buttonRemoveTrolleybus.Location = new System.Drawing.Point(6, 425);
this.buttonRemoveTrolleybus.Name = "buttonRemoveTrolleybus";
this.buttonRemoveTrolleybus.Size = new System.Drawing.Size(182, 23);
this.buttonRemoveTrolleybus.TabIndex = 3;
this.buttonRemoveTrolleybus.Text = "Удалить троллейбус";
this.buttonRemoveTrolleybus.UseVisualStyleBackColor = true;
this.buttonRemoveTrolleybus.Click += new System.EventHandler(this.ButtonRemoveTrolleybus_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 383);
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(181, 20);
this.maskedTextBoxPosition.TabIndex = 2;
//
// buttonAddTrolleybus
//
this.buttonAddTrolleybus.Location = new System.Drawing.Point(7, 340);
this.buttonAddTrolleybus.Name = "buttonAddTrolleybus";
this.buttonAddTrolleybus.Size = new System.Drawing.Size(181, 23);
this.buttonAddTrolleybus.TabIndex = 1;
this.buttonAddTrolleybus.Text = "Добавить троллейбус";
this.buttonAddTrolleybus.UseVisualStyleBackColor = true;
this.buttonAddTrolleybus.Click += new System.EventHandler(this.ButtonAddTrolleybus_Click);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(600, 648);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetTrolleybus
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 648);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
this.Name = "FormMapWithSetTrolleybus";
this.Text = "FormMapWithSetTrolleybus";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button buttonAddTrolleybus;
private System.Windows.Forms.ComboBox comboBoxSelectorMap;
private System.Windows.Forms.PictureBox pictureBox;
private System.Windows.Forms.Button buttonLeft;
private System.Windows.Forms.Button buttonRight;
private System.Windows.Forms.Button buttonDown;
private System.Windows.Forms.Button buttonUp;
private System.Windows.Forms.Button buttonShowOnMap;
private System.Windows.Forms.Button buttonShowStorage;
private System.Windows.Forms.Button buttonRemoveTrolleybus;
private System.Windows.Forms.MaskedTextBox maskedTextBoxPosition;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button buttonDeleteMap;
private System.Windows.Forms.ListBox listBoxMaps;
private System.Windows.Forms.Button buttonAddMap;
private System.Windows.Forms.TextBox textBoxNewMapName;
}
}

View File

@ -0,0 +1,212 @@
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 FormMapWithSetTrolleybus : Form
{
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{ "Сложная карта", new AutoStopMap() },
};
private readonly MapsCollection _mapsCollection;
public FormMapWithSetTrolleybus()
{
InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
private void ReloadMaps()
{
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
foreach (string map in _mapsCollection.Keys)
{
listBoxMaps.Items.Add(map);
}
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
}
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{
listBoxMaps.SelectedIndex = index;
}
}
private void ButtonAddMap_Click(object sender, EventArgs e)
{
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
}
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
private MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap> _mapTrolleybusCollectionGeneric;
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Сложная карта":
map = new AutoStopMap();
break;
}
if (map != null)
{
_mapTrolleybusCollectionGeneric = new MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapTrolleybusCollectionGeneric = null;
}
}
private void ButtonAddTrolleybus_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
Form1 form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectTrolleybus tractor = new(form.SelectedTrolleybus);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + tractor != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveTrolleybus_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text) ||
MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
//получаем имя кнопки
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;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace Trolleybus
{
internal interface IDrawningObject
{
/// <summary>
/// Шаг перемещения объекта
/// </summary>
public float Step { get; }
/// <summary>
/// Установка позиции объекта
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина полотна</param>
/// <param name="height">Высота полотна</param>
void SetObject(int x, int y, int width, int height);
/// <summary>
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
/// <returns></returns>
void MoveObject(Direction direction);
/// <summary>
/// Отрисовка объекта
/// </summary>
/// <param name="g"></param>
void DrawningObject(Graphics g);
/// <summary>
/// Получение текущей позиции объекта
/// </summary>
/// <returns></returns>
void nothing();
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
}
}

View File

@ -0,0 +1,188 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace Trolleybus
{
internal class MapWithSetTrolleybusGeneric<T, U>
where T : class, IDrawningObject
where U : AbstractMap
{
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetTrolleybusGeneric<T> _setTrolleybus;
/// <summary>
/// Карта
/// </summary>
private readonly U _map;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="map"></param>
public MapWithSetTrolleybusGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setTrolleybus = new SetTrolleybusGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="map"></param>
/// <param name="trolleybus"></param>
/// <returns></returns>
public static int operator +(MapWithSetTrolleybusGeneric<T, U> map, T trolleybus)
{
return map._setTrolleybus.Insert(trolleybus);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="map"></param>
/// <param name="position"></param>
/// <returns></returns>
public static T operator -(MapWithSetTrolleybusGeneric<T, U> map, int position)
{
return map._setTrolleybus.Remove(position);
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawTrolleybus(gr);
return bmp;
}
/// <summary>
/// Просмотр объекта на карте
/// </summary>
/// <returns></returns>
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setTrolleybus.Count; i++)
{
var car = _setTrolleybus[i];
if (car != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
}
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// Перемещение объекта по крате
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary>
private void Shaking()
{
int j = _setTrolleybus.Count - 1;
for (int i = 0; i < _setTrolleybus.Count; i++)
{
if (_setTrolleybus[j] == null)
{
for (; j > i; j--)
{
var car = _setTrolleybus[j];
if (car != null)
{
_setTrolleybus.Insert(car, i);
_setTrolleybus.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight + 10, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + 10);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawTrolleybus(Graphics g)
{
int xForLocomotive = _pictureWidth - 2 * _placeSizeWidth + 60;
int yForLocomotive = 10;
int countInRow = 0;
for (int i = 0; i < _setTrolleybus.Count; i++)
{
if (countInRow >= _pictureWidth / (_placeSizeWidth + 30))
{
xForLocomotive = _pictureWidth - 2 * _placeSizeWidth + 60;
yForLocomotive += _placeSizeHeight;
countInRow = 0;
}
if (_setTrolleybus[i] != null)
{
T locomotive = _setTrolleybus[i];
locomotive.SetObject(xForLocomotive, yForLocomotive, _pictureWidth, _pictureHeight);
locomotive.DrawningObject(g);
}
xForLocomotive -= _placeSizeWidth + 30;
countInRow++;
}
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Trolleybus
{
internal class MapsCollection
{
/// Словарь (хранилище) с картами
readonly Dictionary<string, MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus,
AbstractMap>> _mapStorages;
/// Возвращение списка названий карт
public List<string> Keys => _mapStorages.Keys.ToList();
/// Ширина окна отрисовки
private readonly int _pictureWidth;
/// Высота окна отрисовки
private readonly int _pictureHeight;
/// Конструктор
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string,
MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// Добавление карты
/// <param name="name">Название карты</param>
/// <param name="map">Карта</param>
public void AddMap(string name, AbstractMap map)
{
if (Keys.Contains(name))
return;
_mapStorages.Add(name, new(_pictureWidth, _pictureHeight, map));
}
/// Удаление карты
/// <param name="name">Название карты</param>
public void DelMap(string name)
{
_mapStorages.Remove(name);
}
/// Доступ к депо
/// <param name="ind"></param>
/// <returns></returns>
public MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap> this[string ind]
{
get
{
_mapStorages.TryGetValue(ind, out var mapWithSetTractorsGeneric);
return mapWithSetTractorsGeneric;
}
}
}
}

View File

@ -16,7 +16,7 @@ namespace Trolleybus
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new FormMapWithSetTrolleybus());
}
}
}

View File

@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Trolleybus
{
// Параметризованный набор объектов
internal class SetTrolleybusGeneric<T>
where T : class
{
// Массив объектов, которые храним
private readonly List<T> _places;
// Количество объектов в массиве
public int Count => _places.Count;
private readonly int _maxCount;
// Конструктор
public SetTrolleybusGeneric(int count)
{
_maxCount = count;
_places = new List<T>();
}
private bool CorrectPos(int pos)
{
return 0 <= pos && pos < _maxCount;
}
// Добавление объекта в набор
public int Insert(T trolleybus)
{
// вставка в начало набора
return Insert(trolleybus, 0);
}
// Добавление объекта в набор на конкретную позицию
public int Insert(T trolleybus, int position)
{
// проверка позиции
if (!CorrectPos(position))
{
return -1;
}
// вставка по позиции
_places.Insert(position, trolleybus);
return position;
}
// Удаление объекта из набора с конкретной позиции
public T Remove(int position)
{
// проверка позиции
if (!CorrectPos(position))
return null;
// удаление объекта из массива, присовив элементу массива значение null
T temp = _places[position];
_places.RemoveAt(position);
return temp;
}
// Получение объекта из набора по позиции
public T this[int position]
{
get
{
return CorrectPos(position) && position < Count ? _places[position] : null;
}
set
{
Insert(value, position);
}
}
public IEnumerable<T> GetTractors()
{
foreach (var tractor in _places)
{
if (tractor != null)
{
yield return tractor;
}
else
{
yield break;
}
}
}
}
}

View File

@ -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
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Black);
/// <summary>
/// Цвет участка открытого
/// </summary>
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++;
}
}
}
}
}

View File

@ -11,6 +11,7 @@
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<LangVersion>9.0</LangVersion>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@ -46,8 +47,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AbstractMap.cs" />
<Compile Include="Direction.cs" />
<Compile Include="DrawingSmallTrolleybus.cs" />
<Compile Include="DrawingTrolleybus.cs" />
<Compile Include="DrawningObject.cs" />
<Compile Include="DrawningObjectTrolleybus.cs" />
<Compile Include="EntitySmallTrolleybus.cs" />
<Compile Include="EntityTrolleybus.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
@ -55,11 +61,35 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="FormMap.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FormMap.Designer.cs">
<DependentUpon>FormMap.cs</DependentUpon>
</Compile>
<Compile Include="FormMapWithSetTrolleybus.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FormMapWithSetTrolleybus.Designer.cs">
<DependentUpon>FormMapWithSetTrolleybus.cs</DependentUpon>
</Compile>
<Compile Include="AutoStopMap.cs" />
<Compile Include="IDrawingObject.cs" />
<Compile Include="MapsCollection.cs" />
<Compile Include="MapWithSetTrolleybusGeneric.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SetTrolleybusGeneric.cs" />
<Compile Include="SimpleMap.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FormMap.resx">
<DependentUpon>FormMap.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FormMapWithSetTrolleybus.resx">
<DependentUpon>FormMapWithSetTrolleybus.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>

View File

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{07E18270-5508-4D1A-A699-8B170C1E8502}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>Trolleybus</RootNamespace>
<AssemblyName>Trolleybus</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AbstractMap.cs" />
<Compile Include="Direction.cs" />
<Compile Include="DrawingSmallTrolleybus.cs" />
<Compile Include="DrawingTrolleybus.cs" />
<Compile Include="DrawningObject.cs" />
<Compile Include="EntitySmallTrolleybus.cs" />
<Compile Include="EntityTrolleybus.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="FormMap.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FormMap.Designer.cs">
<DependentUpon>FormMap.cs</DependentUpon>
</Compile>
<Compile Include="IDrawingObject.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SimpleMap.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FormMap.resx">
<DependentUpon>FormMap.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\up30.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\left30.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\down30.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\right30.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>