Лабораторная работа 3
This commit is contained in:
parent
1883c5f919
commit
4d138f7172
51
Monorail/Monorail/BushesMap.cs
Normal file
51
Monorail/Monorail/BushesMap.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Monorail
|
||||||
|
{
|
||||||
|
internal class BushesMap : AbstractMap
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly Pen barrierColor = new Pen(Color.DarkGreen, 3);
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Brown);
|
||||||
|
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.DrawLine(barrierColor, new Point(Convert.ToInt32(i * (_size_x - 1)), Convert.ToInt32(j * (_size_y - 1))), new Point(Convert.ToInt32(i * (_size_x - 1) + 7), Convert.ToInt32(j * (_size_y - 1)) + 7));
|
||||||
|
g.DrawLine(barrierColor, new Point(Convert.ToInt32(i * (_size_x - 1) + 7), Convert.ToInt32(j * (_size_y - 1))), new Point(Convert.ToInt32(i * (_size_x - 1) + 7), Convert.ToInt32(j * (_size_y - 1)) + 7));
|
||||||
|
g.DrawLine(barrierColor, new Point(Convert.ToInt32(i * (_size_x - 1) + 7), Convert.ToInt32(j * (_size_y - 1)) + 7), new Point(Convert.ToInt32(i * (_size_x - 1) + 14), Convert.ToInt32(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 < 20)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 100);
|
||||||
|
int y = _random.Next(0, 100);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Monorail
|
namespace Monorail
|
||||||
{
|
{
|
||||||
internal enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
Up = 1,
|
Up = 1,
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Monorail
|
namespace Monorail
|
||||||
{
|
{
|
||||||
internal class DrawingLocomotive
|
public class DrawingLocomotive
|
||||||
{
|
{
|
||||||
public EntityLocomotive Locomotive { get; protected set; }
|
public EntityLocomotive Locomotive { get; protected set; }
|
||||||
protected float _startPosX;
|
protected float _startPosX;
|
||||||
@ -98,7 +98,7 @@ namespace Monorail
|
|||||||
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DrawingLocomotive(int speed, float weight, Color bodyColor, int locomotiveWidth, int locomotiveHeight) :
|
public DrawingLocomotive(int speed, float weight, Color bodyColor, int locomotiveWidth, int locomotiveHeight) :
|
||||||
this(speed, weight, bodyColor)
|
this(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
_locomotiveWidth = locomotiveWidth;
|
_locomotiveWidth = locomotiveWidth;
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Monorail
|
namespace Monorail
|
||||||
{
|
{
|
||||||
internal class EntityLocomotive
|
public class EntityLocomotive
|
||||||
{
|
{
|
||||||
public int Speed { get; private set; }
|
public int Speed { get; private set; }
|
||||||
public float Weight { get; private set; }
|
public float Weight { get; private set; }
|
||||||
|
47
Monorail/Monorail/FieldMap.cs
Normal file
47
Monorail/Monorail/FieldMap.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Monorail
|
||||||
|
{
|
||||||
|
internal class FieldMap : AbstractMap
|
||||||
|
{
|
||||||
|
private readonly Brush barrierColor = new SolidBrush(Color.Brown);
|
||||||
|
private readonly Brush roadColor = new SolidBrush(Color.Green);
|
||||||
|
|
||||||
|
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillEllipse(barrierColor, i * (_size_x - 1), j * (_size_y - 1), 30, 15);
|
||||||
|
}
|
||||||
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x), j * (_size_y));
|
||||||
|
}
|
||||||
|
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 < 20)
|
||||||
|
{
|
||||||
|
int x = _random.Next(0, 100);
|
||||||
|
int y = _random.Next(0, 100);
|
||||||
|
if (_map[x, y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x, y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
Monorail/Monorail/FormLocomotive.Designer.cs
generated
26
Monorail/Monorail/FormLocomotive.Designer.cs
generated
@ -39,6 +39,8 @@
|
|||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
|
buttonCreateModify = new Button();
|
||||||
|
ButtonSelectLocomotive = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).BeginInit();
|
||||||
statusStrip.SuspendLayout();
|
statusStrip.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -139,11 +141,33 @@
|
|||||||
buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
buttonDown.Click += ButtonMove_Click;
|
buttonDown.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreateModify
|
||||||
|
//
|
||||||
|
buttonCreateModify.Location = new Point(93, 390);
|
||||||
|
buttonCreateModify.Name = "buttonCreateModify";
|
||||||
|
buttonCreateModify.Size = new Size(152, 23);
|
||||||
|
buttonCreateModify.TabIndex = 7;
|
||||||
|
buttonCreateModify.Text = "Модифицировать";
|
||||||
|
buttonCreateModify.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateModify.Click += ButtonCreateModify_Click;
|
||||||
|
//
|
||||||
|
// ButtonSelectLocomotive
|
||||||
|
//
|
||||||
|
ButtonSelectLocomotive.Location = new Point(635, 12);
|
||||||
|
ButtonSelectLocomotive.Name = "ButtonSelectLocomotive";
|
||||||
|
ButtonSelectLocomotive.Size = new Size(153, 33);
|
||||||
|
ButtonSelectLocomotive.TabIndex = 8;
|
||||||
|
ButtonSelectLocomotive.Text = "Выбрать";
|
||||||
|
ButtonSelectLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSelectLocomotive.Click += ButtonSelectLocomotive_Click;
|
||||||
|
//
|
||||||
// FormLocomotive
|
// FormLocomotive
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(ButtonSelectLocomotive);
|
||||||
|
Controls.Add(buttonCreateModify);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
@ -172,5 +196,7 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
|
private Button buttonCreateModify;
|
||||||
|
private Button ButtonSelectLocomotive;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,19 +13,11 @@ namespace Monorail
|
|||||||
public partial class FormLocomotive : Form
|
public partial class FormLocomotive : Form
|
||||||
{
|
{
|
||||||
private DrawingLocomotive _locomotive;
|
private DrawingLocomotive _locomotive;
|
||||||
|
public DrawingLocomotive SelectedLocomotive { get; private set; }
|
||||||
public FormLocomotive()
|
public FormLocomotive()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Random rnd = new();
|
|
||||||
_locomotive = new DrawingLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
||||||
SetData();
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
Bitmap bmp = new(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
Bitmap bmp = new(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
@ -33,16 +25,31 @@ namespace Monorail
|
|||||||
_locomotive?.DrawTransport(gr);
|
_locomotive?.DrawTransport(gr);
|
||||||
pictureBoxLocomotive.Image = bmp;
|
pictureBoxLocomotive.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
private void SetData()
|
||||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
{
|
||||||
/// </summary>
|
Random rnd = new();
|
||||||
/// <param name="sender"></param>
|
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
|
||||||
/// <param name="e"></param>
|
pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
/// <summary>
|
toolStripStatusLabelSpeed.Text = $"Ńęîđîńňü: {_locomotive.Locomotive.Speed}";
|
||||||
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
toolStripStatusLabelWeight.Text = $"Âĺń: {_locomotive.Locomotive.Weight}";
|
||||||
/// </summary>
|
toolStripStatusLabelBodyColor.Text = $"Öâĺň: {_locomotive.Locomotive.BodyColor.Name} ";
|
||||||
/// <param name="sender"></param>
|
}
|
||||||
/// <param name="e"></param>
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
|
||||||
|
rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_locomotive = new DrawingLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
color);
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
//ïîëó÷àåì èìÿ êíîïêè
|
//ïîëó÷àåì èìÿ êíîïêè
|
||||||
@ -64,25 +71,40 @@ namespace Monorail
|
|||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void PictureBoxLocomotive_Resize(object sender, EventArgs e)
|
private void PictureBoxLocomotive_Resize(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetData()
|
private void ButtonCreateModify_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_locomotive.Locomotive.Speed}";
|
rnd.Next(0, 256));
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_locomotive.Locomotive.Weight}";
|
ColorDialog dialog = new();
|
||||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_locomotive.Locomotive.BodyColor.Name}";
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
|
||||||
|
rnd.Next(0, 256));
|
||||||
|
ColorDialog dialogDop = new();
|
||||||
|
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogDop.Color;
|
||||||
|
}
|
||||||
|
_locomotive = new DrawingMonorailLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedLocomotive = _locomotive;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
2
Monorail/Monorail/FormMap.Designer.cs
generated
2
Monorail/Monorail/FormMap.Designer.cs
generated
@ -154,7 +154,7 @@
|
|||||||
//
|
//
|
||||||
comboBoxSelectorMap.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxSelectorMap.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxSelectorMap.FormattingEnabled = true;
|
comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
comboBoxSelectorMap.Items.AddRange(new object[] { "SimpleMap" });
|
comboBoxSelectorMap.Items.AddRange(new object[] { "Простая карта", "Поле с грязью", "Кусты на карте" });
|
||||||
comboBoxSelectorMap.Location = new Point(12, 12);
|
comboBoxSelectorMap.Location = new Point(12, 12);
|
||||||
comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
comboBoxSelectorMap.Size = new Size(121, 23);
|
comboBoxSelectorMap.Size = new Size(121, 23);
|
||||||
|
@ -91,6 +91,12 @@ namespace Monorail
|
|||||||
case "Простая карта":
|
case "Простая карта":
|
||||||
_abstractMap = new SimpleMap();
|
_abstractMap = new SimpleMap();
|
||||||
break;
|
break;
|
||||||
|
case "Поле с грязью":
|
||||||
|
_abstractMap = new FieldMap();
|
||||||
|
break;
|
||||||
|
case "Кусты на карте":
|
||||||
|
_abstractMap = new BushesMap();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,11 +55,14 @@
|
|||||||
//
|
//
|
||||||
// comboBoxSelectorMap
|
// comboBoxSelectorMap
|
||||||
//
|
//
|
||||||
|
comboBoxSelectorMap.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxSelectorMap.FormattingEnabled = true;
|
comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
|
comboBoxSelectorMap.Items.AddRange(new object[] { "Простая карта", "Карта с грязью", "Карта с кустами" });
|
||||||
comboBoxSelectorMap.Location = new Point(26, 22);
|
comboBoxSelectorMap.Location = new Point(26, 22);
|
||||||
comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
comboBoxSelectorMap.Size = new Size(168, 23);
|
comboBoxSelectorMap.Size = new Size(168, 23);
|
||||||
comboBoxSelectorMap.TabIndex = 2;
|
comboBoxSelectorMap.TabIndex = 2;
|
||||||
|
comboBoxSelectorMap.SelectedIndexChanged += ComboBoxSelectorMap_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
// buttonAddCar
|
// buttonAddCar
|
||||||
//
|
//
|
||||||
@ -67,8 +70,9 @@
|
|||||||
buttonAddCar.Name = "buttonAddCar";
|
buttonAddCar.Name = "buttonAddCar";
|
||||||
buttonAddCar.Size = new Size(168, 28);
|
buttonAddCar.Size = new Size(168, 28);
|
||||||
buttonAddCar.TabIndex = 3;
|
buttonAddCar.TabIndex = 3;
|
||||||
buttonAddCar.Text = "Добавить автомобиль";
|
buttonAddCar.Text = "Добавить локомотив";
|
||||||
buttonAddCar.UseVisualStyleBackColor = true;
|
buttonAddCar.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddCar.Click += ButtonAddLocomotive_Click;
|
||||||
//
|
//
|
||||||
// buttonRemoveCar
|
// buttonRemoveCar
|
||||||
//
|
//
|
||||||
@ -76,8 +80,9 @@
|
|||||||
buttonRemoveCar.Name = "buttonRemoveCar";
|
buttonRemoveCar.Name = "buttonRemoveCar";
|
||||||
buttonRemoveCar.Size = new Size(169, 30);
|
buttonRemoveCar.Size = new Size(169, 30);
|
||||||
buttonRemoveCar.TabIndex = 4;
|
buttonRemoveCar.TabIndex = 4;
|
||||||
buttonRemoveCar.Text = "Удалить автомобиль";
|
buttonRemoveCar.Text = "Удалить локомотив";
|
||||||
buttonRemoveCar.UseVisualStyleBackColor = true;
|
buttonRemoveCar.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemoveCar.Click += ButtonRemoveLocomotive_Click;
|
||||||
//
|
//
|
||||||
// buttonShowStorage
|
// buttonShowStorage
|
||||||
//
|
//
|
||||||
@ -87,6 +92,7 @@
|
|||||||
buttonShowStorage.TabIndex = 5;
|
buttonShowStorage.TabIndex = 5;
|
||||||
buttonShowStorage.Text = "Посмотреть хранилище";
|
buttonShowStorage.Text = "Посмотреть хранилище";
|
||||||
buttonShowStorage.UseVisualStyleBackColor = true;
|
buttonShowStorage.UseVisualStyleBackColor = true;
|
||||||
|
buttonShowStorage.Click += ButtonShowStorage_Click;
|
||||||
//
|
//
|
||||||
// buttonShowOnMap
|
// buttonShowOnMap
|
||||||
//
|
//
|
||||||
@ -96,6 +102,7 @@
|
|||||||
buttonShowOnMap.TabIndex = 6;
|
buttonShowOnMap.TabIndex = 6;
|
||||||
buttonShowOnMap.Text = "Посмотреть карту";
|
buttonShowOnMap.Text = "Посмотреть карту";
|
||||||
buttonShowOnMap.UseVisualStyleBackColor = true;
|
buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
|
buttonShowOnMap.Click += ButtonShowOnMap_Click;
|
||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
@ -113,6 +120,7 @@
|
|||||||
buttonUp.Size = new Size(30, 30);
|
buttonUp.Size = new Size(30, 30);
|
||||||
buttonUp.TabIndex = 8;
|
buttonUp.TabIndex = 8;
|
||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
@ -123,6 +131,7 @@
|
|||||||
buttonLeft.Size = new Size(30, 30);
|
buttonLeft.Size = new Size(30, 30);
|
||||||
buttonLeft.TabIndex = 9;
|
buttonLeft.TabIndex = 9;
|
||||||
buttonLeft.UseVisualStyleBackColor = true;
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
@ -133,6 +142,7 @@
|
|||||||
buttonDown.Size = new Size(30, 30);
|
buttonDown.Size = new Size(30, 30);
|
||||||
buttonDown.TabIndex = 10;
|
buttonDown.TabIndex = 10;
|
||||||
buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
@ -143,6 +153,7 @@
|
|||||||
buttonRight.Size = new Size(30, 30);
|
buttonRight.Size = new Size(30, 30);
|
||||||
buttonRight.TabIndex = 11;
|
buttonRight.TabIndex = 11;
|
||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
//
|
//
|
||||||
|
@ -12,9 +12,120 @@ namespace Monorail
|
|||||||
{
|
{
|
||||||
public partial class FormMapWithSetLocomotive : Form
|
public partial class FormMapWithSetLocomotive : Form
|
||||||
{
|
{
|
||||||
|
private MapWithSetLocomotiveGeneric <DrawingObjectLocomotive, AbstractMap> _mapLocomotivesCollectionGeneric;
|
||||||
public FormMapWithSetLocomotive()
|
public FormMapWithSetLocomotive()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender,
|
||||||
|
EventArgs e)
|
||||||
|
{
|
||||||
|
AbstractMap map = null;
|
||||||
|
switch (comboBoxSelectorMap.Text)
|
||||||
|
{
|
||||||
|
case "Простая карта":
|
||||||
|
map = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "Карта с грязью":
|
||||||
|
map = new FieldMap();
|
||||||
|
break;
|
||||||
|
case "Карта с кустами":
|
||||||
|
map = new BushesMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (map != null)
|
||||||
|
{
|
||||||
|
_mapLocomotivesCollectionGeneric = new MapWithSetLocomotiveGeneric<DrawingObjectLocomotive, AbstractMap>(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height, map);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_mapLocomotivesCollectionGeneric = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapLocomotivesCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormLocomotive form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
DrawingObjectLocomotive Locomotive = new(form.SelectedLocomotive);
|
||||||
|
if (_mapLocomotivesCollectionGeneric + Locomotive != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxLocomotive.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRemoveLocomotive_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 (_mapLocomotivesCollectionGeneric - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxLocomotive.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapLocomotivesCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxLocomotive.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapLocomotivesCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxLocomotive.Image = _mapLocomotivesCollectionGeneric.ShowOnMap();
|
||||||
|
}
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_mapLocomotivesCollectionGeneric == 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;
|
||||||
|
}
|
||||||
|
pictureBoxLocomotive.Image = _mapLocomotivesCollectionGeneric.MoveObject(dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Monorail
|
namespace Monorail
|
||||||
{
|
{
|
||||||
internal class MapWithSetLocomotivGeneric<T, U>
|
internal class MapWithSetLocomotiveGeneric<T, U>
|
||||||
where T : class, IDrawingObject
|
where T : class, IDrawingObject
|
||||||
where U : AbstractMap
|
where U : AbstractMap
|
||||||
{
|
{
|
||||||
@ -19,28 +19,28 @@ where T : class, IDrawingObject
|
|||||||
// Размер занимаемого объектом места (высота)
|
// Размер занимаемого объектом места (высота)
|
||||||
private readonly int _placeSizeHeight = 150;
|
private readonly int _placeSizeHeight = 150;
|
||||||
// Набор объектов
|
// Набор объектов
|
||||||
private readonly SetLocomotivGeneric<T> _setLocomotive;
|
private readonly SetLocomotiveGeneric<T> _setLocomotive;
|
||||||
// Карта
|
// Карта
|
||||||
private readonly U _map;
|
private readonly U _map;
|
||||||
|
|
||||||
private readonly T[] _places;
|
private readonly T[] _places;
|
||||||
// Конструктор
|
// Конструктор
|
||||||
public MapWithSetLocomotivGeneric(int picWidth, int picHeight, U map)
|
public MapWithSetLocomotiveGeneric(int picWidth, int picHeight, U map)
|
||||||
{
|
{
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
int height = picHeight / _placeSizeHeight;
|
int height = picHeight / _placeSizeHeight;
|
||||||
_setLocomotive = new SetLocomotivGeneric<T>(width * height);
|
_setLocomotive = new SetLocomotiveGeneric<T>(width * height);
|
||||||
_pictureWidth = picWidth;
|
_pictureWidth = picWidth;
|
||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_map = map;
|
_map = map;
|
||||||
}
|
}
|
||||||
// Перегрузка оператора сложения
|
// Перегрузка оператора сложения
|
||||||
public static int operator +(MapWithSetLocomotivGeneric<T, U> map, T Locomotive)
|
public static int operator +(MapWithSetLocomotiveGeneric<T, U> map, T Locomotive)
|
||||||
{
|
{
|
||||||
return map._setLocomotive.Insert(Locomotive);
|
return map._setLocomotive.Insert(Locomotive);
|
||||||
}
|
}
|
||||||
// Перегрузка оператора вычитания
|
// Перегрузка оператора вычитания
|
||||||
public static T operator -(MapWithSetLocomotivGeneric<T, U> map, int position)
|
public static T operator -(MapWithSetLocomotiveGeneric<T, U> map, int position)
|
||||||
{
|
{
|
||||||
|
|
||||||
return map._setLocomotive.Remove(position);
|
return map._setLocomotive.Remove(position);
|
||||||
@ -121,30 +121,20 @@ where T : class, IDrawingObject
|
|||||||
// Метод прорисовки объектов
|
// Метод прорисовки объектов
|
||||||
private void DrawLocomotive(Graphics g)
|
private void DrawLocomotive(Graphics g)
|
||||||
{
|
{
|
||||||
int widthEl = _pictureWidth / _placeSizeWidth;
|
int xPosition = _pictureWidth - _placeSizeWidth;
|
||||||
int heightEl = _pictureHeight / _placeSizeHeight;
|
int yPosition = 12;
|
||||||
|
|
||||||
int curWidth = 0;
|
for (int i = 0; i < _setLocomotive.Count; i++)
|
||||||
int curHeight = 0;
|
|
||||||
|
|
||||||
for (int i = _setLocomotive.Count; i >= 0; i--)
|
|
||||||
{
|
{
|
||||||
_setLocomotive.Get(i)?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 85,
|
_setLocomotive.Get(i)?.SetObject(xPosition, yPosition, _pictureWidth, _pictureHeight);
|
||||||
curHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
|
||||||
_setLocomotive.Get(i)?.DrawingObject(g);
|
_setLocomotive.Get(i)?.DrawingObject(g);
|
||||||
|
|
||||||
if (curWidth < widthEl)
|
xPosition -= _placeSizeWidth;
|
||||||
curWidth++;
|
if (xPosition < _placeSizeWidth)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
curWidth = 1;
|
yPosition += _placeSizeHeight;
|
||||||
curHeight++;
|
xPosition = _pictureWidth - _placeSizeWidth;
|
||||||
}
|
}
|
||||||
if (curHeight > heightEl)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace Monorail
|
|||||||
// 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 FormMapWithSetLocomotive());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Monorail
|
namespace Monorail
|
||||||
{
|
{
|
||||||
internal class SetLocomotivGeneric<T>
|
internal class SetLocomotiveGeneric<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
// Массив объектов, которые храним
|
// Массив объектов, которые храним
|
||||||
@ -14,7 +14,7 @@ where T : class
|
|||||||
// Количество объектов в массиве
|
// Количество объектов в массиве
|
||||||
public int Count => _places.Length;
|
public int Count => _places.Length;
|
||||||
// Конструктор
|
// Конструктор
|
||||||
public SetLocomotivGeneric(int count)
|
public SetLocomotiveGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T[count];
|
_places = new T[count];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user