Продвинутый объект
This commit is contained in:
parent
59f5022d99
commit
b06afd9786
@ -5,9 +5,9 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal class DrawningShip
|
internal class DrawningShip
|
||||||
{
|
{
|
||||||
public EntityShip Ship { get; private set; }
|
public EntityShip Ship { get; protected set; }
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
private int? _pictureWidth = null;
|
private int? _pictureWidth = null;
|
||||||
private int? _pictureHeight = null;
|
private int? _pictureHeight = null;
|
||||||
private readonly int _shipWidth = 80;
|
private readonly int _shipWidth = 80;
|
||||||
@ -16,6 +16,12 @@
|
|||||||
{
|
{
|
||||||
Ship = new EntityShip(speed, weight, сolor);
|
Ship = new EntityShip(speed, weight, сolor);
|
||||||
}
|
}
|
||||||
|
protected DrawningShip(int speed, float weight, Color bodyColor, int shipWidth, int shipHeight) :
|
||||||
|
this(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
_shipWidth = shipWidth;
|
||||||
|
_shipHeight = shipHeight;
|
||||||
|
}
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
if (x + _shipWidth <= width && y + _shipHeight <= height && x >= 0 && y >= 0)
|
if (x + _shipWidth <= width && y + _shipHeight <= height && x >= 0 && y >= 0)
|
||||||
@ -64,7 +70,7 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
49
WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs
Normal file
49
WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WarmlyShip
|
||||||
|
{
|
||||||
|
internal class DrawningWarmlyShip : DrawningShip
|
||||||
|
{
|
||||||
|
public DrawningWarmlyShip(int speed, float weight, Color bodyColor, Color dopColor, bool anchor, bool pipe, bool window) :
|
||||||
|
base(speed, weight, bodyColor, 110, 60)
|
||||||
|
{
|
||||||
|
Ship = new EntityWarmlyShip(speed, weight, bodyColor, dopColor, anchor, pipe, window);
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Ship is not EntityWarmlyShip warmlyShip)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush dopBrush = new SolidBrush(warmlyShip.DopColor);
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
if (warmlyShip.Anchor)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, _startPosX + 52, _startPosY + 40, _startPosX + 52, _startPosY + 60);
|
||||||
|
g.DrawLine(pen, _startPosX + 46, _startPosY + 60, _startPosX + 58, _startPosY + 60);
|
||||||
|
g.DrawLine(pen, _startPosX + 46, _startPosY + 60, _startPosX + 46, _startPosY + 50);
|
||||||
|
g.DrawLine(pen, _startPosX + 58, _startPosY + 60, _startPosX + 58, _startPosY + 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warmlyShip.Window)
|
||||||
|
{
|
||||||
|
g.FillEllipse(new SolidBrush(Color.White), _startPosX + 84, _startPosY + 30, 15, 15);
|
||||||
|
g.FillEllipse(new SolidBrush(Color.White), _startPosX + 59, _startPosY + 30, 15, 15);
|
||||||
|
g.FillEllipse(new SolidBrush(Color.White), _startPosX + 35, _startPosY + 30, 15, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warmlyShip.Pipe)
|
||||||
|
{
|
||||||
|
g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 5, 10, 15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
WarmlyShip/WarmlyShip/EntityWarmlyShip.cs
Normal file
36
WarmlyShip/WarmlyShip/EntityWarmlyShip.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WarmlyShip
|
||||||
|
{
|
||||||
|
internal class EntityWarmlyShip : EntityShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color DopColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия якоря
|
||||||
|
/// </summary>
|
||||||
|
public bool Anchor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия трубы
|
||||||
|
/// </summary>
|
||||||
|
public bool Pipe { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия окон
|
||||||
|
/// </summary>
|
||||||
|
public bool Window { get; private set; }
|
||||||
|
public EntityWarmlyShip(int speed, float weight, Color bodyColor, Color dopColor, bool anchor, bool pipe, bool window) :
|
||||||
|
base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
DopColor = dopColor;
|
||||||
|
Anchor = anchor;
|
||||||
|
Pipe = pipe;
|
||||||
|
Window = window;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
WarmlyShip/WarmlyShip/FormShip.Designer.cs
generated
13
WarmlyShip/WarmlyShip/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.buttonCreateModify = 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();
|
||||||
@ -140,11 +141,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);
|
||||||
//
|
//
|
||||||
|
// buttonCreateModify
|
||||||
|
//
|
||||||
|
this.buttonCreateModify.Location = new System.Drawing.Point(93, 402);
|
||||||
|
this.buttonCreateModify.Name = "buttonCreateModify";
|
||||||
|
this.buttonCreateModify.Size = new System.Drawing.Size(101, 23);
|
||||||
|
this.buttonCreateModify.TabIndex = 7;
|
||||||
|
this.buttonCreateModify.Text = "Модификация";
|
||||||
|
this.buttonCreateModify.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModify.Click += new System.EventHandler(this.buttonCreateModify_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.buttonCreateModify);
|
||||||
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);
|
||||||
@ -174,5 +186,6 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
private Button buttonCreateModify;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,14 +14,22 @@ namespace WarmlyShip
|
|||||||
_ship?.DrawTransport(gr);
|
_ship?.DrawTransport(gr);
|
||||||
pictureBoxShip.Image = bmp;
|
pictureBoxShip.Image = bmp;
|
||||||
}
|
}
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
/// <summary>
|
||||||
|
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||||
|
/// </summary>
|
||||||
|
private void SetData()
|
||||||
{
|
{
|
||||||
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.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
||||||
toolStripStatusSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
toolStripStatusSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
||||||
toolStripStatusWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
toolStripStatusWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
||||||
toolStripStatusColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
toolStripStatusColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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)));
|
||||||
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
private void PictureBoxShip_Resize(object sender, EventArgs e)
|
private void PictureBoxShip_Resize(object sender, EventArgs e)
|
||||||
@ -50,5 +58,20 @@ namespace WarmlyShip
|
|||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateModify_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_ship = new DrawningWarmlyShip(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…
x
Reference in New Issue
Block a user