Лабораторная работа№1
This commit is contained in:
parent
18baaa5880
commit
71156a3ec2
@ -36,7 +36,7 @@ public class DrawningAirFighter
|
||||
/// <summary>
|
||||
/// Ширина прорисовки истребителя
|
||||
/// </summary>
|
||||
private int? _drawningAirFlighterWidth = 130;
|
||||
private int? _drawningAirFlighterWidth = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки истребителя
|
||||
@ -53,10 +53,11 @@ public class DrawningAirFighter
|
||||
/// <param name="bodyKit">Признак наличия корпуса</param>
|
||||
/// <param name="rocket">Признак наличия рокет</param>
|
||||
/// <param name="additionalWing">Признак наличия дополнительных крыльев</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool rocket, bool additionalWing)
|
||||
//public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing)
|
||||
public void Init(EntityAirFighter entityAirFighter)
|
||||
{
|
||||
EntityAirFighter = new EntityAirFighter();
|
||||
EntityAirFighter.Init(speed, weight, bodyColor, additionalColor, bodyKit, rocket, additionalWing);
|
||||
EntityAirFighter = entityAirFighter;
|
||||
//EntityAirFighter.Init(speed, weight, bodyColor, additionalColor, rocket, additionalWing);
|
||||
_pictureHeight = null;
|
||||
_pictureWidth = null;
|
||||
_startPosX = null;
|
||||
@ -78,8 +79,14 @@ public class DrawningAirFighter
|
||||
_pictureHeight = height;
|
||||
if (_startPosX != null && _startPosY != null)
|
||||
{
|
||||
if (_startPosX.Value < 0) _startPosX = 0;
|
||||
if (_startPosY.Value < 0) _startPosY = 0;
|
||||
if (_startPosX.Value < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_startPosY.Value < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
if (_startPosX.Value + _drawningAirFlighterWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningAirFlighterWidth;
|
||||
@ -111,13 +118,19 @@ public class DrawningAirFighter
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
if (_startPosX.Value < 0) _startPosX = 0;
|
||||
if (_startPosY.Value < 0) _startPosY = 0;
|
||||
if (_startPosX.Value + _drawningAirFlighterWidth > _pictureWidth)
|
||||
if (_startPosX.Value < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_startPosY.Value < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
if (_startPosX + _drawningAirFlighterWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningAirFlighterWidth;
|
||||
}
|
||||
if (_startPosY.Value + _drawningAirFlighterHeight > _pictureHeight)
|
||||
if (_startPosY + _drawningAirFlighterHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningAirFlighterHeight;
|
||||
}
|
||||
@ -203,9 +216,9 @@ public class DrawningAirFighter
|
||||
}
|
||||
|
||||
//корпус
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 60, 100, 20);
|
||||
Point[] body = { new Point(_startPosX.Value + 110, _startPosY.Value + 80),
|
||||
new Point(_startPosX.Value + 130, _startPosY.Value + 70), new Point(_startPosX.Value + 110, _startPosY.Value + 60) };
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 60, 100, 20);
|
||||
Point[] body = { new Point(_startPosX.Value + 100, _startPosY.Value + 80),
|
||||
new Point(_startPosX.Value + 120, _startPosY.Value + 70), new Point(_startPosX.Value + 100, _startPosY.Value + 60) };
|
||||
g.DrawPolygon(pen, body);
|
||||
//нижнее крыло
|
||||
Point[] wingUpper = { new Point(_startPosX.Value + 80, _startPosY.Value + 80),
|
||||
@ -218,12 +231,12 @@ public class DrawningAirFighter
|
||||
g.DrawPolygon(pen, wingLower);
|
||||
//задние крылья
|
||||
//верхнее
|
||||
Point[] rearWingUpper = { new Point(_startPosX.Value + 10, _startPosY.Value + 60), new Point(_startPosX.Value + 10, _startPosY.Value + 30),
|
||||
Point[] rearWingUpper = { new Point(_startPosX.Value, _startPosY.Value + 60), new Point(_startPosX.Value, _startPosY.Value + 30),
|
||||
new Point(_startPosX.Value + 25, _startPosY.Value + 50), new Point(_startPosX.Value + 25, _startPosY.Value + 60)};
|
||||
g.DrawPolygon(pen, rearWingUpper);
|
||||
//нижнее
|
||||
Point[] rearWingLower = { new Point(_startPosX.Value + 10, _startPosY.Value + 80),
|
||||
new Point(_startPosX.Value + 10, _startPosY.Value + 110),new Point(_startPosX.Value + 25, _startPosY.Value + 90),
|
||||
Point[] rearWingLower = { new Point(_startPosX.Value, _startPosY.Value + 80),
|
||||
new Point(_startPosX.Value, _startPosY.Value + 110),new Point(_startPosX.Value + 25, _startPosY.Value + 90),
|
||||
new Point(_startPosX.Value + 25, _startPosY.Value + 80) };
|
||||
g.DrawPolygon(pen, rearWingLower);
|
||||
|
||||
@ -233,7 +246,7 @@ public class DrawningAirFighter
|
||||
|
||||
//залив корпуса
|
||||
Brush br = new SolidBrush(EntityAirFighter.BodyColor);
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 60, 100, 20);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 60, 100, 20);
|
||||
|
||||
g.FillPolygon(br, wingLower);
|
||||
g.FillPolygon(br, wingUpper);
|
||||
|
@ -46,10 +46,9 @@ public class EntityAirFighter
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия корпуса</param>
|
||||
/// <param name="rocket">Признак наличия рокет</param>
|
||||
/// <param name="additionalWing">Признак наличия дополнительных крыльев</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool rocket, bool additionalWing)
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
|
@ -41,16 +41,20 @@
|
||||
//
|
||||
pictureBoxAirFighter.Dock = DockStyle.Fill;
|
||||
pictureBoxAirFighter.Location = new Point(0, 0);
|
||||
pictureBoxAirFighter.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxAirFighter.Name = "pictureBoxAirFighter";
|
||||
pictureBoxAirFighter.Size = new Size(924, 557);
|
||||
pictureBoxAirFighter.Size = new Size(1056, 743);
|
||||
pictureBoxAirFighter.TabIndex = 0;
|
||||
pictureBoxAirFighter.TabStop = false;
|
||||
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(12, 476);
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(14, 635);
|
||||
buttonCreate.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.Size = new Size(86, 31);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
@ -61,9 +65,10 @@
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.left;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(785, 510);
|
||||
buttonLeft.Location = new Point(897, 680);
|
||||
buttonLeft.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
buttonLeft.Size = new Size(40, 47);
|
||||
buttonLeft.TabIndex = 2;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.ClientSizeChanged += FormAirFighter_SizeChanged;
|
||||
@ -74,9 +79,10 @@
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.up;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(828, 469);
|
||||
buttonUp.Location = new Point(946, 625);
|
||||
buttonUp.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.Size = new Size(40, 47);
|
||||
buttonUp.TabIndex = 3;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.ClientSizeChanged += FormAirFighter_SizeChanged;
|
||||
@ -87,9 +93,10 @@
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.down;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.Location = new Point(828, 510);
|
||||
buttonDown.Location = new Point(946, 680);
|
||||
buttonDown.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
buttonDown.Size = new Size(40, 47);
|
||||
buttonDown.TabIndex = 4;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.ClientSizeChanged += FormAirFighter_SizeChanged;
|
||||
@ -100,9 +107,10 @@
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.right;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(869, 510);
|
||||
buttonRight.Location = new Point(993, 680);
|
||||
buttonRight.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
buttonRight.Size = new Size(40, 47);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.ClientSizeChanged += FormAirFighter_SizeChanged;
|
||||
@ -110,15 +118,16 @@
|
||||
//
|
||||
// FormAirFighter
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(924, 557);
|
||||
ClientSize = new Size(1056, 743);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxAirFighter);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormAirFighter";
|
||||
Text = "Истребитель";
|
||||
SizeChanged += FormAirFighter_SizeChanged;
|
||||
|
@ -11,6 +11,8 @@ using System.Windows.Forms;
|
||||
namespace ProjectAirFighter
|
||||
{
|
||||
public partial class FormAirFighter : Form
|
||||
|
||||
|
||||
{
|
||||
private DrawningAirFighter? _drawningAirFighter;
|
||||
|
||||
@ -35,13 +37,13 @@ namespace ProjectAirFighter
|
||||
_drawningAirFighter = new DrawningAirFighter();
|
||||
_entityAirFighter = new EntityAirFighter();
|
||||
|
||||
_drawningAirFighter.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
_entityAirFighter.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)));
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningAirFighter.Init(_entityAirFighter);
|
||||
_drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
_drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
_drawningAirFighter.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_drawningAirFighter.SetPosition(random.Next(40, 100), random.Next(40, 100));
|
||||
|
||||
Draw();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user