Прорисовка продвинутого объекта.
This commit is contained in:
parent
b9ad742c3f
commit
6196569b70
45
Ship/Ship/DrawingMotorShip.cs
Normal file
45
Ship/Ship/DrawingMotorShip.cs
Normal 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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,15 +11,15 @@ namespace Ship
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityShip Ship { private set; get; }
|
public EntityShip Ship { protected set; get; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки корабля
|
/// Левая координата отрисовки корабля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната отрисовки корабля
|
/// Верхняя кооридната отрисовки корабля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -46,6 +46,20 @@ namespace Ship
|
|||||||
{
|
{
|
||||||
Ship = new EntityShip(speed, weight, bodyColor);
|
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>
|
||||||
/// Установка позиции корабля
|
/// Установка позиции корабля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -119,7 +133,7 @@ namespace Ship
|
|||||||
/// Отрисовка автомобиля
|
/// Отрисовка автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
|
40
Ship/Ship/EntityMotorShip.cs
Normal file
40
Ship/Ship/EntityMotorShip.cs
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
Ship/Ship/FormShip.Designer.cs
generated
13
Ship/Ship/FormShip.Designer.cs
generated
@ -38,6 +38,7 @@
|
|||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = 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();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
|
||||||
this.statusStrip.SuspendLayout();
|
this.statusStrip.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -141,11 +142,22 @@
|
|||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
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
|
// FormShip
|
||||||
//
|
//
|
||||||
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.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
@ -175,5 +187,6 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
private Button buttonCreateModif;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,6 +19,15 @@ namespace Ship
|
|||||||
pictureBoxShip.Image = bmp;
|
pictureBoxShip.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||||
|
/// </summary>
|
||||||
|
private void SetData()
|
||||||
|
{
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
||||||
|
toolStripStatusLabelColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
@ -27,11 +36,9 @@ namespace Ship
|
|||||||
{
|
{
|
||||||
Random rnd = new();
|
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 = 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);
|
pictureBoxShip.Width, pictureBoxShip.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
SetData();
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
|
||||||
toolStripStatusLabelColor.Text = $"Öâåò: { _ship.Ship.BodyColor.Name}";
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -70,5 +77,22 @@ namespace Ship
|
|||||||
_ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height);
|
_ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height);
|
||||||
Draw();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user