Почти готовая лаба
This commit is contained in:
parent
86426d0aed
commit
5a9b1fb6ae
31
WarmlyLocomotive/FormWarmlyLocomotive.Designer.cs
generated
31
WarmlyLocomotive/FormWarmlyLocomotive.Designer.cs
generated
@ -28,24 +28,24 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBox1 = new PictureBox();
|
pictureBoxWarmlyLocomotive = new PictureBox();
|
||||||
createButton = new Button();
|
createButton = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBox1
|
// pictureBoxWarmlyLocomotive
|
||||||
//
|
//
|
||||||
pictureBox1.Dock = DockStyle.Fill;
|
pictureBoxWarmlyLocomotive.Dock = DockStyle.Fill;
|
||||||
pictureBox1.Location = new Point(0, 0);
|
pictureBoxWarmlyLocomotive.Location = new Point(0, 0);
|
||||||
pictureBox1.Name = "pictureBox1";
|
pictureBoxWarmlyLocomotive.Name = "pictureBoxWarmlyLocomotive";
|
||||||
pictureBox1.Size = new Size(884, 461);
|
pictureBoxWarmlyLocomotive.Size = new Size(884, 461);
|
||||||
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
|
pictureBoxWarmlyLocomotive.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
pictureBox1.TabIndex = 0;
|
pictureBoxWarmlyLocomotive.TabIndex = 0;
|
||||||
pictureBox1.TabStop = false;
|
pictureBoxWarmlyLocomotive.TabStop = false;
|
||||||
//
|
//
|
||||||
// createButton
|
// createButton
|
||||||
//
|
//
|
||||||
@ -56,6 +56,7 @@
|
|||||||
createButton.TabIndex = 1;
|
createButton.TabIndex = 1;
|
||||||
createButton.Text = "Создать";
|
createButton.Text = "Создать";
|
||||||
createButton.UseVisualStyleBackColor = true;
|
createButton.UseVisualStyleBackColor = true;
|
||||||
|
createButton.Click += createButton_Click;
|
||||||
//
|
//
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
@ -67,6 +68,7 @@
|
|||||||
buttonUp.Size = new Size(35, 35);
|
buttonUp.Size = new Size(35, 35);
|
||||||
buttonUp.TabIndex = 2;
|
buttonUp.TabIndex = 2;
|
||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += moveButton_Click;
|
||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
@ -78,6 +80,7 @@
|
|||||||
buttonDown.Size = new Size(35, 35);
|
buttonDown.Size = new Size(35, 35);
|
||||||
buttonDown.TabIndex = 3;
|
buttonDown.TabIndex = 3;
|
||||||
buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += moveButton_Click;
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
@ -90,6 +93,7 @@
|
|||||||
buttonLeft.Size = new Size(35, 35);
|
buttonLeft.Size = new Size(35, 35);
|
||||||
buttonLeft.TabIndex = 4;
|
buttonLeft.TabIndex = 4;
|
||||||
buttonLeft.UseVisualStyleBackColor = true;
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += moveButton_Click;
|
||||||
//
|
//
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
@ -101,6 +105,7 @@
|
|||||||
buttonRight.Size = new Size(35, 35);
|
buttonRight.Size = new Size(35, 35);
|
||||||
buttonRight.TabIndex = 5;
|
buttonRight.TabIndex = 5;
|
||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += moveButton_Click;
|
||||||
//
|
//
|
||||||
// FormWarmlyLocomotive
|
// FormWarmlyLocomotive
|
||||||
//
|
//
|
||||||
@ -112,18 +117,18 @@
|
|||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(createButton);
|
Controls.Add(createButton);
|
||||||
Controls.Add(pictureBox1);
|
Controls.Add(pictureBoxWarmlyLocomotive);
|
||||||
Name = "FormWarmlyLocomotive";
|
Name = "FormWarmlyLocomotive";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "Тепловоз";
|
Text = "Тепловоз";
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBox1;
|
private PictureBox pictureBoxWarmlyLocomotive;
|
||||||
private Button createButton;
|
private Button createButton;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
|
@ -12,9 +12,77 @@ namespace WarmlyLocomotive
|
|||||||
{
|
{
|
||||||
public partial class FormWarmlyLocomotive : Form
|
public partial class FormWarmlyLocomotive : Form
|
||||||
{
|
{
|
||||||
|
private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
|
||||||
|
|
||||||
public FormWarmlyLocomotive()
|
public FormWarmlyLocomotive()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawningWarmlyLocomotive == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new(pictureBoxWarmlyLocomotive.Width,
|
||||||
|
pictureBoxWarmlyLocomotive.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawningWarmlyLocomotive.DrawTransport(gr);
|
||||||
|
pictureBoxWarmlyLocomotive.Image = bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void createButton_Click(object sender, EventArgs e){
|
||||||
|
Random random = new();
|
||||||
|
_drawningWarmlyLocomotive = new DrawningWarmlyLocomotive();
|
||||||
|
_drawningWarmlyLocomotive.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)));
|
||||||
|
_drawningWarmlyLocomotive.SetPictureSize(pictureBoxWarmlyLocomotive.Width,
|
||||||
|
pictureBoxWarmlyLocomotive.Height);
|
||||||
|
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
|
100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningWarmlyLocomotive == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
bool result = false;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
result =
|
||||||
|
_drawningWarmlyLocomotive.MoveTransport(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
result =
|
||||||
|
_drawningWarmlyLocomotive.MoveTransport(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
result =
|
||||||
|
_drawningWarmlyLocomotive.MoveTransport(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
result =
|
||||||
|
_drawningWarmlyLocomotive.MoveTransport(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ namespace WarmlyLocomotive
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormWarmlyLocomotive());
|
Application.Run(new FormWarmlyLocomotive());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user