Этап 3. Готовая лабороторная работа4

This commit is contained in:
Sem730 2022-11-02 09:55:02 +03:00
parent 75635ecc48
commit b9c1c9ca87
14 changed files with 178 additions and 98 deletions

View File

@ -17,7 +17,6 @@ namespace ProjectLocomotive
protected readonly Random _random = new(); protected readonly Random _random = new();
protected readonly int _freeRoad = 0; protected readonly int _freeRoad = 0;
protected readonly int _barrier = 1; protected readonly int _barrier = 1;
public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject) public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
{ {
_width = width; _width = width;
@ -36,7 +35,6 @@ namespace ProjectLocomotive
int startY = (int)(Right / _size_y); int startY = (int)(Right / _size_y);
int endX = (int)(Top / _size_x); int endX = (int)(Top / _size_x);
int endY = (int)(Bottom / _size_y); int endY = (int)(Bottom / _size_y);
for (int i = startX; i <= endX; i++) for (int i = startX; i <= endX; i++)
{ {
for (int j = startY; j <= endY; j++) for (int j = startY; j <= endY; j++)
@ -59,7 +57,6 @@ namespace ProjectLocomotive
_drawningObject.MoveObject(MoveObjectBack(direction)); _drawningObject.MoveObject(MoveObjectBack(direction));
} }
return DrawMapWithObject(); return DrawMapWithObject();
} }
private Direction MoveObjectBack(Direction direction) private Direction MoveObjectBack(Direction direction)
{ {
@ -137,7 +134,6 @@ namespace ProjectLocomotive
_drawningObject.DrawningObject(gr); _drawningObject.DrawningObject(gr);
return bmp; return bmp;
} }
protected abstract void GenerateMap(); protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j);

View File

@ -142,7 +142,6 @@ namespace ProjectLocomotive
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
// кузов электролокомотива (верхняя часть) // кузов электролокомотива (верхняя часть)
//g.DrawRectangle(pen, _startPosX - 1, _startPosY - 1, 80, 30);
g.DrawLine(pen, _startPosX + 7, _startPosY, _startPosX + 80, _startPosY); g.DrawLine(pen, _startPosX + 7, _startPosY, _startPosX + 80, _startPosY);
g.DrawLine(pen, _startPosX + 80, _startPosY, _startPosX + 80, _startPosY + 15); g.DrawLine(pen, _startPosX + 80, _startPosY, _startPosX + 80, _startPosY + 15);
g.DrawLine(pen, _startPosX + 80, _startPosY + 15, _startPosX + 2, _startPosY + 15); g.DrawLine(pen, _startPosX + 80, _startPosY + 15, _startPosX + 2, _startPosY + 15);
@ -167,8 +166,6 @@ namespace ProjectLocomotive
g.DrawLine(pen, _startPosX + 30, _startPosY + 8, _startPosX + 30, _startPosY + 25); g.DrawLine(pen, _startPosX + 30, _startPosY + 8, _startPosX + 30, _startPosY + 25);
g.DrawLine(pen, _startPosX + 30, _startPosY + 25, _startPosX + 20, _startPosY + 25); g.DrawLine(pen, _startPosX + 30, _startPosY + 25, _startPosX + 20, _startPosY + 25);
g.DrawLine(pen, _startPosX + 20, _startPosY + 25, _startPosX + 20, _startPosY + 6); g.DrawLine(pen, _startPosX + 20, _startPosY + 25, _startPosX + 20, _startPosY + 6);
} }
/// <summary> /// <summary>
/// Смена границ формы отрисовки /// Смена границ формы отрисовки

View File

