Lisov N.A. Lab_work2 #2

Merged
eegov merged 11 commits from LabWork02 into LabWork01 2022-09-30 09:43:17 +04:00
5 changed files with 173 additions and 11 deletions
Showing only changes of commit 6c1da36415 - Show all commits

View File

@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonCreateModification = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
this.statusStripAircraft.SuspendLayout();
this.SuspendLayout();
@ -141,11 +142,22 @@
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonCreateModification
//
this.buttonCreateModification.Location = new System.Drawing.Point(103, 389);
this.buttonCreateModification.Name = "buttonCreateModification";
this.buttonCreateModification.Size = new System.Drawing.Size(110, 23);
this.buttonCreateModification.TabIndex = 7;
this.buttonCreateModification.Text = "Modification";
this.buttonCreateModification.UseVisualStyleBackColor = true;
this.buttonCreateModification.Click += new System.EventHandler(this.buttonCreateModification_Click);
//
// AirFighterForm
//
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.buttonCreateModification);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
@ -175,5 +187,6 @@
private Button buttonLeft;
private Button buttonRight;
private Button buttonDown;
private Button buttonCreateModification;
}
}

View File

@ -17,16 +17,24 @@ namespace AirFighter
pictureBoxAirFighter.Image = bmp;
}
private void SetData()
{
Random rnd = new Random();
_aircraft.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
toolStripStatusSpeed.Text = $"Speed: {_aircraft.Plane.Speed}";
toolStripStatusWeight.Text = $"Weight: {_aircraft.Plane.Weight}";
toolStripStatusBodyColor.Text = $"BodyColor: {_aircraft.Plane.BodyColor.Name}";
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
_aircraft = new DrawingAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_aircraft.SetPosition(rnd.Next(10,100),rnd.Next(10,100),pictureBoxAirFighter.Width,pictureBoxAirFighter.Height);
toolStripStatusSpeed.Text = $"Speed: {_aircraft.Plane.Speed}";
toolStripStatusWeight.Text = $"Weight: {_aircraft.Plane.Weight}";
toolStripStatusBodyColor.Text = $"BodyColor: {_aircraft.Plane.BodyColor.Name}";
SetData();
Draw();
}
@ -64,5 +72,17 @@ namespace AirFighter
_aircraft?.ChangeBorders(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
Draw();
}
private void buttonCreateModification_Click(object sender, EventArgs e)
{
Random rnd = new Random();
_aircraft = new DrawingMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0,2)),Convert.ToBoolean(rnd.Next(0,2)));
SetData();
Draw();
}
}
}

View File

@ -11,23 +11,30 @@ namespace AirFighter
{
internal class DrawingAircraft
{
public EntityAircraft Plane { get; private set; }
public EntityAircraft Plane { get; protected set; }
private float _startPosX;
protected float _startPosX;
private float _startPosY;
protected float _startPosY;
private int? _pictureWidth = null;
private int? _pictureHeight = null;
protected readonly int _aircraftWidth = 100;
protected readonly int _aircraftHeight = 100;
private readonly int _aircraftWidth = 100;
private readonly int _aircraftHeight = 100;
public DrawingAircraft(int speed, float weight, Color bodyColor)
{
Plane = new EntityAircraft(speed, weight, bodyColor);
}
protected DrawingAircraft(int speed, float weight, Color bodyColor, int aircraftWidth, int aircraftHeight) : this(speed, weight,bodyColor)
{
_aircraftHeight = aircraftHeight;
_aircraftWidth = aircraftWidth;
}
public void SetPosition(int x, int y, int width, int height)
{
@ -126,7 +133,7 @@ namespace AirFighter
}
}
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{

View File

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter
{
internal class DrawingMilitaryAircraft : DrawingAircraft
{
public DrawingMilitaryAircraft(int speed, float weight, Color bodyColor, Color extraColor, bool rockets, bool extraWings) : base(speed,weight,bodyColor, 100, 100)
{
Plane = new EntityMilitaryAircraft(speed, weight, bodyColor, extraColor, rockets, extraWings);
}
public override void DrawTransport(Graphics g)
{
if (Plane is not EntityMilitaryAircraft militaryAircraft)
{
return;
}
Pen pen = new(Color.Black);
Brush extraBrush = new SolidBrush(militaryAircraft.ExtraColor);
base.DrawTransport(g);
Review

Много пустых строк

Много пустых строк
if (militaryAircraft.ExtraWings)
{
GraphicsPath pathExtraWing1 = new GraphicsPath();
Point point1W1 = new Point((int)(_startPosX + 30), (int)(_startPosY + 45));
Point point2W1 = new Point(point1W1.X , point1W1.Y - 40);
Point point3W1 = new Point(point2W1.X + 10,point1W1.Y);
Point[] pointsExtraWing1 = new Point[] { point1W1,point2W1,point3W1};
pathExtraWing1.AddLines(pointsExtraWing1);
g.DrawPath(pen, pathExtraWing1);
g.FillPath(extraBrush, pathExtraWing1);
GraphicsPath pathExtraWing2 = new GraphicsPath();
Point point1W2 = new Point((int)(_startPosX + 30),(int)(_startPosY + 60));
Point point2W2 = new Point(point1W2.X , point1W2.Y + 40);
Point point3W3 = new Point(point2W2.X + 10,point1W2.Y);
Point[] pointsExtraWing2 = new Point[] {point1W2,point2W2,point3W3};
pathExtraWing2.AddLines(pointsExtraWing2);
g.DrawPath(pen, pathExtraWing2);
g.FillPath(extraBrush, pathExtraWing2);
}
if (militaryAircraft.Rockets)
{
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 30,17,4);
GraphicsPath pathRocketHead1 = new GraphicsPath();
Point point1R1 = new Point((int)(_startPosX + 50),(int)(_startPosY + 30));
Point point2R1 = new Point(point1R1.X - 5,point1R1.Y + 2);
Point point3R1 = new Point(point1R1.X , point1R1.Y + 4);
Point[] pointsExtraRocketHead1 = new Point[] { point1R1, point2R1, point3R1 };
pathRocketHead1.AddLines(pointsExtraRocketHead1);
g.DrawPath(pen, pathRocketHead1);
g.FillPath(extraBrush, pathRocketHead1);
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 70, 17, 4);
GraphicsPath pathRocketHead2 = new GraphicsPath();
Point point1R2 = new Point((int)(_startPosX + 50),(int)(_startPosY + 70));
Point point2R2 = new Point(point1R2.X - 5,point1R2.Y + 2);
Point point3R2 = new Point(point1R2.X, point1R2.Y + 4);
Point[] pointsExtraRocketHead2 = new Point[] { point1R2, point2R2, point3R2 };
pathRocketHead2.AddLines(pointsExtraRocketHead2);
g.DrawPath(pen, pathRocketHead2);
g.FillPath(extraBrush, pathRocketHead2);
Review

Много пустых строк

Много пустых строк
}
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter
{
internal class EntityMilitaryAircraft : EntityAircraft
{
public Color ExtraColor { get; private set; }
public bool Rockets { get; private set; }
public bool ExtraWings { get; private set; }
public EntityMilitaryAircraft(int speed, float weight, Color bodyColor, Color extraColor, bool rockets, bool extraWings) : base(speed, weight, bodyColor)
{
ExtraColor = extraColor;
Rockets = rockets;
ExtraWings = extraWings;
}
}
}