8 Commits
lab_3 ... 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
Alenka
735492bfe2 Чуть пофиксила 2023-10-27 08:32:54 +04:00
Alenka
842e5a8ca4 почти done 2023-10-26 23:10:37 +04:00
Alenka
f5d9e89692 почти done 2023-10-26 16:46:27 +04:00
Alenka
1bacab8f18 start 2023-10-26 00:36:02 +04:00
26 changed files with 1516 additions and 581 deletions

View File

@@ -1,44 +1,20 @@
using Cruiser;
using DumpTruck.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Monorail.DrawningObjects;
namespace DumpTruck.MovementStrategy
namespace Monorail.MovementStrategy
{
public abstract class AbstractStrategy
{
/// <summary>
/// Перемещаемый объект
/// </summary>
private IMoveableObject? _moveableObject;
/// <summary>
/// Статус перемещения
/// </summary>
private Status _state = Status.NotInit;
/// <summary>
/// Ширина поля
/// </summary>
protected int FieldWidth { get; private set; }
/// <summary>
/// Высота поля
/// </summary>
protected int FieldHeight { get; private set; }
/// <summary>
/// Статус перемещения
/// </summary>
public Status GetStatus() { return _state; }
/// <summary>
/// Установка данных
/// </summary>
/// <param name="moveableObject">Перемещаемый объект</param>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
public void SetData(IMoveableObject moveableObject, int width, int
height)
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
{
@@ -50,9 +26,7 @@ namespace DumpTruck.MovementStrategy
FieldWidth = width;
FieldHeight = height;
}
/// <summary>
/// Шаг перемещения
/// </summary>
public void MakeStep()
{
if (_state != Status.InProgress)
@@ -66,35 +40,18 @@ namespace DumpTruck.MovementStrategy
}
MoveToTarget();
}
/// <summary>
/// Перемещение влево
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveLeft() => MoveTo(DirectionType.Left);
/// <summary>
/// Перемещение вправо
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveRight() => MoveTo(DirectionType.Right);
/// <summary>
/// Перемещение вверх
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveUp() => MoveTo(DirectionType.Up);
/// <summary>
/// Перемещение вниз
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
protected bool MoveDown() => MoveTo(DirectionType.Down);
/// <summary>
/// Параметры объекта
/// </summary>
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
/// <summary>
/// Шаг объекта
/// </summary>
/// <returns></returns>
_moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != Status.InProgress)
@@ -103,20 +60,11 @@ namespace DumpTruck.MovementStrategy
}
return _moveableObject?.GetStep;
}
/// <summary>
/// Перемещение к цели
/// </summary>
protected abstract void MoveToTarget();
/// <summary>
/// Достигнута ли цель
/// </summary>
/// <returns></returns>
protected abstract bool IsTargetDestinaion();
/// <summary>
/// Попытка перемещения в требуемом направлении
/// </summary>
/// <param name="directionType">Направление</param>
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
@@ -130,5 +78,7 @@ namespace DumpTruck.MovementStrategy
}
return false;
}
}
}
}

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

@@ -1,41 +1,32 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck.Entities
namespace Monorail.Entities
{
public class EntityCar
public class EntityPlane
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public Color BodyColor { get; set; }
public double Step => (double)Speed * 100 / Weight;
/// <summary>
/// Конструктор с параметрами
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityCar(int speed, double weight, Color bodyColor)
public EntityPlane(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
public void setBodyColor(Color color)
{
BodyColor = color;
}
}
}

View File

