Лабораторная работа 2

This commit is contained in:
efi16 2023-03-31 21:01:31 +04:00
parent 823459e86a
commit 24f96b5ae0
10 changed files with 590 additions and 172 deletions

View File

@ -18,6 +18,7 @@ namespace Monorail
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, IDrawingObject drawingObject) public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject)
{ {
_width = width; _width = width;
@ -32,90 +33,108 @@ namespace Monorail
} }
public Bitmap MoveObject(Direction direction) public Bitmap MoveObject(Direction direction)
{ {
(float leftX, float topY, float rightX, float bottomY) = _drawingObject.GetCurrentPosition(); bool isFree = true;
int startPosX = (int)(_drawingObject.GetCurrentPosition().Left / _size_x);
int startPosY = (int)(_drawingObject.GetCurrentPosition().Right / _size_y);
int locomotiveWidth = (int)(_drawingObject.GetCurrentPosition().Top / _size_x);
int locomotiveHeight = (int)(_drawingObject.GetCurrentPosition().Bottom / _size_y);
float locomotiveWidth = rightX - leftX; switch (direction)
float locomotiveHeight = bottomY - topY;
for (int i = 0; i < _map.GetLength(0); i++)
{ {
for (int j = 0; j < _map.GetLength(1); j++) // вправо
case Direction.Right:
for (int i = locomotiveWidth; i <= locomotiveWidth + (int)(_drawingObject.Step / _size_x); i++)
{
for (int j = startPosY; j <= locomotiveHeight; j++)
{ {
if (_map[i, j] == _barrier) if (_map[i, j] == _barrier)
{ {
switch (direction) isFree = false;
{ break;
case Direction.Up: }
if (_size_y * (j + 1) >= topY - _drawingObject.Step && _size_y * (j + 1) < topY && _size_x * (i + 1) > leftX }
&& _size_x * (i + 1) <= rightX)
{
return DrawMapWithObject();
}
break;
case Direction.Down:
if (_size_y * j <= bottomY + _drawingObject.Step && _size_y * j > bottomY && _size_x * (i + 1) > leftX
&& _size_x * (i + 1) <= rightX)
{
return DrawMapWithObject();
} }
break; break;
//влево
case Direction.Left: case Direction.Left:
if (_size_x * (i + 1) >= leftX - _drawingObject.Step && _size_x * (i + 1) < leftX && _size_y * (j + 1) < bottomY for (int i = startPosX; i >= (int)(_drawingObject.Step / _size_x); i--)
&& _size_y * (j + 1) >= topY)
{ {
return DrawMapWithObject(); for (int j = startPosY; j <= locomotiveHeight; j++)
}
break;
case Direction.Right:
if (_size_x * i <= rightX + _drawingObject.Step && _size_x * i > leftX && _size_y * (j + 1) < bottomY
&& _size_y * (j + 1) >= topY)
{ {
return DrawMapWithObject(); if (_map[i, j] == _barrier)
} {
isFree = false;
break; break;
} }
} }
} }
break;
//вверх
case Direction.Up:
for (int i = startPosX; i <= locomotiveWidth; i++)
{
for (int j = startPosY; j >= (int)(_drawingObject.Step / _size_y); j--)
{
if (_map[i, j] == _barrier)
{
isFree = false;
break;
} }
if (true) }
}
break;
//вниз
case Direction.Down:
for (int i = startPosX; i <= locomotiveWidth; i++)
{
for (int j = locomotiveHeight; j <= locomotiveHeight + (int)(_drawingObject.Step / _size_y); j++)
{
if (_map[i, j] == _barrier)
{
isFree = false;
break;
}
}
}
break;
}
if (isFree)
{ {
_drawingObject.MoveObject(direction); _drawingObject.MoveObject(direction);
} }
return DrawMapWithObject(); return DrawMapWithObject();
} }
private bool SetObjectOnMap() private bool SetObjectOnMap()
{ {
(float leftX, float topY, float rightX, float bottomY) = _drawingObject.GetCurrentPosition();
if (_drawingObject == null || _map == null) if (_drawingObject == null || _map == null)
{ {
return false; return false;
} }
float locomotiveWidth = rightX - leftX;
float locomotiveHeight = bottomY - topY;
int x = _random.Next(0, 10); int x = _random.Next(0, 10);
int y = _random.Next(0, 10); int y = _random.Next(0, 10);
for (int i = 0; i < _map.GetLength(0); ++i) _drawingObject.SetObject(x, y, _width, _height);
// TODO првоерка, что объект не "накладывается" на закрытые участки
_drawingObject.SetObject(x, y, _width, _height);
int startPosX = (int)(_drawingObject.GetCurrentPosition().Left / _size_x);
int startPosY = (int)(_drawingObject.GetCurrentPosition().Right / _size_y);
int locomotiveWidth = (int)(_drawingObject.GetCurrentPosition().Top / _size_x);
int locomotiveHeight = (int)(_drawingObject.GetCurrentPosition().Bottom / _size_y);
for (int i = startPosX; i <= locomotiveWidth; i++)
{ {
for (int j = 0; j < _map.GetLength(1); ++j) for (int j = startPosY; j <= locomotiveHeight; j++)
{ {
if (_map[i, j] == _barrier) if (_map[i, j] == _barrier)
{
if (x + locomotiveWidth >= _size_x * i && x <= _size_x * i && y + locomotiveHeight > _size_y * j && y <= _size_y * j)
{ {
return false; return false;
} }
} }
} }
}
_drawingObject.SetObject(x, y, _width, _height);
return true; return true;
} }
private Bitmap DrawMapWithObject() private Bitmap DrawMapWithObject()
{ {
Bitmap bmp = new(_width, _height); Bitmap bmp = new Bitmap(_width, _height);
if (_drawingObject == null || _map == null) if (_drawingObject == null || _map == null)
{ {
return bmp; return bmp;

View File

@ -8,6 +8,7 @@ namespace Monorail
{ {
internal enum Direction internal enum Direction
{ {
None = 0,
Up = 1, Up = 1,
Down = 2, Down = 2,
Left = 3, Left = 3,

View File

@ -9,8 +9,8 @@ namespace Monorail
internal class DrawingLocomotive internal class DrawingLocomotive
{ {
public EntityLocomotive Locomotive { get; protected set; } public EntityLocomotive Locomotive { get; protected set; }
private float _startPosX; protected float _startPosX;
private float _startPosY; protected float _startPosY;
private int? _pictureWidth = null; private int? _pictureWidth = null;
private int? _pictureHeight = null; private int? _pictureHeight = null;
private readonly int _locomotiveWidth = 80; private readonly int _locomotiveWidth = 80;
@ -157,7 +157,10 @@ namespace Monorail
g.FillEllipse(brBlack, _startPosX + 120, _startPosY + 40, 20, 20); g.FillEllipse(brBlack, _startPosX + 120, _startPosY + 40, 20, 20);
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 40, 20, 20); g.DrawEllipse(pen, _startPosX + 120, _startPosY + 40, 20, 20);
Brush brBlue = new SolidBrush(Color.Blue);
//window
g.FillRectangle(brBlue, _startPosX + 110, _startPosY + 5, 20, 20);
g.DrawRectangle(pen, _startPosX + 110, _startPosY + 5, 20, 20);
} }

View File

@ -39,12 +39,19 @@ namespace Monorail
if (monorailLocomotive.DopCabin) if (monorailLocomotive.DopCabin)
{ {
Brush brBlue = new SolidBrush(Color.Blue);
// задняя кабина // задняя кабина
g.FillRectangle(brBlue, _startPosX + 25, _startPosY + 5, 20, 20);
g.DrawRectangle(pen, _startPosX + 25, _startPosY + 5, 20, 20);
} }
if (monorailLocomotive.Monorail) if (monorailLocomotive.Monorail)
{ {
Brush brBlack = new SolidBrush(Color.Black);
//монорельса //монорельса
g.FillRectangle(brBlack, _startPosX + 10, _startPosY + 45, 130, 20);
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 45, 130, 20);
} }
} }

View File

@ -29,139 +29,135 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox(); pictureBoxLocomotive = new PictureBox();
this.statusStrip = new System.Windows.Forms.StatusStrip(); statusStrip = new StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); toolStripStatusLabelSpeed = new ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); toolStripStatusLabelWeight = new ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); toolStripStatusLabelBodyColor = new ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button(); buttonCreate = new Button();
this.buttonUp = new System.Windows.Forms.Button(); buttonUp = new Button();
this.buttonLeft = new System.Windows.Forms.Button(); buttonLeft = new Button();
this.buttonRight = new System.Windows.Forms.Button(); buttonRight = new Button();
this.buttonDown = new System.Windows.Forms.Button(); buttonDown = new Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).BeginInit();
this.statusStrip.SuspendLayout(); statusStrip.SuspendLayout();
this.SuspendLayout(); SuspendLayout();
// //
// pictureBoxLocomotive // pictureBoxLocomotive
// //
this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill; pictureBoxLocomotive.Dock = DockStyle.Fill;
this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0); pictureBoxLocomotive.Location = new Point(0, 0);
this.pictureBoxLocomotive.Name = "pictureBoxLocomotive"; pictureBoxLocomotive.Name = "pictureBoxLocomotive";
this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 428); pictureBoxLocomotive.Size = new Size(800, 428);
this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; pictureBoxLocomotive.SizeMode = PictureBoxSizeMode.AutoSize;
this.pictureBoxLocomotive.TabIndex = 0; pictureBoxLocomotive.TabIndex = 0;
this.pictureBoxLocomotive.TabStop = false; pictureBoxLocomotive.TabStop = false;
this.pictureBoxLocomotive.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize); pictureBoxLocomotive.Resize += PictureBoxLocomotive_Resize;
// //
// statusStrip // statusStrip
// //
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { statusStrip.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelSpeed, toolStripStatusLabelWeight, toolStripStatusLabelBodyColor });
this.toolStripStatusLabelSpeed, statusStrip.Location = new Point(0, 428);
this.toolStripStatusLabelWeight, statusStrip.Name = "statusStrip";
this.toolStripStatusLabelBodyColor}); statusStrip.Size = new Size(800, 22);
this.statusStrip.Location = new System.Drawing.Point(0, 428); statusStrip.TabIndex = 1;
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22);
this.statusStrip.TabIndex = 1;
// //
// toolStripStatusLabelSpeed // toolStripStatusLabelSpeed
// //
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17); toolStripStatusLabelSpeed.Size = new Size(62, 17);
this.toolStripStatusLabelSpeed.Text = "Скорость:"; toolStripStatusLabelSpeed.Text = "Скорость:";
// //
// toolStripStatusLabelWeight // toolStripStatusLabelWeight
// //
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17); toolStripStatusLabelWeight.Size = new Size(29, 17);
this.toolStripStatusLabelWeight.Text = "Вес:"; toolStripStatusLabelWeight.Text = "Вес:";
// //
// toolStripStatusLabelBodyColor // toolStripStatusLabelBodyColor
// //
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); toolStripStatusLabelBodyColor.Size = new Size(36, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет:"; toolStripStatusLabelBodyColor.Text = "Цвет:";
// //
// buttonCreate // buttonCreate
// //
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
this.buttonCreate.Location = new System.Drawing.Point(12, 390); buttonCreate.Location = new Point(12, 390);
this.buttonCreate.Name = "buttonCreate"; buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23); buttonCreate.Size = new Size(75, 23);
this.buttonCreate.TabIndex = 2; buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать"; buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true; buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); buttonCreate.Click += ButtonCreate_Click;
// //
// buttonUp // buttonUp
// //
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
this.buttonUp.BackgroundImage = global::Monorail.Properties.Resources.arrowUp; buttonUp.BackgroundImage = Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(722, 350); buttonUp.Location = new Point(722, 350);
this.buttonUp.Name = "buttonUp"; buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30); buttonUp.Size = new Size(30, 30);
this.buttonUp.TabIndex = 3; buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true; buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); buttonUp.Click += ButtonMove_Click;
// //
// buttonLeft // buttonLeft
// //
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
this.buttonLeft.BackgroundImage = global::Monorail.Properties.Resources.arrowLeft; buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(686, 386); buttonLeft.Location = new Point(686, 386);
this.buttonLeft.Name = "buttonLeft"; buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30); buttonLeft.Size = new Size(30, 30);
this.buttonLeft.TabIndex = 4; buttonLeft.TabIndex = 4;
this.buttonLeft.UseVisualStyleBackColor = true; buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); buttonLeft.Click += ButtonMove_Click;
// //
// buttonRight // buttonRight
// //
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
this.buttonRight.BackgroundImage = global::Monorail.Properties.Resources.arrowRight; buttonRight.BackgroundImage = Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(758, 386); buttonRight.Location = new Point(758, 386);
this.buttonRight.Name = "buttonRight"; buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30); buttonRight.Size = new Size(30, 30);
this.buttonRight.TabIndex = 5; buttonRight.TabIndex = 5;
this.buttonRight.UseVisualStyleBackColor = true; buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); buttonRight.Click += ButtonMove_Click;
// //
// buttonDown // buttonDown
// //
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
this.buttonDown.BackgroundImage = global::Monorail.Properties.Resources.arrowDown; buttonDown.BackgroundImage = Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(722, 386); buttonDown.Location = new Point(722, 386);
this.buttonDown.Name = "buttonDown"; buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30); buttonDown.Size = new Size(30, 30);
this.buttonDown.TabIndex = 6; buttonDown.TabIndex = 6;
this.buttonDown.UseVisualStyleBackColor = true; buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); buttonDown.Click += ButtonMove_Click;
// //
// FormLocomotive // FormLocomotive
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); ClientSize = new Size(800, 450);
this.Controls.Add(this.buttonDown); Controls.Add(buttonDown);
this.Controls.Add(this.buttonRight); Controls.Add(buttonRight);
this.Controls.Add(this.buttonLeft); Controls.Add(buttonLeft);
this.Controls.Add(this.buttonUp); Controls.Add(buttonUp);
this.Controls.Add(this.buttonCreate); Controls.Add(buttonCreate);
this.Controls.Add(this.pictureBoxLocomotive); Controls.Add(pictureBoxLocomotive);
this.Controls.Add(this.statusStrip); Controls.Add(statusStrip);
this.Name = "FormLocomotive"; Name = "FormLocomotive";
this.Text = "Локомотив"; Text = "Локомотив";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).EndInit();
this.statusStrip.ResumeLayout(false); statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout(); statusStrip.PerformLayout();
this.ResumeLayout(false); ResumeLayout(false);
this.PerformLayout(); PerformLayout();
} }
#endregion #endregion
@ -176,6 +172,5 @@
private Button buttonLeft; private Button buttonLeft;
private Button buttonRight; private Button buttonRight;
private Button buttonDown; private Button buttonDown;
} }
} }

