Продвинутый объект
This commit is contained in:
parent
8ad0fe65dc
commit
471887324e
87
Warship/Warship/DrawingPlaneWarship.cs
Normal file
87
Warship/Warship/DrawingPlaneWarship.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AircraftCarrier
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
internal class DrawingPlaneWarship : DrawingWarship
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес корабля</param>
|
||||
/// <param name="bodyColor">Цвет</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="controlplace">Признак наличия рубки управления</param>
|
||||
/// <param name="runway">Признак наличия взлетной полосы</param>
|
||||
public DrawingPlaneWarship(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool controlplace, bool runway) :
|
||||
base(speed, weight, bodyColor, 244, 100)
|
||||
{
|
||||
Ship = new EntityPlaneWarship(speed, weight, bodyColor, dopColor, bodyKit, controlplace, runway);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Ship is not EntityPlaneWarship planeWarship)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(planeWarship.DopColor);
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
Brush br = new SolidBrush(Ship?.BodyColor ?? Color.White);
|
||||
if (planeWarship.BodyKit)
|
||||
{
|
||||
// броня носовой части корабля
|
||||
PointF pointShipArmor1 = new PointF(_startPosX + 167, _startPosY + 25);
|
||||
PointF pointShipArmor2 = new PointF(_startPosX + 237, _startPosY + 40);
|
||||
PointF pointShipArmor3 = new PointF(_startPosX + 167, _startPosY + 75);
|
||||
PointF pointShipArmor4 = new PointF(_startPosX + 237, _startPosY + 55);
|
||||
PointF[] PointsShipArmor =
|
||||
{
|
||||
pointShipArmor1, pointShipArmor2, pointShipArmor3, pointShipArmor4,
|
||||
};
|
||||
g.FillPolygon(br, PointsShipArmor);
|
||||
g.DrawPolygon(pen, PointsShipArmor);
|
||||
g.DrawEllipse(pen, _startPosX + 224, _startPosY + 37, 20, 20);
|
||||
g.FillEllipse(br, _startPosX + 224, _startPosY + 37, 20, 20);
|
||||
}
|
||||
|
||||
if (planeWarship.RunWay)
|
||||
{
|
||||
//взлетная полоса
|
||||
g.DrawRectangle(pen, _startPosX + 27, _startPosY + 75, 140, 25);
|
||||
g.DrawRectangle(pen, _startPosX + 32, _startPosY + 87, 25, 5);
|
||||
g.DrawRectangle(pen, _startPosX + 82, _startPosY + 87, 25, 5);
|
||||
g.DrawRectangle(pen, _startPosX + 132, _startPosY + 87, 25, 5);
|
||||
g.FillRectangle(brYellow, _startPosX + 32, _startPosY + 87, 25, 5);
|
||||
g.FillRectangle(brYellow, _startPosX + 82, _startPosY + 87, 25, 5);
|
||||
g.FillRectangle(brYellow, _startPosX + 132, _startPosY + 87, 25, 5);
|
||||
}
|
||||
|
||||
_startPosX += 22;
|
||||
_startPosY += 25;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 22;
|
||||
_startPosY -= 25;
|
||||
|
||||
if (planeWarship.СontrolPlace)
|
||||
{
|
||||
g.FillEllipse(dopBrush, _startPosX + 127, _startPosY + 30, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 127, _startPosY + 30, 10, 10);
|
||||
|
||||
g.FillEllipse(dopBrush, _startPosX + 137, _startPosY + 30, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 137, _startPosY + 30, 10, 10);
|
||||
|
||||
g.FillRectangle(dopBrush, _startPosX + 132, _startPosY + 30, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX + 132, _startPosY + 30, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,15 +14,15 @@ namespace AircraftCarrier
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityWarship Ship { private set; get; }
|
||||
public EntityWarship Ship { protected set; get; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки корабля
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки корабля
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -50,6 +50,21 @@ namespace AircraftCarrier
|
||||
Ship = new EntityWarship(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 DrawingWarship(int speed, float weight, Color bodyColor, int
|
||||
shipWidth, int shipHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_shipWidth = shipWidth;
|
||||
_shipHeight = shipHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции корабля
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
@ -119,7 +134,7 @@ namespace AircraftCarrier
|
||||
/// Отрисовка корабля
|
||||
/// </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)
|
||||
|
50
Warship/Warship/EntityPlaneWarship.cs
Normal file
50
Warship/Warship/EntityPlaneWarship.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AircraftCarrier
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Авианосец"
|
||||
/// </summary>
|
||||
internal class EntityPlaneWarship : EntityWarship
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия обвеса
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия рубки управления
|
||||
/// </summary>
|
||||
public bool СontrolPlace { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия взлетной полосы
|
||||
/// </summary>
|
||||
public bool RunWay { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес корабля</param>
|
||||
/// <param name="bodyColor">Цвет</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="controlplace">Признак наличия рубки управления</param>
|
||||
/// <param name="runway">Признак наличия взлетной полосы</param>
|
||||
public EntityPlaneWarship(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool controlplace, bool runway) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
BodyKit = bodyKit;
|
||||
СontrolPlace = controlplace;
|
||||
RunWay = runway;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
13
Warship/Warship/FormShip.Designer.cs
generated
13
Warship/Warship/FormShip.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonUp = 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();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -141,11 +142,22 @@
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(107, 382);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(130, 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(800, 450);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
@ -175,5 +187,6 @@
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ namespace AircraftCarrier
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||
/// Ìåòîä ïðîðèñîâêè êîðàáëÿ
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
@ -18,6 +18,17 @@ namespace AircraftCarrier
|
||||
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}";
|
||||
toolStripStatusLabelColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
@ -27,11 +38,7 @@ namespace AircraftCarrier
|
||||
Random rnd = new();
|
||||
_ship = new DrawingWarship(rnd.Next(50, 100), rnd.Next(20000, 30000),
|
||||
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}";
|
||||
toolStripStatusLabelColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
||||
Setdata();
|
||||
Draw();
|
||||
}
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
@ -61,6 +68,21 @@ namespace AircraftCarrier
|
||||
_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 DrawingPlaneWarship(rnd.Next(50, 100), rnd.Next(20000, 30000),
|
||||
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