change forms

This commit is contained in:
Марат Заргаров 2022-11-27 16:52:38 +04:00
parent 6ee33ab213
commit d4b8f8a0b4
11 changed files with 335 additions and 262 deletions

View File

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

View File

@ -9,7 +9,7 @@ namespace DoubleDeckerBus
/// <summary> /// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary> /// </summary>
internal class DrawningBus public class DrawningBus
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность

View File

@ -9,7 +9,7 @@ namespace DoubleDeckerBus
/// <summary> /// <summary>
/// Класс-сущность "Автобус" /// Класс-сущность "Автобус"
/// </summary> /// </summary>
internal class EntityBus public class EntityBus
{ {
/// <summary> /// <summary>
/// Скорость /// Скорость

View File

@ -39,6 +39,7 @@
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button(); this.buttonCreateModif = new System.Windows.Forms.Button();
this.buttonSelectBus = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).BeginInit();
this.statusStrip.SuspendLayout(); this.statusStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -151,11 +152,22 @@
this.buttonCreateModif.UseVisualStyleBackColor = true; this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
// //
// buttonSelectBus
//
this.buttonSelectBus.Location = new System.Drawing.Point(562, 390);
this.buttonSelectBus.Name = "buttonSelectBus";
this.buttonSelectBus.Size = new System.Drawing.Size(104, 23);
this.buttonSelectBus.TabIndex = 8;
this.buttonSelectBus.Text = "Выбрать";
this.buttonSelectBus.UseVisualStyleBackColor = true;
this.buttonSelectBus.Click += new System.EventHandler(this.ButtonSelectBus_Click);
//
// FormBus // FormBus
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonSelectBus);
this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
@ -187,5 +199,6 @@
private Button buttonDown; private Button buttonDown;
private Button buttonRight; private Button buttonRight;
private Button buttonCreateModif; private Button buttonCreateModif;
private Button buttonSelectBus;
} }
} }

View File

@ -7,6 +7,8 @@ namespace DoubleDeckerBus
{ {
InitializeComponent(); InitializeComponent();
} }
public DrawningBus SelectedCar { get; private set; }
private void Draw() private void Draw()
{ {
Bitmap bmp = new(pictureBoxBus.Width, pictureBoxBus.Height); Bitmap bmp = new(pictureBoxBus.Width, pictureBoxBus.Height);
@ -97,5 +99,12 @@ namespace DoubleDeckerBus
SetData(); SetData();
Draw(); Draw();
} }
private void ButtonSelectBus_Click(object sender, EventArgs e)
{
SelectedCar = _bus;
DialogResult = DialogResult.OK;
}
} }
} }

View File

@ -1,103 +0,0 @@
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 DoubleDeckerBus
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
comboBoxSelectorMap.Text = "Простая карта";
}
/// <summary>
/// Заполнение информации по объекту
/// </summary>
/// <param name="bus"></param>
private void SetData(DrawningBus bus)
{
toolStripStatusLabelSpeed.Text = $"Скорость: {bus.Bus.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {bus.Bus.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет:" + $"{bus.Bus.BodyColor.Name}"; pictureBoxBus.Image = _abstractMap.CreateMap(pictureBoxBus.Width,pictureBoxBus.Height,new DrawningObjectBus(bus));
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
var car = new DrawningBus(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetData(car);
}
/// <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;
}
pictureBoxBus.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();
var car = new DrawningDoubleDeckerBus(rnd.Next(100, 300), rnd.Next(1000,2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0,256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0,256)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(car);
}
/// <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;
case "Моя карта":
_abstractMap = new MyMap();
break;
}
}
}
}

View File