@ -13,24 +13,19 @@ namespace ProjectLocomotive
{ {
_loc = loc; _loc = loc;
} }
public float Step => _loc?.Locomotivе?.Step ?? 0; public float Step => _loc?.Locomotivе?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{ {
return _loc?.GetCurrentPosition() ?? default; return _loc?.GetCurrentPosition() ?? default;
} }
public void MoveObject(Direction direction) public void MoveObject(Direction direction)
{ {
_loc?.MoveTransport(direction); _loc?.MoveTransport(direction);
} }
public void SetObject(int x, int y, int width, int height) public void SetObject(int x, int y, int width, int height)
{ {
_loc.SetPosition(x, y, width, height); _loc.SetPosition(x, y, width, height);
} }
void IDrawningObject.DrawningObject(Graphics g) void IDrawningObject.DrawningObject(Graphics g)
{ {
// TODO // TODO

View File

@ -29,7 +29,6 @@ namespace ProjectLocomotive
/// <param name="dopColor">Дополнительный цвет</param> /// <param name="dopColor">Дополнительный цвет</param>
/// <param name="electroLines">Признак наличия "рогов" для подключения</param> /// <param name="electroLines">Признак наличия "рогов" для подключения</param>
/// <param name="electroBattery">Признак наличия отсека электро-батарей</param> /// <param name="electroBattery">Признак наличия отсека электро-батарей</param>
public EntityElectricLocomotive(int speed, float weight, Color bodyColor, Color public EntityElectricLocomotive(int speed, float weight, Color bodyColor, Color
dopColor, bool electroLines, bool electroBattery) : dopColor, bool electroLines, bool electroBattery) :
base(speed, weight, bodyColor) base(speed, weight, bodyColor)

View File

@ -187,7 +187,6 @@
this.statusStrip.PerformLayout(); this.statusStrip.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
} }
#endregion #endregion

View File

@ -118,6 +118,6 @@ namespace ProjectLocomotive
{ {
SelectedLocomotive = _elloc; SelectedLocomotive = _elloc;
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }
} }
} }

View File

