Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e00356f4c1 | ||
|
|
f08466a718 | ||
|
|
065b937d2c |
@@ -1,14 +1,19 @@
|
||||
using System;
|
||||
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;
|
||||
|
||||
namespace Cruiser.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
@@ -65,22 +70,22 @@ namespace Cruiser.MovementStrategy
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(Direction.Left);
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(Direction.Right);
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(Direction.Up);
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(Direction.Down);
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
@@ -112,7 +117,7 @@ namespace Cruiser.MovementStrategy
|
||||
/// </summary>
|
||||
/// <param name="directionType">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||
private bool MoveTo(Direction directionType)
|
||||
private bool MoveTo(DirectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
@@ -127,4 +132,3 @@ namespace Cruiser.MovementStrategy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
147
Cruiser/Cruiser/CruiserGenericCollection.cs
Normal file
147
Cruiser/Cruiser/CruiserGenericCollection.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Cruiser.Generics;
|
||||
|
||||
using Cruiser.DrawningObjects;
|
||||
using Cruiser.Entities;
|
||||
using Cruiser.MovementStrategy;
|
||||
|
||||
namespace DumpTruck.Generics
|
||||
{
|
||||
internal class CruiserGenericCollection<T, U>
|
||||
where T : DrawningCar
|
||||
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;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public CruiserGenericCollection(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 int operator +(CruiserGenericCollection<T, U> collect, T?
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(obj) ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(CruiserGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowCars()
|
||||
{
|
||||
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)
|
||||
{
|
||||
DrawningCar car;
|
||||
int numPlacesInRow = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
// TODO получение объекта
|
||||
// TODO установка позиции
|
||||
// TODO прорисовка объекта
|
||||
car = _collection.Get(i);
|
||||
if (car != 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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Cruiser
|
||||
{
|
||||
public enum Direction
|
||||
public enum DirectionType
|
||||
{
|
||||
/// Вверх
|
||||
|
||||
|
||||
60
Cruiser/Cruiser/DrawningAdvancedCruiser.cs
Normal file
60
Cruiser/Cruiser/DrawningAdvancedCruiser.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using DumpTruck;
|
||||
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 Cruiser.Entities;
|
||||
|
||||
|
||||
namespace Cruiser.DrawningObjects
|
||||
{
|
||||
public class DrawningDumpTruck : DrawningCar
|
||||
{
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if (EntityCar != null)
|
||||
{
|
||||
EntityCar = new EntityAdvancedCruiser(speed, weight, bodyColor, additionalColor, bodyKit, tent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCar is not EntityAdvancedCruiser dumpTruck)
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,17 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Cruiser.Entities;
|
||||
using Cruiser.MovementStrategy;
|
||||
using Cruiser;
|
||||
|
||||
|
||||
namespace Cruiser.DrawningObjects
|
||||
{
|
||||
public class DrawningCruiser
|
||||
{
|
||||
|
||||
public EntityCruiser ? EntityCruiser { get; protected set; }
|
||||
public EntityCruiser? EntityCar { get; protected set; }
|
||||
|
||||
private int _pictureWidth;
|
||||
|
||||
@@ -20,11 +23,13 @@ namespace Cruiser.DrawningObjects
|
||||
|
||||
protected int _startPosY;
|
||||
|
||||
private readonly int _cruiserWidth = 150;
|
||||
private readonly int _carWidth = 110;
|
||||
|
||||
private readonly int _carHeight = 60;
|
||||
|
||||
private readonly int _cruiserHeight = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
@@ -33,30 +38,27 @@ namespace Cruiser.DrawningObjects
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _cruiserWidth;
|
||||
public int GetWidth => _carWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _cruiserHeight;
|
||||
public int GetHeight => _carHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectCruiser(this);
|
||||
|
||||
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
|
||||
public DrawningCruiser(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
if (width < _cruiserWidth || height < _cruiserHeight)
|
||||
if (width < _carWidth || height < _carHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
|
||||
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
|
||||
EntityCar = new EntityCruiser(speed, weight, bodyColor);
|
||||
|
||||
|
||||
|
||||
@@ -65,26 +67,17 @@ namespace Cruiser.DrawningObjects
|
||||
protected DrawningCruiser(int speed, double weight, Color bodyColor, int
|
||||
width, int height, int carWidth, int carHeight)
|
||||
{
|
||||
if (width <= _cruiserWidth || height <= _cruiserHeight)
|
||||
if (width <= _carWidth || height <= _carHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_cruiserWidth = carWidth;
|
||||
_cruiserHeight = carHeight;
|
||||
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
|
||||
_carWidth = carWidth;
|
||||
_carHeight = carHeight;
|
||||
EntityCar = new EntityCruiser(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x >= _pictureWidth || y < 0 || y >= _pictureHeight)
|
||||
@@ -94,68 +87,68 @@ width, int height, int carWidth, int carHeight)
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
}
|
||||
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(Direction direction)
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityCruiser == null)
|
||||
if (!CanMove(direction) || EntityCar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case Direction.Left:
|
||||
_startPosX -= (int)EntityCruiser.Step;
|
||||
case DirectionType.Left:
|
||||
_startPosX -= (int)EntityCar.Step;
|
||||
break;
|
||||
//вверх
|
||||
case Direction.Up:
|
||||
_startPosY -= (int)EntityCruiser.Step;
|
||||
case DirectionType.Up:
|
||||
_startPosY -= (int)EntityCar.Step;
|
||||
break;
|
||||
// вправо
|
||||
case Direction.Right:
|
||||
_startPosX += (int)EntityCruiser.Step;
|
||||
case DirectionType.Right:
|
||||
_startPosX += (int)EntityCar.Step;
|
||||
break;
|
||||
//вниз
|
||||
case Direction.Down:
|
||||
_startPosY += (int)EntityCruiser.Step;
|
||||
case DirectionType.Down:
|
||||
_startPosY += (int)EntityCar.Step;
|
||||
break;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
public bool CanMove(Direction direction)
|
||||
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityCruiser == null)
|
||||
if (EntityCar == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
Direction.Left => _startPosX - EntityCruiser.Step > 0,
|
||||
DirectionType.Left => _startPosX - EntityCar.Step > 0,
|
||||
//вверх
|
||||
Direction.Up => _startPosY - EntityCruiser.Step > 0,
|
||||
DirectionType.Up => _startPosY - EntityCar.Step > 0,
|
||||
// вправо
|
||||
Direction.Right => _startPosX + EntityCruiser.Step + _cruiserWidth < _pictureWidth,
|
||||
DirectionType.Right => _startPosX + EntityCar.Step + _carWidth < _pictureWidth,
|
||||
//вниз
|
||||
Direction.Down => _startPosY + EntityCruiser.Step + _cruiserHeight < _pictureHeight,
|
||||
DirectionType.Down => _startPosY + EntityCar.Step + _carHeight < _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// <param name="g"></param>
|
||||
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCruiser == null)
|
||||
if (EntityCar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush brush = new SolidBrush(EntityCruiser.BodyColor);
|
||||
Brush brush = new SolidBrush(EntityCar.BodyColor);
|
||||
|
||||
//границы автомобиля
|
||||
|
||||
//SolidBrush(Cruiser.AdditionalColor);
|
||||
|
||||
|
||||
@@ -170,17 +163,17 @@ width, int height, int carWidth, int carHeight)
|
||||
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);
|
||||
|
||||
//если есть доп.фонари
|
||||
/* if (Cruiser.Headlights)
|
||||
{
|
||||
/* 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 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(EntityCruiser.BodyColor);
|
||||
Brush br = new SolidBrush(EntityCar.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);
|
||||
@@ -204,22 +197,8 @@ width, int height, int carWidth, int carHeight)
|
||||
g.DrawRectangle(Pens.Black, _startPosX + 50,
|
||||
_startPosY + 19, 30, 25);
|
||||
|
||||
/* if (Cruiser.HelicopterPad)
|
||||
{
|
||||
//если есть площадка под вертолет
|
||||
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 20, 20);
|
||||
}
|
||||
if (Cruiser.Coating)
|
||||
{
|
||||
//если есть спец покрытие для площадки под вертолет
|
||||
g.FillEllipse(Brushes.Red, _startPosX + 90, _startPosY + 20, 20, 20);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -3,23 +3,25 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Cruiser;
|
||||
using Cruiser.DrawningObjects;
|
||||
using Cruiser.MovementStrategy;
|
||||
|
||||
|
||||
namespace Cruiser.MovementStrategy
|
||||
{
|
||||
internal class DrawningObjectCar : IMoveableObject
|
||||
internal class DrawningObjectCruiser : IMoveableObject
|
||||
{
|
||||
private readonly DrawningCruiser? _drawningCar = null;
|
||||
public DrawningObjectCar(DrawningCruiser drawningCar)
|
||||
public DrawningObjectCruiser(DrawningCruiser drawningCruiser)
|
||||
{
|
||||
_drawningCar = drawningCar;
|
||||
_drawningCar = drawningCruiser;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningCar == null || _drawningCar.EntityCruiser ==
|
||||
if (_drawningCar == null || _drawningCar.EntityCar ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
@@ -28,11 +30,10 @@ namespace Cruiser.MovementStrategy
|
||||
_drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningCar?.EntityCruiser?.Step ?? 0);
|
||||
public bool CheckCanMove(Direction direction) =>
|
||||
public int GetStep => (int)(_drawningCar?.EntityCar?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawningCar?.CanMove(direction) ?? false;
|
||||
public void MoveObject(Direction direction) =>
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawningCar?.MoveTransport(direction);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using Cruiser.DrawningObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Cruiser.Entities;
|
||||
using Cruiser;
|
||||
|
||||
namespace Cruiser.DrawningObjects
|
||||
{
|
||||
|
||||
public class DrawningPro : DrawningCruiser
|
||||
{
|
||||
public DrawningPro(int speed, double weight, Color bodyColor, Color additionalColor, bool headlights, bool helicopterPad, bool coating, int width, int height) : base(speed, weight, bodyColor, width, height, 150, 50)
|
||||
{
|
||||
if (EntityCruiser != null)
|
||||
{
|
||||
EntityCruiser = new Pro(speed, weight, bodyColor, additionalColor, headlights, helicopterPad, coating);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCruiser is not Pro cruiser)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush addBrush = new SolidBrush(cruiser.AdditionalColor);
|
||||
Brush brush = new SolidBrush(cruiser.BodyColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
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);
|
||||
}
|
||||
|
||||
if (cruiser.HelicopterPad)
|
||||
{
|
||||
//если есть площадка под вертолет
|
||||
|
||||
g.FillEllipse(Brushes.Green, _startPosX + 90, _startPosY + 20, 20, 20);
|
||||
|
||||
}
|
||||
|
||||
/* if (cruiser.Coating)
|
||||
{
|
||||
//если есть спец покрытие для площадки под вертолет
|
||||
g.FillEllipse(Brushes.Red, _startPosX + 90, _startPosY + 20, 20, 20);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
42
Cruiser/Cruiser/EntityAdvancedCruiser.cs
Normal file
42
Cruiser/Cruiser/EntityAdvancedCruiser.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
|
||||
namespace Cruiser.Entities
|
||||
{
|
||||
public class EntityAdvancedCruiser : EntityCruiser
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия кузова
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия tent
|
||||
/// </summary>
|
||||
public bool Tent { get; private set; }
|
||||
|
||||
|
||||
public EntityAdvancedCruiser(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool tent) : base(speed, weight, bodyColor)
|
||||
{
|
||||
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Tent = tent;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,28 +8,28 @@ namespace Cruiser.Entities
|
||||
{
|
||||
public class EntityCruiser
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
// public Color AdditionalColor { get; private set; }
|
||||
|
||||
|
||||
// public bool Headlights { get; private set; }
|
||||
// public bool HelicopterPad { get; private set; }
|
||||
|
||||
// public bool Coating { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор с параметрами
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public EntityCruiser(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
@@ -38,4 +38,4 @@ namespace Cruiser.Entities
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Cruiser/Cruiser/Form1.Designer.cs
generated
19
Cruiser/Cruiser/Form1.Designer.cs
generated
@@ -1,6 +1,6 @@
|
||||
namespace Cruiser
|
||||
{
|
||||
partial class CruiserForm
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@@ -31,6 +31,7 @@
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.comboBox1 = new System.Windows.Forms.ComboBox();
|
||||
this.ButtonStep = new System.Windows.Forms.Button();
|
||||
this.SelectedCruiser = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@@ -109,7 +110,7 @@
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(218, 34);
|
||||
this.buttonCreate.TabIndex = 5;
|
||||
this.buttonCreate.Text = "Создать Про версию";
|
||||
this.buttonCreate.Text = "Создать простую";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
//
|
||||
@@ -120,7 +121,7 @@
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(251, 37);
|
||||
this.button2.TabIndex = 6;
|
||||
this.button2.Text = "Создать простую версию";
|
||||
this.button2.Text = "Создать про версию";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||
//
|
||||
@@ -146,9 +147,20 @@
|
||||
this.ButtonStep.UseVisualStyleBackColor = true;
|
||||
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
||||
//
|
||||
// SelectedCruiser
|
||||
//
|
||||
this.SelectedCruiser.Location = new System.Drawing.Point(210, 261);
|
||||
this.SelectedCruiser.Name = "SelectedCruiser";
|
||||
this.SelectedCruiser.Size = new System.Drawing.Size(112, 34);
|
||||
this.SelectedCruiser.TabIndex = 9;
|
||||
this.SelectedCruiser.Text = "Выбрать";
|
||||
this.SelectedCruiser.UseVisualStyleBackColor = true;
|
||||
this.SelectedCruiser.Click += new System.EventHandler(this.SelectedCruiser_Click);
|
||||
//
|
||||
// CruiserForm
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(667, 358);
|
||||
this.Controls.Add(this.SelectedCruiser);
|
||||
this.Controls.Add(this.ButtonStep);
|
||||
this.Controls.Add(this.comboBox1);
|
||||
this.Controls.Add(this.button2);
|
||||
@@ -178,5 +190,6 @@ private Button button1;
|
||||
private Button button2;
|
||||
private ComboBox comboBox1;
|
||||
private Button ButtonStep;
|
||||
private Button SelectedCruiser;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,41 @@
|
||||
using System.Windows.Forms;
|
||||
using Cruiser.DrawningObjects;
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.Entities;
|
||||
|
||||
using Cruiser.MovementStrategy;
|
||||
using DumpTruck.MovementStrategy;
|
||||
|
||||
namespace Cruiser
|
||||
{
|
||||
|
||||
public partial class CruiserForm : Form
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private DrawningCruiser? _drawningCruiser;
|
||||
|
||||
private DrawningCar? _drawningCar;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public CruiserForm()
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public DrawningCar? SelectedCar { get; private set; }
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
SelectedCar = null;
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
if (_drawningCar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningCruiser.DrawTransport(gr);
|
||||
_drawningCar.DrawTransport(gr);
|
||||
pictureBox1.Image = bmp;
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
if (_drawningCar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -36,16 +43,16 @@ namespace Cruiser
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningCruiser.MoveTransport(Direction.Up);
|
||||
_drawningCar.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningCruiser.MoveTransport(Direction.Down);
|
||||
_drawningCar.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningCruiser.MoveTransport(Direction.Left);
|
||||
_drawningCar.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningCruiser.MoveTransport(Direction.Right);
|
||||
_drawningCar.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
@@ -54,12 +61,27 @@ namespace Cruiser
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningCruiser = new DrawningCruiser(random.Next(100, 300),
|
||||
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));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialog.Color;
|
||||
}
|
||||
|
||||
_drawningCar = new DrawningDumpTruck(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
color,
|
||||
dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBox1.Width, pictureBox1.Height);
|
||||
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
_drawningCar.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
@@ -70,7 +92,7 @@ namespace Cruiser
|
||||
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
if (_drawningCar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -87,7 +109,7 @@ namespace Cruiser
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawningObjectCar(_drawningCruiser), pictureBox1.Width,
|
||||
_abstractStrategy.SetData(new DrawningObjectCruiser(_drawningCar), pictureBox1.Width,
|
||||
pictureBox1.Height);
|
||||
comboBox1.Enabled = false;
|
||||
}
|
||||
@@ -107,21 +129,28 @@ namespace Cruiser
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningCruiser = new DrawningPro(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
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));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawningCar = new DrawningCar(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
color,
|
||||
pictureBox1.Width, pictureBox1.Height);
|
||||
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
_drawningCar.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
public void SelectedCruiser_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedCar = _drawningCar;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
114
Cruiser/Cruiser/FormCruiserCollection.Designer.cs
generated
Normal file
114
Cruiser/Cruiser/FormCruiserCollection.Designer.cs
generated
Normal file
@@ -0,0 +1,114 @@
|
||||
namespace Cruiser
|
||||
{
|
||||
partial class FormCruiserCollection
|
||||
{
|
||||
/// <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.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.ButtonRemoveCar = new System.Windows.Forms.Button();
|
||||
this.ButtonAddCruiser = new System.Windows.Forms.Button();
|
||||
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.panel1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(800, 450);
|
||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBox1.TabIndex = 0;
|
||||
this.pictureBox1.TabStop = false;
|
||||
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
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.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(211, 438);
|
||||
this.panel1.TabIndex = 1;
|
||||
//
|
||||
// ButtonRemoveCar
|
||||
//
|
||||
this.ButtonRemoveCar.Location = new System.Drawing.Point(31, 168);
|
||||
this.ButtonRemoveCar.Name = "ButtonRemoveCar";
|
||||
this.ButtonRemoveCar.Size = new System.Drawing.Size(150, 34);
|
||||
this.ButtonRemoveCar.TabIndex = 2;
|
||||
this.ButtonRemoveCar.Text = "Удалить";
|
||||
this.ButtonRemoveCar.UseVisualStyleBackColor = true;
|
||||
this.ButtonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
|
||||
//
|
||||
// ButtonAddCruiser
|
||||
//
|
||||
this.ButtonAddCruiser.Location = new System.Drawing.Point(31, 37);
|
||||
this.ButtonAddCruiser.Name = "ButtonAddCruiser";
|
||||
this.ButtonAddCruiser.Size = new System.Drawing.Size(150, 34);
|
||||
this.ButtonAddCruiser.TabIndex = 3;
|
||||
this.ButtonAddCruiser.Text = "Добавить";
|
||||
this.ButtonAddCruiser.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click);
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
this.textBox1.Location = new System.Drawing.Point(31, 104);
|
||||
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);
|
||||
//
|
||||
// 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.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Name = "FormCruiserCollection";
|
||||
this.Text = "FormCruiserCollection";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBox1;
|
||||
private Panel panel1;
|
||||
private Button ButtonRemoveCar;
|
||||
private Button ButtonAddCruiser;
|
||||
private TextBox textBox1;
|
||||
}
|
||||
}
|
||||
99
Cruiser/Cruiser/FormCruiserCollection.cs
Normal file
99
Cruiser/Cruiser/FormCruiserCollection.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
|
||||
using DumpTruck.Generics;
|
||||
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;
|
||||
using Cruiser;
|
||||
using DumpTruck.DrawningObjects;
|
||||
using DumpTruck.Generics;
|
||||
using DumpTruck.MovementStrategy;
|
||||
|
||||
|
||||
namespace Cruiser
|
||||
{
|
||||
public partial class FormCruiserCollection : Form
|
||||
{
|
||||
private readonly CruiserGenericCollection<DrawningCar, DrawningObjectCruiser> _cars;
|
||||
|
||||
public FormCruiserCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_cars = new CruiserGenericCollection<DrawningCar, DrawningObjectCruiser>(pictureBox1.Width, pictureBox1.Height);
|
||||
}
|
||||
|
||||
private void pictureBox1_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void ButtonAddCruiser_Click(object sender, EventArgs e)
|
||||
{
|
||||
Form1 form = new();
|
||||
|
||||
|
||||
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_cars + form.SelectedCar != null)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox1.Image = _cars.ShowCars();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos;
|
||||
if (textBox1.Text == null || !int.TryParse(textBox1.Text, out pos))
|
||||
{
|
||||
MessageBox.Show("Введите номер парковочного места");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_cars - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox1.Image = _cars.ShowCars();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox1.Image = _cars.ShowCars();
|
||||
}
|
||||
|
||||
private void maskedTextBoxNumber_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void textBox1_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
60
Cruiser/Cruiser/FormCruiserCollection.resx
Normal file
60
Cruiser/Cruiser/FormCruiserCollection.resx
Normal 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>
|
||||
@@ -1,14 +1,23 @@
|
||||
using System;
|
||||
using DumpTruck;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Cruiser.MovementStrategy;
|
||||
|
||||
using Cruiser;
|
||||
|
||||
namespace Cruiser.MovementStrategy
|
||||
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты X объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
@@ -19,12 +28,12 @@ namespace Cruiser.MovementStrategy
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool CheckCanMove(Direction direction);
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(Direction direction);
|
||||
void MoveObject(DirectionType direction);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using DumpTruck.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Cruiser.MovementStrategy;
|
||||
|
||||
namespace Cruiser.MovementStrategy
|
||||
{
|
||||
@@ -47,5 +47,4 @@ namespace Cruiser.MovementStrategy
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using DumpTruck.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Cruiser.MovementStrategy;
|
||||
|
||||
namespace Cruiser.MovementStrategy
|
||||
{
|
||||
internal class MoveToCenter : AbstractStrategy
|
||||
@@ -54,5 +55,4 @@ namespace Cruiser.MovementStrategy
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Cruiser.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
/// </summary>
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
@@ -51,5 +54,4 @@ namespace Cruiser.MovementStrategy
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace Cruiser.Entities
|
||||
{
|
||||
public class Pro : EntityCruiser
|
||||
{
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
|
||||
public bool Headlights { get; private set; }
|
||||
public bool HelicopterPad { get; private set; }
|
||||
|
||||
public bool Coating { get; private set; }
|
||||
|
||||
public Pro(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool headlights, bool helicopterPad, bool coating) : base(speed, weight, bodyColor)
|
||||
{
|
||||
|
||||
AdditionalColor = additionalColor;
|
||||
Headlights = headlights;
|
||||
HelicopterPad = helicopterPad;
|
||||
Coating = coating;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Cruiser
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new CruiserForm());
|
||||
Application.Run(new FormCruiserCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
102
Cruiser/Cruiser/SetGeneric.cs
Normal file
102
Cruiser/Cruiser/SetGeneric.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Cruiser.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;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T cruiser)
|
||||
{
|
||||
if (_places[Count - 1] != null)
|
||||
return -1;
|
||||
return Insert(cruiser, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T cruiser, 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] = cruiser;
|
||||
return position;
|
||||
}
|
||||
// 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;
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < Count && position >= 0) { return _places[position]; }
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user