4 Commits
lab_4 ... lab6

Author SHA1 Message Date
Alenka
be33c0e4bc Done 2023-11-22 23:31:07 +04:00
Alenka
62a7064012 fix 2023-11-10 10:59:30 +04:00
Alenka
8c293b6d5c fix 2023-11-09 19:10:08 +04:00
Alenka
71fca0840e start 2023-11-09 16:42:28 +04:00
20 changed files with 1336 additions and 406 deletions

View File

@@ -1 +0,0 @@


View File

@@ -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
{
/// <summary>
/// Делегат для передачи объекта
/// </summary>
public delegate void PlaneDelegate(DrawingPlane plane);
}

View File

@@ -7,26 +7,26 @@ 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 Color BodyColor { get; 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;
}
public void setBodyColor(Color color)
{
BodyColor = color;
}
}
}

View File

@@ -0,0 +1,137 @@
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Monorail.DrawningObjects;
using System.Drawing;
namespace Monorail.Generics
{
internal class PlanesGenericCollection<T, U>
where T : DrawingPlane
where U : IMoveableObject
{
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public PlanesGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(PlanesGenericCollection<T, U>? collect, T? obj)
{
if (obj == null || collect == null)
return false;
return collect._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(PlanesGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
collect._collection.Remove(pos);
return obj;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowPlanes()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{//линия разметки места
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
int i = 0;
foreach (var plane in _collection.GetPlanes())
{
if (plane != null)
{
int inRow = _pictureWidth / _placeSizeWidth;
plane.SetPosition((i % inRow) * (_placeSizeWidth) + _placeSizeWidth / 20, _placeSizeHeight * (i / inRow) + _placeSizeHeight / 20);
plane.DrawTransport(g);
}
i++;
}
}
}
}

View File

@@ -0,0 +1,147 @@
using Cruiser;
using Monorail.DrawningObjects;
using Monorail.Generics;
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Monorail.Generics
{
internal class PlanesGenericStorage
{
private static readonly char _separatorForKeyValue = '|';
/// <summary>
/// Разделитель для записей коллекции данных в файл
/// </summary>
private readonly char _separatorRecords = ';';
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly char _separatorForObject = ':';
/// <summary>
/// Сохранение информации по самолетам в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка сохранении данных</returns>
public bool SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
StringBuilder data = new();
foreach (KeyValuePair<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> record in _planeStorage)
{
StringBuilder records = new();
foreach (DrawingPlane? elem in record.Value.GetPlanes)
{
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
}
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
}
if (data.Length == 0)
{
return false;
}
using (StreamWriter sw = new(filename))
{
sw.WriteLine($"PlaneStorage{Environment.NewLine}{data}");
}
return true;
}
/// <summary>
/// Загрузка информации по автомобилям в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
using (StreamReader sr = new(filename))
{
string str = sr.ReadLine();
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
return false;
}
if (!strs[0].StartsWith("PlaneStorage"))
{
return false;
}
_planeStorage.Clear();
do
{
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{
str = sr.ReadLine();
continue;
}
PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords,
StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawingPlane? plane =
elem?.CreateDrawingPlane(_separatorForObject, _pictureWidth, _pictureHeight);
if (plane != null)
{
if (!(collection + plane))
{
return false;
}
}
}
_planeStorage.Add(record[0], collection);
str = sr.ReadLine();
} while (str != null);
}
return true;
}
readonly Dictionary<string, PlanesGenericCollection<DrawingPlane,
DrawingObjectPlane>> _planeStorage;
public List<string> Keys => _planeStorage.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
{
_planeStorage = new Dictionary<string, PlanesGenericCollection<DrawingPlane,
DrawingObjectPlane>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
_planeStorage.Add(name,
new PlanesGenericCollection<DrawingPlane,
DrawingObjectPlane>(_pictureWidth, _pictureHeight));
}
public void DelSet(string name)
{
if (!_planeStorage.ContainsKey(name))
return;
_planeStorage.Remove(name);
}
public PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>? this[string ind]
{
get
{
if (_planeStorage.ContainsKey(ind))
return _planeStorage[ind];
return null;
}
}
}
}

