готовый проект
This commit is contained in:
parent
1d8824c3e4
commit
3fc0d392b0
@ -28,18 +28,105 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxAirplaneWithRadar = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxAirplaneWithRadar
|
||||
//
|
||||
pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill;
|
||||
pictureBoxAirplaneWithRadar.Location = new Point(0, 0);
|
||||
pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar";
|
||||
pictureBoxAirplaneWithRadar.Size = new Size(887, 454);
|
||||
pictureBoxAirplaneWithRadar.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxAirplaneWithRadar.TabIndex = 0;
|
||||
pictureBoxAirplaneWithRadar.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 413);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(94, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Create";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.Location = new Point(825, 402);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(50, 40);
|
||||
buttonRight.TabIndex = 2;
|
||||
buttonRight.Text = "→";
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.Location = new Point(769, 402);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(50, 40);
|
||||
buttonDown.TabIndex = 3;
|
||||
buttonDown.Text = "↓";
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.Location = new Point(713, 402);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(50, 40);
|
||||
buttonLeft.TabIndex = 4;
|
||||
buttonLeft.Text = "←";
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.Location = new Point(769, 356);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(50, 40);
|
||||
buttonUp.TabIndex = 5;
|
||||
buttonUp.Text = "↑";
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
//
|
||||
// FormAirplaneWithRadar
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
ClientSize = new Size(887, 454);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxAirplaneWithRadar);
|
||||
Name = "FormAirplaneWithRadar";
|
||||
Text = "FormAirplaneWithRadar";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxAirplaneWithRadar;
|
||||
private Button buttonCreate;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
}
|
||||
}
|
@ -2,9 +2,62 @@ namespace ProjectAirplaneWithRadar
|
||||
{
|
||||
public partial class FormAirplaneWithRadar : Form
|
||||
{
|
||||
private DrawningAirplaneWithRadar _drawningAirplaneWithRadar;
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAirplaneWithRadar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new Bitmap(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAirplaneWithRadar.DrawTransport(gr);
|
||||
pictureBoxAirplaneWithRadar.Image = bmp;
|
||||
}
|
||||
public FormAirplaneWithRadar()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAirplaneWithRadar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
_drawningAirplaneWithRadar = new DrawningAirplaneWithRadar();
|
||||
if (_drawningAirplaneWithRadar.Init
|
||||
(random.Next(100, 300), // speed
|
||||
random.Next(1000, 3000),// weight
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),// bodycolor
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), //additionalColor
|
||||
Convert.ToBoolean(random.Next(0, 2)), // radar
|
||||
Convert.ToBoolean(random.Next(0, 2)), //dopbak
|
||||
pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height))
|
||||
{
|
||||
_drawningAirplaneWithRadar.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user