@ -1,6 +1,6 @@
namespace DoubleDeckerBus namespace DoubleDeckerBus
{ {
partial class FormMap partial class FormMapWithSetBuses
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@ -28,179 +28,188 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.pictureBoxBus = new System.Windows.Forms.PictureBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveBus = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddBus = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).BeginInit(); this.pictureBox = new System.Windows.Forms.PictureBox();
this.statusStrip.SuspendLayout(); this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// pictureBoxBus // groupBox1
// //
this.pictureBoxBus.Dock = System.Windows.Forms.DockStyle.Fill; this.groupBox1.Controls.Add(this.buttonLeft);
this.pictureBoxBus.Location = new System.Drawing.Point(0, 0); this.groupBox1.Controls.Add(this.buttonUp);
this.pictureBoxBus.Name = "pictureBoxBus"; this.groupBox1.Controls.Add(this.buttonRight);
this.pictureBoxBus.Size = new System.Drawing.Size(800, 428); this.groupBox1.Controls.Add(this.buttonDown);
this.pictureBoxBus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.groupBox1.Controls.Add(this.buttonShowOnMap);
this.pictureBoxBus.TabIndex = 0; this.groupBox1.Controls.Add(this.buttonShowStorage);
this.pictureBoxBus.TabStop = false; this.groupBox1.Controls.Add(this.buttonRemoveBus);
// this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
// statusStrip this.groupBox1.Controls.Add(this.buttonAddBus);
// this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.toolStripStatusLabelSpeed, this.groupBox1.Location = new System.Drawing.Point(600, 0);
this.toolStripStatusLabelWeight, this.groupBox1.Name = "groupBox1";
this.toolStripStatusLabelBodyColor}); this.groupBox1.Size = new System.Drawing.Size(200, 450);
this.statusStrip.Location = new System.Drawing.Point(0, 428); this.groupBox1.TabIndex = 0;
this.statusStrip.Name = "statusStrip"; this.groupBox1.TabStop = false;
this.statusStrip.Size = new System.Drawing.Size(800, 22); this.groupBox1.Text = "Инструменты";
this.statusStrip.TabIndex = 1;
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17);
this.toolStripStatusLabelSpeed.Text = "Скорость:";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17);
this.toolStripStatusLabelWeight.Text = "Вес:";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(12, 393);
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);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.Up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(722, 350);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonLeft // buttonLeft
// //
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.Left; this.buttonLeft.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.Left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(686, 386); this.buttonLeft.Location = new System.Drawing.Point(52, 408);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4; this.buttonLeft.TabIndex = 9;
this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonDown // buttonUp
// //
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.Down; this.buttonUp.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.Up;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(722, 386); this.buttonUp.Location = new System.Drawing.Point(88, 372);
this.buttonDown.Name = "buttonDown"; this.buttonUp.Name = "buttonUp";
this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 5; this.buttonUp.TabIndex = 8;
this.buttonDown.UseVisualStyleBackColor = true; this.buttonUp.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonRight // buttonRight
// //
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.Right; this.buttonRight.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.Right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(758, 386); this.buttonRight.Location = new System.Drawing.Point(124, 408);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 6; this.buttonRight.TabIndex = 7;
this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonCreateModif // buttonDown
// //
this.buttonCreateModif.Location = new System.Drawing.Point(93, 393); this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCreateModif.Name = "buttonCreateModif"; this.buttonDown.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.Down;
this.buttonCreateModif.Size = new System.Drawing.Size(104, 23); this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonCreateModif.TabIndex = 7; this.buttonDown.Location = new System.Drawing.Point(88, 408);
this.buttonCreateModif.Text = "Модификация"; this.buttonDown.Name = "buttonDown";
this.buttonCreateModif.UseVisualStyleBackColor = true; this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); this.buttonDown.TabIndex = 6;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(6, 302);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(188, 29);
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(6, 235);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(188, 30);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonRemoveBus
//
this.buttonRemoveBus.Location = new System.Drawing.Point(6, 150);
this.buttonRemoveBus.Name = "buttonRemoveBus";
this.buttonRemoveBus.Size = new System.Drawing.Size(188, 28);
this.buttonRemoveBus.TabIndex = 3;
this.buttonRemoveBus.Text = "Удалить автобус";
this.buttonRemoveBus.UseVisualStyleBackColor = true;
this.buttonRemoveBus.Click += new System.EventHandler(this.ButtonRemoveBus_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 121);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23);
this.maskedTextBoxPosition.TabIndex = 2;
//
// buttonAddBus
//
this.buttonAddBus.Location = new System.Drawing.Point(6, 73);
this.buttonAddBus.Name = "buttonAddBus";
this.buttonAddBus.Size = new System.Drawing.Size(188, 28);
this.buttonAddBus.TabIndex = 1;
this.buttonAddBus.Text = "Добавить автобус";
this.buttonAddBus.UseVisualStyleBackColor = true;
this.buttonAddBus.Click += new System.EventHandler(this.ButtonAddBus_Click);
// //
// comboBoxSelectorMap // comboBoxSelectorMap
// //
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] { this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта", "Простая карта",
"Моя карта"}); "Моя карта"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23);
this.comboBoxSelectorMap.TabIndex = 8; this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
// //
// FormMap // 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;
//
// FormMapWithSetBuses
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.comboBoxSelectorMap); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.groupBox1);
this.Controls.Add(this.buttonRight); this.Name = "FormMapWithSetBuses";
this.Controls.Add(this.buttonDown); this.Text = "Карта с набором объектов";
this.Controls.Add(this.buttonLeft); this.groupBox1.ResumeLayout(false);
this.Controls.Add(this.buttonUp); this.groupBox1.PerformLayout();
this.Controls.Add(this.buttonCreate); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.Controls.Add(this.pictureBoxBus);
this.Controls.Add(this.statusStrip);
this.Name = "FormMap";
this.Text = "FormMap";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
#endregion #endregion
private PictureBox pictureBoxBus;
private StatusStrip statusStrip; private GroupBox groupBox1;
private ToolStripStatusLabel toolStripStatusLabelSpeed; private PictureBox pictureBox;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonCreateModif;
private ComboBox comboBoxSelectorMap; private ComboBox comboBoxSelectorMap;
private Button buttonAddBus;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonRemoveBus;
private Button buttonShowStorage;
private Button buttonShowOnMap;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
} }
} }

