Продвинутый объект
This commit is contained in:
parent
fc67dec55e
commit
29b463dd8b
56
WarmlyShip/WarmlyShip/DrawningLiner.cs
Normal file
56
WarmlyShip/WarmlyShip/DrawningLiner.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WarmlyShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
internal class DrawningLiner : DrawningShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес корабля</param>
|
||||||
|
/// <param name="bodyColor">Цвет палубы</param>
|
||||||
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="swimmingPool">Признак наличия бассейна</param>
|
||||||
|
/// <param name="dopDeck">Признак наличия дополнительной палубы</param>
|
||||||
|
public DrawningLiner(int speed, float weight, Color bodyColor, Color dopColor, bool swimmingPool, bool dopDeck) :
|
||||||
|
base(speed, weight, bodyColor, 110, 60)
|
||||||
|
{
|
||||||
|
Ship = new EntityLiner(speed, weight, bodyColor, dopColor, swimmingPool, dopDeck);
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Ship is not EntityLiner liner)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush dopBrush = new SolidBrush(liner.DopColor);
|
||||||
|
|
||||||
|
if (liner.DopDeck)
|
||||||
|
{
|
||||||
|
g.FillRectangle(dopBrush, _startPosX + 45, _startPosY, 35, 15);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 45, _startPosY, 35, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
_startPosY += 10;
|
||||||
|
base.DrawTransport(g);
|
||||||
|
_startPosY -= 10;
|
||||||
|
|
||||||
|
if (liner.SwimmingPool)
|
||||||
|
{
|
||||||
|
g.FillRectangle(dopBrush, _startPosX + 25, _startPosY + 15, 15, 7);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 25, _startPosY + 15, 15, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,15 +14,15 @@ namespace WarmlyShip
|
|||||||
/// <summary>>
|
/// <summary>>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityShip Ship { get; private set; }
|
public EntityShip Ship { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки корабля
|
/// Левая координата отрисовки корабля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната отрисовки корабля
|
/// Верхняя кооридната отрисовки корабля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -49,7 +49,20 @@ namespace WarmlyShip
|
|||||||
{
|
{
|
||||||
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="shipWidth">Ширина отрисовки корабля</param>
|
||||||
|
/// <param name="shipHeight">Высота отрисовки корабля</param>
|
||||||
|
protected DrawningShip(int speed, float weight, Color bodyColor, int shipWidth, int shipHeight) :
|
||||||
|
this(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
_shipWidth = shipWidth;
|
||||||
|
_shipHeight = shipHeight;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции корабля
|
/// Установка позиции корабля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -116,7 +129,7 @@ namespace WarmlyShip
|
|||||||
/// Отрисовка корабля
|
/// Отрисовка корабля
|
||||||
/// </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)
|
||||||
|
45
WarmlyShip/WarmlyShip/EntityLiner.cs
Normal file
45
WarmlyShip/WarmlyShip/EntityLiner.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WarmlyShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Лайнер"
|
||||||
|
/// </summary>
|
||||||
|
internal class EntityLiner : EntityShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color DopColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия бассейна
|
||||||
|
/// </summary>
|
||||||
|
public bool SwimmingPool { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия дополнительной палубы
|
||||||
|
/// </summary>
|
||||||
|
public bool DopDeck { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес корабля</param>
|
||||||
|
/// <param name="bodyColor">Цвет палубы</param>
|
||||||
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="swimmingPool">Признак наличия бассейна</param>
|
||||||
|
/// <param name="dopDeck">Признак наличия дополнительной палубы</param>
|
||||||
|
public EntityLiner(int speed, float weight, Color bodyColor, Color dopColor, bool swimmingPool, bool dopDeck) :
|
||||||
|
base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
DopColor = dopColor;
|
||||||
|
SwimmingPool = swimmingPool;
|
||||||
|
DopDeck = dopDeck;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
14
WarmlyShip/WarmlyShip/FormShip.Designer.cs
generated
14
WarmlyShip/WarmlyShip/FormShip.Designer.cs
generated
@ -38,6 +38,7 @@
|
|||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = 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.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -51,7 +52,6 @@
|
|||||||
this.pictureBoxShip.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
this.pictureBoxShip.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
this.pictureBoxShip.TabIndex = 0;
|
this.pictureBoxShip.TabIndex = 0;
|
||||||
this.pictureBoxShip.TabStop = false;
|
this.pictureBoxShip.TabStop = false;
|
||||||
this.pictureBoxShip.Click += new System.EventHandler(this.ButtonMove_Click);
|
|
||||||
//
|
//
|
||||||
// statusStrip1
|
// statusStrip1
|
||||||
//
|
//
|
||||||
@ -143,11 +143,22 @@
|
|||||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
|
// buttonCreateModif
|
||||||
|
//
|
||||||
|
this.buttonCreateModif.Location = new System.Drawing.Point(93, 403);
|
||||||
|
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||||
|
this.buttonCreateModif.Size = new System.Drawing.Size(110, 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(824, 462);
|
this.ClientSize = new System.Drawing.Size(824, 462);
|
||||||
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
@ -177,5 +188,6 @@
|
|||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
|
private Button buttonCreateModif;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,6 +21,17 @@ namespace WarmlyShip
|
|||||||
pictureBoxShip.Image = bmp;
|
pictureBoxShip.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||||
|
/// </summary>
|
||||||
|
private void SetData()
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
||||||
|
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
@ -29,10 +40,7 @@ namespace WarmlyShip
|
|||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_ship = new DrawningShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
_ship = new DrawningShip(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), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
SetData();
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
|
||||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -71,5 +79,20 @@ namespace WarmlyShip
|
|||||||
_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 DrawningLiner(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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -60,4 +60,7 @@
|
|||||||
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>17, 17</value>
|
<value>17, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>63</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
Loading…
Reference in New Issue
Block a user