Продвинутый объект
This commit is contained in:
parent
36c2bf68a1
commit
31532e6d54
@ -9,10 +9,10 @@ namespace MotorBoat
|
||||
{
|
||||
class DrawningBoat
|
||||
{
|
||||
public EntityBoat Boat { get; private set; }
|
||||
public EntityBoat Boat { get; protected set; }
|
||||
|
||||
private float _startPosX;
|
||||
private float _startPosY;
|
||||
protected float _startPosX;
|
||||
protected float _startPosY;
|
||||
|
||||
private int? _pictureWidth = null;
|
||||
private int? _pictureHeight = null;
|
||||
@ -23,6 +23,12 @@ namespace MotorBoat
|
||||
{
|
||||
Boat = new EntityBoat(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawningBoat(int speed, float weight, Color bodyColor, int boatWidth, int boatHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_boatWidth = boatWidth;
|
||||
_boatHeight = boatHeight;
|
||||
}
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
// TODO checks
|
||||
@ -72,7 +78,7 @@ namespace MotorBoat
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
@ -90,13 +96,13 @@ namespace MotorBoat
|
||||
new Point(Convert.ToInt32(_startPosX),Convert.ToInt32(_startPosY-40)),
|
||||
};
|
||||
|
||||
g.DrawPolygon(pen, points);
|
||||
Brush brBody = new SolidBrush(Boat?.BodyColor ?? Color.Black);
|
||||
g.FillPolygon(brBody, points);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX + 5, _startPosY - 30, 50, 20);
|
||||
g.DrawPolygon(pen, points);
|
||||
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
g.FillEllipse(brYellow, _startPosX + 5, _startPosY - 30, 50, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 5, _startPosY - 30, 50, 20);
|
||||
|
||||
}
|
||||
public void ChangeBorders(int width, int height)
|
||||
|
98
MotorBoat/MotorBoat/DrawningMotorBoat.cs
Normal file
98
MotorBoat/MotorBoat/DrawningMotorBoat.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat
|
||||
{
|
||||
internal class DrawningMotorBoat : DrawningBoat
|
||||
{
|
||||
/// <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 DrawningMotorBoat(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) :
|
||||
base(speed, weight, bodyColor, 110, 60)
|
||||
{
|
||||
Boat = new EntityMotorBoat(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Boat is not EntityMotorBoat motorBoat)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Point[] points;
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(motorBoat.DopColor);
|
||||
|
||||
|
||||
g.FillEllipse(new SolidBrush(Color.Black), _startPosX - 17, _startPosY - 24, 14, 5);
|
||||
g.FillEllipse(new SolidBrush(Color.Black), _startPosX - 17, _startPosY - 21, 14, 5);
|
||||
|
||||
g.FillRectangle(dopBrush, _startPosX - 10, _startPosY - 30, 10, 20);
|
||||
g.DrawRectangle(pen, _startPosX - 10, _startPosY - 30, 10, 20);
|
||||
|
||||
if (motorBoat.BodyKit)
|
||||
{
|
||||
points = new Point[]
|
||||
{
|
||||
new Point(Convert.ToInt32(_startPosX),Convert.ToInt32(_startPosY-50)),
|
||||
new Point(Convert.ToInt32(_startPosX),Convert.ToInt32(_startPosY+10)),
|
||||
new Point(Convert.ToInt32(_startPosX+50),Convert.ToInt32(_startPosY)),
|
||||
new Point(Convert.ToInt32(_startPosX+50),Convert.ToInt32(_startPosY-40)),
|
||||
};
|
||||
g.FillPolygon(dopBrush, points);
|
||||
g.DrawPolygon(pen, points);
|
||||
}
|
||||
|
||||
if (motorBoat.Wing)
|
||||
{
|
||||
points = new Point[]
|
||||
{
|
||||
new Point(Convert.ToInt32(_startPosX)+50,Convert.ToInt32(_startPosY-40)),
|
||||
new Point(Convert.ToInt32(_startPosX)+80,Convert.ToInt32(_startPosY-20)),
|
||||
new Point(Convert.ToInt32(_startPosX+50),Convert.ToInt32(_startPosY)),
|
||||
};
|
||||
g.FillPolygon(dopBrush, points);
|
||||
g.DrawPolygon(pen, points);
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
points = new Point[]
|
||||
{
|
||||
new Point(Convert.ToInt32(_startPosX)+50,Convert.ToInt32(_startPosY-34)),
|
||||
new Point(Convert.ToInt32(_startPosX)+57,Convert.ToInt32(_startPosY-20)),
|
||||
new Point(Convert.ToInt32(_startPosX+50),Convert.ToInt32(_startPosY-6)),
|
||||
};
|
||||
g.FillPolygon(new SolidBrush(Color.LightBlue), points);
|
||||
g.DrawPolygon(pen, points);
|
||||
|
||||
if (motorBoat.SportLine)
|
||||
{
|
||||
points = new Point[]
|
||||
{
|
||||
new Point(Convert.ToInt32(_startPosX)+5,Convert.ToInt32(_startPosY-37)),
|
||||
new Point(Convert.ToInt32(_startPosX)+5,Convert.ToInt32(_startPosY-30)),
|
||||
new Point(Convert.ToInt32(_startPosX+35),Convert.ToInt32(_startPosY-37)),
|
||||
};
|
||||
g.FillPolygon(dopBrush, points);
|
||||
g.DrawPolygon(pen, points);
|
||||
points = new Point[]
|
||||
{
|
||||
new Point(Convert.ToInt32(_startPosX)+5,Convert.ToInt32(_startPosY-3)),
|
||||
new Point(Convert.ToInt32(_startPosX)+5,Convert.ToInt32(_startPosY-10)),
|
||||
new Point(Convert.ToInt32(_startPosX+35),Convert.ToInt32(_startPosY-3)),
|
||||
};
|
||||
g.FillPolygon(dopBrush, points);
|
||||
g.DrawPolygon(pen, points);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
32
MotorBoat/MotorBoat/EntityMotorBoat.cs
Normal file
32
MotorBoat/MotorBoat/EntityMotorBoat.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat
|
||||
{
|
||||
internal class EntityMotorBoat : EntityBoat
|
||||
{
|
||||
public Color DopColor { get; private set; }
|
||||
public bool BodyKit { get; private set; }
|
||||
public bool Wing { get; private set; }
|
||||
public bool SportLine { get; private set; }
|
||||
/// <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 EntityMotorBoat(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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
18
MotorBoat/MotorBoat/FormBoat.Designer.cs
generated
18
MotorBoat/MotorBoat/FormBoat.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxMotorBoat)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -141,11 +142,23 @@
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// FormMotorBoat
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(133, 369);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(111, 44);
|
||||
this.buttonCreateModif.TabIndex = 6;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||
//
|
||||
// FormBoat
|
||||
//
|
||||
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.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
@ -153,7 +166,7 @@
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.pictureBoxMotorBoat);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Name = "FormMotorBoat";
|
||||
this.Name = "FormBoat";
|
||||
this.Text = "Моторная лодка";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxMotorBoat)).EndInit();
|
||||
this.statusStrip1.ResumeLayout(false);
|
||||
@ -175,5 +188,6 @@
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -20,10 +20,7 @@ namespace MotorBoat
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_boat = new DrawningBoat(rnd.Next(50, 150), rnd.Next(100, 200), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_boat.SetPosition(rnd.Next(10, 100), rnd.Next(0,100), pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_boat.Boat.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_boat.Boat.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_boat.Boat.BodyColor.Name}";
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
private void Draw()
|
||||
@ -33,7 +30,14 @@ namespace MotorBoat
|
||||
_boat?.DrawTransport(gr);
|
||||
pictureBoxMotorBoat.Image = bmp;
|
||||
}
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_boat.Boat.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_boat.Boat.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_boat.Boat.BodyColor.Name}";
|
||||
}
|
||||
private void PictureBoxCar_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_boat?.ChangeBorders(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
||||
@ -61,5 +65,19 @@ namespace MotorBoat
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_boat = new DrawningMotorBoat(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user