View File

@@ -10,137 +10,134 @@ 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)
public void ChangeColor(Color col)
{
if (width <= _monoRailWidth || height <= _monoRailHeight)
if (EntityPlane == null)
return;
EntityPlane.BodyColor = col;
}
protected DrawingPlane(int speed, double weight, Color bodyColor, int width, int height, int planeWidth, int planeHeight)
{
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);
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному направлению</returns>
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,
};
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
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;
}
Pen pen = new Pen(Color.Black, 2);
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);
Brush br = new SolidBrush(EntityPlane.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);
@@ -166,12 +163,7 @@ DrawningObjectMonorail(this);
// _monoRailWidth += dif;
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -8,59 +8,52 @@ 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;
}
Pen additionalPen = new(advancedMonorail.AdditionalColor);
Brush additionalBrush = new SolidBrush(advancedMonorail.AdditionalColor);
//3 колеса
/* if (advancedMonorail.AddWheelsNumb >= 3)
{
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)
Point[] trianglePoints1 =
{
g.FillEllipse(Brushes.Green, _startPosX + 90, _startPosY + 20, 20, 20);
}
new Point(_startPosX + 20, _startPosY + 5),
new Point(_startPosX + 40, _startPosY + 25),
new Point(_startPosX + 60, _startPosY + 5)
};
Point[] trianglePoints2 =
{
new Point(_startPosX + 20, _startPosY + 55),
new Point(_startPosX + 40, _startPosY + 35),
new Point(_startPosX + 60, _startPosY + 55)
};
g.FillPolygon(additionalBrush, trianglePoints1);
g.FillPolygon(additionalBrush, trianglePoints2);
}
if (airBomber.Bombs)
{
g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 20, 20, 20);
}
}
}
}

View File

@@ -0,0 +1,56 @@
using Monorail.DrawningObjects;
using Monorail.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser
{
public static class ExtentionDrawingPlane
{
public static DrawingPlane? CreateDrawingPlane(this string info, char
separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawingPlane(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
if (strs.Length == 6)
{
return new DrawingAirBomber(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]),
Color.FromName(strs[2]),
Color.FromName(strs[3]),
Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]), width, height);
}
return null;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawingPlane">Сохраняемый объект</param>
/// <param name="separatorForObject">Разделитель даннных</param>
/// <returns>Строка с данными по объекту</returns>
public static string GetDataForSave(this DrawingPlane drawingPlane,
char separatorForObject)
{
var plane = drawingPlane.EntityPlane;
if (plane == null)
{
return string.Empty;
}
var str = $"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}";
if (plane is not EntityAirBomber airBomber)
{
return str;
}
return
$"{str}{separatorForObject}{airBomber.AdditionalColor.Name}{separatorForObject}{airBomber.Bombs}{separatorForObject}{airBomber.Fuel}";
}
}
}

View File

@@ -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;
}

383
Cruiser/Cruiser/Form2.Designer.cs generated Normal file
View File

@@ -0,0 +1,383 @@
namespace Cruiser
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.panel3 = new System.Windows.Forms.Panel();
this.label_addit_color = new System.Windows.Forms.Label();
this.label_color = 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.panel9 = new System.Windows.Forms.Panel();
this.panel8 = new System.Windows.Forms.Panel();
this.panel7 = new System.Windows.Forms.Panel();
this.panel6 = new System.Windows.Forms.Panel();
this.panel5 = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
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.checkBox2);
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 = "Параметры";
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(33, 277);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(232, 29);
this.checkBox2.TabIndex = 12;
this.checkBox2.Text = "Наличие ракетных шахт";
this.checkBox2.UseVisualStyleBackColor = true;
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
//
// button2
//
this.button2.Location = new System.Drawing.Point(991, 321);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(127, 38);
this.button2.TabIndex = 11;
this.button2.Text = "Отмена";
this.button2.UseVisualStyleBackColor = true;
//
// button1
//
this.button1.Location = new System.Drawing.Point(838, 321);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(136, 38);
this.button1.TabIndex = 10;
this.button1.Text = "Добавить";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// panel3
//
this.panel3.AllowDrop = true;
this.panel3.Controls.Add(this.label_addit_color);
this.panel3.Controls.Add(this.label_color);
this.panel3.Controls.Add(this.pictureBox1);
this.panel3.Location = new System.Drawing.Point(822, 45);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(312, 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);
//
// label_addit_color
//
this.label_addit_color.AllowDrop = true;
this.label_addit_color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_addit_color.Location = new System.Drawing.Point(169, 23);
this.label_addit_color.Name = "label_addit_color";
this.label_addit_color.Size = new System.Drawing.Size(117, 38);
this.label_addit_color.TabIndex = 10;
this.label_addit_color.Text = "Доп.цвет";
this.label_addit_color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_addit_color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelAddColor_DragDrop);
this.label_addit_color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelAddColor_DragEnter);
//
// label_color
//
this.label_color.AllowDrop = true;
this.label_color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_color.Location = new System.Drawing.Point(30, 23);
this.label_color.Name = "label_color";
this.label_color.Size = new System.Drawing.Size(110, 38);
this.label_color.TabIndex = 9;
this.label_color.Text = "Цвет";
this.label_color.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_color.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
this.label_color.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(76, 64);
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(521, 293);
this.labelAdvanced.Name = "labelAdvanced";
this.labelAdvanced.Size = new System.Drawing.Size(141, 47);
this.labelAdvanced.TabIndex = 7;
this.labelAdvanced.Text = "Продвинутый";
this.labelAdvanced.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
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(369, 293);
this.labelBasic.Name = "labelBasic";
this.labelBasic.Size = new System.Drawing.Size(131, 47);
this.labelBasic.TabIndex = 6;
this.labelBasic.Text = "Простой";
this.labelBasic.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBasic.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.panel9);
this.groupBox2.Controls.Add(this.panel8);
this.groupBox2.Controls.Add(this.panel7);
this.groupBox2.Controls.Add(this.panel6);
this.groupBox2.Controls.Add(this.panel5);
this.groupBox2.Controls.Add(this.panel4);
this.groupBox2.Controls.Add(this.panel2);
this.groupBox2.Controls.Add(this.panel1);
this.groupBox2.Location = new System.Drawing.Point(335, 40);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(357, 231);
this.groupBox2.TabIndex = 5;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Цвета";
//
// panel9
//
this.panel9.BackColor = System.Drawing.Color.Fuchsia;
this.panel9.Location = new System.Drawing.Point(264, 153);
this.panel9.Name = "panel9";
this.panel9.Size = new System.Drawing.Size(53, 49);
this.panel9.TabIndex = 7;
//
// panel8
//
this.panel8.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
this.panel8.Location = new System.Drawing.Point(180, 153);
this.panel8.Name = "panel8";
this.panel8.Size = new System.Drawing.Size(53, 49);
this.panel8.TabIndex = 6;
//
// panel7
//
this.panel7.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
this.panel7.Location = new System.Drawing.Point(108, 153);
this.panel7.Name = "panel7";
this.panel7.Size = new System.Drawing.Size(53, 49);
this.panel7.TabIndex = 5;
//
// panel6
//
this.panel6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
this.panel6.Location = new System.Drawing.Point(34, 153);
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(53, 49);
this.panel6.TabIndex = 4;
//
// panel5
//
this.panel5.BackColor = System.Drawing.Color.Purple;
this.panel5.Location = new System.Drawing.Point(264, 44);
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(53, 49);
this.panel5.TabIndex = 3;
//
// panel4
//
this.panel4.BackColor = System.Drawing.Color.DarkOrchid;
this.panel4.Location = new System.Drawing.Point(186, 44);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(53, 49);
this.panel4.TabIndex = 2;
//
// panel2
//
this.panel2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.panel2.Location = new System.Drawing.Point(108, 44);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(53, 49);
this.panel2.TabIndex = 1;
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.ButtonHighlight;
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(33, 213);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(310, 29);
this.checkBox1.TabIndex = 4;
this.checkBox1.Text = "Наличие площадки под вертолет";
this.checkBox1.UseVisualStyleBackColor = true;
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(128, 143);
this.numericUpDown2.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDown2.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(84, 31);
this.numericUpDown2.TabIndex = 3;
this.numericUpDown2.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(128, 75);
this.numericUpDown1.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDown1.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(74, 31);
this.numericUpDown1.TabIndex = 2;
this.numericUpDown1.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// 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(43, 25);
this.label2.TabIndex = 1;
this.label2.Text = "Вес:";
//
// 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(93, 25);
this.label1.TabIndex = 0;
this.label1.Text = "Скорость:";
//
// 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 = "Создание объекта";
this.Load += new System.EventHandler(this.Form2_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.panel3.ResumeLayout(false);
((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 label_addit_color;
private Label label_color;
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;
private CheckBox checkBox2;
private Panel panel9;
private Panel panel8;
private Panel panel7;
private Panel panel6;
private Panel panel5;
private Panel panel4;
}
}

214
Cruiser/Cruiser/Form2.cs Normal file
View File

@@ -0,0 +1,214 @@
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; }
/// <summary>
/// Переменная
/// </summary>
DrawingPlane? _plane = null;
/// <summary>
/// Событие
/// </summary>
public event Action<DrawingPlane>? EventAddPlane;
public Form2(int pictureWidth, int pictureHeight)
{
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
InitializeComponent();
panel1.MouseDown += PanelColor_MouseDown;
panel2.MouseDown += PanelColor_MouseDown;
panel3.MouseDown += PanelColor_MouseDown;
panel4.MouseDown += PanelColor_MouseDown;
panel5.MouseDown += PanelColor_MouseDown;
panel6.MouseDown += PanelColor_MouseDown;
panel7.MouseDown += PanelColor_MouseDown;
panel8.MouseDown += PanelColor_MouseDown;
panel9.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(Action<DrawingPlane> 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);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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,
checkBox2.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);
}
/// <summary>
/// Добавление
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
switch (((Label)sender).Name)
{
case "label_color":
_plane?.EntityPlane?.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "label_addit_color":
if (!(_plane is DrawingAirBomber))
return;
(_plane.EntityPlane as EntityAirBomber)?.setAdditionalColor(color: (Color)e.Data.GetData(typeof(Color)));
break;
}
//на всякий случай
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,
checkBox2.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,
checkBox2.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;
}
}
private void ButtonAddCruiser()
{
throw new NotImplementedException();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
}
}
}

View File

@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -1,4 +1,6 @@
namespace Cruiser
using System.Windows.Forms;
namespace Cruiser
{
partial class FormCruiserCollection
{
@@ -38,16 +40,23 @@
this.ButtonRemoveCar = new System.Windows.Forms.Button();
this.ButtonAddCruiser = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.panel1.SuspendLayout();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Location = new System.Drawing.Point(0, 33);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(971, 544);
this.pictureBox1.Size = new System.Drawing.Size(971, 511);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
@@ -143,6 +152,49 @@
this.textBox1.TabIndex = 2;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// saveFileDialog
//
this.saveFileDialog.FileName = "PlanesStorage";
this.saveFileDialog.Filter = "txt file | *.txt";
//
// openFileDialog
//
this.openFileDialog.FileName = "openFileDialog1";
this.openFileDialog.Filter = "txt file | *.txt";
//
// menuStrip
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem,
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(971, 33);
this.menuStrip.TabIndex = 2;
this.menuStrip.Text = "menuStrip";
//
// ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(69, 29);
this.ToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(114, 29);
this.SaveToolStripMenuItem.Text = "Сохранить";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(108, 29);
this.LoadToolStripMenuItem.Text = "Загрузить";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
// FormCruiserCollection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
@@ -150,11 +202,14 @@
this.ClientSize = new System.Drawing.Size(971, 544);
this.Controls.Add(this.panel1);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.menuStrip);
this.Name = "FormCruiserCollection";
this.Text = "FormCruiserCollection";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -172,5 +227,11 @@
private Button addStorageButton;
private ListBox listBoxStorages;
private Button button2;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
private MenuStrip menuStrip;
private ToolStripMenuItem ToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
}
}

View File

@@ -16,21 +16,61 @@ 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)
{
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Обработка нажатия "Загрузка"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storage.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
foreach (var collection in _storage.Keys)
{
listBoxStorages.Items.Add(collection);
}
}
else
{
MessageBox.Show("Не удалось загрузить", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonAddCruiser_Click(object sender, EventArgs e)
public void ButtonAddCruiser_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
@@ -42,23 +82,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();
Action<DrawingPlane>? 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 +147,7 @@ namespace Cruiser
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox1.Image = obj.ShowMonorails();
pictureBox1.Image = obj.ShowPlanes();
}
else
{
@@ -120,26 +158,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 +184,7 @@ namespace Cruiser
{
return;
}
pictureBox1.Image = obj.ShowMonorails();
pictureBox1.Image = obj.ShowPlanes();
}
@@ -173,7 +192,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)

View File

@@ -57,4 +57,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>28, 24</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>216, 24</value>
</metadata>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>400, 24</value>
</metadata>
</root>

View File

@@ -1,102 +0,0 @@
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Monorail.DrawningObjects;
using System.Drawing;
namespace Monorail.Generics
{
internal class MonorailGenericCollection<T, U>
where T : DrawningMonorail
where U : IMoveableObject
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeHeight = 90;
private readonly SetGeneric<T> _collection;
public MonorailGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static bool operator +(MonorailGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
return false;
return collect?._collection.Insert(obj) ?? false;
}
public static T? operator -(MonorailGenericCollection<T, U> collect, int
pos)
{
T? obj = collect._collection[pos];
if (obj != null)
collect._collection.Remove(pos);
return obj;
}
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
public Bitmap ShowMonorails()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
private void DrawObjects(Graphics g)
{
int i = 0;
foreach (var monorail in _collection.GetMonorails())
{
if (monorail != 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);
}
i++;
}
}
}
}

View File

@@ -1,51 +0,0 @@
using Monorail.DrawningObjects;
using Monorail.Generics;
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Monorail.Generics
{
internal class MonorailGenericStorage
{
readonly Dictionary<string, MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>> _monorailStorages;
public List<string> Keys => _monorailStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public MonorailGenericStorage(int pictureWidth, int pictureHeight)
{
_monorailStorages = new Dictionary<string,
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
_monorailStorages.Add(name, new MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>(_pictureWidth, _pictureHeight));
}
public void DelSet(string name)
{
if (!_monorailStorages.ContainsKey(name))
return;
_monorailStorages.Remove(name);
}
public MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>? this[string ind]
{
get
{
if (_monorailStorages.ContainsKey(ind))
return _monorailStorages[ind];
return null;
}
}
}
}

View File

@@ -7,22 +7,23 @@ 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;
}
public void setAdditionalColor(Color color)
{
AdditionalColor = color;
}
}
}
}

View File

@@ -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<T?>(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<T?> GetMonorails(int? maxMonorails = null)
public IEnumerable<T?> 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;
}
}
}
}
}