Fadeeva A.A. LabWork02 #3
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>
|
||||
public EntityShip Ship { get; private set; }
|
||||
public EntityShip Ship { get; protected set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки корабля
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки корабля
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -49,7 +49,20 @@ namespace WarmlyShip
|
||||
{
|
||||
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>
|
||||
@ -116,7 +129,7 @@ namespace WarmlyShip
|
||||
/// Отрисовка корабля
|
||||
/// </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)
|
||||
|
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.buttonRight = 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();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -51,7 +52,6 @@
|
||||
this.pictureBoxShip.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxShip.TabIndex = 0;
|
||||
this.pictureBoxShip.TabStop = false;
|
||||
this.pictureBoxShip.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// statusStrip1
|
||||
//
|
||||
@ -143,11 +143,22 @@
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
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
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(824, 462);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
@ -177,5 +188,6 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -21,6 +21,17 @@ namespace WarmlyShip
|
||||
pictureBoxShip.Image = bmp;
|
||||
}
|
||||
/// <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>
|
||||
/// <param name="sender"></param>
|
||||
@ -29,10 +40,7 @@ namespace WarmlyShip
|
||||
{
|
||||
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.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}";
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -71,5 +79,20 @@ namespace WarmlyShip
|
||||
_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 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">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>63</value>
|
||||
</metadata>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user