From 24f96b5ae0ff17ce96e12f49c13f15b2cc4e9449 Mon Sep 17 00:00:00 2001 From: efi16 Date: Fri, 31 Mar 2023 21:01:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Monorail/Monorail/AbstractMap.cs | 123 ++++++----- Monorail/Monorail/Direction.cs | 1 + Monorail/Monorail/DrawingLocomotive.cs | 9 +- .../Monorail/DrawingMonorailLocomotive.cs | 7 + Monorail/Monorail/FormLocomotive.Designer.cs | 199 +++++++++-------- Monorail/Monorail/FormLocomotive.cs | 57 +++-- Monorail/Monorail/FormMap.Designer.cs | 203 ++++++++++++++++++ Monorail/Monorail/FormMap.cs | 98 +++++++++ Monorail/Monorail/FormMap.resx | 63 ++++++ Monorail/Monorail/Program.cs | 2 +- 10 files changed, 590 insertions(+), 172 deletions(-) create mode 100644 Monorail/Monorail/FormMap.Designer.cs create mode 100644 Monorail/Monorail/FormMap.cs create mode 100644 Monorail/Monorail/FormMap.resx diff --git a/Monorail/Monorail/AbstractMap.cs b/Monorail/Monorail/AbstractMap.cs index 189be65..9b5ca8b 100644 --- a/Monorail/Monorail/AbstractMap.cs +++ b/Monorail/Monorail/AbstractMap.cs @@ -18,6 +18,7 @@ namespace Monorail protected readonly int _freeRoad = 0; protected readonly int _barrier = 1; + public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject) { _width = width; @@ -32,90 +33,108 @@ namespace Monorail } 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; - float locomotiveHeight = bottomY - topY; - - for (int i = 0; i < _map.GetLength(0); i++) + switch (direction) { - for (int j = 0; j < _map.GetLength(1); j++) - { - if (_map[i, j] == _barrier) + // вправо + case Direction.Right: + for (int i = locomotiveWidth; i <= locomotiveWidth + (int)(_drawingObject.Step / _size_x); i++) { - switch (direction) + for (int j = startPosY; j <= locomotiveHeight; j++) { - 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; - case Direction.Left: - if (_size_x * (i + 1) >= leftX - _drawingObject.Step && _size_x * (i + 1) < leftX && _size_y * (j + 1) < bottomY - && _size_y * (j + 1) >= topY) - { - return DrawMapWithObject(); - } - 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; + //влево + case Direction.Left: + for (int i = startPosX; i >= (int)(_drawingObject.Step / _size_x); i--) + { + for (int j = startPosY; j <= locomotiveHeight; j++) + { + if (_map[i, j] == _barrier) + { + isFree = false; + 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; + } + } + } + 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 (true) + + if (isFree) { _drawingObject.MoveObject(direction); } return DrawMapWithObject(); } - private bool SetObjectOnMap() { - (float leftX, float topY, float rightX, float bottomY) = _drawingObject.GetCurrentPosition(); if (_drawingObject == null || _map == null) { return false; } - - float locomotiveWidth = rightX - leftX; - float locomotiveHeight = bottomY - topY; - int x = _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 (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; } private Bitmap DrawMapWithObject() { - Bitmap bmp = new(_width, _height); + Bitmap bmp = new Bitmap(_width, _height); if (_drawingObject == null || _map == null) { return bmp; diff --git a/Monorail/Monorail/Direction.cs b/Monorail/Monorail/Direction.cs index ef85c14..de8df2e 100644 --- a/Monorail/Monorail/Direction.cs +++ b/Monorail/Monorail/Direction.cs @@ -8,6 +8,7 @@ namespace Monorail { internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/Monorail/Monorail/DrawingLocomotive.cs b/Monorail/Monorail/DrawingLocomotive.cs index 148f349..f1fbb71 100644 --- a/Monorail/Monorail/DrawingLocomotive.cs +++ b/Monorail/Monorail/DrawingLocomotive.cs @@ -9,8 +9,8 @@ namespace Monorail internal class DrawingLocomotive { public EntityLocomotive Locomotive { get; protected set; } - private float _startPosX; - private float _startPosY; + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; private readonly int _locomotiveWidth = 80; @@ -157,7 +157,10 @@ namespace Monorail g.FillEllipse(brBlack, _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); } diff --git a/Monorail/Monorail/DrawingMonorailLocomotive.cs b/Monorail/Monorail/DrawingMonorailLocomotive.cs index 562ff49..9f13dc5 100644 --- a/Monorail/Monorail/DrawingMonorailLocomotive.cs +++ b/Monorail/Monorail/DrawingMonorailLocomotive.cs @@ -39,12 +39,19 @@ namespace Monorail 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) { + Brush brBlack = new SolidBrush(Color.Black); //монорельса + g.FillRectangle(brBlack, _startPosX + 10, _startPosY + 45, 130, 20); + g.DrawRectangle(pen, _startPosX + 10, _startPosY + 45, 130, 20); } } diff --git a/Monorail/Monorail/FormLocomotive.Designer.cs b/Monorail/Monorail/FormLocomotive.Designer.cs index 78e9d94..6f8638f 100644 --- a/Monorail/Monorail/FormLocomotive.Designer.cs +++ b/Monorail/Monorail/FormLocomotive.Designer.cs @@ -29,142 +29,138 @@ private void InitializeComponent() { - this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox(); - this.statusStrip = new System.Windows.Forms.StatusStrip(); - this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.buttonCreate = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); - this.statusStrip.SuspendLayout(); - this.SuspendLayout(); + pictureBoxLocomotive = new PictureBox(); + statusStrip = new StatusStrip(); + toolStripStatusLabelSpeed = new ToolStripStatusLabel(); + toolStripStatusLabelWeight = new ToolStripStatusLabel(); + toolStripStatusLabelBodyColor = new ToolStripStatusLabel(); + buttonCreate = new Button(); + buttonUp = new Button(); + buttonLeft = new Button(); + buttonRight = new Button(); + buttonDown = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).BeginInit(); + statusStrip.SuspendLayout(); + SuspendLayout(); // // pictureBoxLocomotive // - this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0); - this.pictureBoxLocomotive.Name = "pictureBoxLocomotive"; - this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 428); - this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxLocomotive.TabIndex = 0; - this.pictureBoxLocomotive.TabStop = false; - this.pictureBoxLocomotive.Resize += new System.EventHandler(this.PictureBoxLocomotive_Resize); + pictureBoxLocomotive.Dock = DockStyle.Fill; + pictureBoxLocomotive.Location = new Point(0, 0); + pictureBoxLocomotive.Name = "pictureBoxLocomotive"; + pictureBoxLocomotive.Size = new Size(800, 428); + pictureBoxLocomotive.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxLocomotive.TabIndex = 0; + pictureBoxLocomotive.TabStop = false; + pictureBoxLocomotive.Resize += PictureBoxLocomotive_Resize; // // statusStrip // - this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelBodyColor}); - this.statusStrip.Location = new System.Drawing.Point(0, 428); - this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(800, 22); - this.statusStrip.TabIndex = 1; + statusStrip.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelSpeed, toolStripStatusLabelWeight, toolStripStatusLabelBodyColor }); + statusStrip.Location = new Point(0, 428); + statusStrip.Name = "statusStrip"; + statusStrip.Size = new Size(800, 22); + statusStrip.TabIndex = 1; // // toolStripStatusLabelSpeed // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17); - this.toolStripStatusLabelSpeed.Text = "Скорость:"; + toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + toolStripStatusLabelSpeed.Size = new Size(62, 17); + toolStripStatusLabelSpeed.Text = "Скорость:"; // // toolStripStatusLabelWeight // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17); - this.toolStripStatusLabelWeight.Text = "Вес:"; + toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + toolStripStatusLabelWeight.Size = new Size(29, 17); + toolStripStatusLabelWeight.Text = "Вес:"; // // toolStripStatusLabelBodyColor // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); - this.toolStripStatusLabelBodyColor.Text = "Цвет:"; + toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + toolStripStatusLabelBodyColor.Size = new Size(36, 17); + toolStripStatusLabelBodyColor.Text = "Цвет:"; // // buttonCreate // - this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCreate.Location = new System.Drawing.Point(12, 390); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(75, 23); - this.buttonCreate.TabIndex = 2; - this.buttonCreate.Text = "Создать"; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(12, 390); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 2; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; // // buttonUp // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::Monorail.Properties.Resources.arrowUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(722, 350); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - this.buttonUp.TabIndex = 3; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.arrowUp; + buttonUp.BackgroundImageLayout = ImageLayout.Stretch; + buttonUp.Location = new Point(722, 350); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(30, 30); + buttonUp.TabIndex = 3; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += ButtonMove_Click; // // buttonLeft // - this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeft.BackgroundImage = global::Monorail.Properties.Resources.arrowLeft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(686, 386); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(30, 30); - this.buttonLeft.TabIndex = 4; - this.buttonLeft.UseVisualStyleBackColor = true; - this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; + buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; + buttonLeft.Location = new Point(686, 386); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(30, 30); + buttonLeft.TabIndex = 4; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += ButtonMove_Click; // // buttonRight // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::Monorail.Properties.Resources.arrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(758, 386); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 5; - this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.arrowRight; + buttonRight.BackgroundImageLayout = ImageLayout.Stretch; + buttonRight.Location = new Point(758, 386); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(30, 30); + buttonRight.TabIndex = 5; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += ButtonMove_Click; // // buttonDown // - this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDown.BackgroundImage = global::Monorail.Properties.Resources.arrowDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(722, 386); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(30, 30); - this.buttonDown.TabIndex = 6; - this.buttonDown.UseVisualStyleBackColor = true; - this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.arrowDown; + buttonDown.BackgroundImageLayout = ImageLayout.Stretch; + buttonDown.Location = new Point(722, 386); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(30, 30); + buttonDown.TabIndex = 6; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += ButtonMove_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.buttonDown); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.pictureBoxLocomotive); - this.Controls.Add(this.statusStrip); - this.Name = "FormLocomotive"; - this.Text = "Локомотив"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); - this.statusStrip.ResumeLayout(false); - this.statusStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonDown); + Controls.Add(buttonRight); + Controls.Add(buttonLeft); + Controls.Add(buttonUp); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxLocomotive); + Controls.Add(statusStrip); + Name = "FormLocomotive"; + Text = "Локомотив"; + ((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).EndInit(); + statusStrip.ResumeLayout(false); + statusStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); } -#endregion + #endregion private PictureBox pictureBoxLocomotive; private StatusStrip statusStrip; @@ -176,6 +172,5 @@ private Button buttonLeft; private Button buttonRight; private Button buttonDown; - } } \ No newline at end of file diff --git a/Monorail/Monorail/FormLocomotive.cs b/Monorail/Monorail/FormLocomotive.cs index 03bbbe1..255a672 100644 --- a/Monorail/Monorail/FormLocomotive.cs +++ b/Monorail/Monorail/FormLocomotive.cs @@ -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 { public partial class FormLocomotive : Form @@ -8,6 +18,14 @@ namespace Monorail 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() { Bitmap bmp = new(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); @@ -15,19 +33,16 @@ namespace Monorail _locomotive?.DrawTransport(gr); pictureBoxLocomotive.Image = bmp; } - - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - _locomotive = new DrawingLocomotive(); - _locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255))); - _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}"; - Draw(); - } - + /// + /// "" + /// + /// + /// + /// + /// + /// + /// + /// private void ButtonMove_Click(object sender, EventArgs e) { // @@ -49,11 +64,25 @@ namespace Monorail } Draw(); } - + /// + /// + /// + /// + /// private void PictureBoxLocomotive_Resize(object sender, EventArgs e) { _locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); 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}"; + } + } } \ No newline at end of file diff --git a/Monorail/Monorail/FormMap.Designer.cs b/Monorail/Monorail/FormMap.Designer.cs new file mode 100644 index 0000000..80ec9b9 --- /dev/null +++ b/Monorail/Monorail/FormMap.Designer.cs @@ -0,0 +1,203 @@ +namespace Monorail +{ + partial class FormMap : Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Monorail/Monorail/FormMap.cs b/Monorail/Monorail/FormMap.cs new file mode 100644 index 0000000..91bb925 --- /dev/null +++ b/Monorail/Monorail/FormMap.cs @@ -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)); + } + /// + /// Обработка нажатия кнопки "Создать" + /// + /// + /// + 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); + } + /// + /// Изменение размеров формы + /// + /// + /// + 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); + } + /// + /// Обработка нажатия кнопки "Модификация" + /// + /// + /// + 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); + } + /// + /// Смена карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + } + } + + } +} diff --git a/Monorail/Monorail/FormMap.resx b/Monorail/Monorail/FormMap.resx new file mode 100644 index 0000000..5cb320f --- /dev/null +++ b/Monorail/Monorail/FormMap.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Monorail/Monorail/Program.cs b/Monorail/Monorail/Program.cs index 024d25a..e71a664 100644 --- a/Monorail/Monorail/Program.cs +++ b/Monorail/Monorail/Program.cs @@ -11,7 +11,7 @@ namespace Monorail // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormLocomotive()); + Application.Run(new FormMap()); } } } \ No newline at end of file