Intermediate 2
This commit is contained in:
parent
717fbc3ca5
commit
9b74a54dbf
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Trolleybus
|
namespace Trolleybus
|
||||||
{
|
{
|
||||||
@ -22,6 +23,14 @@ namespace Trolleybus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosY;
|
private float _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// левая координата начала отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private float _startX;
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя координата начала отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private float _startY;
|
||||||
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureWidth = null;
|
private int? _pictureWidth = null;
|
||||||
@ -32,11 +41,11 @@ namespace Trolleybus
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина отрисовки
|
/// Ширина отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly int _trolleybusWidth = 0;
|
protected readonly int _trolleybusWidth = 200;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота отрисовки
|
/// Высота отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly int _trolleybusHeight = 0;
|
protected readonly int _trolleybusHeight = 50;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -55,10 +64,13 @@ namespace Trolleybus
|
|||||||
/// <param name="y">Координата Y</param>
|
/// <param name="y">Координата Y</param>
|
||||||
/// <param name="width">Ширина картинки</param>
|
/// <param name="width">Ширина картинки</param>
|
||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
// public void SetPosition(int x, int y, int startX, int startY, int width, int height)
|
||||||
|
public void SetPosition(int x, int y, int startX, int startY, int width, int height)
|
||||||
{
|
{
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
|
_startX = startX;
|
||||||
|
_startY = startY;
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
}
|
}
|
||||||
@ -76,30 +88,30 @@ namespace Trolleybus
|
|||||||
{
|
{
|
||||||
//вправо
|
//вправо
|
||||||
case Direction.Right:
|
case Direction.Right:
|
||||||
if(_startPosX + _trolleybusWidth + Trolleybus.Step< _pictureWidth)
|
if(_startPosX + _trolleybusWidth + Trolleybus.Step < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += Trolleybus.Step;
|
_startPosX += Trolleybus.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//влево
|
//влево
|
||||||
case Direction.Left:
|
case Direction.Left:
|
||||||
if (_startPosX + _trolleybusWidth - Trolleybus.Step < _pictureWidth)
|
if (_startPosX > _startX)
|
||||||
{
|
{
|
||||||
_startPosX += Trolleybus.Step;
|
_startPosX -= Trolleybus.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вверх
|
//вверх
|
||||||
case Direction.Up:
|
case Direction.Up:
|
||||||
if (_startPosX + _trolleybusWidth - Trolleybus.Step < _pictureHeight)
|
if (_startPosY > _startY)
|
||||||
{
|
{
|
||||||
_startPosX += Trolleybus.Step;
|
_startPosY -= Trolleybus.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вниз
|
//вниз
|
||||||
case Direction.Down:
|
case Direction.Down:
|
||||||
if (_startPosX + _trolleybusWidth + Trolleybus.Step < _pictureHeight)
|
if (_startPosY + _trolleybusHeight + Trolleybus.Step < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosX += Trolleybus.Step;
|
_startPosY += Trolleybus.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
96
Trolleybus/Trolleybus/Form1.Designer.cs
generated
96
Trolleybus/Trolleybus/Form1.Designer.cs
generated
@ -34,10 +34,10 @@ namespace Trolleybus
|
|||||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||||
this.buttonCreate = new System.Windows.Forms.Button();
|
this.buttonCreate = new System.Windows.Forms.Button();
|
||||||
this.button5 = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.button4 = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.button3 = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.button2 = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.pictureBoxTrolleybus = new System.Windows.Forms.PictureBox();
|
this.pictureBoxTrolleybus = new System.Windows.Forms.PictureBox();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTrolleybus)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTrolleybus)).BeginInit();
|
||||||
@ -83,51 +83,55 @@ namespace Trolleybus
|
|||||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||||
//
|
//
|
||||||
// button5
|
// buttonUp
|
||||||
//
|
//
|
||||||
this.button5.BackgroundImage = global::Trolleybus.Properties.Resources.up30;
|
this.buttonUp.BackgroundImage = global::Trolleybus.Properties.Resources.up30;
|
||||||
this.button5.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.button5.Location = new System.Drawing.Point(729, 347);
|
this.buttonUp.Location = new System.Drawing.Point(729, 347);
|
||||||
this.button5.Name = "button5";
|
this.buttonUp.Name = "buttonUp";
|
||||||
this.button5.Size = new System.Drawing.Size(30, 30);
|
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||||
this.button5.TabIndex = 6;
|
this.buttonUp.TabIndex = 6;
|
||||||
this.button5.UseVisualStyleBackColor = true;
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// button4
|
// buttonRight
|
||||||
//
|
//
|
||||||
this.button4.BackgroundImage = global::Trolleybus.Properties.Resources.right30;
|
this.buttonRight.BackgroundImage = global::Trolleybus.Properties.Resources.right30;
|
||||||
this.button4.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.button4.Location = new System.Drawing.Point(765, 383);
|
this.buttonRight.Location = new System.Drawing.Point(765, 383);
|
||||||
this.button4.Name = "button4";
|
this.buttonRight.Name = "buttonRight";
|
||||||
this.button4.Size = new System.Drawing.Size(30, 30);
|
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||||
this.button4.TabIndex = 5;
|
this.buttonRight.TabIndex = 5;
|
||||||
this.button4.UseVisualStyleBackColor = true;
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// button3
|
// buttonLeft
|
||||||
//
|
//
|
||||||
this.button3.BackgroundImage = global::Trolleybus.Properties.Resources.left30;
|
this.buttonLeft.BackgroundImage = global::Trolleybus.Properties.Resources.left30;
|
||||||
this.button3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.button3.Location = new System.Drawing.Point(693, 383);
|
this.buttonLeft.Location = new System.Drawing.Point(693, 383);
|
||||||
this.button3.Name = "button3";
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
this.button3.Size = new System.Drawing.Size(30, 30);
|
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||||
this.button3.TabIndex = 4;
|
this.buttonLeft.TabIndex = 4;
|
||||||
this.button3.UseVisualStyleBackColor = true;
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// button2
|
// buttonDown
|
||||||
//
|
//
|
||||||
this.button2.BackgroundImage = global::Trolleybus.Properties.Resources.down30;
|
this.buttonDown.BackgroundImage = global::Trolleybus.Properties.Resources.down30;
|
||||||
this.button2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.button2.Location = new System.Drawing.Point(729, 383);
|
this.buttonDown.Location = new System.Drawing.Point(729, 383);
|
||||||
this.button2.Name = "button2";
|
this.buttonDown.Name = "buttonDown";
|
||||||
this.button2.Size = new System.Drawing.Size(30, 30);
|
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||||
this.button2.TabIndex = 3;
|
this.buttonDown.TabIndex = 3;
|
||||||
this.button2.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// pictureBoxTrolleybus
|
// pictureBoxTrolleybus
|
||||||
//
|
//
|
||||||
this.pictureBoxTrolleybus.Location = new System.Drawing.Point(0, 0);
|
this.pictureBoxTrolleybus.Location = new System.Drawing.Point(12, 12);
|
||||||
this.pictureBoxTrolleybus.Name = "pictureBoxTrolleybus";
|
this.pictureBoxTrolleybus.Name = "pictureBoxTrolleybus";
|
||||||
this.pictureBoxTrolleybus.Size = new System.Drawing.Size(800, 425);
|
this.pictureBoxTrolleybus.Size = new System.Drawing.Size(776, 413);
|
||||||
this.pictureBoxTrolleybus.TabIndex = 0;
|
this.pictureBoxTrolleybus.TabIndex = 0;
|
||||||
this.pictureBoxTrolleybus.TabStop = false;
|
this.pictureBoxTrolleybus.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -136,10 +140,10 @@ namespace Trolleybus
|
|||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
this.Controls.Add(this.button5);
|
this.Controls.Add(this.buttonUp);
|
||||||
this.Controls.Add(this.button4);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.button3);
|
this.Controls.Add(this.buttonLeft);
|
||||||
this.Controls.Add(this.button2);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonCreate);
|
this.Controls.Add(this.buttonCreate);
|
||||||
this.Controls.Add(this.statusStrip1);
|
this.Controls.Add(this.statusStrip1);
|
||||||
this.Controls.Add(this.pictureBoxTrolleybus);
|
this.Controls.Add(this.pictureBoxTrolleybus);
|
||||||
@ -161,10 +165,10 @@ namespace Trolleybus
|
|||||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelWeight;
|
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||||
private System.Windows.Forms.Button buttonCreate;
|
private System.Windows.Forms.Button buttonCreate;
|
||||||
private System.Windows.Forms.Button button2;
|
private System.Windows.Forms.Button buttonDown;
|
||||||
private System.Windows.Forms.Button button3;
|
private System.Windows.Forms.Button buttonLeft;
|
||||||
private System.Windows.Forms.Button button4;
|
private System.Windows.Forms.Button buttonRight;
|
||||||
private System.Windows.Forms.Button button5;
|
private System.Windows.Forms.Button buttonUp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,11 +40,39 @@ namespace Trolleybus
|
|||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
_trolleybus = new DrawingTrolleybus();
|
_trolleybus = new DrawingTrolleybus();
|
||||||
_trolleybus.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
_trolleybus.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||||
_trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
_trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), Location.X, Location.Y, pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
||||||
|
// _trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_trolleybus.Trolleybus.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Скорость: {_trolleybus.Trolleybus.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Вес: {_trolleybus.Trolleybus.Weight}";
|
toolStripStatusLabelWeight.Text = $"Вес: {_trolleybus.Trolleybus.Weight}";
|
||||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_trolleybus.Trolleybus.BodyColor.Name}";
|
toolStripStatusLabelBodyColor.Text = $"Цвет: {_trolleybus.Trolleybus.BodyColor.Name}";
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//получаем имя кнопки
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_trolleybus?.MoveTransport(Direction.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_trolleybus?.MoveTransport(Direction.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_trolleybus?.MoveTransport(Direction.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_trolleybus?.MoveTransport(Direction.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void PictureBoxTrolleybus_Resize(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_trolleybus?.ChangeBorders(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user