Логика доведена до рабочего состояния
This commit is contained in:
parent
9d9893d6ff
commit
fcf8c4df4e
@ -47,8 +47,13 @@ namespace Trolleybus
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_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)));
|
||||
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();
|
||||
}
|
||||
@ -82,11 +87,20 @@ namespace Trolleybus
|
||||
|
||||
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)));
|
||||
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();
|
||||
}
|
||||
|
@ -29,17 +29,17 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.buttonAddTrolleybus = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRemoveTrolleybus = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
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.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -64,85 +64,16 @@
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
// buttonLeft
|
||||
//
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 42);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(182, 21);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
//
|
||||
// buttonAddTrolleybus
|
||||
//
|
||||
this.buttonAddTrolleybus.Location = new System.Drawing.Point(7, 85);
|
||||
this.buttonAddTrolleybus.Name = "buttonAddTrolleybus";
|
||||
this.buttonAddTrolleybus.Size = new System.Drawing.Size(181, 23);
|
||||
this.buttonAddTrolleybus.TabIndex = 1;
|
||||
this.buttonAddTrolleybus.Text = "Добавить троллейбус";
|
||||
this.buttonAddTrolleybus.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// 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, 450);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 128);
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(181, 20);
|
||||
this.maskedTextBoxPosition.TabIndex = 2;
|
||||
//
|
||||
// buttonRemoveTrolleybus
|
||||
//
|
||||
this.buttonRemoveTrolleybus.Location = new System.Drawing.Point(6, 170);
|
||||
this.buttonRemoveTrolleybus.Name = "buttonRemoveTrolleybus";
|
||||
this.buttonRemoveTrolleybus.Size = new System.Drawing.Size(182, 23);
|
||||
this.buttonRemoveTrolleybus.TabIndex = 3;
|
||||
this.buttonRemoveTrolleybus.Text = "Удалить троллейбус";
|
||||
this.buttonRemoveTrolleybus.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(7, 216);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(181, 23);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 256);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(181, 23);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.BackgroundImage = global::Trolleybus.Properties.Resources.up30;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(97, 365);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonUp.TabIndex = 6;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.BackgroundImage = global::Trolleybus.Properties.Resources.down30;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(97, 402);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonDown.TabIndex = 7;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.BackgroundImage = global::Trolleybus.Properties.Resources.left30;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(59, 402);
|
||||
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
|
||||
//
|
||||
@ -153,16 +84,97 @@
|
||||
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);
|
||||
//
|
||||
// buttonLeft
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonLeft.BackgroundImage = global::Trolleybus.Properties.Resources.left30;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(59, 402);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(32, 31);
|
||||
this.buttonLeft.TabIndex = 9;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.BackgroundImage = global::Trolleybus.Properties.Resources.down30;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(97, 402);
|
||||
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(97, 365);
|
||||
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, 256);
|
||||
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, 216);
|
||||
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, 170);
|
||||
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, 128);
|
||||
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, 85);
|
||||
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);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Сложная карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 42);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(182, 21);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// 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, 450);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetTrolleybus
|
||||
//
|
||||
|
@ -12,11 +12,11 @@ namespace Trolleybus
|
||||
{
|
||||
public partial class FormMapWithSetTrolleybus : Form
|
||||
{
|
||||
private MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap> _mapCarsCollectionGeneric;
|
||||
public FormMapWithSetTrolleybus()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap> _mapTrolleybusCollectionGeneric;
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
@ -25,36 +25,34 @@ namespace Trolleybus
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Сложная карта":
|
||||
map = new HardMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapCarsCollectionGeneric = new MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap>(
|
||||
_mapTrolleybusCollectionGeneric = new MapWithSetTrolleybusGeneric<DrawningObjectTrolleybus, AbstractMap>(
|
||||
pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapCarsCollectionGeneric = null;
|
||||
_mapTrolleybusCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddCar_Click(object sender, EventArgs e)
|
||||
private void ButtonAddTrolleybus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Form1 form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawningObjectTrolleybus car = new(form.SelectedTrolleybus);
|
||||
if (_mapCarsCollectionGeneric + car)
|
||||
DrawningObjectTrolleybus trolleybus = new(form.SelectedTrolleybus);
|
||||
if (_mapTrolleybusCollectionGeneric + trolleybus !=-1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -67,7 +65,7 @@ namespace Trolleybus
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||||
private void ButtonRemoveTrolleybus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
@ -78,10 +76,10 @@ namespace Trolleybus
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapCarsCollectionGeneric - pos)
|
||||
if (_mapTrolleybusCollectionGeneric - pos !=null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -95,11 +93,11 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
@ -108,11 +106,11 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapCarsCollectionGeneric.ShowOnMap();
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
@ -121,7 +119,7 @@ namespace Trolleybus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapTrolleybusCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -143,7 +141,7 @@ namespace Trolleybus
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapCarsCollectionGeneric.MoveObject(dir);
|
||||
pictureBox.Image = _mapTrolleybusCollectionGeneric.MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
30
Trolleybus/Trolleybus/HardMap.cs
Normal file
30
Trolleybus/Trolleybus/HardMap.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System.Threading;
|
||||
using Trolleybus;
|
||||
|
||||
namespace Trolleybus
|
||||
{
|
||||
internal class HardMap : 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -54,11 +54,11 @@ namespace Trolleybus
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="car"></param>
|
||||
/// <param name="trolleybus"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(MapWithSetTrolleybusGeneric<T, U> map, T car)
|
||||
public static int operator +(MapWithSetTrolleybusGeneric<T, U> map, T trolleybus)
|
||||
{
|
||||
return map._setTrolleybus.Insert(car);
|
||||
return map._setTrolleybus.Insert(trolleybus);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
@ -66,7 +66,7 @@ namespace Trolleybus
|
||||
/// <param name="map"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(MapWithSetTrolleybusGeneric<T, U> map, int position)
|
||||
public static T operator -(MapWithSetTrolleybusGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setTrolleybus.Remove(position);
|
||||
}
|
||||
@ -79,7 +79,7 @@ namespace Trolleybus
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawCars(gr);
|
||||
DrawTrolleybus(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
@ -159,12 +159,29 @@ namespace Trolleybus
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawCars(Graphics g)
|
||||
private void DrawTrolleybus(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _setTrolleybus.Count; i++)
|
||||
{
|
||||
// TODO установка позиции
|
||||
_setTrolleybus.Get(i)?.DrawningObject(g);
|
||||
int xForLocomotive = 2;
|
||||
int yForLocomotive = 10;
|
||||
int countInRow = 0;
|
||||
for (int i = 0; i < _setTrolleybus.Count; i++)
|
||||
{
|
||||
if (countInRow >= _pictureWidth / (_placeSizeWidth + 30))
|
||||
{
|
||||
xForLocomotive = 2;
|
||||
yForLocomotive += _placeSizeHeight;
|
||||
countInRow = 0;
|
||||
}
|
||||
if (_setTrolleybus.Get(i) != null)
|
||||
{
|
||||
T locomotive = _setTrolleybus.Get(i);
|
||||
locomotive.SetObject(xForLocomotive, yForLocomotive, _pictureWidth, _pictureHeight);
|
||||
locomotive.DrawningObject(g);
|
||||
}
|
||||
xForLocomotive += _placeSizeWidth + 30;
|
||||
countInRow++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace Trolleybus
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormMap());
|
||||
Application.Run(new FormMapWithSetTrolleybus());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,71 +6,76 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Trolleybus
|
||||
{
|
||||
// Параметризованный набор объектов
|
||||
internal class SetTrolleybusGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
// Массив объектов, которые храним
|
||||
private readonly T[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
// Количество объектов в массиве
|
||||
public int Count => _places.Length;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
// Конструктор
|
||||
public SetTrolleybusGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T trolleybus)
|
||||
// Добавление объекта в набор
|
||||
public int Insert(T trolleybus)
|
||||
{
|
||||
// TODO вставка в начало набора
|
||||
return true;
|
||||
// вставка в начало набора
|
||||
return Insert(trolleybus, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T trolleybus, int position)
|
||||
// Добавление объекта в набор на конкретную позицию
|
||||
public int Insert(T trolleybus, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
return -1;
|
||||
//проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = trolleybus;
|
||||
return position;
|
||||
}
|
||||
//проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
int findEmptyPos = -1;
|
||||
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
findEmptyPos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (findEmptyPos < 0) return -1;
|
||||
|
||||
//сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
for (int i = findEmptyPos; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
// вставка по позиции
|
||||
_places[position] = trolleybus;
|
||||
return true;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
// Удаление объекта из набора с конкретной позиции
|
||||
public T Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присовив элементу массива значение null
|
||||
return true;
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0) return null;
|
||||
// удаление объекта из массива, присовив элементу массива значение null
|
||||
T temp = _places[position];
|
||||
_places[position] = null;
|
||||
return temp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
// Получение объекта из набора по позиции
|
||||
public T Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -73,6 +73,7 @@
|
||||
<Compile Include="FormMapWithSetTrolleybus.Designer.cs">
|
||||
<DependentUpon>FormMapWithSetTrolleybus.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="HardMap.cs" />
|
||||
<Compile Include="IDrawingObject.cs" />
|
||||
<Compile Include="MapWithSetTrolleybusGeneric.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user