Compare commits
No commits in common. "f0beec428c6f830b624a31016ae346a1d6b2cb1e" and "6c34a47e966d0831692fe727b69fb395aa4ecbc4" have entirely different histories.
f0beec428c
...
6c34a47e96
@ -1,34 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectElectricLocomotive
|
|
||||||
{
|
|
||||||
public class EntityElectricLocomotive
|
|
||||||
{
|
|
||||||
public int Speed { get; private set; }
|
|
||||||
public double Weight { get; private set; }
|
|
||||||
public Color BodyColor { get; private set; }
|
|
||||||
public Color AdditionalColor { get; private set; }
|
|
||||||
public bool Pantograph { get; private set; }
|
|
||||||
public bool Compartment { get; private set; }
|
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес локомотива</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="pantograph">Признак наличия токоприемника</param>
|
|
||||||
/// <param name="compartment">Признак наличия отсеков под электрические батареи</param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pantograph, bool compartment)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
Pantograph = pantograph;
|
|
||||||
Compartment = compartment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,111 +28,12 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxElectricLocomotive = new PictureBox();
|
components = new System.ComponentModel.Container();
|
||||||
buttonCreate = new Button();
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
buttonLeft = new Button();
|
ClientSize = new Size(800, 450);
|
||||||
buttonRight = new Button();
|
Text = "Form1";
|
||||||
buttonUp = new Button();
|
|
||||||
buttonDown = new Button();
|
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// pictureBoxElectricLocomotive
|
|
||||||
//
|
|
||||||
pictureBoxElectricLocomotive.Cursor = Cursors.No;
|
|
||||||
pictureBoxElectricLocomotive.Dock = DockStyle.Fill;
|
|
||||||
pictureBoxElectricLocomotive.Enabled = false;
|
|
||||||
pictureBoxElectricLocomotive.Location = new Point(0, 0);
|
|
||||||
pictureBoxElectricLocomotive.Name = "pictureBoxElectricLocomotive";
|
|
||||||
pictureBoxElectricLocomotive.Size = new Size(1052, 553);
|
|
||||||
pictureBoxElectricLocomotive.SizeMode = PictureBoxSizeMode.AutoSize;
|
|
||||||
pictureBoxElectricLocomotive.TabIndex = 0;
|
|
||||||
pictureBoxElectricLocomotive.TabStop = false;
|
|
||||||
pictureBoxElectricLocomotive.Click += buttonMove_Click;
|
|
||||||
//
|
|
||||||
// buttonCreate
|
|
||||||
//
|
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreate.Location = new Point(0, 490);
|
|
||||||
buttonCreate.Name = "buttonCreate";
|
|
||||||
buttonCreate.Size = new Size(172, 63);
|
|
||||||
buttonCreate.TabIndex = 1;
|
|
||||||
buttonCreate.Text = "Создать";
|
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreate.Click += buttonCreate_Click;
|
|
||||||
//
|
|
||||||
// buttonLeft
|
|
||||||
//
|
|
||||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
|
||||||
buttonLeft.BackgroundImage = Properties.Resources.free_icon_left_arrow_line_symbol_54321;
|
|
||||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
|
||||||
buttonLeft.Location = new Point(938, 511);
|
|
||||||
buttonLeft.Name = "buttonLeft";
|
|
||||||
buttonLeft.Size = new Size(30, 30);
|
|
||||||
buttonLeft.TabIndex = 2;
|
|
||||||
buttonLeft.UseVisualStyleBackColor = true;
|
|
||||||
buttonLeft.Click += buttonMove_Click;
|
|
||||||
//
|
|
||||||
// buttonRight
|
|
||||||
//
|
|
||||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
|
||||||
buttonRight.BackgroundImage = Properties.Resources.free_icon_right_arrow_angle_54833;
|
|
||||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
|
||||||
buttonRight.Location = new Point(1010, 511);
|
|
||||||
buttonRight.Name = "buttonRight";
|
|
||||||
buttonRight.Size = new Size(30, 30);
|
|
||||||
buttonRight.TabIndex = 3;
|
|
||||||
buttonRight.UseVisualStyleBackColor = true;
|
|
||||||
buttonRight.Click += buttonMove_Click;
|
|
||||||
//
|
|
||||||
// buttonUp
|
|
||||||
//
|
|
||||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
|
||||||
buttonUp.BackgroundImage = Properties.Resources.free_icon_up_arrow_angle_54817;
|
|
||||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
|
||||||
buttonUp.Location = new Point(974, 475);
|
|
||||||
buttonUp.Name = "buttonUp";
|
|
||||||
buttonUp.Size = new Size(30, 30);
|
|
||||||
buttonUp.TabIndex = 4;
|
|
||||||
buttonUp.UseVisualStyleBackColor = true;
|
|
||||||
buttonUp.Click += buttonMove_Click;
|
|
||||||
//
|
|
||||||
// buttonDown
|
|
||||||
//
|
|
||||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
|
||||||
buttonDown.BackgroundImage = Properties.Resources.free_icon_down_arrow_54785;
|
|
||||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
|
||||||
buttonDown.Location = new Point(974, 511);
|
|
||||||
buttonDown.Name = "buttonDown";
|
|
||||||
buttonDown.Size = new Size(30, 30);
|
|
||||||
buttonDown.TabIndex = 5;
|
|
||||||
buttonDown.UseVisualStyleBackColor = true;
|
|
||||||
buttonDown.Click += buttonMove_Click;
|
|
||||||
//
|
|
||||||
// FormElectricLocomotive
|
|
||||||
//
|
|
||||||
ClientSize = new Size(1052, 553);
|
|
||||||
Controls.Add(buttonDown);
|
|
||||||
Controls.Add(buttonUp);
|
|
||||||
Controls.Add(buttonRight);
|
|
||||||
Controls.Add(buttonLeft);
|
|
||||||
Controls.Add(buttonCreate);
|
|
||||||
Controls.Add(pictureBoxElectricLocomotive);
|
|
||||||
Name = "FormElectricLocomotive";
|
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
|
||||||
Text = "ElectricLocomotive";
|
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).EndInit();
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxElectricLocomotive;
|
|
||||||
private Button buttonCreate;
|
|
||||||
private Button buttonLeft;
|
|
||||||
private Button buttonRight;
|
|
||||||
private Button buttonUp;
|
|
||||||
private Button buttonDown;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,63 +2,9 @@ namespace ProjectElectricLocomotive
|
|||||||
{
|
{
|
||||||
public partial class FormElectricLocomotive : Form
|
public partial class FormElectricLocomotive : Form
|
||||||
{
|
{
|
||||||
private DrawningElectricLocomotive? _drawningElectricLocomotive;
|
|
||||||
public FormElectricLocomotive()
|
public FormElectricLocomotive()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
private void Draw()
|
|
||||||
{
|
|
||||||
if (_drawningElectricLocomotive == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Bitmap bmp = new(pictureBoxElectricLocomotive.Width,
|
|
||||||
pictureBoxElectricLocomotive.Height);
|
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
|
||||||
_drawningElectricLocomotive.DrawTransport(gr);
|
|
||||||
pictureBoxElectricLocomotive.Image = bmp;
|
|
||||||
}
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
_drawningElectricLocomotive = new DrawningElectricLocomotive();
|
|
||||||
_drawningElectricLocomotive.Init(random.Next(100, 300), random.Next(1000, 3000),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
|
||||||
pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
|
|
||||||
_drawningElectricLocomotive.SetPosition(random.Next(1, 100), random.Next(1, 100));
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_drawningElectricLocomotive == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
||||||
switch (name)
|
|
||||||
{
|
|
||||||
case "buttonUp":
|
|
||||||
_drawningElectricLocomotive.MoveTransport(Direction.Up);
|
|
||||||
break;
|
|
||||||
case "buttonDown":
|
|
||||||
_drawningElectricLocomotive.MoveTransport(Direction.Down);
|
|
||||||
break;
|
|
||||||
case "buttonLeft":
|
|
||||||
_drawningElectricLocomotive.MoveTransport(Direction.Left);
|
|
||||||
break;
|
|
||||||
case "buttonRight":
|
|
||||||
_drawningElectricLocomotive.MoveTransport(Direction.Right);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user