Продвинутый объект

This commit is contained in:
Дарья Антонова 2022-12-16 18:46:39 +04:00
parent b190f9518e
commit 6f9ccc81d4
4 changed files with 181 additions and 22 deletions

View File

@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
internal class DrawningSportJet : DrawningJet
{
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Цвет</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine"></param>
public DrawningSportJet(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) :
base(speed, weight, bodyColor, 110, 60)
{
Jet = new EntitySportJet(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
}
public override void DrawTransport(Graphics g)
{
if (Jet is not EntitySportJet sportJet)
{
return;
}
Pen pen = new Pen(Color.Black);
Brush dopBrush = new SolidBrush(sportJet.DopColor);
int x = Convert.ToInt32(_startPosX);
int y = Convert.ToInt32(_startPosY);
if (sportJet.Wing)
{
GraphicsPath path1 = new GraphicsPath();
Point pt1 = new Point(x + 100, y + 10);
Point pt2 = new Point(x + 100, y + 40);
Rectangle rect1 = new Rectangle(x + 80, y + 10, 30, 30);
path1.AddLine(pt1, pt2);
path1.AddArc(rect1, 90, 180);
g.DrawPath(pen, path1);
g.FillPath(dopBrush, path1);
GraphicsPath path2 = new GraphicsPath();
Point pt3 = new Point(x + 100, y + 80);
Point pt4 = new Point(x + 100, y + 110);
Rectangle rect2 = new Rectangle(x + 80, y + 80, 30, 30);
path2.AddLine(pt3, pt4);
path2.AddArc(rect2, 90, 180);
g.DrawPath(pen, path2);
g.FillPath(dopBrush, path2);
}
if (sportJet.SportLine) { }
_startPosX += 10;
_startPosY += 5;
base.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 5;
if (sportJet.BodyKit)
{
Rectangle rect = new Rectangle(x + 146, y + 45, 10, 40);
g.DrawRectangle(pen, rect);
g.FillRectangle(dopBrush, rect);
Point pt5 = new Point(x + 30, y + 65);
Point pt6 = new Point(x + 145, y + 65);
g.DrawLine(pen, pt5, pt6);
}
}
}
}

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
internal class EntitySportJet : EntityJet
{
///<summary>
///Класс-сущность "Спортивный автомобиль"
///</summary>
public Color DopColor { get; private set; }
/// <summary>
/// Признак наличия обвеса
/// </summary>
public bool BodyKit { get; private set; }
/// <summary>
/// Признак наличия антикрыла
/// </summary>
public bool Wing { get; private set; }
/// <summary>
/// Признак наличия гоночной полосы
/// </summary>
public bool SportLine { get; private set; }
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public EntitySportJet(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
BodyKit = bodyKit;
Wing = wing;
SportLine = sportLine;
}
}
}

View File

@ -28,7 +28,7 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.pictureBoxCar = new System.Windows.Forms.PictureBox(); this.pictureBoxJet = new System.Windows.Forms.PictureBox();
this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
@ -38,20 +38,21 @@
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = 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();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit(); this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxJet)).BeginInit();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// pictureBoxCar // pictureBoxJet
// //
this.pictureBoxCar.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxJet.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCar.Location = new System.Drawing.Point(0, 0); this.pictureBoxJet.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCar.Name = "pictureBoxCar"; this.pictureBoxJet.Name = "pictureBoxJet";
this.pictureBoxCar.Size = new System.Drawing.Size(800, 428); this.pictureBoxJet.Size = new System.Drawing.Size(800, 450);
this.pictureBoxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxJet.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCar.TabIndex = 0; this.pictureBoxJet.TabIndex = 0;
this.pictureBoxCar.TabStop = false; this.pictureBoxJet.TabStop = false;
this.pictureBoxCar.Click += new System.EventHandler(this.PictureBoxCar_Resize); this.pictureBoxJet.Click += new System.EventHandler(this.PictureBoxCar_Resize);
// //
// statusStrip1 // statusStrip1
// //
@ -142,21 +143,32 @@
this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
// //
// buttonCreateModif
//
this.buttonCreateModif.Location = new System.Drawing.Point(93, 402);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(107, 23);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
//
// WarJet // WarJet
// //
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(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonCreate); this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxCar);
this.Controls.Add(this.statusStrip1); this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.pictureBoxJet);
this.Name = "WarJet"; this.Name = "WarJet";
this.Text = "Военный самолет"; this.Text = "Военный самолет";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxJet)).EndInit();
this.statusStrip1.ResumeLayout(false); this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout(); this.statusStrip1.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -166,7 +178,7 @@
#endregion #endregion
private PictureBox pictureBoxCar; private PictureBox pictureBoxJet;
private StatusStrip statusStrip1; private StatusStrip statusStrip1;
private ToolStripStatusLabel toolStripStatusLabelSpeed; private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight; private ToolStripStatusLabel toolStripStatusLabelWeight;
@ -176,5 +188,6 @@
private Button buttonLeft; private Button buttonLeft;
private Button buttonRight; private Button buttonRight;
private Button buttonDown; private Button buttonDown;
private Button buttonCreateModif;
} }
} }

View File

@ -12,12 +12,22 @@ namespace AirBomber
/// </summary> /// </summary>
private void Draw() private void Draw()
{ {
Bitmap bmp = new Bitmap(pictureBoxCar.Width, pictureBoxCar.Height); Bitmap bmp = new Bitmap(pictureBoxJet.Width, pictureBoxJet.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_jet?.DrawTransport(gr); _jet?.DrawTransport(gr);
pictureBoxCar.Image = bmp; pictureBoxJet.Image = bmp;
}
/// <summary>
/// Ìåòîä óñòàíîâêè äàííûõ
/// </summary>
private void SetData()
{
Random rnd = new Random();
_jet.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxJet.Width, pictureBoxJet.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_jet.Jet.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_jet.Jet.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_jet.Jet.BodyColor.Name}";
} }
private void buttonMove_Click(object sender, EventArgs e) private void buttonMove_Click(object sender, EventArgs e)
{ {
//ïîëó÷àåì èìÿ êíîïêè //ïîëó÷àåì èìÿ êíîïêè
@ -46,7 +56,7 @@ namespace AirBomber
/// <param name="e"></param> /// <param name="e"></param>
private void PictureBoxCar_Resize(object sender, EventArgs e) private void PictureBoxCar_Resize(object sender, EventArgs e)
{ {
_jet?.ChangeBorders(pictureBoxCar.Width, pictureBoxCar.Height); _jet?.ChangeBorders(pictureBoxJet.Width, pictureBoxJet.Height);
Draw(); Draw();
} }
/// <summary> /// <summary>
@ -58,10 +68,19 @@ namespace AirBomber
{ {
Random rnd = new Random(); Random rnd = new Random();
_jet = new DrawningJet(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _jet = new DrawningJet(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_jet.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height); _jet.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxJet.Width, pictureBoxJet.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_jet.Jet.Speed}"; SetData();
toolStripStatusLabelWeight.Text = $"Âåñ: {_jet.Jet.Weight}"; Draw();
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_jet.Jet.BodyColor.Name}"; }
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new Random();
var jet = new DrawningSportJet(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)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw(); Draw();
} }
} }