@@ -1,18 +1,17 @@
using System;
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.Generics;
using Monorail.DrawningObjects;
using System.Drawing;
using DumpTruck.DrawningObjects;
using DumpTruck.Entities;
using DumpTruck.MovementStrategy;
namespace DumpTruck.Generics
namespace Monorail.Generics
{
internal class CarsGenericCollection<T, U>
where T : DrawningCar
internal class PlanesGenericCollection<T, U>
where T : DrawingPlane
where U : IMoveableObject
{
/// <summary>
@@ -35,12 +34,13 @@ namespace DumpTruck.Generics
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public CarsGenericCollection(int picWidth, int picHeight)
public PlanesGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
@@ -54,14 +54,11 @@ namespace DumpTruck.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static int operator +(CarsGenericCollection<T, U> collect, T?
obj)
public static bool operator +(PlanesGenericCollection<T, U>? collect, T? obj)
{
if (obj == null)
{
return -1;
}
return collect._collection.Insert(obj) ;
if (obj == null || collect == null)
return false;
return collect._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
@@ -69,15 +66,12 @@ namespace DumpTruck.Generics
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static bool operator -(CarsGenericCollection<T, U> collect, int
pos)
public static T? operator -(PlanesGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection.Get(pos);
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return true;
return obj;
}
/// <summary>
/// Получение объекта IMoveableObject
@@ -86,13 +80,13 @@ namespace DumpTruck.Generics
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
return (U?)_collection[pos]?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowCars()
public Bitmap ShowPlanes()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
@@ -111,37 +105,33 @@ namespace DumpTruck.Generics
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{//линия рамзетки места
{//линия разметки места
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
_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)
{
DrawningCar car;
int numPlacesInRow = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++)
int i = 0;
foreach (var plane in _collection.GetPlanes())
{
// TODO получение объекта
// TODO установка позиции
// TODO прорисовка объекта
car = _collection.Get(i);
if (car != null)
if (plane != null)
{
car.SetPosition((i % numPlacesInRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / numPlacesInRow) + _placeSizeHeight / 10);
//car.SetPosition(_placeSizeWidth * (i/ numPlacesInColumn) + _placeSizeWidth / 20, (i % numPlacesInColumn ) *_placeSizeHeight + _placeSizeHeight / 10);
car.DrawTransport(g);
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

@@ -4,27 +4,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser
namespace Monorail
{
public enum DirectionType
{
/// Вверх
/// </summary>
Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4
}
}
}

View File

@@ -1,19 +1,18 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DumpTruck.Entities;
using DumpTruck.MovementStrategy;
using Cruiser;
using Monorail.Entities;
using Monorail.MovementStrategy;
namespace DumpTruck.DrawningObjects
namespace Monorail.DrawningObjects
{
public class DrawningCar
public class DrawingPlane
{
public EntityCar? EntityCar { get; protected set; }
public EntityPlane? EntityPlane { get; protected set; }
private int _pictureWidth;
@@ -23,75 +22,84 @@ namespace DumpTruck.DrawningObjects
protected int _startPosY;
private readonly int _carWidth = 110;
protected readonly int _planeWidth = 160;
private readonly int _carHeight = 60;
protected readonly int _planeHeight = 160;
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY => _startPosY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _carWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _carHeight;
/// <summary>
/// Получение объекта IMoveableObject из объекта DrawningCar
/// </summary>
public IMoveableObject GetMoveableObject => new DrawningObjectCar(this);
public int GetWidth => _planeWidth;
public DrawningCar(int speed, double weight, Color bodyColor, int width, int height)
public int GetHeight => _planeHeight;
public DrawingPlane(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _carWidth || height < _carHeight)
{
if (_planeWidth > width || _planeHeight > height)
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityCar = new EntityCar(speed, weight, bodyColor);
EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
protected DrawningCar(int speed, double weight, Color bodyColor, int
width, int height, int carWidth, int carHeight)
public void ChangeColor(Color col)
{
if (width <= _carWidth || height <= _carHeight)
{
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;
_carWidth = carWidth;
_carHeight = carHeight;
EntityCar = new EntityCar(speed, weight, bodyColor);
_planeWidth = planeWidth;
_planeHeight = planeHeight;
EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
public IMoveableObject GetMoveableObject => new DrawingObjectPlane(this);
public void SetPosition(int x, int y)
{
if (x < 0 || x >= _pictureWidth || y < 0 || y >= _pictureHeight)
{
_startPosX = 0;
_startPosY = 0;
}
if (x < 0 || y < 0 || x + _planeWidth >= _pictureWidth || y + _planeHeight >= _pictureHeight)
x = y = 2;
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному направлению</returns>
public bool CanMove(DirectionType direction)
{
if (EntityPlane == null)
{
return false;
}
return direction switch
{
//влево
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) || EntityCar == null)
if (!CanMove(direction) || EntityPlane == null)
{
return;
}
@@ -99,81 +107,37 @@ width, int height, int carWidth, int carHeight)
{
//влево
case DirectionType.Left:
_startPosX -= (int)EntityCar.Step;
_startPosX -= (int)EntityPlane.Step;
break;
//вверх
case DirectionType.Up:
_startPosY -= (int)EntityCar.Step;
_startPosY -= (int)EntityPlane.Step;
break;
// вправо
case DirectionType.Right:
_startPosX += (int)EntityCar.Step;
_startPosX += (int)EntityPlane.Step;
break;
//вниз
case DirectionType.Down:
_startPosY += (int)EntityCar.Step;
_startPosY += (int)EntityPlane.Step;
break;
}
}
public bool CanMove(DirectionType direction)
{
if (EntityCar == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityCar.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityCar.Step > 0,
// вправо
DirectionType.Right => _startPosX + EntityCar.Step + _carWidth < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + EntityCar.Step + _carHeight < _pictureHeight,
_ => false,
};
}
public virtual void DrawTransport(Graphics g)
{
if (EntityCar == null)
if (EntityPlane == null)
{
return;
}
Pen pen = new Pen(Color.Black);
Brush brush = new SolidBrush(EntityCar.BodyColor);
//границы автомобиля
//SolidBrush(Cruiser.AdditionalColor);
//границы автомобиля
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(EntityCar.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);
@@ -198,7 +162,8 @@ width, int height, int carWidth, int carHeight)
_startPosY + 19, 30, 25);
}
}
}
}
}

View File

@@ -3,37 +3,35 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser;
using DumpTruck.DrawningObjects;
using DumpTruck.MovementStrategy;
using Monorail.DrawningObjects;
namespace DumpTruck.MovementStrategy
namespace Monorail.MovementStrategy
{
internal class DrawningObjectCar : IMoveableObject
public class DrawingObjectPlane : IMoveableObject
{
private readonly DrawningCar? _drawningCar = null;
public DrawningObjectCar(DrawningCar drawningCar)
private readonly DrawingPlane? _drawningPlane = null;
public DrawingObjectPlane(DrawingPlane drawingPlane)
{
_drawningCar = drawningCar;
_drawningPlane = drawingPlane;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningCar == null || _drawningCar.EntityCar ==
if (_drawningPlane == null || _drawningPlane.EntityPlane ==
null)
{
return null;
}
return new ObjectParameters(_drawningCar.GetPosX,
_drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight);
return new ObjectParameters(_drawningPlane.GetPosX,
_drawningPlane.GetPosY, _drawningPlane.GetWidth, _drawningPlane.GetHeight);
}
}
public int GetStep => (int)(_drawningCar?.EntityCar?.Step ?? 0);
public int GetStep => (int)(_drawningPlane?.EntityPlane?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawningCar?.CanMove(direction) ?? false;
_drawningPlane?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawningCar?.MoveTransport(direction);
_drawningPlane?.MoveTransport(direction);
}
}
}

View File

@@ -1,60 +1,59 @@
using DumpTruck;
using System;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DumpTruck.Entities;
using Monorail.Entities;
namespace DumpTruck.DrawningObjects
namespace Monorail.DrawningObjects
{
public class DrawningDumpTruck : DrawningCar
public class DrawingAirBomber : DrawingPlane
{
public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tent, int width, int height) : base(speed, weight, bodyColor, width, height, 110, 60)
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 (EntityCar != null)
if (EntityPlane != null)
{
EntityCar = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, bodyKit, tent);
EntityPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, wing);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityCar is not EntityDumpTruck dumpTruck)
if (EntityPlane is not EntityAirBomber airBomber)
{
return;
}
Pen pen = new Pen(Color.Black);
Brush addBrush = new SolidBrush(dumpTruck.AdditionalColor);
Brush brush = new SolidBrush(dumpTruck.BodyColor);
base.DrawTransport(g);
if (dumpTruck.Tent)
{
Brush brYellow = new SolidBrush(Color.Yellow);
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
20);
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
20);
}
if (dumpTruck.BodyKit)
{
g.FillEllipse(Brushes.Green, _startPosX + 90, _startPosY + 20, 20, 20);
}
Pen pen = new Pen(Color.Black, 2);
Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor);
if (airBomber.Fuel)
{
Point[] trianglePoints1 =
{
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

@@ -136,6 +136,7 @@
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(182, 33);
this.comboBox1.TabIndex = 7;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// ButtonStep
//

View File

@@ -1,41 +1,48 @@
using System;
using Cruiser;
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;
using DumpTruck.DrawningObjects;
using DumpTruck.Entities;
using Monorail.DrawningObjects;
using Monorail.MovementStrategy;
using Monorail;
using DumpTruck.MovementStrategy;
namespace Cruiser
{
public partial class CruiserForm : Form
{
private DrawningCar? _drawningCar;
private AbstractStrategy? _abstractStrategy;
private DrawingPlane? _drawingPlane;
private AbstractStrategy? _strategy;
public DrawningCar? SelectedCar { get; private set; }
public DrawingPlane? SelectedPlane { get; private set; }
public CruiserForm()
{
InitializeComponent();
_strategy = null;
SelectedCar = null;
SelectedPlane = null;
}
private void Draw()
{
if (_drawningCar == null)
if (_drawingPlane == null)
{
return;
}
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningCar.DrawTransport(gr);
_drawingPlane.DrawTransport(gr);
pictureBox1.Image = bmp;
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawningCar == null)
if (_drawingPlane == null)
{
return;
}
@@ -43,16 +50,16 @@ namespace Cruiser
switch (name)
{
case "buttonUp":
_drawningCar.MoveTransport(DirectionType.Up);
_drawingPlane.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawningCar.MoveTransport(DirectionType.Down);
_drawingPlane.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawningCar.MoveTransport(DirectionType.Left);
_drawingPlane.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawningCar.MoveTransport(DirectionType.Right);
_drawingPlane.MoveTransport(DirectionType.Right);
break;
}
Draw();
@@ -61,28 +68,23 @@ namespace Cruiser
private void button2_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color dopColor = 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)
{
color = dialog.Color;
mainColor = dialog.Color;
}
if (dialog.ShowDialog() == DialogResult.OK)
{
dopColor = dialog.Color;
additColor = dialog.Color;
}
_drawningCar = new DrawningDumpTruck(random.Next(100, 300),
random.Next(1000, 3000),
color,
dopColor,
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
_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);
_drawningCar.SetPosition(random.Next(10, 100), random.Next(10,
100));
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
@@ -92,65 +94,70 @@ namespace Cruiser
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawningCar == null)
if (_drawingPlane == null)
{
return;
}
if (comboBox1.Enabled)
{
_abstractStrategy = comboBox1.SelectedIndex
_strategy = comboBox1.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
1 => new MoveToEdge(),
_ => null,
};
if (_abstractStrategy == null)
if (_strategy == null)
{
return;
}
_abstractStrategy.SetData(new DrawningObjectCar(_drawningCar), 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 color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color dopColor = 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)
{
color = dialog.Color;
}
_drawningCar = new DrawningCar(random.Next(100, 300),
random.Next(1000, 3000),
color,
_drawingPlane = new DrawingPlane(random.Next(100, 300),
random.Next(1000, 3000), color,
pictureBox1.Width, pictureBox1.Height);
_drawningCar.SetPosition(random.Next(10, 100), random.Next(10,
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
public void SelectedCruiser_Click(object sender, EventArgs e)
{
SelectedCar = _drawningCar;
SelectedPlane = _drawingPlane;
DialogResult = DialogResult.OK;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}

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
{
@@ -30,19 +32,31 @@
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel1 = new System.Windows.Forms.Panel();
this.textBox2 = new System.Windows.Forms.TextBox();
this.addStorageButton = new System.Windows.Forms.Button();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.button2 = new System.Windows.Forms.Button();
this.updateCollectionButton = new System.Windows.Forms.Button();
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(800, 450);
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;
@@ -50,17 +64,69 @@
//
// panel1
//
this.panel1.Controls.Add(this.textBox2);
this.panel1.Controls.Add(this.addStorageButton);
this.panel1.Controls.Add(this.listBoxStorages);
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.updateCollectionButton);
this.panel1.Controls.Add(this.ButtonRemoveCar);
this.panel1.Controls.Add(this.ButtonAddCruiser);
this.panel1.Controls.Add(this.textBox1);
this.panel1.Location = new System.Drawing.Point(589, 12);
this.panel1.Location = new System.Drawing.Point(692, 12);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(211, 438);
this.panel1.Size = new System.Drawing.Size(267, 520);
this.panel1.TabIndex = 1;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(60, 36);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(150, 31);
this.textBox2.TabIndex = 2;
//
// addStorageButton
//
this.addStorageButton.Location = new System.Drawing.Point(79, 88);
this.addStorageButton.Name = "addStorageButton";
this.addStorageButton.Size = new System.Drawing.Size(112, 34);
this.addStorageButton.TabIndex = 2;
this.addStorageButton.Text = "Добавить";
this.addStorageButton.UseVisualStyleBackColor = true;
this.addStorageButton.Click += new System.EventHandler(this.addStorageButton_Click);
//
// listBoxStorages
//
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 25;
this.listBoxStorages.Location = new System.Drawing.Point(60, 128);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(152, 104);
this.listBoxStorages.TabIndex = 4;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged);
//
// button2
//
this.button2.Location = new System.Drawing.Point(60, 264);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(159, 36);
this.button2.TabIndex = 2;
this.button2.Text = "Удалить набор";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.delStorageButton_Click);
//
// updateCollectionButton
//
this.updateCollectionButton.Location = new System.Drawing.Point(79, 469);
this.updateCollectionButton.Name = "updateCollectionButton";
this.updateCollectionButton.Size = new System.Drawing.Size(112, 34);
this.updateCollectionButton.TabIndex = 2;
this.updateCollectionButton.Text = "Обновить";
this.updateCollectionButton.UseVisualStyleBackColor = true;
this.updateCollectionButton.Click += new System.EventHandler(this.button1_Click);
//
// ButtonRemoveCar
//
this.ButtonRemoveCar.Location = new System.Drawing.Point(31, 168);
this.ButtonRemoveCar.Location = new System.Drawing.Point(60, 429);
this.ButtonRemoveCar.Name = "ButtonRemoveCar";
this.ButtonRemoveCar.Size = new System.Drawing.Size(150, 34);
this.ButtonRemoveCar.TabIndex = 2;
@@ -70,7 +136,7 @@
//
// ButtonAddCruiser
//
this.ButtonAddCruiser.Location = new System.Drawing.Point(31, 37);
this.ButtonAddCruiser.Location = new System.Drawing.Point(60, 317);
this.ButtonAddCruiser.Name = "ButtonAddCruiser";
this.ButtonAddCruiser.Size = new System.Drawing.Size(150, 34);
this.ButtonAddCruiser.TabIndex = 3;
@@ -80,24 +146,70 @@
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(31, 104);
this.textBox1.Location = new System.Drawing.Point(60, 381);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(150, 31);
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);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
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();
@@ -110,5 +222,16 @@
private Button ButtonRemoveCar;
private Button ButtonAddCruiser;
private TextBox textBox1;
private Button updateCollectionButton;
private TextBox textBox2;
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

@@ -1,5 +1,6 @@

using DumpTruck.Generics;
using Monorail.DrawningObjects;
using Monorail.Generics;
using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -9,53 +10,128 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cruiser;
using DumpTruck.DrawningObjects;
using DumpTruck.Generics;
using DumpTruck.MovementStrategy;
namespace Cruiser
{
public partial class FormCruiserCollection : Form
{
private readonly CarsGenericCollection<DrawningCar, DrawningObjectCar> _cars;
private readonly PlanesGenericStorage _storage;
public FormCruiserCollection()
{
InitializeComponent();
_cars = new CarsGenericCollection<DrawningCar, DrawningObjectCar>(pictureBox1.Width, pictureBox1.Height);
_storage = new PlanesGenericStorage(pictureBox1.Width, pictureBox1.Height);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void ButtonAddCruiser_Click(object sender, EventArgs e)
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
CruiserForm form = new();
if (form.ShowDialog() == DialogResult.OK)
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_cars + form.SelectedCar != null)
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);
}
}
}
public void ButtonAddCruiser_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
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 = _cars.ShowCars();
pictureBox1.Image = obj.ShowPlanes();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
});
form.AddEvent(planeDelegate);
}
private void ReloadObjects()
{
int index = listBoxStorages.SelectedIndex;
listBoxStorages.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
listBoxStorages.Items.Add(_storage.Keys[i]);
}
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
>= listBoxStorages.Items.Count))
{
listBoxStorages.SelectedIndex = 0;
}
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
index < listBoxStorages.Items.Count)
{
listBoxStorages.SelectedIndex = index;
}
}
private void ButtonRemoveCar_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
@@ -68,10 +144,10 @@ namespace Cruiser
return;
}
if (_cars - pos != null)
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox1.Image = _cars.ShowCars();
pictureBox1.Image = obj.ShowPlanes();
}
else
{
@@ -82,8 +158,9 @@ namespace Cruiser
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBox1.Image = _cars.ShowCars();
}
private void maskedTextBoxNumber_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
@@ -94,6 +171,59 @@ namespace Cruiser
{
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBox1.Image = obj.ShowPlanes();
}
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox1.Image =
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
}
private void delStorageButton_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
private void addStorageButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBox2.Text);
ReloadObjects();
}
}
}

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,38 +1,16 @@
using DumpTruck;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DumpTruck.MovementStrategy;
using Cruiser;
using Monorail.DrawningObjects;
using Cruiser;
namespace DumpTruck.MovementStrategy
namespace Monorail.MovementStrategy
{
/// <summary>
/// Интерфейс для работы с перемещаемым объектом
/// </summary>
public interface IMoveableObject
{
/// <summary>
/// Получение координаты X объекта
/// </summary>
ObjectParameters? GetObjectPosition { get; }
/// <summary>
/// Шаг объекта
/// </summary>
int GetStep { get; }
/// <summary>
/// Проверка, можно ли переместиться по нужному направлению
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
bool CheckCanMove(DirectionType direction);
/// <summary>
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
void MoveObject(DirectionType direction);
}

View File

@@ -1,13 +1,14 @@
using DumpTruck.MovementStrategy;

using Monorail.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck.MovementStrategy
namespace Monorail.MovementStrategy
{
internal class MoveToBorder : AbstractStrategy
public class MoveToEdge : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
@@ -16,10 +17,8 @@ namespace DumpTruck.MovementStrategy
{
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight;
return objParams.RightBorder < FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder < FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
@@ -29,22 +28,22 @@ namespace DumpTruck.MovementStrategy
{
return;
}
var diffX = FieldWidth - objParams.ObjectMiddleHorizontal;
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
MoveRight();
if (diffX < 0)
{
MoveRight();
}
}
var diffY = FieldHeight - objParams.ObjectMiddleVertical;
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
MoveDown();
if (diffY < 0)
{
MoveDown();
}
}
}
}
}