@ -6,7 +6,6 @@
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
@ -29,6 +28,12 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxTools = new System.Windows.Forms.GroupBox(); this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.groupBox1 = 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.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
@ -38,14 +43,15 @@
this.buttonRemoveLocomotive = new System.Windows.Forms.Button(); this.buttonRemoveLocomotive = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddLocomotive = new System.Windows.Forms.Button(); this.buttonAddLocomotive = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox(); this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout(); this.groupBoxTools.SuspendLayout();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBoxTools // groupBoxTools
// //
this.groupBoxTools.Controls.Add(this.groupBox1);
this.groupBoxTools.Controls.Add(this.buttonLeft); this.groupBoxTools.Controls.Add(this.buttonLeft);
this.groupBoxTools.Controls.Add(this.buttonRight); this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Controls.Add(this.buttonDown);
@ -55,22 +61,84 @@
this.groupBoxTools.Controls.Add(this.buttonRemoveLocomotive); this.groupBoxTools.Controls.Add(this.buttonRemoveLocomotive);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonAddLocomotive); this.groupBoxTools.Controls.Add(this.buttonAddLocomotive);
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(725, 0); this.groupBoxTools.Location = new System.Drawing.Point(794, 0);
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(4); this.groupBoxTools.Margin = new System.Windows.Forms.Padding(4);
this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(4); this.groupBoxTools.Padding = new System.Windows.Forms.Padding(4);
this.groupBoxTools.Size = new System.Drawing.Size(275, 630); this.groupBoxTools.Size = new System.Drawing.Size(220, 654);
this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты"; this.groupBoxTools.Text = "Инструменты";
// //
// groupBox1
//
this.groupBox1.Controls.Add(this.buttonDeleteMap);
this.groupBox1.Controls.Add(this.listBoxMaps);
this.groupBox1.Controls.Add(this.buttonAddMap);
this.groupBox1.Controls.Add(this.textBoxNewMapName);
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.groupBox1.Location = new System.Drawing.Point(6, 26);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(208, 250);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Maps";
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(6, 198);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(196, 34);
this.buttonDeleteMap.TabIndex = 3;
this.buttonDeleteMap.Text = "Удалить карту";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 25;
this.listBoxMaps.Location = new System.Drawing.Point(6, 128);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(196, 54);
this.listBoxMaps.TabIndex = 2;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(6, 93);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(196, 29);
this.buttonAddMap.TabIndex = 1;
this.buttonAddMap.Text = "Добавить карту";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 26);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(196, 31);
this.textBoxNewMapName.TabIndex = 0;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Simple Map",
"Spike Map",
"Rail Map"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 59);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(196, 33);
this.comboBoxSelectorMap.TabIndex = 0;
//
// buttonLeft // buttonLeft
// //
this.buttonLeft.BackgroundImage = global::ProjectLocomotive.Properties.Resources.left; this.buttonLeft.BackgroundImage = global::ProjectLocomotive.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(52, 558); this.buttonLeft.Location = new System.Drawing.Point(22, 591);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(4); this.buttonLeft.Margin = new System.Windows.Forms.Padding(4);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(50, 50); this.buttonLeft.Size = new System.Drawing.Size(50, 50);
@ -82,7 +150,7 @@
// //
this.buttonRight.BackgroundImage = global::ProjectLocomotive.Properties.Resources.right; this.buttonRight.BackgroundImage = global::ProjectLocomotive.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(168, 558); this.buttonRight.Location = new System.Drawing.Point(138, 591);
this.buttonRight.Margin = new System.Windows.Forms.Padding(4); this.buttonRight.Margin = new System.Windows.Forms.Padding(4);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(50, 50); this.buttonRight.Size = new System.Drawing.Size(50, 50);
@ -94,7 +162,7 @@
// //
this.buttonDown.BackgroundImage = global::ProjectLocomotive.Properties.Resources.down; this.buttonDown.BackgroundImage = global::ProjectLocomotive.Properties.Resources.down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(110, 558); this.buttonDown.Location = new System.Drawing.Point(80, 591);
this.buttonDown.Margin = new System.Windows.Forms.Padding(4); this.buttonDown.Margin = new System.Windows.Forms.Padding(4);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(50, 50); this.buttonDown.Size = new System.Drawing.Size(50, 50);
@ -106,7 +174,7 @@
// //
this.buttonUp.BackgroundImage = global::ProjectLocomotive.Properties.Resources.up; this.buttonUp.BackgroundImage = global::ProjectLocomotive.Properties.Resources.up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(110, 500); this.buttonUp.Location = new System.Drawing.Point(80, 533);
this.buttonUp.Margin = new System.Windows.Forms.Padding(4); this.buttonUp.Margin = new System.Windows.Forms.Padding(4);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(50, 50); this.buttonUp.Size = new System.Drawing.Size(50, 50);
@ -116,10 +184,10 @@
// //
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(9, 352); this.buttonShowOnMap.Location = new System.Drawing.Point(0, 489);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(4); this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(4);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(259, 36); this.buttonShowOnMap.Size = new System.Drawing.Size(220, 36);
this.buttonShowOnMap.TabIndex = 5; this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту"; this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true; this.buttonShowOnMap.UseVisualStyleBackColor = true;
@ -127,10 +195,10 @@
// //
// buttonShowStorage // buttonShowStorage
// //
this.buttonShowStorage.Location = new System.Drawing.Point(9, 309); this.buttonShowStorage.Location = new System.Drawing.Point(7, 418);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(4); this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(4);
this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(259, 36); this.buttonShowStorage.Size = new System.Drawing.Size(208, 63);
this.buttonShowStorage.TabIndex = 4; this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище"; this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true; this.buttonShowStorage.UseVisualStyleBackColor = true;
@ -138,10 +206,10 @@
// //
// buttonRemoveLocomotive // buttonRemoveLocomotive
// //
this.buttonRemoveLocomotive.Location = new System.Drawing.Point(9, 264); this.buttonRemoveLocomotive.Location = new System.Drawing.Point(7, 364);
this.buttonRemoveLocomotive.Margin = new System.Windows.Forms.Padding(4); this.buttonRemoveLocomotive.Margin = new System.Windows.Forms.Padding(4);
this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive"; this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
this.buttonRemoveLocomotive.Size = new System.Drawing.Size(259, 38); this.buttonRemoveLocomotive.Size = new System.Drawing.Size(207, 46);
this.buttonRemoveLocomotive.TabIndex = 3; this.buttonRemoveLocomotive.TabIndex = 3;
this.buttonRemoveLocomotive.Text = "Удалить локомотив"; this.buttonRemoveLocomotive.Text = "Удалить локомотив";
this.buttonRemoveLocomotive.UseVisualStyleBackColor = true; this.buttonRemoveLocomotive.UseVisualStyleBackColor = true;
@ -149,7 +217,7 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(8, 199); this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 317);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(4); this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(4);
this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
@ -158,36 +226,22 @@
// //
// buttonAddLocomotive // buttonAddLocomotive
// //
this.buttonAddLocomotive.Location = new System.Drawing.Point(8, 120); this.buttonAddLocomotive.Location = new System.Drawing.Point(6, 282);
this.buttonAddLocomotive.Margin = new System.Windows.Forms.Padding(4); this.buttonAddLocomotive.Margin = new System.Windows.Forms.Padding(4);
this.buttonAddLocomotive.Name = "buttonAddLocomotive"; this.buttonAddLocomotive.Name = "buttonAddLocomotive";
this.buttonAddLocomotive.Size = new System.Drawing.Size(260, 36); this.buttonAddLocomotive.Size = new System.Drawing.Size(208, 40);
this.buttonAddLocomotive.TabIndex = 1; this.buttonAddLocomotive.TabIndex = 1;
this.buttonAddLocomotive.Text = "Добавить локомотив"; this.buttonAddLocomotive.Text = "Добавить локомотив";
this.buttonAddLocomotive.UseVisualStyleBackColor = true; this.buttonAddLocomotive.UseVisualStyleBackColor = true;
this.buttonAddLocomotive.Click += new System.EventHandler(this.buttonAddLocomotive_Click); this.buttonAddLocomotive.Click += new System.EventHandler(this.buttonAddLocomotive_Click);
// //
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Simple Map",
"Spike Map",
"Rail Map"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(8, 49);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(4);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(259, 33);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged);
//
// pictureBox // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0); this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Margin = new System.Windows.Forms.Padding(4); this.pictureBox.Margin = new System.Windows.Forms.Padding(4);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(725, 630); this.pictureBox.Size = new System.Drawing.Size(794, 654);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -195,7 +249,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1000, 630); this.ClientSize = new System.Drawing.Size(1014, 654);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Margin = new System.Windows.Forms.Padding(4); this.Margin = new System.Windows.Forms.Padding(4);
@ -203,11 +257,12 @@
this.Text = "Карта с набором объектов"; this.Text = "Карта с набором объектов";
this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout(); this.groupBoxTools.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #endregion
private GroupBox groupBoxTools; private GroupBox groupBoxTools;
@ -222,5 +277,10 @@
private Button buttonDown; private Button buttonDown;
private Button buttonRight; private Button buttonRight;
private Button buttonLeft; private Button buttonLeft;
private GroupBox groupBox1;
private TextBox textBoxNewMapName;
private Button buttonAddMap;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
} }
} }

