Прорисовка продвинутого объекта.

This commit is contained in:
the 2022-09-27 10:59:08 +04:00
parent b9ad742c3f
commit 6196569b70
5 changed files with 145 additions and 9 deletions

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ship
{
internal class DrawingMotorShip : DrawingShip
{
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="pipes">Признак наличия труб</param>
/// <param name="fuelTank">Признак наличия отсека для топлива</param>
public DrawingMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool pipes, bool fuelTank) : base(speed, weight, bodyColor, 110, 60)
{
Ship = new EntityMotorShip(speed, weight, bodyColor, dopColor, pipes, fuelTank);
}
public override void DrawTransport(Graphics g)
{
if (Ship is not EntityMotorShip motorShip)
{
return;
}
Pen pen = new(Color.Black);
Brush dopBrush = new SolidBrush(motorShip.DopColor);
if (motorShip.Pipes)
{
g.FillRectangle(dopBrush, _startPosX, _startPosY, 10, 10);
}
base.DrawTransport(g);
if (motorShip.Fueltank)
{
}
}
}
}

View File

@ -11,15 +11,15 @@ namespace Ship
/// <summary>
/// Класс-сущность
/// </summary>
public EntityShip Ship { private set; get; }
public EntityShip Ship { protected set; get; }
/// <summary>
/// Левая координата отрисовки корабля
/// </summary>
private float _startPosX;
protected float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки корабля
/// </summary>
private float _startPosY;
protected float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -46,6 +46,20 @@ namespace Ship
{
Ship = new EntityShip(speed, weight, bodyColor);
}
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес корабля</param>
/// <param name="bodyColor">Цвет корпуса</param>
/// <param name="carWidth">Ширина отрисовки корабля</param>
/// <param name="carHeight">Высота отрисовки корабля</param>
protected DrawingShip(int speed, float weight, Color bodyColor, int shipWidth, int shipHeight) : this(speed, weight, bodyColor)
{
_shipWidth = shipWidth;
_shipHeight = shipHeight;
}
/// <summary>
/// Установка позиции корабля
/// </summary>
@ -119,7 +133,7 @@ namespace Ship
/// Отрисовка автомобиля
/// </summary>
/// <param name="g"></param>
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,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ship
{
internal class EntityMotorShip : EntityShip
{
/// <summary>
/// Дополнительный цвет
/// </summary>
public Color DopColor { get; private set; }
/// <summary>
/// Признак наличия антикрыла
/// </summary>
public bool Pipes { get; private set; }
/// <summary>
/// Признак наличия гоночной полосы
/// </summary>
public bool Fueltank { get; private set; }
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public EntityMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool pipes, bool fuelTank) : base(speed, weight, bodyColor)
{
DopColor = dopColor;
Pipes = pipes;
Fueltank = fuelTank;
}
}
}

View File

@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@ -141,11 +142,22 @@
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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(101, 23);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
//
// FormShip
//
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.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
@ -175,5 +187,6 @@
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonCreateModif;
}
}

View File

@ -19,6 +19,15 @@ namespace Ship
pictureBoxShip.Image = bmp;
}
/// <summary>
/// Ìåòîä óñòàíîâêè äàííûõ
/// </summary>
private void SetData()
{
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
toolStripStatusLabelColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
/// </summary>
/// <param name="sender"></param>
@ -27,11 +36,9 @@ namespace Ship
{
Random rnd = new();
_ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_ship.SetPosition(rnd.Next(10, 100), pictureBoxShip.Height - rnd.Next(20, 100),
_ship.SetPosition(rnd.Next(10, 100), pictureBoxShip.Height - rnd.Next(50, 100),
pictureBoxShip.Width, pictureBoxShip.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
toolStripStatusLabelColor.Text = $"Öâåò: { _ship.Ship.BodyColor.Name}";
SetData();
Draw();
}
/// <summary>
@ -70,5 +77,22 @@ namespace Ship
_ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height);
Draw();
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_ship = new DrawingMotorShip(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)));
_ship.SetPosition(rnd.Next(50, 100), pictureBoxShip.Height - rnd.Next(80, 100), pictureBoxShip.Width, pictureBoxShip.Height);
SetData();
Draw();
}
}
}