View File

@@ -1,13 +1,13 @@
using DumpTruck.MovementStrategy;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck.MovementStrategy
namespace Monorail.MovementStrategy
{
internal class MoveToCenter : AbstractStrategy
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
@@ -16,12 +16,12 @@ namespace DumpTruck.MovementStrategy
{
return false;
}
return (objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2);
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
@@ -54,5 +54,6 @@ namespace DumpTruck.MovementStrategy
}
}
}
}
}

View File

@@ -1,51 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck.MovementStrategy
namespace Monorail.MovementStrategy
{
/// <summary>
/// Параметры-координаты объекта
/// </summary>
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
/// <summary>
/// Левая граница
/// </summary>
public int LeftBorder => _x;
/// <summary>
/// Верхняя граница
/// </summary>
public int TopBorder => _y;
/// <summary>
/// Правая граница
/// </summary>
public int RightBorder => _x + _width;
/// <summary>
/// Нижняя граница
/// </summary>
public int DownBorder => _y + _height;
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleHorizontal => _x + _width / 2;
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleVertical => _y + _height / 2;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина</param>
/// <param name="height">Высота</param>
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
@@ -53,5 +27,6 @@ namespace DumpTruck.MovementStrategy
_width = width;
_height = height;
}
}
}

View File