View File

@ -1,4 +1,5 @@
using System; using Locomotive;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@ -12,42 +13,49 @@ namespace ProjectLocomotive
{ {
public partial class FormMapWithSetLocomotives : Form public partial class FormMapWithSetLocomotives : Form
{ {
/// Объект от класса карты с набором объектов ///// Объект от класса карты с набором объектов
private MapWithSetLocomotivesGeneric<DrawningObject, AbstractMap> _mapLocomotivesCollectionGeneric; /// Словарь для выпадающего списка
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Simple Map", new SimpleMap() },
{ "Spike Map", new SpikeMap() },
{ "Rail Map", new RailroadMap() }
};
/// Объект от коллекции карт
private readonly MapsCollection _mapsCollection;
public FormMapWithSetLocomotives() public FormMapWithSetLocomotives()
{ {
InitializeComponent(); InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
} }
/// Выбор карты ///// Выбор карты
private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) /// Заполнение listBoxMaps
private void ReloadMaps()
{ {
AbstractMap map = null; int index = listBoxMaps.SelectedIndex;
switch (comboBoxSelectorMap.Text) listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{ {
case "Simple Map": listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
map = new SimpleMap();
break;
case "Spike Map":
map = new SpikeMap();
break;
case "Rail Map":
map = new RailroadMap();
break;
} }
if (map != null) if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{ {
_mapLocomotivesCollectionGeneric = new MapWithSetLocomotivesGeneric<DrawningObject, AbstractMap> listBoxMaps.SelectedIndex = 0;
(pictureBox.Width, pictureBox.Height, map);
} }
else else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{ {
_mapLocomotivesCollectionGeneric = null; listBoxMaps.SelectedIndex = index;
} }
} }
/// Добавление объекта /// Добавление объекта
private void buttonAddLocomotive_Click(object sender, EventArgs e) private void buttonAddLocomotive_Click(object sender, EventArgs e)
{ {
if (_mapLocomotivesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -55,10 +63,10 @@ namespace ProjectLocomotive
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
DrawningObject locomotive = new(form.SelectedLocomotive); DrawningObject locomotive = new(form.SelectedLocomotive);
if (_mapLocomotivesCollectionGeneric + locomotive != -1) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -69,6 +77,10 @@ namespace ProjectLocomotive
/// Удаление объекта /// Удаление объекта
private void buttonRemoveLocomotive_Click(object sender, EventArgs e) private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{ {
return; return;
@ -78,10 +90,10 @@ namespace ProjectLocomotive
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapLocomotivesCollectionGeneric - pos is not null) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -91,25 +103,27 @@ namespace ProjectLocomotive
/// Вывод набора /// Вывод набора
private void buttonShowStorage_Click(object sender, EventArgs e) private void buttonShowStorage_Click(object sender, EventArgs e)
{ {
if (_mapLocomotivesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); pictureBox.Image =
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
/// Вывод карты /// Вывод карты
private void buttonShowOnMap_Click(object sender, EventArgs e) private void buttonShowOnMap_Click(object sender, EventArgs e)
{ {
if (_mapLocomotivesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowOnMap(); pictureBox.Image =
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
} }
/// Перемещение /// Перемещение
private void buttonMove_Click(object sender, EventArgs e) private void buttonMove_Click(object sender, EventArgs e)
{ {
if (_mapLocomotivesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -131,7 +145,41 @@ namespace ProjectLocomotive
dir = Direction.Right; dir = Direction.Right;
break; break;
} }
pictureBox.Image = _mapLocomotivesCollectionGeneric.MoveObject(dir); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
/// Удаление карты
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 void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// Добавление карты
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();
} }
} }
} }

View File

@ -133,13 +133,11 @@ namespace ProjectLocomotive
{ {
int width = _pictureWidth / _placeSizeWidth; int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight; int height = _pictureHeight / _placeSizeHeight;
int curWidth = 0; int curWidth = 0;
int curHeight = 0; int curHeight = 0;
foreach (var locomotive in _setLocomotives.GetLocomotives()) foreach (var locomotive in _setLocomotives.GetLocomotives())
{ {
locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight); locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 560, _pictureWidth, _pictureHeight);
locomotive?.DrawningObject(g); locomotive?.DrawningObject(g);
if (curWidth < width) curWidth++; if (curWidth < width) curWidth++;
else else

View File

@ -48,6 +48,5 @@ namespace Locomotive
return null; return null;
} }
} }
} }
} }

