diff --git a/Cruiser/Cruiser/ClassDelegate.cs b/Cruiser/Cruiser/ClassDelegate.cs
new file mode 100644
index 0000000..d239e99
--- /dev/null
+++ b/Cruiser/Cruiser/ClassDelegate.cs
@@ -0,0 +1,14 @@
+using Monorail.DrawningObjects;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Cruiser
+{
+ ///
+ /// Делегат для передачи объекта
+ ///
+ public delegate void PlaneDelegate(DrawingPlane plane);
+}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/Cruiser.cs b/Cruiser/Cruiser/Cruiser.cs
index 9877dd3..ffe66ba 100644
--- a/Cruiser/Cruiser/Cruiser.cs
+++ b/Cruiser/Cruiser/Cruiser.cs
@@ -7,26 +7,21 @@ using System.Threading.Tasks;
namespace Monorail.Entities
{
- public class EntityMonorail
+ public class EntityPlane
{
public int Speed { get; private set; }
+
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
- public Color WheelColor { get; private set; }
-
- public Color TireColor { get; private set; }
public double Step => (double)Speed * 100 / Weight;
-
- public EntityMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor)
+ public EntityPlane(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
- WheelColor = wheelColor;
- TireColor = tireColor;
}
}
-}
\ No newline at end of file
+}
diff --git a/Cruiser/Cruiser/DrawningCruiser.cs b/Cruiser/Cruiser/DrawningCruiser.cs
index 22d60f1..6d500a0 100644
--- a/Cruiser/Cruiser/DrawningCruiser.cs
+++ b/Cruiser/Cruiser/DrawningCruiser.cs
@@ -10,168 +10,171 @@ using Monorail.MovementStrategy;
namespace Monorail.DrawningObjects
{
- public class DrawningMonorail
+ public class DrawingPlane
{
- public EntityMonorail? EntityMonorail { get; protected set; }
-
- public int GetPosX => _startPosX;
-
- public int GetPosY => _startPosY;
-
- public int GetWidth => _monoRailWidth;
-
- public int GetHeight => _monoRailHeight;
+ public EntityPlane? EntityPlane { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
- protected int _startPosX = 0;
+ protected int _startPosX;
- protected int _startPosY = 0;
+ protected int _startPosY;
- protected int _monoRailWidth = 110;
+ protected readonly int _planeWidth = 160;
- protected int _monoRailHeight = 60;
+ protected readonly int _planeHeight = 160;
- protected int wheelSz;
- public DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int width, int height)
+ public int GetPosX => _startPosX;
+
+ public int GetPosY => _startPosY;
+
+ public int GetWidth => _planeWidth;
+
+ public int GetHeight => _planeHeight;
+
+ public DrawingPlane(int speed, double weight, Color bodyColor, int width, int height)
{
- if (width <= _monoRailWidth || height <= _monoRailHeight)
+ if (_planeWidth > width || _planeHeight > height)
return;
_pictureWidth = width;
_pictureHeight = height;
- wheelSz = _monoRailHeight - _monoRailHeight * 7 / 10;
- EntityMonorail = new EntityMonorail(speed, weight, bodyColor, wheelColor, tireColor);
+ EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
- protected DrawningMonorail(int speed, double weight, Color bodyColor, int width, int height, Color wheelColor, Color tireColor, int monoRailWidth, int monoRailHeight)
+ protected DrawingPlane(int speed, double weight, Color bodyColor, int width, int height, int planeWidth, int planeHeight)
{
- if (width <= _monoRailWidth || height <= _monoRailHeight)
+ if (_planeWidth > width || _planeHeight > height)
return;
_pictureWidth = width;
_pictureHeight = height;
- _monoRailHeight = monoRailHeight;
- _monoRailWidth = monoRailWidth;
- wheelSz = _monoRailHeight - _monoRailHeight * 7 / 10;
- EntityMonorail = new EntityMonorail(speed, weight, bodyColor, wheelColor, tireColor);
+ _planeWidth = planeWidth;
+ _planeHeight = planeHeight;
+ EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
+
+ public IMoveableObject GetMoveableObject => new DrawingObjectPlane(this);
+
public void SetPosition(int x, int y)
{
- if (EntityMonorail == null)
- return;
+ if (x < 0 || y < 0 || x + _planeWidth >= _pictureWidth || y + _planeHeight >= _pictureHeight)
+ x = y = 2;
_startPosX = x;
_startPosY = y;
- if (x + _monoRailWidth >= _pictureWidth || y + _monoRailHeight >= _pictureHeight)
- {
- _startPosX = 1;
- _startPosY = 1;
- }
}
- public IMoveableObject GetMoveableObject => new
-DrawningObjectMonorail(this);
+
+ ///
+ /// Проверка, что объект может переместится по указанному направлению
+ ///
+ /// Направление
+ /// true - можно переместится по указанному направлению
public bool CanMove(DirectionType direction)
{
- if (EntityMonorail == null)
+ if (EntityPlane == null)
+ {
return false;
+ }
return direction switch
{
- DirectionType.Left => _startPosX - EntityMonorail.Step > 0,
- DirectionType.Up => _startPosY - EntityMonorail.Step > 0,
- DirectionType.Right => _startPosX + EntityMonorail.Step < _pictureWidth,
- DirectionType.Down => _startPosY - +EntityMonorail.Step < _pictureHeight
+ //влево
+ DirectionType.Left => _startPosX - EntityPlane.Step > 0,
+ //вверх
+ DirectionType.Up => _startPosY - EntityPlane.Step > 0,
+ // вправо
+ DirectionType.Right => _startPosX + EntityPlane.Step + _planeWidth < _pictureWidth,
+ //вниз
+ DirectionType.Down => _startPosY + EntityPlane.Step + _planeHeight < _pictureHeight,
+ _ => false,
};
}
+ ///
+ /// Изменение направления перемещения
+ ///
+ /// Направление
public void MoveTransport(DirectionType direction)
{
- if (!CanMove(direction) || EntityMonorail == null)
+ if (!CanMove(direction) || EntityPlane == null)
+ {
return;
+ }
switch (direction)
{
+ //влево
case DirectionType.Left:
- if (_startPosX - EntityMonorail.Step >= 0)
- _startPosX -= (int)EntityMonorail.Step;
+ _startPosX -= (int)EntityPlane.Step;
break;
+ //вверх
case DirectionType.Up:
- if (_startPosY - EntityMonorail.Step >= 0)
- _startPosY -= (int)EntityMonorail.Step;
+ _startPosY -= (int)EntityPlane.Step;
break;
+ // вправо
case DirectionType.Right:
- if (_startPosX + EntityMonorail.Step + _monoRailWidth < _pictureWidth)
- _startPosX += (int)EntityMonorail.Step;
+ _startPosX += (int)EntityPlane.Step;
break;
+ //вниз
case DirectionType.Down:
- if (_startPosY + EntityMonorail.Step + _monoRailHeight < _pictureHeight)
- _startPosY += (int)EntityMonorail.Step;
+ _startPosY += (int)EntityPlane.Step;
break;
}
}
public virtual void DrawTransport(Graphics g)
{
- if (EntityMonorail == null)
+ if (EntityPlane == null)
+ {
return;
- int dif = _monoRailWidth / 10;
- _monoRailWidth -= dif;
- Pen pen = new(Color.Black);
- Brush cartBrush = new SolidBrush(Color.Black);
- Brush bodyBrush = new SolidBrush(EntityMonorail.BodyColor);
- Pen windowPen = new(Color.Blue);
- Brush wheelBrush = new SolidBrush(EntityMonorail.WheelColor);
- Brush windowBrush = new SolidBrush(Color.White);
- Pen tirePen = new Pen(EntityMonorail.TireColor);
- if (_monoRailWidth - _monoRailWidth / 20 * 17 < wheelSz)
- wheelSz = _monoRailWidth - _monoRailWidth / 20 * 17;
- g.DrawEllipse(pen, _startPosX + 15, _startPosY + 5, 20, 20);
- g.DrawEllipse(pen, _startPosX + 15, _startPosY + 35, 20, 20);
- g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30);
- g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10,
- 30);
- g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
-
- //если есть доп.фонари
- /* if (Cruiser.Headlights)
- {
-
- Brush brYellow = new SolidBrush(Color.Yellow);
- g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
- 20);
- g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
- 20);
- }*/
- //основание лодки!!!
- Brush br = new SolidBrush(EntityMonorail.BodyColor);
- g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
- g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
- g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
- Point[] points = new Point[3];// нос лодки
- points[0] = new Point(_startPosX + 100, _startPosY + 5);
- points[1] = new Point(_startPosX + 100, _startPosY + 55);
- points[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
- g.FillPolygon(Brushes.Pink, points);
- //границы носа лодки
- Point[] points1 = new Point[3];// нос лодки
- points1[0] = new Point(_startPosX + 100, _startPosY + 5);
- points1[1] = new Point(_startPosX + 100, _startPosY + 55);
- points1[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
- g.DrawPolygon(pen, points1);
- g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 15, 10, 10);
- g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 35, 10, 10);
-
- //если есть ракетные шахты, добавить условие
- g.DrawRectangle(Pens.Black, _startPosX + 35,
- _startPosY + 23, 15, 15);
- g.DrawRectangle(Pens.Black, _startPosX + 50,
- _startPosY + 19, 30, 25);
-
-
-
-
-
- // _monoRailWidth += dif;
+ }
+ Pen pen = new Pen(Color.Black, 2);
+ //фюзеляж
+ Brush br = new SolidBrush(EntityPlane.BodyColor);
+ g.FillRectangle(br, _startPosX + 20, _startPosY + 70, 140, 20);
+ //кабина
+ Point[] point = new Point[3]{
+ new Point(_startPosX + 0, _startPosY + 80),
+ new Point(_startPosX + 20, _startPosY + 70),
+ new Point(_startPosX + 20, _startPosY + 90)
+ };
+ Brush cabin = new SolidBrush(Color.LightBlue);
+ g.FillPolygon(cabin, point);
+ //границы самолета
+ g.DrawPolygon(pen, point);
+ g.DrawRectangle(pen, _startPosX + 20, _startPosY + 70, 140, 20);
+ //Крылья
+ point = new Point[4] {
+ new Point(_startPosX + 70, _startPosY + 70),
+ new Point(_startPosX + 70, _startPosY + 0),
+ new Point(_startPosX + 90, _startPosY + 0),
+ new Point(_startPosX + 100, _startPosY + 70)
+ };
+ g.FillPolygon(br, point);
+ g.DrawPolygon(pen, point);
+ point = new Point[4] {
+ new Point(_startPosX + 70, _startPosY + 90),
+ new Point(_startPosX + 70, _startPosY + 160),
+ new Point(_startPosX + 90, _startPosY + 160),
+ new Point(_startPosX + 100, _startPosY + 90)
+ };
+ g.FillPolygon(br, point);
+ g.DrawPolygon(pen, point);
+ point = new Point[4] {
+ new Point(_startPosX + 130, _startPosY + 70),
+ new Point(_startPosX + 130, _startPosY + 50),
+ new Point(_startPosX + 160, _startPosY + 30),
+ new Point(_startPosX + 160, _startPosY + 70)
+ };
+ g.FillPolygon(br, point);
+ g.DrawPolygon(pen, point);
+ point = new Point[4] {
+ new Point(_startPosX + 130, _startPosY + 90),
+ new Point(_startPosX + 130, _startPosY + 110),
+ new Point(_startPosX + 160, _startPosY + 130),
+ new Point(_startPosX + 160, _startPosY + 90)
+ };
+ g.FillPolygon(br, point);
+ g.DrawPolygon(pen, point);
}
}
-
}
diff --git a/Cruiser/Cruiser/DrawningObjectCar.cs b/Cruiser/Cruiser/DrawningObjectCar.cs
index e5d7161..7f65df1 100644
--- a/Cruiser/Cruiser/DrawningObjectCar.cs
+++ b/Cruiser/Cruiser/DrawningObjectCar.cs
@@ -8,32 +8,30 @@ using Monorail.DrawningObjects;
namespace Monorail.MovementStrategy
{
- public class DrawningObjectMonorail : IMoveableObject
+ public class DrawingObjectPlane : IMoveableObject
{
- private readonly DrawningMonorail? _drawningMonorail = null;
-
- public DrawningObjectMonorail(DrawningMonorail drawningMonorail)
+ private readonly DrawingPlane? _drawningPlane = null;
+ public DrawingObjectPlane(DrawingPlane drawingPlane)
{
- _drawningMonorail = drawningMonorail;
+ _drawningPlane = drawingPlane;
}
-
public ObjectParameters? GetObjectPosition
{
get
{
- if (_drawningMonorail == null || _drawningMonorail.EntityMonorail == null)
+ if (_drawningPlane == null || _drawningPlane.EntityPlane ==
+ null)
{
return null;
}
- return new ObjectParameters(_drawningMonorail.GetPosX,
- _drawningMonorail.GetPosY, _drawningMonorail.GetWidth, _drawningMonorail.GetHeight);
+ return new ObjectParameters(_drawningPlane.GetPosX,
+ _drawningPlane.GetPosY, _drawningPlane.GetWidth, _drawningPlane.GetHeight);
}
-
}
- public int GetStep => (int)(_drawningMonorail?.EntityMonorail?.Step ?? 0);
+ public int GetStep => (int)(_drawningPlane?.EntityPlane?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
- _drawningMonorail?.CanMove(direction) ?? false;
+ _drawningPlane?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
- _drawningMonorail?.MoveTransport(direction);
+ _drawningPlane?.MoveTransport(direction);
}
-}
\ No newline at end of file
+}
diff --git a/Cruiser/Cruiser/DrawningPro.cs b/Cruiser/Cruiser/DrawningPro.cs
index 20216ee..ec07d07 100644
--- a/Cruiser/Cruiser/DrawningPro.cs
+++ b/Cruiser/Cruiser/DrawningPro.cs
@@ -8,59 +8,63 @@ using Monorail.Entities;
namespace Monorail.DrawningObjects
{
- public class DrawningLocomotive : DrawningMonorail
+ public class DrawingAirBomber : DrawingPlane
{
- public DrawningLocomotive(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int width, int height, int addWheelsNumb,
- Color additionalColor, bool secondCabine, bool magniteRail) : base(speed, weight, bodyColor, wheelColor, tireColor, width, height)
+ public DrawingAirBomber(int speed, double weight, Color bodyColor, Color
+ additionalColor, bool bombs, bool wing, int width, int height)
+ : base(speed, width, bodyColor, width, height, 160, 160)
{
- if (EntityMonorail != null)
+ if (EntityPlane != null)
{
- EntityMonorail = new EntityLocomotive(speed, weight, bodyColor, wheelColor, tireColor,
- addWheelsNumb, additionalColor, secondCabine, magniteRail);
+ EntityPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, wing);
}
}
+
public override void DrawTransport(Graphics g)
{
+ if (EntityPlane is not EntityAirBomber airBomber)
+ {
+ return;
+ }
base.DrawTransport(g);
- int dif = _monoRailWidth / 10;
- _monoRailWidth -= dif;
- Pen windowPen = new(Color.Blue);
- Brush wheelBrush = new SolidBrush(EntityMonorail.WheelColor);
- Brush windowBrush = new SolidBrush(Color.White);
- if (EntityMonorail == null)
- return;
- if (EntityMonorail is not EntityLocomotive advancedMonorail)
+ Pen pen = new Pen(Color.Black, 2);
+ Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor);
+ // топливо
+ if (airBomber.Fuel)
{
- return;
+ g.FillEllipse(additionalBrush, _startPosX + 60, _startPosY - 1, 40, 10);
+ g.DrawEllipse(pen, _startPosX + 60, _startPosY - 1, 40, 10);
+ g.FillEllipse(additionalBrush, _startPosX + 60, _startPosY + 150, 40, 10);
+ g.DrawEllipse(pen, _startPosX + 60, _startPosY + 150, 40, 10);
}
- Pen additionalPen = new(advancedMonorail.AdditionalColor);
- Brush additionalBrush = new SolidBrush(advancedMonorail.AdditionalColor);
-
- //3 колеса
- /* if (advancedMonorail.AddWheelsNumb >= 3)
+ //бомбы
+ if (airBomber.Bombs)
{
- g.FillEllipse(additionalBrush, _startPosX + _monoRailWidth / 10 * 6, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
- g.DrawEllipse(additionalPen, _startPosX + _monoRailWidth / 10 * 6, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
- }
-
- g.DrawEllipse(additionalPen, _startPosX + _monoRailWidth / 10 * 3, _startPosY + _monoRailHeight / 10 * 7, wheelSz, wheelSz);
- }*/
-
- if (advancedMonorail.SecondCabine)
- {
- Brush brYellow = new SolidBrush(Color.Yellow);
- g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
- 20);
- g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
- 20);
- _monoRailWidth += dif;
- //магнитная линия
- if (advancedMonorail.MagniteRail)
- {
- g.FillEllipse(Brushes.Green, _startPosX + 90, _startPosY + 20, 20, 20);
- }
+ Point[] point = new Point[8] {
+ new Point(_startPosX + 70 - 20, _startPosY + 75),
+ new Point(_startPosX + 90 - 20, _startPosY + 75),
+ new Point(_startPosX + 100 - 20, _startPosY + 80),
+ new Point(_startPosX + 110 - 20, _startPosY + 75),
+ new Point(_startPosX + 110 - 20, _startPosY + 85),
+ new Point(_startPosX + 100 - 20, _startPosY + 80),
+ new Point(_startPosX + 90 - 20, _startPosY + 85),
+ new Point(_startPosX + 70 - 20, _startPosY + 85)
+ };
+ g.FillPolygon(additionalBrush, point);
+ g.DrawPolygon(pen, point);
+ point = new Point[8] {
+ new Point(_startPosX + 70 + 30, _startPosY + 75),
+ new Point(_startPosX + 90 + 30, _startPosY + 75),
+ new Point(_startPosX + 100 + 30, _startPosY + 80),
+ new Point(_startPosX + 110 + 30, _startPosY + 75),
+ new Point(_startPosX + 110 + 30, _startPosY + 85),
+ new Point(_startPosX + 100 + 30, _startPosY + 80),
+ new Point(_startPosX + 90 + 30, _startPosY + 85),
+ new Point(_startPosX + 70 + 30, _startPosY + 85)
+ };
+ g.FillPolygon(additionalBrush, point);
+ g.DrawPolygon(pen, point);
}
}
-
}
}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/Form1.cs b/Cruiser/Cruiser/Form1.cs
index ac40e3b..afc73b7 100644
--- a/Cruiser/Cruiser/Form1.cs
+++ b/Cruiser/Cruiser/Form1.cs
@@ -18,33 +18,31 @@ namespace Cruiser
public partial class CruiserForm : Form
{
- private DrawningMonorail? _drawningMonorail;
-
- private AbstractStrategy? _abstractStrategy;
+ private DrawingPlane? _drawingPlane;
private AbstractStrategy? _strategy;
-
- public DrawningMonorail? SelectedCar { get; private set; }
+ public DrawingPlane? SelectedPlane { get; private set; }
public CruiserForm()
{
InitializeComponent();
_strategy = null;
- SelectedCar = null;
+ SelectedPlane = null;
+
}
private void Draw()
{
- if (_drawningMonorail == null)
+ if (_drawingPlane == null)
{
return;
}
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawningMonorail.DrawTransport(gr);
+ _drawingPlane.DrawTransport(gr);
pictureBox1.Image = bmp;
}
private void buttonMove_Click(object sender, EventArgs e)
{
- if (_drawningMonorail == null)
+ if (_drawingPlane == null)
{
return;
}
@@ -52,16 +50,16 @@ namespace Cruiser
switch (name)
{
case "buttonUp":
- _drawningMonorail.MoveTransport(DirectionType.Up);
+ _drawingPlane.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- _drawningMonorail.MoveTransport(DirectionType.Down);
+ _drawingPlane.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- _drawningMonorail.MoveTransport(DirectionType.Left);
+ _drawingPlane.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
- _drawningMonorail.MoveTransport(DirectionType.Right);
+ _drawingPlane.MoveTransport(DirectionType.Right);
break;
}
Draw();
@@ -70,17 +68,23 @@ namespace Cruiser
private void button2_Click(object sender, EventArgs e)
{
Random random = new();
- Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- Color wheelColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- Color tireColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ Color mainColor = Color.FromArgb(random.Next(0, 256),
+ random.Next(0, 256), random.Next(0, 256));
+ Color additColor = Color.FromArgb(random.Next(0, 256),
+ random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
- bodyColor = dialog.Color;
+ mainColor = dialog.Color;
}
- _drawningMonorail = new DrawningMonorail(random.Next(100, 300), random.Next(1000, 3000),
- bodyColor, wheelColor, tireColor,
- pictureBox1.Width, pictureBox1.Height);
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ additColor = dialog.Color;
+ }
+ _drawingPlane = new DrawingAirBomber(random.Next(100, 300),
+ random.Next(1000, 3000), mainColor, additColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
+ pictureBox1.Width, pictureBox1.Height);
+ _drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
@@ -90,63 +94,63 @@ namespace Cruiser
private void ButtonStep_Click(object sender, EventArgs e)
{
- if (_drawningMonorail == null)
+ if (_drawingPlane == null)
{
return;
}
if (comboBox1.Enabled)
{
- _abstractStrategy = comboBox1.SelectedIndex
+ _strategy = comboBox1.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToEdge(),
_ => null,
};
- if (_abstractStrategy == null)
+ if (_strategy == null)
{
return;
}
- _abstractStrategy.SetData(new DrawningObjectMonorail(_drawningMonorail), pictureBox1.Width,
+ _strategy.SetData(new
+ DrawingObjectPlane(_drawingPlane), pictureBox1.Width,
pictureBox1.Height);
comboBox1.Enabled = false;
}
- if (_abstractStrategy == null)
+ if (_strategy == null)
{
return;
}
- _abstractStrategy.MakeStep();
+ _strategy.MakeStep();
Draw();
- if (_abstractStrategy.GetStatus() == Status.Finish)
+ if (_strategy.GetStatus() == Status.Finish)
{
comboBox1.Enabled = true;
- _abstractStrategy = null;
+ _strategy = null;
}
+
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
- Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- Color wheelColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- Color tireColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ Color color = Color.FromArgb(random.Next(0, 256),
+ random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
- bodyColor = dialog.Color;
- if (dialog.ShowDialog() == DialogResult.OK)
- additionalColor = dialog.Color;
- int addWheelNumb = random.Next(3, 5);
- _drawningMonorail = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000),
- bodyColor, wheelColor, tireColor,
- pictureBox1.Width, pictureBox1.Height, addWheelNumb,
- additionalColor, random.Next(0, 2) > 0, random.Next(0, 2) > 0);
+ {
+ color = dialog.Color;
+ }
+ _drawingPlane = new DrawingPlane(random.Next(100, 300),
+ random.Next(1000, 3000), color,
+ pictureBox1.Width, pictureBox1.Height);
+ _drawingPlane.SetPosition(random.Next(10, 100), random.Next(10,
+ 100));
Draw();
}
public void SelectedCruiser_Click(object sender, EventArgs e)
{
- SelectedCar = _drawningMonorail;
+ SelectedPlane = _drawingPlane;
DialogResult = DialogResult.OK;
}
diff --git a/Cruiser/Cruiser/Form2.Designer.cs b/Cruiser/Cruiser/Form2.Designer.cs
new file mode 100644
index 0000000..876b8b5
--- /dev/null
+++ b/Cruiser/Cruiser/Form2.Designer.cs
@@ -0,0 +1,269 @@
+namespace Cruiser
+{
+ partial class Form2
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.groupBox1 = new System.Windows.Forms.GroupBox();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button1 = new System.Windows.Forms.Button();
+ this.panel3 = new System.Windows.Forms.Panel();
+ this.label6 = new System.Windows.Forms.Label();
+ this.label5 = new System.Windows.Forms.Label();
+ this.pictureBox1 = new System.Windows.Forms.PictureBox();
+ this.labelAdvanced = new System.Windows.Forms.Label();
+ this.labelBasic = new System.Windows.Forms.Label();
+ this.groupBox2 = new System.Windows.Forms.GroupBox();
+ this.panel2 = new System.Windows.Forms.Panel();
+ this.panel1 = new System.Windows.Forms.Panel();
+ this.checkBox1 = new System.Windows.Forms.CheckBox();
+ this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
+ this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label1 = new System.Windows.Forms.Label();
+ this.groupBox1.SuspendLayout();
+ this.panel3.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
+ this.groupBox2.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
+ this.SuspendLayout();
+ //
+ // groupBox1
+ //
+ this.groupBox1.Controls.Add(this.button2);
+ this.groupBox1.Controls.Add(this.button1);
+ this.groupBox1.Controls.Add(this.panel3);
+ this.groupBox1.Controls.Add(this.labelAdvanced);
+ this.groupBox1.Controls.Add(this.labelBasic);
+ this.groupBox1.Controls.Add(this.groupBox2);
+ this.groupBox1.Controls.Add(this.checkBox1);
+ this.groupBox1.Controls.Add(this.numericUpDown2);
+ this.groupBox1.Controls.Add(this.numericUpDown1);
+ this.groupBox1.Controls.Add(this.label2);
+ this.groupBox1.Controls.Add(this.label1);
+ this.groupBox1.Location = new System.Drawing.Point(57, 43);
+ this.groupBox1.Name = "groupBox1";
+ this.groupBox1.Size = new System.Drawing.Size(1163, 391);
+ this.groupBox1.TabIndex = 0;
+ this.groupBox1.TabStop = false;
+ this.groupBox1.Text = "groupBox1";
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(1034, 338);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(74, 33);
+ this.button2.TabIndex = 11;
+ this.button2.Text = "button2";
+ this.button2.UseVisualStyleBackColor = true;
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(902, 331);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(84, 38);
+ this.button1.TabIndex = 10;
+ this.button1.Text = "button1";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // panel3
+ //
+ this.panel3.AllowDrop = true;
+ this.panel3.Controls.Add(this.label6);
+ this.panel3.Controls.Add(this.label5);
+ this.panel3.Controls.Add(this.pictureBox1);
+ this.panel3.Location = new System.Drawing.Point(906, 45);
+ this.panel3.Name = "panel3";
+ this.panel3.Size = new System.Drawing.Size(228, 261);
+ this.panel3.TabIndex = 9;
+ this.panel3.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
+ this.panel3.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
+ //
+ // label6
+ //
+ this.label6.AllowDrop = true;
+ this.label6.AutoSize = true;
+ this.label6.Location = new System.Drawing.Point(124, 29);
+ this.label6.Name = "label6";
+ this.label6.Size = new System.Drawing.Size(59, 25);
+ this.label6.TabIndex = 10;
+ this.label6.Text = "label6";
+ this.label6.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelAddColor_DragDrop);
+ this.label6.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
+ //
+ // label5
+ //
+ this.label5.AllowDrop = true;
+ this.label5.AutoSize = true;
+ this.label5.Location = new System.Drawing.Point(27, 23);
+ this.label5.Name = "label5";
+ this.label5.Size = new System.Drawing.Size(59, 25);
+ this.label5.TabIndex = 9;
+ this.label5.Text = "label5";
+ this.label5.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
+ this.label5.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
+ //
+ // pictureBox1
+ //
+ this.pictureBox1.Location = new System.Drawing.Point(39, 67);
+ this.pictureBox1.Name = "pictureBox1";
+ this.pictureBox1.Size = new System.Drawing.Size(163, 178);
+ this.pictureBox1.TabIndex = 8;
+ this.pictureBox1.TabStop = false;
+ //
+ // labelAdvanced
+ //
+ this.labelAdvanced.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.labelAdvanced.Location = new System.Drawing.Point(671, 305);
+ this.labelAdvanced.Name = "labelAdvanced";
+ this.labelAdvanced.Size = new System.Drawing.Size(59, 25);
+ this.labelAdvanced.TabIndex = 7;
+ this.labelAdvanced.Text = "label4";
+ this.labelAdvanced.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
+ //
+ // labelBasic
+ //
+ this.labelBasic.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.labelBasic.Location = new System.Drawing.Point(515, 305);
+ this.labelBasic.Name = "labelBasic";
+ this.labelBasic.Size = new System.Drawing.Size(59, 25);
+ this.labelBasic.TabIndex = 6;
+ this.labelBasic.Text = "label3";
+ this.labelBasic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
+ //
+ // groupBox2
+ //
+ this.groupBox2.Controls.Add(this.panel2);
+ this.groupBox2.Controls.Add(this.panel1);
+ this.groupBox2.Location = new System.Drawing.Point(508, 59);
+ this.groupBox2.Name = "groupBox2";
+ this.groupBox2.Size = new System.Drawing.Size(333, 231);
+ this.groupBox2.TabIndex = 5;
+ this.groupBox2.TabStop = false;
+ this.groupBox2.Text = "groupBox2";
+ //
+ // panel2
+ //
+ this.panel2.BackColor = System.Drawing.SystemColors.ControlDarkDark;
+ this.panel2.Location = new System.Drawing.Point(124, 45);
+ this.panel2.Name = "panel2";
+ this.panel2.Size = new System.Drawing.Size(64, 54);
+ this.panel2.TabIndex = 1;
+ //
+ // panel1
+ //
+ this.panel1.BackColor = System.Drawing.SystemColors.ActiveBorder;
+ this.panel1.Location = new System.Drawing.Point(32, 44);
+ this.panel1.Name = "panel1";
+ this.panel1.Size = new System.Drawing.Size(55, 49);
+ this.panel1.TabIndex = 0;
+ //
+ // checkBox1
+ //
+ this.checkBox1.AutoSize = true;
+ this.checkBox1.Location = new System.Drawing.Point(280, 69);
+ this.checkBox1.Name = "checkBox1";
+ this.checkBox1.Size = new System.Drawing.Size(121, 29);
+ this.checkBox1.TabIndex = 4;
+ this.checkBox1.Text = "checkBox1";
+ this.checkBox1.UseVisualStyleBackColor = true;
+ //
+ // numericUpDown2
+ //
+ this.numericUpDown2.Location = new System.Drawing.Point(171, 143);
+ this.numericUpDown2.Name = "numericUpDown2";
+ this.numericUpDown2.Size = new System.Drawing.Size(54, 31);
+ this.numericUpDown2.TabIndex = 3;
+ //
+ // numericUpDown1
+ //
+ this.numericUpDown1.Location = new System.Drawing.Point(171, 69);
+ this.numericUpDown1.Name = "numericUpDown1";
+ this.numericUpDown1.Size = new System.Drawing.Size(53, 31);
+ this.numericUpDown1.TabIndex = 2;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(33, 145);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(59, 25);
+ this.label2.TabIndex = 1;
+ this.label2.Text = "label2";
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(33, 75);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(59, 25);
+ this.label1.TabIndex = 0;
+ this.label1.Text = "label1";
+ //
+ // Form2
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1279, 552);
+ this.Controls.Add(this.groupBox1);
+ this.Name = "Form2";
+ this.Text = "Form2";
+ this.groupBox1.ResumeLayout(false);
+ this.groupBox1.PerformLayout();
+ this.panel3.ResumeLayout(false);
+ this.panel3.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
+ this.groupBox2.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private GroupBox groupBox1;
+ private Button button2;
+ private Button button1;
+ private Panel panel3;
+ private Label label6;
+ private Label label5;
+ private PictureBox pictureBox1;
+ private Label labelAdvanced;
+ private Label labelBasic;
+ private GroupBox groupBox2;
+ private Panel panel2;
+ private Panel panel1;
+ private CheckBox checkBox1;
+ private NumericUpDown numericUpDown2;
+ private NumericUpDown numericUpDown1;
+ private Label label2;
+ private Label label1;
+ }
+}
\ No newline at end of file
diff --git a/Cruiser/Cruiser/Form2.cs b/Cruiser/Cruiser/Form2.cs
new file mode 100644
index 0000000..1dc2bc4
--- /dev/null
+++ b/Cruiser/Cruiser/Form2.cs
@@ -0,0 +1,176 @@
+using Monorail.DrawningObjects;
+using Monorail.Entities;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+namespace Cruiser
+{
+ public partial class Form2 : Form
+ {
+ public int _pictureWidth { get; private set; }
+ public int _pictureHeight { get; private set; }
+ ///
+ /// Переменная
+ ///
+ DrawingPlane? _plane = null;
+ ///
+ /// Событие
+ ///
+ private event PlaneDelegate? EventAddPlane;
+
+ public Form2(int pictureWidth, int pictureHeight)
+ {
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ InitializeComponent();
+ panel1.MouseDown += PanelColor_MouseDown;
+ panel2.MouseDown += PanelColor_MouseDown;
+ button2.Click += (s, e) => Close();
+ }
+
+ private void DrawPlane()
+ {
+ Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _plane?.SetPosition(5, 5);
+ _plane?.DrawTransport(gr);
+ pictureBox1.Image = bmp;
+ }
+ public void AddEvent(PlaneDelegate ev)
+ {
+ if (EventAddPlane == null)
+ {
+ EventAddPlane = ev;
+ }
+ else
+ {
+ EventAddPlane += ev;
+ }
+ }
+ private void LabelObject_MouseDown(object sender, MouseEventArgs e)
+ {
+ (sender as Label)?.DoDragDrop((sender as Label)?.Name,
+ DragDropEffects.Move | DragDropEffects.Copy);
+ }
+ ///
+ /// Проверка получаемой информации (ее типа на соответствие требуемому)
+ ///
+ ///
+ ///
+ private void PanelObject_DragEnter(object sender, DragEventArgs e)
+ {
+ if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+ ///
+ /// Действия при приеме перетаскиваемой информации
+ ///
+ ///
+ ///
+ private void PanelObject_DragDrop(object sender, DragEventArgs e)
+ {
+ switch (e.Data?.GetData(DataFormats.Text).ToString())
+ {
+ case "labelBasic":
+ _plane = new DrawingPlane((int)numericUpDown1.Value,
+ (int)numericUpDown2.Value, Color.White, _pictureWidth, _pictureHeight);
+ break;
+ case "labelAdvanced":
+ _plane = new DrawingAirBomber((int)numericUpDown1.Value,
+ (int)numericUpDown2.Value, Color.White, Color.Black, checkBox1.Checked,
+ checkBox1.Checked, _pictureWidth, _pictureHeight);
+ break;
+ }
+ DrawPlane();
+ }
+
+ private void PanelColor_MouseDown(object? sender, MouseEventArgs e)
+ {
+ (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
+ DragDropEffects.Move | DragDropEffects.Copy);
+ }
+
+ ///
+ /// Добавление
+ ///
+ ///
+ ///
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ if (_plane == null)
+ return;
+ EventAddPlane?.Invoke(_plane);
+ Close();
+ }
+
+ private void labelColor_DragDrop(object sender, DragEventArgs e)
+ {
+ if (_plane?.EntityPlane == null)
+ return;
+ Color bodyColor = (Color)e.Data.GetData(typeof(Color));
+ if (_plane is DrawingAirBomber)
+ {
+ _plane = new DrawingAirBomber((int)numericUpDown1.Value,
+ (int)numericUpDown2.Value, bodyColor, ((EntityAirBomber)_plane.EntityPlane).AdditionalColor, checkBox1.Checked,
+ checkBox1.Checked, _pictureWidth, _pictureHeight);
+ }
+ else
+ {
+ _plane = new DrawingPlane((int)numericUpDown1.Value,
+ (int)numericUpDown2.Value, bodyColor, _pictureWidth, _pictureHeight);
+ }
+ DrawPlane();
+ }
+
+ private void labelColor_DragEnter(object sender, DragEventArgs e)
+ {
+ if (e.Data.GetDataPresent(typeof(Color)))
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+
+ private void labelAddColor_DragDrop(object sender, DragEventArgs e)
+ {
+ if ((_plane?.EntityPlane == null) || (_plane is DrawingAirBomber == false))
+ return;
+ Color additionalColor = (Color)e.Data.GetData(typeof(Color));
+ _plane = new DrawingAirBomber((int)numericUpDown1.Value,
+ (int)numericUpDown1.Value, _plane.EntityPlane.BodyColor, additionalColor, checkBox1.Checked,
+ checkBox1.Checked, _pictureWidth, _pictureHeight);
+ DrawPlane();
+ }
+
+ private void labelAddColor_DragEnter(object sender, DragEventArgs e)
+ {
+ if (e.Data.GetDataPresent(typeof(Color)))
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
+ }
+
+ }
+
+
+ }
+
diff --git a/Cruiser/Cruiser/Form2.resx b/Cruiser/Cruiser/Form2.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Cruiser/Cruiser/Form2.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Cruiser/Cruiser/FormCruiserCollection.cs b/Cruiser/Cruiser/FormCruiserCollection.cs
index fcc2f5a..8d2d95c 100644
--- a/Cruiser/Cruiser/FormCruiserCollection.cs
+++ b/Cruiser/Cruiser/FormCruiserCollection.cs
@@ -16,12 +16,12 @@ namespace Cruiser
{
public partial class FormCruiserCollection : Form
{
- private readonly MonorailGenericStorage _storage;
+ private readonly PlanesGenericStorage _storage;
public FormCruiserCollection()
{
InitializeComponent();
- _storage = new MonorailGenericStorage(pictureBox1.Width, pictureBox1.Height);
+ _storage = new PlanesGenericStorage(pictureBox1.Width, pictureBox1.Height);
}
private void pictureBox1_Click(object sender, EventArgs e)
@@ -42,23 +42,21 @@ namespace Cruiser
{
return;
}
- CruiserForm form = new();
-
-
-
-
- if (form.ShowDialog() == DialogResult.OK)
- {
- if (obj + form.SelectedCar != null)
+ Form2 form = new Form2(pictureBox1.Width, pictureBox1.Height);
+ form.Show();
+ PlaneDelegate? planeDelegate = new((m) => {
+ bool q = (obj + m);
+ if (q)
{
MessageBox.Show("Объект добавлен");
- pictureBox1.Image = obj.ShowMonorails();
+ pictureBox1.Image = obj.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
- }
+ });
+ form.AddEvent(planeDelegate);
}
private void ReloadObjects()
{
@@ -109,7 +107,7 @@ namespace Cruiser
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
- pictureBox1.Image = obj.ShowMonorails();
+ pictureBox1.Image = obj.ShowPlanes();
}
else
{
@@ -120,26 +118,7 @@ namespace Cruiser
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
- var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
- string.Empty];
-
- CruiserForm form = new();
-
-
-
-
- if (form.ShowDialog() == DialogResult.OK)
- {
- if (obj + form.SelectedCar != null)
- {
- MessageBox.Show("Объект добавлен");
- pictureBox1.Image = obj.ShowMonorails();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
- }
+
}
@@ -165,7 +144,7 @@ namespace Cruiser
{
return;
}
- pictureBox1.Image = obj.ShowMonorails();
+ pictureBox1.Image = obj.ShowPlanes();
}
@@ -173,7 +152,7 @@ namespace Cruiser
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox1.Image =
-_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
+_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
}
private void delStorageButton_Click(object sender, EventArgs e)
diff --git a/Cruiser/Cruiser/MonorailGenericCollection.cs b/Cruiser/Cruiser/MonorailGenericCollection.cs
index e093ade..41783fb 100644
--- a/Cruiser/Cruiser/MonorailGenericCollection.cs
+++ b/Cruiser/Cruiser/MonorailGenericCollection.cs
@@ -10,21 +10,36 @@ using System.Drawing;
namespace Monorail.Generics
{
- internal class MonorailGenericCollection
- where T : DrawningMonorail
+ internal class PlanesGenericCollection
+ where T : DrawingPlane
where U : IMoveableObject
{
+ ///
+ /// Ширина окна прорисовки
+ ///
private readonly int _pictureWidth;
-
+ ///
+ /// Высота окна прорисовки
+ ///
private readonly int _pictureHeight;
-
- private readonly int _placeSizeWidth = 210;
-
- private readonly int _placeSizeHeight = 90;
-
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 170;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 200;
+ ///
+ /// Набор объектов
+ ///
private readonly SetGeneric _collection;
-
- public MonorailGenericCollection(int picWidth, int picHeight)
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public PlanesGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
@@ -32,30 +47,45 @@ namespace Monorail.Generics
_pictureHeight = picHeight;
_collection = new SetGeneric(width * height);
}
-
- public static bool operator +(MonorailGenericCollection collect, T? obj)
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
+ public static bool operator +(PlanesGenericCollection? collect, T? obj)
{
- if (obj == null)
+ if (obj == null || collect == null)
return false;
-
- return collect?._collection.Insert(obj) ?? false;
+ return collect._collection.Insert(obj);
}
-
- public static T? operator -(MonorailGenericCollection collect, int
-pos)
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static T? operator -(PlanesGenericCollection collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
collect._collection.Remove(pos);
return obj;
}
-
+ ///
+ /// Получение объекта IMoveableObject
+ ///
+ ///
+ ///
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
-
- public Bitmap ShowMonorails()
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowPlanes()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
@@ -63,7 +93,10 @@ pos)
DrawObjects(gr);
return bmp;
}
-
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
@@ -71,32 +104,32 @@ pos)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
- {
- g.DrawLine(pen, i * _placeSizeWidth, j *
- _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
+ {//линия разметки места
+ g.DrawLine(pen, i * _placeSizeWidth + 10, j *
+ _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 50, j *
_placeSizeHeight);
}
- g.DrawLine(pen, i * _placeSizeWidth, 0, i *
- _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth + 10, 0, i *
+ _placeSizeWidth + 10, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
-
+ ///
+ /// Метод прорисовки объектов
+ ///
+ ///
private void DrawObjects(Graphics g)
{
int i = 0;
- foreach (var monorail in _collection.GetMonorails())
+ foreach (var plane in _collection.GetPlanes())
{
- if (monorail != null)
+ if (plane != null)
{
int inRow = _pictureWidth / _placeSizeWidth;
- // monorail.SetPosition(i % inRow * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / inRow + 1) * _placeSizeHeight + 5);
- monorail.SetPosition((i % inRow) * (_placeSizeWidth) + _placeSizeWidth / 20, _placeSizeHeight * (i / inRow) + _placeSizeHeight / 20);
-
- monorail.DrawTransport(g);
+ plane.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeHeight / 2 - 8, i / inRow * _placeSizeHeight + 20);
+ plane.DrawTransport(g);
}
i++;
}
}
-
}
-}
\ No newline at end of file
+}
diff --git a/Cruiser/Cruiser/MonorailGenericStorage.cs b/Cruiser/Cruiser/MonorailGenericStorage.cs
index 55ef868..5416ced 100644
--- a/Cruiser/Cruiser/MonorailGenericStorage.cs
+++ b/Cruiser/Cruiser/MonorailGenericStorage.cs
@@ -9,41 +9,42 @@ using System.Threading.Tasks;
namespace Monorail.Generics
{
- internal class MonorailGenericStorage
+ internal class PlanesGenericStorage
{
- readonly Dictionary> _monorailStorages;
- public List Keys => _monorailStorages.Keys.ToList();
-
+ readonly Dictionary> _planeStorage;
+ public List Keys => _planeStorage.Keys.ToList();
private readonly int _pictureWidth;
-
private readonly int _pictureHeight;
- public MonorailGenericStorage(int pictureWidth, int pictureHeight)
+ public PlanesGenericStorage(int pictureWidth, int pictureHeight)
{
- _monorailStorages = new Dictionary>();
+ _planeStorage = new Dictionary>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
- _monorailStorages.Add(name, new MonorailGenericCollection(_pictureWidth, _pictureHeight));
+ _planeStorage.Add(name,
+ new PlanesGenericCollection(_pictureWidth, _pictureHeight));
}
public void DelSet(string name)
{
- if (!_monorailStorages.ContainsKey(name))
+ if (!_planeStorage.ContainsKey(name))
return;
- _monorailStorages.Remove(name);
+ _planeStorage.Remove(name);
}
- public MonorailGenericCollection? this[string ind]
+ public PlanesGenericCollection? this[string ind]
{
get
{
- if (_monorailStorages.ContainsKey(ind))
- return _monorailStorages[ind];
+ if (_planeStorage.ContainsKey(ind))
+ return _planeStorage[ind];
return null;
}
}
diff --git a/Cruiser/Cruiser/Pro.cs b/Cruiser/Cruiser/Pro.cs
index 3d34488..1869ea9 100644
--- a/Cruiser/Cruiser/Pro.cs
+++ b/Cruiser/Cruiser/Pro.cs
@@ -7,22 +7,19 @@ using System.Threading.Tasks;
namespace Monorail.Entities
{
- public class EntityLocomotive : EntityMonorail
+ public class EntityAirBomber : EntityPlane
{
public Color AdditionalColor { get; private set; }
- public int AddWheelsNumb { get; private set; }
+ public bool Bombs { get; private set; }
+ public bool Fuel { get; private set; }
- public bool SecondCabine { get; private set; }
-
- public bool MagniteRail { get; private set; }
- public EntityLocomotive(int speed, double weight, Color bodyColor, Color wheelColor,
- Color tireColor, int addWheelsNumb, Color secondCabineColor, bool secondCabine, bool magniteRail) : base(speed, weight, bodyColor, wheelColor, tireColor)
+ public EntityAirBomber(int speed, double weight, Color bodyColor, Color
+ additionalColor, bool bombs, bool fuel)
+ : base(speed, weight, bodyColor)
{
- AdditionalColor = secondCabineColor;
- AddWheelsNumb = addWheelsNumb;
- SecondCabine = secondCabine;
- MagniteRail = magniteRail;
+ AdditionalColor = additionalColor;
+ Bombs = bombs;
+ Fuel = fuel;
}
-
}
-}
\ No newline at end of file
+}
diff --git a/Cruiser/Cruiser/SetGeneric.cs b/Cruiser/Cruiser/SetGeneric.cs
index 06f50a9..da4f4da 100644
--- a/Cruiser/Cruiser/SetGeneric.cs
+++ b/Cruiser/Cruiser/SetGeneric.cs
@@ -14,26 +14,26 @@ namespace Monorail.Generics
public int Count => _places.Count;
private readonly int _maxCount;
+
public SetGeneric(int count)
{
_maxCount = count;
_places = new List(count);
}
- public bool Insert(T monorail)
+ public bool Insert(T plane)
{
if (_places.Count == _maxCount)
return false;
- Insert(monorail, 0);
+ Insert(plane, 0);
return true;
-
}
- public bool Insert(T monorail, int position)
+ public bool Insert(T plane, int position)
{
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
return false;
- _places.Insert(position, monorail);
+ _places.Insert(position, plane);
return true;
}
public bool Remove(int position)
@@ -43,34 +43,30 @@ namespace Monorail.Generics
_places.RemoveAt(position);
return true;
}
+
public T? this[int position]
{
get
{
- if (!(position >= 0 && position < Count))
+ if (!(position >= 0 && position <= Count))
return null;
return _places[position];
}
set
{
- if (!(position >= 0 && position < Count && _places.Count < _maxCount))
+ if (!(position >= 0 && position <= Count))
return;
_places.Insert(position, value);
- return;
}
}
-
- public IEnumerable GetMonorails(int? maxMonorails = null)
+ public IEnumerable GetPlanes(int? maxPlanes = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
- if (maxMonorails.HasValue && i == maxMonorails.Value)
- {
+ if (maxPlanes.HasValue && i == maxPlanes.Value)
yield break;
- }
}
}
-
}
}
\ No newline at end of file