@@ -2,41 +2,28 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DumpTruck.Entities
namespace Monorail.Entities
{
public class EntityDumpTruck : EntityCar
public class EntityAirBomber : EntityPlane
{
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; }
public bool Bombs { get; private set; }
public bool Fuel { get; private set; }
/// <summary>
/// Признак (опция) наличия кузова
/// </summary>
public bool BodyKit { get; private set; }
/// <summary>
/// Признак (опция) наличия tent
/// </summary>
public bool Tent { get; private set; }
public EntityDumpTruck(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool tent) : base(speed, weight, bodyColor)
public EntityAirBomber(int speed, double weight, Color bodyColor, Color
additionalColor, bool bombs, bool fuel)
: base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
BodyKit = bodyKit;
Tent = tent;
Bombs = bombs;
Fuel = fuel;
}
public void setAdditionalColor(Color color)
{
AdditionalColor = color;
}
}
}

View File

@@ -1,5 +1,6 @@
namespace Cruiser
{
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
internal static class Program
{
/// <summary>

View File

@@ -4,99 +4,69 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.Generics
namespace Monorail.Generics
{
internal class SetGeneric<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private readonly T?[] _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Length;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
///
public int startPointer = 0;
private readonly List<T?> _places;
public int Count => _places.Count;
private readonly int _maxCount;
public SetGeneric(int count)
{
_places = new T?[count];
_maxCount = count;
_places = new List<T?>(count);
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <returns></returns>
public int Insert(T car)
public bool Insert(T plane)
{
if (_places[Count - 1] != null)
return -1;
return Insert(car, 0);
if (_places.Count == _maxCount)
return false;
Insert(plane, 0);
return true;
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public int Insert(T car, int position)
public bool Insert(T plane, int position)
{
if (!(position >= 0 && position < Count))
return -1;
if (_places[position] != null)
{
int indexEnd = position + 1;
while (_places[indexEnd] != null)
{
indexEnd++;
}
for (int i = indexEnd + 1; i > position; i--)
{
_places[i] = _places[i - 1];
}
}
_places[position] = car;
return position;
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
return false;
_places.Insert(position, plane);
return true;
}
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
{
if (position < Count && position >= 0)
{
_places[position] = null;
return true;
}
return false;
if (!(position >= 0 && position < Count))
return false;
_places.RemoveAt(position);
return true;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? Get(int position)
{
if (position < Count && position >= 0) { return _places[position]; }
return null;
public T? this[int position]
{
get
{
if (!(position >= 0 && position <= Count))
return null;
return _places[position];
}
set
{
if (!(position >= 0 && position <= Count))
return;
_places.Insert(position, value);
}
}
public IEnumerable<T?> GetPlanes(int? maxPlanes = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxPlanes.HasValue && i == maxPlanes.Value)
yield break;
}
}
}
}

View File

@@ -4,12 +4,12 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck.MovementStrategy
namespace Monorail
{
public enum Status
{
NotInit,
InProgress,
Finish
NotInit = 1,
InProgress = 2,
Finish = 3
}
}
}