Почти готовая лаба
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>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBox1 = new PictureBox();
|
||||
pictureBoxWarmlyLocomotive = new PictureBox();
|
||||
createButton = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonRight = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBox1
|
||||
// pictureBoxWarmlyLocomotive
|
||||
//
|
||||
pictureBox1.Dock = DockStyle.Fill;
|
||||
pictureBox1.Location = new Point(0, 0);
|
||||
pictureBox1.Name = "pictureBox1";
|
||||
pictureBox1.Size = new Size(884, 461);
|
||||
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBox1.TabIndex = 0;
|
||||
pictureBox1.TabStop = false;
|
||||
pictureBoxWarmlyLocomotive.Dock = DockStyle.Fill;
|
||||
pictureBoxWarmlyLocomotive.Location = new Point(0, 0);
|
||||
pictureBoxWarmlyLocomotive.Name = "pictureBoxWarmlyLocomotive";
|
||||
pictureBoxWarmlyLocomotive.Size = new Size(884, 461);
|
||||
pictureBoxWarmlyLocomotive.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxWarmlyLocomotive.TabIndex = 0;
|
||||
pictureBoxWarmlyLocomotive.TabStop = false;
|
||||
//
|
||||
// createButton
|
||||
//
|
||||
@ -56,6 +56,7 @@
|
||||
createButton.TabIndex = 1;
|
||||
createButton.Text = "Создать";
|
||||
createButton.UseVisualStyleBackColor = true;
|
||||
createButton.Click += createButton_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
@ -67,6 +68,7 @@
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.TabIndex = 2;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += moveButton_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
@ -78,6 +80,7 @@
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
buttonDown.TabIndex = 3;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += moveButton_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
@ -90,6 +93,7 @@
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
buttonLeft.TabIndex = 4;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += moveButton_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
@ -101,6 +105,7 @@
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += moveButton_Click;
|
||||
//
|
||||
// FormWarmlyLocomotive
|
||||
//
|
||||
@ -112,18 +117,18 @@
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(createButton);
|
||||
Controls.Add(pictureBox1);
|
||||
Controls.Add(pictureBoxWarmlyLocomotive);
|
||||
Name = "FormWarmlyLocomotive";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Тепловоз";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBox1;
|
||||
private PictureBox pictureBoxWarmlyLocomotive;
|
||||
private Button createButton;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
|
@ -12,9 +12,77 @@ namespace WarmlyLocomotive
|
||||
{
|
||||
public partial class FormWarmlyLocomotive : Form
|
||||
{
|
||||
private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
|
||||
|
||||
public FormWarmlyLocomotive()
|
||||
{
|
||||
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]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormWarmlyLocomotive());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user