View File

@ -0,0 +1,165 @@
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;
using static System.Windows.Forms.DataFormats;
namespace DoubleDeckerBus
{
public partial class FormMapWithSetBuses : Form
{
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetBusesGeneric<DrawningObjectBus, AbstractMap> _mapBusesCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetBuses()
{
InitializeComponent();
}
/// <summary>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Моя карта":
map = new MyMap();
break;
}
if (map != null)
{
_mapBusesCollectionGeneric = new
MapWithSetBusesGeneric<DrawningObjectBus, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapBusesCollectionGeneric = null;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddBus_Click(object sender, EventArgs e)
{
if (_mapBusesCollectionGeneric == null)
{
return;
}
FormBus form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectBus bus = new(form.SelectedCar);
if (_mapBusesCollectionGeneric + bus !=-1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapBusesCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveBus_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapBusesCollectionGeneric - pos!=null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapBusesCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapBusesCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapBusesCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapBusesCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapBusesCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapBusesCollectionGeneric == null)
{
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 = _mapBusesCollectionGeneric.MoveObject(dir);
}
}
}

View File

@ -57,7 +57,4 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root> </root>

View File

@ -21,11 +21,11 @@ namespace DoubleDeckerBus
/// <summary> /// <summary>
/// Размер занимаемого объектом места (ширина) /// Размер занимаемого объектом места (ширина)
/// </summary> /// </summary>
private readonly int _placeSizeWidth = 210; private readonly int _placeSizeWidth = 240;
/// <summary> /// <summary>
/// Размер занимаемого объектом места (высота) /// Размер занимаемого объектом места (высота)
/// </summary> /// </summary>
private readonly int _placeSizeHeight = 90; private readonly int _placeSizeHeight = 92;
/// <summary> /// <summary>
/// Набор объектов /// Набор объектов
/// </summary> /// </summary>
@ -145,21 +145,12 @@ namespace DoubleDeckerBus
private void DrawBackground(Graphics g) private void DrawBackground(Graphics g)
{ {
Pen pen = new(Color.Black, 3); Pen pen = new(Color.Black, 3);
Brush pointColor = new SolidBrush(Color.Orange);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{ {
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{ {
//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight,
i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (40)));
g.FillPolygon(pointColor, new Point[] {
new Point(i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (40))),
new Point(i * _placeSizeWidth + _placeSizeWidth / 2 - 10, (int)((j * _placeSizeHeight) - (50))),
new Point(i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (60))),
new Point(i * _placeSizeWidth + _placeSizeWidth / 2 + 10, (int)((j * _placeSizeHeight) - (50)))
});
} }
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
} }
@ -170,28 +161,20 @@ namespace DoubleDeckerBus
/// <param name="g"></param> /// <param name="g"></param>
private void DrawBuses(Graphics g) private void DrawBuses(Graphics g)
{ {
int width = _pictureWidth / _placeSizeWidth; int xPosition = 10;
int height = _pictureHeight / _placeSizeHeight; int yPosition = _pictureHeight / _placeSizeHeight - 1;
int currentWidth = width - 1;
int currentHeight = 0;
for (int i = 0; i < _setBuses.Count; i++) for (int i = 0; i < _setBuses.Count; i++)
{ {
_setBuses.Get(i)?.SetObject(xPosition, yPosition, _pictureWidth, _pictureHeight);
_setBuses.Get(i)?.SetObject(currentWidth * _placeSizeWidth,
currentHeight * _placeSizeHeight,
_pictureWidth, _pictureHeight);
_setBuses.Get(i)?.DrawningObject(g); _setBuses.Get(i)?.DrawningObject(g);
if (currentWidth > 0) xPosition += _placeSizeWidth;
currentWidth--; if (xPosition + _placeSizeWidth > _pictureWidth)
else
{ {
currentWidth = width - 1; yPosition += _placeSizeHeight;
currentHeight++; xPosition = 10;
} }
if (currentHeight > height) return;
} }
} }
} }

View File

@ -11,7 +11,7 @@ namespace DoubleDeckerBus
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormMap()); Application.Run(new FormMapWithSetBuses());
} }
} }
} }