ПИбд-23_Кондратьев_Никита_Lab1 #1

Closed
Itos wants to merge 7 commits from Lab1 into main
2 changed files with 131 additions and 72 deletions
Showing only changes of commit ede02decf3 - Show all commits

View File

@ -28,94 +28,99 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.Window = new System.Windows.Forms.PictureBox(); this.PictureBoxGasolineTanker = new System.Windows.Forms.PictureBox();
this.buttonCreate = new System.Windows.Forms.Button(); this.ButtonCreate = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.ButtonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.ButtonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.ButtonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button(); this.ButtonUp = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.Window)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PictureBoxGasolineTanker)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// Window // PictureBoxGasolineTanker
// //
this.Window.Dock = System.Windows.Forms.DockStyle.Fill; this.PictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill;
this.Window.Location = new System.Drawing.Point(0, 0); this.PictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0);
this.Window.Name = "Window"; this.PictureBoxGasolineTanker.Name = "PictureBoxGasolineTanker";
this.Window.Size = new System.Drawing.Size(884, 461); this.PictureBoxGasolineTanker.Size = new System.Drawing.Size(884, 461);
this.Window.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.PictureBoxGasolineTanker.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.Window.TabIndex = 0; this.PictureBoxGasolineTanker.TabIndex = 0;
this.Window.TabStop = false; this.PictureBoxGasolineTanker.TabStop = false;
// //
// buttonCreate // ButtonCreate
// //
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(12, 426); this.ButtonCreate.Location = new System.Drawing.Point(12, 426);
this.buttonCreate.Name = "buttonCreate"; this.ButtonCreate.Name = "ButtonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23); this.ButtonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 1; this.ButtonCreate.TabIndex = 1;
this.buttonCreate.Text = "Создать"; this.ButtonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true; this.ButtonCreate.UseVisualStyleBackColor = true;
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
// //
// buttonRight // ButtonRight
// //
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::GasolineTanker.Properties.Resources.right; this.ButtonRight.BackgroundImage = global::GasolineTanker.Properties.Resources.right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(842, 419); this.ButtonRight.Location = new System.Drawing.Point(842, 419);
this.buttonRight.Name = "buttonRight"; this.ButtonRight.Name = "ButtonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30); this.ButtonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 2; this.ButtonRight.TabIndex = 2;
this.buttonRight.UseVisualStyleBackColor = true; this.ButtonRight.UseVisualStyleBackColor = true;
this.ButtonRight.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonDown // ButtonDown
// //
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::GasolineTanker.Properties.Resources.down; this.ButtonDown.BackgroundImage = global::GasolineTanker.Properties.Resources.down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(806, 419); this.ButtonDown.Location = new System.Drawing.Point(806, 419);
this.buttonDown.Name = "buttonDown"; this.ButtonDown.Name = "ButtonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30); this.ButtonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 3; this.ButtonDown.TabIndex = 3;
this.buttonDown.UseVisualStyleBackColor = true; this.ButtonDown.UseVisualStyleBackColor = true;
this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonLeft // ButtonLeft
// //
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.left; this.ButtonLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(770, 419); this.ButtonLeft.Location = new System.Drawing.Point(770, 419);
this.buttonLeft.Name = "buttonLeft"; this.ButtonLeft.Name = "ButtonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.ButtonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4; this.ButtonLeft.TabIndex = 4;
this.buttonLeft.UseVisualStyleBackColor = true; this.ButtonLeft.UseVisualStyleBackColor = true;
this.ButtonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonUp // ButtonUp
// //
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::GasolineTanker.Properties.Resources.up; this.ButtonUp.BackgroundImage = global::GasolineTanker.Properties.Resources.up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(806, 383); this.ButtonUp.Location = new System.Drawing.Point(806, 383);
this.buttonUp.Name = "buttonUp"; this.ButtonUp.Name = "ButtonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30); this.ButtonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 5; this.ButtonUp.TabIndex = 5;
this.buttonUp.UseVisualStyleBackColor = true; this.ButtonUp.UseVisualStyleBackColor = true;
this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// GasolineTanker // GasolineTanker
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(884, 461); this.ClientSize = new System.Drawing.Size(884, 461);
this.Controls.Add(this.buttonUp); this.Controls.Add(this.ButtonUp);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.ButtonLeft);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.ButtonDown);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.ButtonRight);
this.Controls.Add(this.buttonCreate); this.Controls.Add(this.ButtonCreate);
this.Controls.Add(this.Window); this.Controls.Add(this.PictureBoxGasolineTanker);
this.Name = "GasolineTanker"; this.Name = "GasolineTanker";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "GasolineTanker"; this.Text = "GasolineTanker";
((System.ComponentModel.ISupportInitialize)(this.Window)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PictureBoxGasolineTanker)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -123,11 +128,11 @@
#endregion #endregion
private PictureBox Window; private PictureBox PictureBoxGasolineTanker;
private Button buttonCreate; private Button ButtonCreate;
private Button buttonRight; private Button ButtonRight;
private Button buttonDown; private Button ButtonDown;
private Button buttonLeft; private Button ButtonLeft;
private Button buttonUp; private Button ButtonUp;
} }
} }

View File

@ -2,9 +2,63 @@ namespace GasolineTanker
{ {
public partial class GasolineTanker : Form public partial class GasolineTanker : Form
Review

Имя файла не соответствует имени элемента проекта

Имя файла не соответствует имени элемента проекта
{ {
private DrawningGasolineTanker? _drawningGasolineTanker;
public GasolineTanker() public GasolineTanker()
{ {
InitializeComponent(); InitializeComponent();
} }
private void Draw()
{
if (_drawningGasolineTanker == null)
return;
Bitmap bmp = new(PictureBoxGasolineTanker.Width, PictureBoxGasolineTanker.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningGasolineTanker.DrawTransport(gr);
PictureBoxGasolineTanker.Image = bmp;
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningGasolineTanker = new DrawningGasolineTanker();
_drawningGasolineTanker.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)), Convert.ToBoolean(random.Next(0, 2)),
PictureBoxGasolineTanker.Width, PictureBoxGasolineTanker.Height);
_drawningGasolineTanker.SetPosition(random.Next(10, 100),
random.Next(10, 100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningGasolineTanker == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "ButtonUp":
_drawningGasolineTanker.MoveTransport(Direction.Up);
break;
case "ButtonDown":
_drawningGasolineTanker.MoveTransport(Direction.Down);
break;
case "ButtonLeft":
_drawningGasolineTanker.MoveTransport(Direction.Left);
break;
case "ButtonRight":
_drawningGasolineTanker.MoveTransport(Direction.Right);
break;
}
Draw();
}
} }
} }