View File

@ -12,19 +12,16 @@ namespace ProjectLocomotive
private readonly Brush barrierColor = new SolidBrush(Color.Black); private readonly Brush barrierColor = new SolidBrush(Color.Black);
/// Цвет участка открытого /// Цвет участка открытого
private readonly Brush roadColor = new SolidBrush(Color.Gray); private readonly Brush roadColor = new SolidBrush(Color.Gray);
protected override void DrawBarrierPart(Graphics g, int i, int j) protected override void DrawBarrierPart(Graphics g, int i, int j)
{ {
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x +
1), j * (_size_y + 1)); 1), j * (_size_y + 1));
} }
protected override void DrawRoadPart(Graphics g, int i, int j) protected override void DrawRoadPart(Graphics g, int i, int j)
{ {
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x +
1), j * (_size_y + 1)); 1), j * (_size_y + 1));
} }
protected override void GenerateMap() protected override void GenerateMap()
{ {
_map = new int[100, 100]; _map = new int[100, 100];

View File

@ -9,9 +9,7 @@ namespace ProjectLocomotive
internal class SeaMap : AbstractMap internal class SeaMap : AbstractMap
{ {
private readonly Brush barrierColor = new SolidBrush(Color.White); private readonly Brush barrierColor = new SolidBrush(Color.White);
private readonly Brush roadColor = new SolidBrush(Color.Blue); private readonly Brush roadColor = new SolidBrush(Color.Blue);
protected override void DrawBarrierPart(Graphics g, int i, int j) 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)); g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));

