Первая лабораторная работа.
This commit is contained in:
parent
0caa128262
commit
372c0be8d8
@ -74,11 +74,10 @@ namespace AirBomber
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
SolidBrush brush = new SolidBrush(AirBomber?.BodyColor ?? Color.Cyan);
|
||||
|
||||
g.FillPolygon(brush, new[] {
|
||||
new Point((int)(_startPosX + _airBomberWidth), (int)(_startPosY + _airBomberHeight / 2 - 20)),
|
||||
new Point((int)(_startPosX + _airBomberWidth), (int)(_startPosY + _airBomberHeight / 2 - 20)),
|
||||
new Point((int)(_startPosX + _airBomberWidth), (int)(_startPosY + _airBomberHeight / 2 + 20)),
|
||||
new Point((int)(_startPosX + _airBomberWidth - 10), (int)(_startPosY + _airBomberHeight / 2 + 10)),
|
||||
new Point((int)(_startPosX + _airBomberWidth - 10), (int)(_startPosY + _airBomberHeight / 2 - 10))
|
||||
@ -91,6 +90,20 @@ namespace AirBomber
|
||||
new Point((int)(_startPosX + _airBomberWidth / 2 + 10), (int)(_startPosY + _airBomberHeight)),
|
||||
new Point((int)(_startPosX + _airBomberWidth / 2), (int)(_startPosY + _airBomberHeight))
|
||||
});
|
||||
|
||||
g.FillPolygon(brush, new[] {
|
||||
new Point((int)(_startPosX + 20), (int)(_startPosY + _airBomberHeight / 2 - 5)),
|
||||
new Point((int)(_startPosX + _airBomberWidth), (int)(_startPosY + _airBomberHeight / 2 - 5)),
|
||||
new Point((int)(_startPosX + _airBomberWidth), (int)(_startPosY + _airBomberHeight / 2 + 5)),
|
||||
new Point((int)(_startPosX + 20), (int)(_startPosY + _airBomberHeight / 2 + 5)),
|
||||
});
|
||||
|
||||
g.FillPolygon(brush, new[] {
|
||||
new Point((int)(_startPosX), (int)(_startPosY + _airBomberHeight / 2)),
|
||||
new Point((int)(_startPosX + 20), (int)(_startPosY + _airBomberHeight / 2 - 5)),
|
||||
new Point((int)(_startPosX + 20), (int)(_startPosY + _airBomberHeight / 2 + 5)),
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
|
109
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
109
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
@ -34,10 +34,10 @@
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.button3 = new System.Windows.Forms.Button();
|
||||
this.button4 = new System.Windows.Forms.Button();
|
||||
this.button5 = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirBomber)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -47,9 +47,10 @@
|
||||
this.pictureBoxAirBomber.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxAirBomber.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxAirBomber.Name = "pictureBoxAirBomber";
|
||||
this.pictureBoxAirBomber.Size = new System.Drawing.Size(800, 450);
|
||||
this.pictureBoxAirBomber.Size = new System.Drawing.Size(874, 515);
|
||||
this.pictureBoxAirBomber.TabIndex = 0;
|
||||
this.pictureBoxAirBomber.TabStop = false;
|
||||
this.pictureBoxAirBomber.Resize += new System.EventHandler(this.PictureBoxAirBomber_Resize);
|
||||
//
|
||||
// statusStrip
|
||||
//
|
||||
@ -57,9 +58,9 @@
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelBodyColor});
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 428);
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 493);
|
||||
this.statusStrip.Name = "statusStrip";
|
||||
this.statusStrip.Size = new System.Drawing.Size(800, 22);
|
||||
this.statusStrip.Size = new System.Drawing.Size(874, 22);
|
||||
this.statusStrip.TabIndex = 1;
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
@ -82,62 +83,72 @@
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Location = new System.Drawing.Point(12, 390);
|
||||
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, 455);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(79, 35);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// button2
|
||||
// buttonUp
|
||||
//
|
||||
this.button2.BackgroundImage = global::AirBomber.Properties.Resources.ArrowUp;
|
||||
this.button2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.button2.Location = new System.Drawing.Point(722, 367);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(30, 30);
|
||||
this.button2.TabIndex = 3;
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.ArrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(796, 432);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 3;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonCreate_Move);
|
||||
//
|
||||
// button3
|
||||
// buttonLeft
|
||||
//
|
||||
this.button3.BackgroundImage = global::AirBomber.Properties.Resources.ArrowLeft;
|
||||
this.button3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.button3.Location = new System.Drawing.Point(686, 403);
|
||||
this.button3.Name = "button3";
|
||||
this.button3.Size = new System.Drawing.Size(30, 30);
|
||||
this.button3.TabIndex = 4;
|
||||
this.button3.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.ArrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(760, 468);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 4;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonCreate_Move);
|
||||
//
|
||||
// button4
|
||||
// buttonDown
|
||||
//
|
||||
this.button4.BackgroundImage = global::AirBomber.Properties.Resources.ArrowDown;
|
||||
this.button4.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.button4.Location = new System.Drawing.Point(722, 403);
|
||||
this.button4.Name = "button4";
|
||||
this.button4.Size = new System.Drawing.Size(30, 30);
|
||||
this.button4.TabIndex = 5;
|
||||
this.button4.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.ArrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(796, 468);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 5;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonCreate_Move);
|
||||
//
|
||||
// button5
|
||||
// buttonRight
|
||||
//
|
||||
this.button5.BackgroundImage = global::AirBomber.Properties.Resources.ArrowRight;
|
||||
this.button5.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.button5.Location = new System.Drawing.Point(758, 403);
|
||||
this.button5.Name = "button5";
|
||||
this.button5.Size = new System.Drawing.Size(30, 30);
|
||||
this.button5.TabIndex = 6;
|
||||
this.button5.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.ArrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(832, 468);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 6;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonCreate_Move);
|
||||
//
|
||||
// FormAirBomber
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.button5);
|
||||
this.Controls.Add(this.button4);
|
||||
this.Controls.Add(this.button3);
|
||||
this.Controls.Add(this.button2);
|
||||
this.ClientSize = new System.Drawing.Size(874, 515);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.statusStrip);
|
||||
this.Controls.Add(this.pictureBoxAirBomber);
|
||||
@ -159,9 +170,9 @@
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private Button buttonCreate;
|
||||
private Button button2;
|
||||
private Button button3;
|
||||
private Button button4;
|
||||
private Button button5;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
}
|
||||
}
|
@ -2,9 +2,57 @@ namespace AirBomber
|
||||
{
|
||||
public partial class FormAirBomber : Form
|
||||
{
|
||||
private DrawningBomber _airBomber;
|
||||
public FormAirBomber()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_airBomber?.DrawTransport(gr);
|
||||
pictureBoxAirBomber.Image = bmp;
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_airBomber = new DrawningBomber();
|
||||
_airBomber.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_airBomber.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airBomber.AirBomber.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airBomber.AirBomber.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airBomber.AirBomber.BodyColor}";
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonCreate_Move(object sender, EventArgs e)
|
||||
{
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch(name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_airBomber?.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_airBomber?.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_airBomber?.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_airBomber?.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void PictureBoxAirBomber_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_airBomber?.ChangeBorders(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user