ISEbd-22. Baygulov A.A. Lab work 1 (hard) #4

Closed
tellsense wants to merge 7 commits from laba1_H into main
2 changed files with 157 additions and 4 deletions
Showing only changes of commit f0beec428c - Show all commits

View File

@ -28,12 +28,111 @@
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Text = "Form1";
pictureBoxElectricLocomotive = new PictureBox();
buttonCreate = new Button();
buttonLeft = new Button();
buttonRight = new Button();
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
private PictureBox pictureBoxElectricLocomotive;
private Button buttonCreate;
private Button buttonLeft;
private Button buttonRight;
private Button buttonUp;
private Button buttonDown;
}
}

View File

@ -2,9 +2,63 @@ namespace ProjectElectricLocomotive
{
public partial class FormElectricLocomotive : Form
{
private DrawningElectricLocomotive? _drawningElectricLocomotive;
public FormElectricLocomotive()
{
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();
}
}
}