View File

@ -19,7 +19,6 @@ namespace ProjectLocomotive
/// Цвет участка открытого /// Цвет участка открытого
/// </summary> /// </summary>
private readonly Brush roadColor = new SolidBrush(Color.Gray); private readonly Brush roadColor = new SolidBrush(Color.Gray);
protected override void DrawBarrierPart(Graphics g, int i, int j) 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)); g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));

View File

@ -12,19 +12,16 @@ namespace ProjectLocomotive
private readonly Brush barrierColor = new SolidBrush(Color.Black); private readonly Brush barrierColor = new SolidBrush(Color.Black);
/// Цвет участка открытого /// Цвет участка открытого
private readonly Brush roadColor = new SolidBrush(Color.Gray); private readonly Brush roadColor = new SolidBrush(Color.Gray);
protected override void DrawBarrierPart(Graphics g, int i, int j) protected override void DrawBarrierPart(Graphics g, int i, int j)
{ {
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x +
1), j * (_size_y + 1)); 1), j * (_size_y + 1));
} }
protected override void DrawRoadPart(Graphics g, int i, int j) protected override void DrawRoadPart(Graphics g, int i, int j)
{ {
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x +
1), j * (_size_y + 1)); 1), j * (_size_y + 1));
} }
protected override void GenerateMap() protected override void GenerateMap()
{ {
_map = new int[100, 100]; _map = new int[100, 100];
@ -45,12 +42,10 @@ namespace ProjectLocomotive
if (_map[x, y] == _freeRoad) if (_map[x, y] == _freeRoad)
{ {
_map[x, y] = _barrier; _map[x, y] = _barrier;
if (_map[x + 1, y] == _freeRoad) _map[x + 1, y] = _barrier; if (_map[x + 1, y] == _freeRoad) _map[x + 1, y] = _barrier;
if (_map[x - 1, y] == _freeRoad) _map[x - 1, y] = _barrier; if (_map[x - 1, y] == _freeRoad) _map[x - 1, y] = _barrier;
if (_map[x, y + 1] == _freeRoad) _map[x, y + 1] = _barrier; if (_map[x, y + 1] == _freeRoad) _map[x, y + 1] = _barrier;
if (_map[x, y - 1] == _freeRoad) _map[x, y - 1] = _barrier; if (_map[x, y - 1] == _freeRoad) _map[x, y - 1] = _barrier;
counter++; counter++;
} }
} }