Продвинутый объект
This commit is contained in:
parent
cd528db9c6
commit
96d2bfbb8f
70
Warship/Warship/DrawingAdvancedWarship.cs
Normal file
70
Warship/Warship/DrawingAdvancedWarship.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Warship
|
||||||
|
{
|
||||||
|
internal class DrawingAdvancedWarship : DrawingWarship
|
||||||
|
{
|
||||||
|
public DrawingAdvancedWarship(int speed,float weight, Color bodyColor, Color dopColor, bool Helipad, bool Antenna, bool Missile) : base(speed, weight, bodyColor, 120, 50)
|
||||||
|
{
|
||||||
|
Warship = new EntityAdvancedWarship(speed, weight, bodyColor, dopColor, Helipad, Antenna, Missile);
|
||||||
|
}
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Warship is not EntityAdvancedWarship advancedWarship)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush dopBrush = new SolidBrush(advancedWarship.DopColor);
|
||||||
|
|
||||||
|
if (advancedWarship.Missile)
|
||||||
|
{
|
||||||
|
g.FillPolygon(dopBrush, new Point[]
|
||||||
|
{
|
||||||
|
new Point(_startPosX+25,_startPosY+5-5),new Point(_startPosX+65,_startPosY+5-5),
|
||||||
|
new Point(_startPosX+75,_startPosY+10-5),new Point(_startPosX+25,_startPosY+10-5),
|
||||||
|
new Point(_startPosX+25,_startPosY+5-5)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 5 - 5), new Point(_startPosX + 65, _startPosY + 5 - 5));
|
||||||
|
g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 5 - 5), new Point(_startPosX + 75, _startPosY + 10 - 5));
|
||||||
|
g.DrawLine(pen, new Point(_startPosX + 75, _startPosY + 10 - 5), new Point(_startPosX + 25, _startPosY + 10 - 5));
|
||||||
|
g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 10 - 5), new Point(_startPosX + 25, _startPosY + 5 - 5));
|
||||||
|
|
||||||
|
g.FillPolygon(dopBrush, new Point[]
|
||||||
|
{
|
||||||
|
new Point(_startPosX+25,_startPosY+50-5),new Point(_startPosX+75,_startPosY+50-5),
|
||||||
|
new Point(_startPosX+65,_startPosY+55-5),new Point(_startPosX+25,_startPosY+55-5),
|
||||||
|
new Point(_startPosX+25,_startPosY+50-5)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 50 - 5), new Point(_startPosX + 75, _startPosY + 50 - 5));
|
||||||
|
g.DrawLine(pen, new Point(_startPosX + 75, _startPosY + 50 - 5), new Point(_startPosX + 65, _startPosY + 55 - 5));
|
||||||
|
g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 55 - 5), new Point(_startPosX + 25, _startPosY + 55 - 5));
|
||||||
|
g.DrawLine(pen, new Point(_startPosX + 25, _startPosY + 55 - 5), new Point(_startPosX + 25, _startPosY + 50 - 5));
|
||||||
|
}
|
||||||
|
_startPosY += 5;
|
||||||
|
base.DrawTransport(g);
|
||||||
|
_startPosY -= 5;
|
||||||
|
|
||||||
|
if (advancedWarship.Helipad)
|
||||||
|
{
|
||||||
|
g.FillEllipse(dopBrush, _startPosX + 85, _startPosY + 20-5, 20, 20);
|
||||||
|
g.DrawEllipse(pen, _startPosX + 85, _startPosY + 20-5, 20, 20);
|
||||||
|
g.DrawLine(pen, _startPosX + 90, _startPosY + 25 - 5, _startPosX + 90, _startPosY + 35 - 5);
|
||||||
|
g.DrawLine(pen, _startPosX + 90+10, _startPosY + 25 - 5, _startPosX + 90+10, _startPosY + 35 - 5);
|
||||||
|
g.DrawLine(pen, _startPosX + 90, _startPosY + 30 - 5, _startPosX + 100, _startPosY + 30 - 5);
|
||||||
|
}
|
||||||
|
if (advancedWarship.Antenna)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, _startPosX + 15, _startPosY + 20 - 5, _startPosX + 15, _startPosY + 40 - 5);
|
||||||
|
g.DrawLine(pen, _startPosX +10, _startPosY + 30 - 5, _startPosX + 20, _startPosY + 30 - 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,9 +8,9 @@ namespace Warship
|
|||||||
{
|
{
|
||||||
internal class DrawingWarship
|
internal class DrawingWarship
|
||||||
{
|
{
|
||||||
public EntityWarship Warship { get; private set; }
|
public EntityWarship Warship { get; protected set; }
|
||||||
private int _startPosX;
|
protected int _startPosX;
|
||||||
private int _startPosY;
|
protected int _startPosY;
|
||||||
private int? _pictureWidth = null;
|
private int? _pictureWidth = null;
|
||||||
private int? _pictureHeight = null;
|
private int? _pictureHeight = null;
|
||||||
private readonly int _warshipWidth = 120;
|
private readonly int _warshipWidth = 120;
|
||||||
@ -21,6 +21,13 @@ namespace Warship
|
|||||||
Warship=new EntityWarship(speed, weight, bodyColor);
|
Warship=new EntityWarship(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected DrawingWarship(int speed, float weight,Color bodyColor, int warshipWidth, int warshipHeight) : this(speed,weight,bodyColor)
|
||||||
|
{
|
||||||
|
_warshipWidth = warshipWidth;
|
||||||
|
_warshipHeight = warshipHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
if (x >= 0 && x+_warshipWidth <= width && y >= 0 && y+_warshipHeight <= height)
|
if (x >= 0 && x+_warshipWidth <= width && y >= 0 && y+_warshipHeight <= height)
|
||||||
@ -71,7 +78,7 @@ namespace Warship
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
{
|
{
|
||||||
|
23
Warship/Warship/EntityAdvancedWarship.cs
Normal file
23
Warship/Warship/EntityAdvancedWarship.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Warship
|
||||||
|
{
|
||||||
|
internal class EntityAdvancedWarship : EntityWarship
|
||||||
|
{
|
||||||
|
public Color DopColor { get; private set; }
|
||||||
|
public bool Helipad { get;private set; }
|
||||||
|
public bool Antenna { get; private set; }
|
||||||
|
public bool Missile { get; private set; }
|
||||||
|
public EntityAdvancedWarship(int speed, float weight, Color bodyColor, Color dopColor, bool helipad, bool antenna, bool missile) : base(speed,weight,bodyColor) {
|
||||||
|
DopColor = dopColor;
|
||||||
|
Helipad = helipad;
|
||||||
|
Antenna = antenna;
|
||||||
|
Missile = missile;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
25
Warship/Warship/FormWarship.Designer.cs
generated
25
Warship/Warship/FormWarship.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.pictureBoxWarship)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit();
|
||||||
this.statusStrip.SuspendLayout();
|
this.statusStrip.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -51,7 +52,7 @@
|
|||||||
this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
this.pictureBoxWarship.TabIndex = 0;
|
this.pictureBoxWarship.TabIndex = 0;
|
||||||
this.pictureBoxWarship.TabStop = false;
|
this.pictureBoxWarship.TabStop = false;
|
||||||
this.pictureBoxWarship.Resize += new System.EventHandler(this.pictureBoxWarship_Resize);
|
this.pictureBoxWarship.Resize += new System.EventHandler(this.PictureBoxWarship_Resize);
|
||||||
//
|
//
|
||||||
// statusStrip
|
// statusStrip
|
||||||
//
|
//
|
||||||
@ -91,7 +92,7 @@
|
|||||||
this.buttonCreate.TabIndex = 2;
|
this.buttonCreate.TabIndex = 2;
|
||||||
this.buttonCreate.Text = "Создать";
|
this.buttonCreate.Text = "Создать";
|
||||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
@ -104,7 +105,7 @@
|
|||||||
this.buttonDown.TabIndex = 3;
|
this.buttonDown.TabIndex = 3;
|
||||||
this.buttonDown.Text = " ";
|
this.buttonDown.Text = " ";
|
||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
@ -117,7 +118,7 @@
|
|||||||
this.buttonUp.TabIndex = 4;
|
this.buttonUp.TabIndex = 4;
|
||||||
this.buttonUp.Text = " ";
|
this.buttonUp.Text = " ";
|
||||||
this.buttonUp.UseVisualStyleBackColor = true;
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
@ -130,7 +131,7 @@
|
|||||||
this.buttonRight.TabIndex = 5;
|
this.buttonRight.TabIndex = 5;
|
||||||
this.buttonRight.Text = " ";
|
this.buttonRight.Text = " ";
|
||||||
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);
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
@ -143,13 +144,24 @@
|
|||||||
this.buttonLeft.TabIndex = 6;
|
this.buttonLeft.TabIndex = 6;
|
||||||
this.buttonLeft.Text = " ";
|
this.buttonLeft.Text = " ";
|
||||||
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, 393);
|
||||||
|
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);
|
||||||
//
|
//
|
||||||
// FormWarship
|
// FormWarship
|
||||||
//
|
//
|
||||||
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.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);
|
||||||
@ -179,5 +191,6 @@
|
|||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
|
private Button buttonCreateModif;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,17 +15,23 @@ namespace Warship
|
|||||||
pictureBoxWarship.Image = bmp;
|
pictureBoxWarship.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void SetData()
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_warship = new DrawingWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
||||||
_warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height);
|
_warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Cêîðîñòü: {_warship.Warship.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Cêîðîñòü: {_warship.Warship.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_warship.Warship.Weight}";
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_warship.Warship.Weight}";
|
||||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_warship.Warship.BodyColor.Name}";
|
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_warship.Warship.BodyColor.Name}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_warship = new DrawingWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||||
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
switch (name)
|
switch (name)
|
||||||
@ -46,10 +52,18 @@ namespace Warship
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pictureBoxWarship_Resize(object sender, EventArgs e)
|
private void PictureBoxWarship_Resize(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_warship?.ChangeBorders(pictureBoxWarship.Width, pictureBoxWarship.Height);
|
_warship?.ChangeBorders(pictureBoxWarship.Width, pictureBoxWarship.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_warship = new DrawingAdvancedWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), 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…
Reference in New Issue
Block a user