View File

@ -1,3 +1,13 @@
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 Monorail namespace Monorail
{ {
public partial class FormLocomotive : Form public partial class FormLocomotive : Form
@ -8,6 +18,14 @@ namespace Monorail
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);
@ -15,19 +33,16 @@ namespace Monorail
_locomotive?.DrawTransport(gr); _locomotive?.DrawTransport(gr);
pictureBoxLocomotive.Image = bmp; pictureBoxLocomotive.Image = bmp;
} }
/// <summary>
private void ButtonCreate_Click(object sender, EventArgs e) /// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
{ /// </summary>
Random rnd = new(); /// <param name="sender"></param>
_locomotive = new DrawingLocomotive(); /// <param name="e"></param>
_locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255))); /// <summary>
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); /// Èçìåíåíèå ðàçìåðîâ ôîðìû
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_locomotive.Locomotive.Speed}"; /// </summary>
toolStripStatusLabelWeight.Text = $"Âåñ: {_locomotive.Locomotive.Weight}"; /// <param name="sender"></param>
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_locomotive.Locomotive.BodyColor.Name}"; /// <param name="e"></param>
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
//ïîëó÷àåì èìÿ êíîïêè //ïîëó÷àåì èìÿ êíîïêè
@ -49,11 +64,25 @@ 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()
{
Random rnd = new();
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_locomotive.Locomotive.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_locomotive.Locomotive.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_locomotive.Locomotive.BodyColor.Name}";
}
} }
} }

