Batylkin A.O. LabWork03 #5
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
|
@ -27,14 +27,14 @@ namespace ElectricLocomotive
|
||||
|
||||
if (sportCar.BodyKit)
|
||||
{
|
||||
Point[] pts = { new Point(Convert.ToInt32(_startPosX) + 15, Convert.ToInt32(_startPosY) - 20), new Point(Convert.ToInt32(_startPosX) + 45, Convert.ToInt32(_startPosY) - 30), new Point(Convert.ToInt32(_startPosX) + 75, Convert.ToInt32(_startPosY) - 20), new Point(Convert.ToInt32(_startPosX) + 45, Convert.ToInt32(_startPosY) + 10) };
|
||||
g.DrawPolygon(window, pts);
|
||||
Point[] pts = { new Point(Convert.ToInt32(_startPosX) + 15, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 45, Convert.ToInt32(_startPosY)), new Point(Convert.ToInt32(_startPosX) + 75, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 45, Convert.ToInt32(_startPosY) + 40) };
|
||||
g.DrawPolygon(Pens.Black, pts);
|
||||
}
|
||||
|
||||
if (sportCar.SportLine)
|
||||
{
|
||||
Point[] pts = { new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 60), new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 30), new Point(Convert.ToInt32(_startPosX) + 150, Convert.ToInt32(_startPosY) + 60)};
|
||||
g.FillPolygon(Brushes.Black, pts);
|
||||
Point[] pts = { new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 90), new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 60), new Point(Convert.ToInt32(_startPosX) + 150, Convert.ToInt32(_startPosY) + 90) };
|
||||
g.FillPolygon(dopBrush, pts);
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal class DrawningLocomotive
|
||||
public class DrawningLocomotive
|
||||
{
|
||||
public EntityLocomotive Locomotive { get; protected set; }
|
||||
protected float _startPosX;
|
||||
@ -16,7 +16,7 @@ namespace ElectricLocomotive
|
||||
protected int? _pictureWidth = null;
|
||||
protected int? _pictureHeight = null;
|
||||
|
||||
protected readonly int _locomotiveWidth = 160;
|
||||
protected readonly int _locomotiveWidth = 200;
|
||||
protected readonly int _locomotiveHeight = 90;
|
||||
public DrawningLocomotive(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
@ -31,8 +31,8 @@ namespace ElectricLocomotive
|
||||
return;
|
||||
}
|
||||
|
||||
_startPosX = x + 20;
|
||||
_startPosY = y + 30;
|
||||
_startPosX = x + 10;
|
||||
_startPosY = y;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
@ -53,14 +53,14 @@ namespace ElectricLocomotive
|
||||
break;
|
||||
//влево
|
||||
case Direction.Left:
|
||||
if(_startPosX - Locomotive.Step > 0)
|
||||
if (_startPosX - Locomotive.Step > 0)
|
||||
{
|
||||
_startPosX -= Locomotive.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case Direction.Up:
|
||||
if(_startPosY - Locomotive.Step - 30 > 0)
|
||||
if (_startPosY - Locomotive.Step - 30 > 0)
|
||||
{
|
||||
_startPosY -= Locomotive.Step;
|
||||
}
|
||||
@ -82,6 +82,7 @@ namespace ElectricLocomotive
|
||||
_locomotiveWidth = locomotiveWidth;
|
||||
_locomotiveHeight = locomotiveHeight;
|
||||
}
|
||||
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
@ -94,37 +95,37 @@ namespace ElectricLocomotive
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Pen window = new Pen(Color.Blue);
|
||||
|
||||
g.FillPolygon(brBody, new Point[] { new Point(Convert.ToInt32(_startPosX) + 10, Convert.ToInt32(_startPosY) + 60), new Point(Convert.ToInt32(_startPosX) + 10, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 110, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 30), new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 60) });
|
||||
g.FillRectangle(blackturbo, _startPosX + 5, _startPosY + 15, 5, 40);
|
||||
g.FillPolygon(brBody, new Point[] { new Point(Convert.ToInt32(_startPosX) + 10, Convert.ToInt32(_startPosY) + 90), new Point(Convert.ToInt32(_startPosX) + 10, Convert.ToInt32(_startPosY) + 40), new Point(Convert.ToInt32(_startPosX) + 110, Convert.ToInt32(_startPosY) + 40), new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 60), new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 90) });
|
||||
g.FillRectangle(blackturbo, _startPosX + 5, _startPosY + 45, 5, 40);
|
||||
|
||||
g.FillEllipse(brBody, _startPosX + 15, _startPosY + 60, 20, 20);
|
||||
g.FillEllipse(brBody, _startPosX + 45, _startPosY + 60, 20, 20);
|
||||
g.FillEllipse(brBody, _startPosX + 15, _startPosY + 90, 20, 20);
|
||||
g.FillEllipse(brBody, _startPosX + 45, _startPosY + 90, 20, 20);
|
||||
|
||||
|
||||
g.FillEllipse(brBody, _startPosX + 85, _startPosY + 60, 20, 20);
|
||||
g.FillEllipse(brBody, _startPosX + 115, _startPosY + 60, 20, 20);
|
||||
g.FillEllipse(brBody, _startPosX + 85, _startPosY + 90, 20, 20);
|
||||
g.FillEllipse(brBody, _startPosX + 115, _startPosY + 90, 20, 20);
|
||||
|
||||
// Окна
|
||||
|
||||
g.DrawRectangle(window, _startPosX + 20, _startPosY + 20, 20, 25);
|
||||
g.DrawRectangle(window, _startPosX + 50, _startPosY + 20, 20, 25);
|
||||
g.DrawRectangle(window, _startPosX + 20, _startPosY + 50, 20, 25);
|
||||
g.DrawRectangle(window, _startPosX + 50, _startPosY + 50, 20, 25);
|
||||
|
||||
// Колёса
|
||||
|
||||
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 60, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 45, _startPosY + 60, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 90, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 45, _startPosY + 90, 20, 20);
|
||||
|
||||
|
||||
g.DrawEllipse(pen, _startPosX + 85, _startPosY + 60, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 115, _startPosY + 60, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 85, _startPosY + 90, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 115, _startPosY + 90, 20, 20);
|
||||
|
||||
// Дверь
|
||||
|
||||
g.DrawRectangle(pen, _startPosX + 85, _startPosY + 15, 20, 40);
|
||||
g.DrawRectangle(pen, _startPosX + 85, _startPosY + 45, 20, 40);
|
||||
|
||||
// Локомотив
|
||||
|
||||
g.DrawPolygon(pen, new Point[] { new Point(Convert.ToInt32(_startPosX) + 10, Convert.ToInt32(_startPosY) + 60), new Point(Convert.ToInt32(_startPosX) + 10, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 110, Convert.ToInt32(_startPosY) + 10), new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 30), new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 60) });
|
||||
g.DrawPolygon(pen, new Point[] { new Point(Convert.ToInt32(_startPosX) + 10, Convert.ToInt32(_startPosY) + 90), new Point(Convert.ToInt32(_startPosX) + 10, Convert.ToInt32(_startPosY) + 40), new Point(Convert.ToInt32(_startPosX) + 110, Convert.ToInt32(_startPosY) + 40), new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 60), new Point(Convert.ToInt32(_startPosX) + 140, Convert.ToInt32(_startPosY) + 90) });
|
||||
|
||||
}
|
||||
public void ChangeBorders(int width, int height)
|
||||
|
@ -9,12 +9,10 @@ namespace ElectricLocomotive
|
||||
internal class DrawningObjectLocomotive : IDrawningObject
|
||||
{
|
||||
private DrawningLocomotive _locomotive = null;
|
||||
|
||||
public DrawningObjectLocomotive(DrawningLocomotive locomotive)
|
||||
{
|
||||
_locomotive = locomotive;
|
||||
}
|
||||
|
||||
public float Step => _locomotive?.Locomotive?.Step ?? 0;
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal class EntityLocomotive
|
||||
public class EntityLocomotive
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public float Weight { get; private set; }
|
||||
|
@ -39,6 +39,7 @@
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.buttonselectlocomotive = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -95,6 +96,7 @@
|
||||
this.pictureBox1.Size = new System.Drawing.Size(800, 428);
|
||||
this.pictureBox1.TabIndex = 2;
|
||||
this.pictureBox1.TabStop = false;
|
||||
this.pictureBox1.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
@ -158,11 +160,22 @@
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// buttonselectlocomotive
|
||||
//
|
||||
this.buttonselectlocomotive.Location = new System.Drawing.Point(202, 396);
|
||||
this.buttonselectlocomotive.Name = "buttonselectlocomotive";
|
||||
this.buttonselectlocomotive.Size = new System.Drawing.Size(82, 23);
|
||||
this.buttonselectlocomotive.TabIndex = 8;
|
||||
this.buttonselectlocomotive.Text = "Выбрать";
|
||||
this.buttonselectlocomotive.UseVisualStyleBackColor = true;
|
||||
this.buttonselectlocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click);
|
||||
//
|
||||
// FormLocomotive
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonselectlocomotive);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
@ -195,5 +208,6 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateModif;
|
||||
private Button buttonselectlocomotive;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -13,19 +13,11 @@ namespace ElectricLocomotive
|
||||
public partial class FormLocomotive : Form
|
||||
{
|
||||
private DrawningLocomotive _locomotive;
|
||||
public DrawningLocomotive SelectedLocomotive { get; private set; }
|
||||
public FormLocomotive()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_locomotive = new DrawningLocomotive(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()
|
||||
{
|
||||
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
|
||||
@ -33,16 +25,31 @@ namespace ElectricLocomotive
|
||||
_locomotive?.DrawTransport(gr);
|
||||
pictureBox1.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
/// <summary>
|
||||
/// Изменение размеров формы
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
|
||||
pictureBox1.Width, pictureBox1.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_locomotive.Locomotive.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_locomotive.Locomotive.Weight}";
|
||||
toolStripStatusLabelColor.Text = $"Цвет: { _locomotive.Locomotive.BodyColor.Name} ";
|
||||
}
|
||||
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 DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
color);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
//получаем имя кнопки
|
||||
@ -64,35 +71,42 @@ namespace ElectricLocomotive
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение размеров формы
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PictureBoxCar_Resize(object sender, EventArgs e)
|
||||
|
||||
private void PictureBoxLocomotive_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_locomotive?.ChangeBorders(pictureBox1.Width, pictureBox1.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox1.Width, pictureBox1.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_locomotive.Locomotive.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_locomotive.Locomotive.Weight}";
|
||||
toolStripStatusLabelColor.Text = $"Цвет: {_locomotive.Locomotive.BodyColor.Name}";
|
||||
}
|
||||
|
||||
private void ButtonCreateModif_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;
|
||||
}
|
||||
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 DrawningElectricLocomotive(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)));
|
||||
color, dopColor,
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,105 +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 ElectricLocomotive
|
||||
{
|
||||
public partial class FormMap : Form
|
||||
{
|
||||
private AbstractMap _abstractMap;
|
||||
public FormMap()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
|
||||
private void SetData(DrawningLocomotive locomotive)
|
||||
{
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}";
|
||||
toolStripStatusLabelColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}";
|
||||
pictureBox1.Image = _abstractMap.CreateMap(pictureBox1.Width, pictureBox1.Height,
|
||||
new DrawningObjectLocomotive(locomotive));
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var car = new DrawningLocomotive(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;
|
||||
}
|
||||
pictureBox1.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 DrawningElectricLocomotive(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 FieldMap();
|
||||
break;
|
||||
case "Кусты на карте":
|
||||
_abstractMap = new BushesMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
partial class FormMap
|
||||
partial class FormMapWithSetLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -28,34 +28,21 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.ButtonCreate = new System.Windows.Forms.Button();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.buttonAddLocomotive = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRemoveCar = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// ButtonCreate
|
||||
//
|
||||
this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreate.AutoSize = true;
|
||||
this.ButtonCreate.Location = new System.Drawing.Point(12, 396);
|
||||
this.ButtonCreate.Name = "ButtonCreate";
|
||||
this.ButtonCreate.Size = new System.Drawing.Size(75, 25);
|
||||
this.ButtonCreate.TabIndex = 8;
|
||||
this.ButtonCreate.Text = "Создать";
|
||||
this.ButtonCreate.UseVisualStyleBackColor = true;
|
||||
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
@ -63,57 +50,17 @@
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(800, 428);
|
||||
this.pictureBox1.Size = new System.Drawing.Size(631, 449);
|
||||
this.pictureBox1.TabIndex = 10;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// statusStrip1
|
||||
//
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelColor});
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 428);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Size = new System.Drawing.Size(800, 22);
|
||||
this.statusStrip1.TabIndex = 9;
|
||||
this.statusStrip1.Text = "statusStrip1";
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(59, 17);
|
||||
this.toolStripStatusLabelSpeed.Text = "Скорость";
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(26, 17);
|
||||
this.toolStripStatusLabelWeight.Text = "Вес";
|
||||
//
|
||||
// toolStripStatusLabelColor
|
||||
//
|
||||
this.toolStripStatusLabelColor.Name = "toolStripStatusLabelColor";
|
||||
this.toolStripStatusLabelColor.Size = new System.Drawing.Size(33, 17);
|
||||
this.toolStripStatusLabelColor.Text = "Цвет";
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(93, 396);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(103, 23);
|
||||
this.buttonCreateModif.TabIndex = 15;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.AutoSize = true;
|
||||
this.buttonUp.BackgroundImage = global::ElectricLocomotive.Properties.Resources.arrowup;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(712, 353);
|
||||
this.buttonUp.Location = new System.Drawing.Point(699, 372);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 14;
|
||||
@ -126,7 +73,7 @@
|
||||
this.buttonRight.AutoSize = true;
|
||||
this.buttonRight.BackgroundImage = global::ElectricLocomotive.Properties.Resources.arrowright;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(748, 389);
|
||||
this.buttonRight.Location = new System.Drawing.Point(735, 408);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 13;
|
||||
@ -139,7 +86,7 @@
|
||||
this.buttonDown.AutoSize = true;
|
||||
this.buttonDown.BackgroundImage = global::ElectricLocomotive.Properties.Resources.arrowdown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(712, 389);
|
||||
this.buttonDown.Location = new System.Drawing.Point(699, 408);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 12;
|
||||
@ -152,64 +99,122 @@
|
||||
this.buttonLeft.AutoSize = true;
|
||||
this.buttonLeft.BackgroundImage = global::ElectricLocomotive.Properties.Resources.arrowleft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(676, 389);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(663, 408);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 11;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(637, 9);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(83, 15);
|
||||
this.label1.TabIndex = 15;
|
||||
this.label1.Text = "Инструменты";
|
||||
//
|
||||
// buttonAddLocomotive
|
||||
//
|
||||
this.buttonAddLocomotive.Location = new System.Drawing.Point(637, 98);
|
||||
this.buttonAddLocomotive.Name = "buttonAddLocomotive";
|
||||
this.buttonAddLocomotive.Size = new System.Drawing.Size(151, 28);
|
||||
this.buttonAddLocomotive.TabIndex = 17;
|
||||
this.buttonAddLocomotive.Text = "Добавить локомотив";
|
||||
this.buttonAddLocomotive.UseVisualStyleBackColor = true;
|
||||
this.buttonAddLocomotive.Click += new System.EventHandler(this.ButtonAddLocomotive_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Поле с грязью",
|
||||
"Кусты на карте"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
|
||||
"Карта с грязью",
|
||||
"Карта с кустами"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(637, 43);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(104, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 16;
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 22;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// FormMap
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(637, 151);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(151, 23);
|
||||
this.maskedTextBoxPosition.TabIndex = 23;
|
||||
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRemoveCar
|
||||
//
|
||||
this.buttonRemoveCar.Location = new System.Drawing.Point(637, 178);
|
||||
this.buttonRemoveCar.Name = "buttonRemoveCar";
|
||||
this.buttonRemoveCar.Size = new System.Drawing.Size(151, 28);
|
||||
this.buttonRemoveCar.TabIndex = 24;
|
||||
this.buttonRemoveCar.Text = "Удалить локомотив";
|
||||
this.buttonRemoveCar.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveLocomotive_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(637, 239);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(151, 28);
|
||||
this.buttonShowStorage.TabIndex = 25;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(637, 328);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(151, 28);
|
||||
this.buttonShowOnMap.TabIndex = 26;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// FormMapWithSetLocomotive
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonRemoveCar);
|
||||
this.Controls.Add(this.buttonShowStorage);
|
||||
this.Controls.Add(this.buttonShowOnMap);
|
||||
this.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.Controls.Add(this.ButtonCreate);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonAddLocomotive);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Name = "FormMap";
|
||||
this.Text = "Карта";
|
||||
this.Name = "FormMapWithSetLocomotive";
|
||||
this.Text = "Карта с набором объектов";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.statusStrip1.ResumeLayout(false);
|
||||
this.statusStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button ButtonCreate;
|
||||
private PictureBox pictureBox1;
|
||||
private StatusStrip statusStrip1;
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelColor;
|
||||
private Button buttonCreateModif;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Label label1;
|
||||
private Button buttonAddLocomotive;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonRemoveCar;
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonShowOnMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
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 ElectricLocomotive
|
||||
{
|
||||
public partial class FormMapWithSetLocomotive : Form
|
||||
{
|
||||
private MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap> _mapLocomotivesCollectionGeneric;
|
||||
public FormMapWithSetLocomotive()
|
||||
{
|
||||
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 MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap>(pictureBox1.Width, pictureBox1.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)
|
||||
{
|
||||
DrawningObjectLocomotive Locomotive = new(form.SelectedLocomotive);
|
||||
if (_mapLocomotivesCollectionGeneric + Locomotive != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox1.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("Объект удален");
|
||||
pictureBox1.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapLocomotivesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox1.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||
}
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapLocomotivesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox1.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;
|
||||
}
|
||||
pictureBox1.Image = _mapLocomotivesCollectionGeneric.MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,4 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal class MapWithSetLocomotivGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where U : AbstractMap
|
||||
{
|
||||
// Ширина окна отрисовки
|
||||
private readonly int _pictureWidth;
|
||||
// Высота окна отрисовки
|
||||
private readonly int _pictureHeight;
|
||||
// Размер занимаемого объектом места (ширина)
|
||||
private readonly int _placeSizeWidth = 180;
|
||||
// Размер занимаемого объектом места (высота)
|
||||
private readonly int _placeSizeHeight = 150;
|
||||
// Набор объектов
|
||||
private readonly SetLocomotivGeneric<T> _setLocomotive;
|
||||
// Карта
|
||||
private readonly U _map;
|
||||
|
||||
private readonly T[] _places;
|
||||
// Конструктор
|
||||
public MapWithSetLocomotivGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setLocomotive = new SetLocomotivGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
// Перегрузка оператора сложения
|
||||
public static int operator +(MapWithSetLocomotivGeneric<T, U> map, T Locomotive)
|
||||
{
|
||||
return map._setLocomotive.Insert(Locomotive);
|
||||
}
|
||||
// Перегрузка оператора вычитания
|
||||
public static T operator -(MapWithSetLocomotivGeneric<T, U> map, int position)
|
||||
{
|
||||
|
||||
return map._setLocomotive.Remove(position);
|
||||
}
|
||||
// Вывод всего набора объектов
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawLocomotive(gr);
|
||||
return bmp;
|
||||
}
|
||||
// Просмотр объекта на карте
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setLocomotive.Count; i++)
|
||||
{
|
||||
var Locomotive = _setLocomotive.Get(i);
|
||||
if (Locomotive != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, Locomotive);
|
||||
}
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
// Перемещение объекта по карте
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setLocomotive.Count - 1;
|
||||
for (int i = 0; i < _setLocomotive.Count; i++)
|
||||
{
|
||||
if (_setLocomotive.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var Locomotive = _setLocomotive.Get(j);
|
||||
if (Locomotive != null)
|
||||
{
|
||||
_setLocomotive.Insert(Locomotive, i);
|
||||
_setLocomotive.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Метод отрисовки фона
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Sienna, 3);
|
||||
Brush brush = new SolidBrush(Color.DodgerBlue);
|
||||
g.FillRectangle(brush, 0, 0, _pictureWidth, _pictureHeight);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight + 2, i * _placeSizeWidth + _placeSizeWidth / 2 + 40, j * _placeSizeHeight + 2);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 7, 2, i * _placeSizeWidth + 7, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 3, 2, i * _placeSizeWidth + 3, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
// Метод прорисовки объектов
|
||||
private void DrawLocomotive(Graphics g)
|
||||
{
|
||||
int widthEl = _pictureWidth / _placeSizeWidth;
|
||||
int heightEl = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int curWidth = 0;
|
||||
int curHeight = 0;
|
||||
|
||||
for (int i = _setLocomotive.Count; i >= 0; i--)
|
||||
{
|
||||
_setLocomotive.Get(i)?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 85,
|
||||
curHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
_setLocomotive.Get(i)?.DrawningObject(g);
|
||||
|
||||
if (curWidth < widthEl)
|
||||
curWidth++;
|
||||
else
|
||||
{
|
||||
curWidth = 1;
|
||||
curHeight++;
|
||||
}
|
||||
if (curHeight > heightEl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace ElectricLocomotive
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormMap());
|
||||
Application.Run(new FormMapWithSetLocomotive());
|
||||
}
|
||||
}
|
||||
}
|
80
ElectricLocomotive/ElectricLocomotive/SetLocomotivGeneric.cs
Normal file
80
ElectricLocomotive/ElectricLocomotive/SetLocomotivGeneric.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal class SetLocomotivGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
// Массив объектов, которые храним
|
||||
private readonly T[] _places;
|
||||
// Количество объектов в массиве
|
||||
public int Count => _places.Length;
|
||||
// Конструктор
|
||||
public SetLocomotivGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
// Добавление объекта в набор
|
||||
public int Insert(T Locomotive)
|
||||
{
|
||||
// вставка в начало набора
|
||||
return Insert(Locomotive, 0);
|
||||
}
|
||||
// Добавление объекта в набор на конкретную позицию
|
||||
public int Insert(T Locomotive, int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
return -1;
|
||||
//проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = Locomotive;
|
||||
return position;
|
||||
}
|
||||
//проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
int findEmptyPos = -1;
|
||||
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
findEmptyPos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (findEmptyPos < 0) return -1;
|
||||
|
||||
//сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
for (int i = findEmptyPos; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
// вставка по позиции
|
||||
_places[position] = Locomotive;
|
||||
return position;
|
||||
}
|
||||
// Удаление объекта из набора с конкретной позиции
|
||||
public T Remove(int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0) return null;
|
||||
// удаление объекта из массива, присовив элементу массива значение null
|
||||
T temp = _places[position];
|
||||
_places[position] = null;
|
||||
return temp;
|
||||
}
|
||||
// Получение объекта из набора по позиции
|
||||
public T Get(int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user