203
Monorail/Monorail/FormMap.Designer.cs generated Normal file
View File

@ -0,0 +1,203 @@
namespace Monorail
{
partial class FormMap : Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
statusStrip1 = new StatusStrip();
toolStripStatusLabelSpeed = new ToolStripStatusLabel();
toolStripStatusLabelWeight = new ToolStripStatusLabel();
toolStripStatusLabelBodyColor = new ToolStripStatusLabel();
pictureBoxLocomotive = new PictureBox();
buttonCreate = new Button();
buttonCreateModify = new Button();
buttonUp = new Button();
buttonLeft = new Button();
buttonRight = new Button();
buttonDown = new Button();
comboBoxSelectorMap = new ComboBox();
statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).BeginInit();
SuspendLayout();
//
// statusStrip1
//
statusStrip1.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelSpeed, toolStripStatusLabelWeight, toolStripStatusLabelBodyColor });
statusStrip1.Location = new Point(0, 428);
statusStrip1.Name = "statusStrip1";
statusStrip1.Size = new Size(800, 22);
statusStrip1.TabIndex = 0;
statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabelSpeed
//
toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
toolStripStatusLabelSpeed.Size = new Size(62, 17);
toolStripStatusLabelSpeed.Text = "Скорость:";
//
// toolStripStatusLabelWeight
//
toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
toolStripStatusLabelWeight.Size = new Size(29, 17);
toolStripStatusLabelWeight.Text = "Вес:";
//
// toolStripStatusLabelBodyColor
//
toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
toolStripStatusLabelBodyColor.Size = new Size(36, 17);
toolStripStatusLabelBodyColor.Text = "Цвет:";
//
// pictureBoxLocomotive
//
pictureBoxLocomotive.Dock = DockStyle.Fill;
pictureBoxLocomotive.Location = new Point(0, 0);
pictureBoxLocomotive.Name = "pictureBoxLocomotive";
pictureBoxLocomotive.Size = new Size(800, 428);
pictureBoxLocomotive.TabIndex = 1;
pictureBoxLocomotive.TabStop = false;
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 386);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(101, 25);
buttonCreate.TabIndex = 2;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// buttonCreateModify
//
buttonCreateModify.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateModify.Location = new Point(138, 386);
buttonCreateModify.Name = "buttonCreateModify";
buttonCreateModify.Size = new Size(139, 25);
buttonCreateModify.TabIndex = 3;
buttonCreateModify.Text = "Модифицировать";
buttonCreateModify.UseVisualStyleBackColor = true;
buttonCreateModify.Click += ButtonCreateModify_Click;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(722, 350);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(686, 386);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 5;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(758, 386);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 6;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(722, 386);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 7;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// comboBoxSelectorMap
//
comboBoxSelectorMap.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorMap.FormattingEnabled = true;
comboBoxSelectorMap.Items.AddRange(new object[] { "SimpleMap" });
comboBoxSelectorMap.Location = new Point(12, 12);
comboBoxSelectorMap.Name = "comboBoxSelectorMap";
comboBoxSelectorMap.Size = new Size(121, 23);
comboBoxSelectorMap.TabIndex = 8;
comboBoxSelectorMap.SelectedIndexChanged += ComboBoxSelectorMap_SelectedIndexChanged;
comboBoxSelectorMap.Click += ComboBoxSelectorMap_SelectedIndexChanged;
//
// FormMap
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(comboBoxSelectorMap);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
Controls.Add(buttonCreateModify);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxLocomotive);
Controls.Add(statusStrip1);
Name = "FormMap";
Text = "Карта";
statusStrip1.ResumeLayout(false);
statusStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private StatusStrip statusStrip1;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private PictureBox pictureBoxLocomotive;
private Button buttonCreate;
private Button buttonCreateModify;
private Button buttonUp;
private Button buttonLeft;
private Button buttonRight;
private Button buttonDown;
private ComboBox comboBoxSelectorMap;
}
}

View File

@ -0,0 +1,98 @@
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 Monorail
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
private void SetData(DrawingLocomotive locomotive)
{
toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}";
pictureBoxLocomotive.Image = _abstractMap.CreateMap(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height,
new DrawingObjectLocomotive(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 DrawingLocomotive(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;
}
pictureBoxLocomotive.Image = _abstractMap?.MoveObject(dir);
}
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateModify_Click(object sender, EventArgs e)
{
Random rnd = new();
var locomotive = new DrawingMonorailLocomotive(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)));
SetData(locomotive);
}
/// <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;
}
}
}
}

View File

@ -0,0 +1,63 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<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>

View File

@ -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 FormLocomotive()); Application.Run(new FormMap());
} }
} }
} }