Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
21721ee795 | ||
|
826cc3be3b | ||
|
7cb5d815f7 | ||
|
d9cadbabc4 | ||
|
31671e87d0 | ||
|
3fc0d392b0 | ||
|
1d8824c3e4 | ||
|
2c1cedade6 | ||
|
aaa540c662 | ||
|
704a27c3aa | ||
|
3a34dff170 | ||
|
534e7be294 |
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
private IMoveableObject? _moveableObject;
|
||||
private Status _state = Status.NotInit;
|
||||
protected int FieldWidth { get; private set; }
|
||||
protected int FieldHeight { get; private set; }
|
||||
public Status GetStatus() { return _state; }
|
||||
public void SetData(IMoveableObject moveableObject, int width, int
|
||||
height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
protected bool MoveLeft() => MoveTo(Direction.Left);
|
||||
protected bool MoveRight() => MoveTo(Direction.Right);
|
||||
protected bool MoveUp() => MoveTo(Direction.Up);
|
||||
protected bool MoveDown() => MoveTo(Direction.Down);
|
||||
protected ObjectParameteres? GetObjectParameters =>_moveableObject?.GetObjectPosition;
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
protected abstract void MoveToTarget();
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
private bool MoveTo(Direction directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
using ProjectAirplaneWithRadar.Generics;
|
||||
using System.Collections.Generic;
|
||||
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||
using ProjectAirplaneWithRadar.MovementStrategy;
|
||||
namespace ProjectAirplaneWithRadar.Generics
|
||||
{
|
||||
internal class AirplanesGenericCollection<T, U>
|
||||
where T : DrawningAirplane
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 215;
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public AirplanesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
public static int operator +(AirplanesGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null || collect == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
public static bool operator -(AirplanesGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect?._collection.Get(pos);
|
||||
if (obj != null && collect != null)
|
||||
return collect._collection.Remove(pos);
|
||||
return false;
|
||||
}
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
public Bitmap ShowAirplanes()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawningAirplane? airplane = _collection.Get(i);
|
||||
if (airplane != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
airplane.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth), i / inRow * _placeSizeHeight) ;
|
||||
airplane.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectAirplaneWithRadar.Entities;
|
||||
using ProjectAirplaneWithRadar.MovementStrategy;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.DrawningObjects
|
||||
{
|
||||
public class DrawningAirplane
|
||||
{
|
||||
public EntityAirplane? EntityAirplane { get; protected set; }
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
protected readonly int _airplaneWidth = 200;
|
||||
protected readonly int _airplaneHeight = 78;
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _airplaneWidth;
|
||||
public int GetHeight => _airplaneHeight;
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectAirplane(this);
|
||||
public DrawningAirplane(int speed, double weight, Color bodyColor, int
|
||||
width, int height)
|
||||
{
|
||||
if (width < _airplaneWidth || height < _airplaneHeight)
|
||||
return;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawningAirplane(int speed, double weight, Color bodyColor, int
|
||||
width, int height, int airplaneWidth, int airplaneHeight)
|
||||
{
|
||||
if (width < _airplaneWidth || height < _airplaneHeight)
|
||||
return;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_airplaneWidth = airplaneWidth;
|
||||
_airplaneHeight = airplaneHeight;
|
||||
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
||||
}
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || y < 0 || x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight)
|
||||
{
|
||||
x = y = 10;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
public bool CanMove(Direction direction)
|
||||
{
|
||||
if (EntityAirplane == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Left:
|
||||
return _startPosX - EntityAirplane.Step > 0;
|
||||
break;
|
||||
case Direction.Up:
|
||||
return _startPosY - EntityAirplane.Step > 0;
|
||||
break;
|
||||
case Direction.Right:
|
||||
return _startPosX + EntityAirplane.Step + _airplaneWidth < _pictureWidth;
|
||||
break;
|
||||
case Direction.Down:
|
||||
return _startPosY + EntityAirplane.Step + _airplaneHeight < _pictureHeight;
|
||||
break;
|
||||
default:return false;
|
||||
};
|
||||
}
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (!CanMove(direction)||EntityAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Left:
|
||||
if (_startPosX - EntityAirplane.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityAirplane.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.Up:
|
||||
if (_startPosY - EntityAirplane.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAirplane.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.Right:
|
||||
if (_startPosX + EntityAirplane.Step + _airplaneWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityAirplane.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.Down:
|
||||
if (_startPosY + EntityAirplane.Step + _airplaneHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAirplane.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(Color.Black, 3);
|
||||
// корпус
|
||||
Brush br = new SolidBrush(EntityAirplane.BodyColor);
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY + 25, 180, 30);
|
||||
g.FillEllipse(br, _startPosX, _startPosY + 25, 180, 30);
|
||||
// крыло
|
||||
Brush blackBrush = new SolidBrush(Color.Black);
|
||||
g.FillEllipse(blackBrush, _startPosX + 70, _startPosY + 35, 80, 10);
|
||||
// стекла
|
||||
Pen blackPen = new Pen(Color.Black, 2);
|
||||
Brush blueBrush = new SolidBrush(Color.LightBlue);
|
||||
Point point1 = new Point(_startPosX + 170, _startPosY + 30);
|
||||
Point point2 = new Point(_startPosX + 200, _startPosY + 40);
|
||||
Point point3 = new Point(_startPosX + 170, _startPosY + 50);
|
||||
Point[] curvePoints =
|
||||
{
|
||||
point1,
|
||||
point2,
|
||||
point3,
|
||||
};
|
||||
g.FillPolygon(blueBrush, curvePoints);
|
||||
g.DrawPolygon(blackPen, curvePoints);
|
||||
g.DrawLine(blackPen, _startPosX + 170, _startPosY + 40, _startPosX + 200, _startPosY + 40);
|
||||
// хвост
|
||||
Point point4 = new Point(_startPosX, _startPosY + 35);
|
||||
Point point5 = new Point(_startPosX, _startPosY + 5);
|
||||
Point point6 = new Point(_startPosX + 30, _startPosY + 35);
|
||||
Point[] curvePoints2 =
|
||||
{
|
||||
point4,
|
||||
point5,
|
||||
point6,
|
||||
};
|
||||
g.FillPolygon(br, curvePoints2);
|
||||
g.DrawPolygon(blackPen, curvePoints2);
|
||||
// шасси
|
||||
g.DrawLine(blackPen, _startPosX + 50, _startPosY + 55, _startPosX + 50, _startPosY + 70);
|
||||
g.DrawLine(blackPen, _startPosX + 150, _startPosY + 51, _startPosX + 150, _startPosY + 70);
|
||||
g.FillEllipse(blackBrush, _startPosX + 40, _startPosY + 65, 10, 10);
|
||||
g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 65, 10, 10);
|
||||
g.FillEllipse(blackBrush, _startPosX + 145, _startPosY + 65, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,130 +7,37 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectAirplaneWithRadar
|
||||
using ProjectAirplaneWithRadar.Entities;
|
||||
namespace ProjectAirplaneWithRadar.DrawningObjects
|
||||
{
|
||||
public class DrawningAirplaneWithRadar
|
||||
public class DrawningAirplaneWithRadar : DrawningAirplane
|
||||
{
|
||||
public EntityAirplaneWithRadar? EntityAirplaneWithRadar { get; private set; }
|
||||
public int _pictureWidth;
|
||||
public int _pictureHeight;
|
||||
public int _startPosX;
|
||||
public int _startPosY;
|
||||
private readonly int _airplaneWidth = 200;
|
||||
private readonly int _airplaneHeight = 78;
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool dopbak, int width, int height)
|
||||
public DrawningAirplaneWithRadar(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool radar, bool dopbak, int width, int height) : base(speed, weight, bodyColor, width, height, 200, 78)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_airplaneWidth > _pictureWidth || _airplaneHeight > _pictureHeight)
|
||||
return false;
|
||||
EntityAirplaneWithRadar = new EntityAirplaneWithRadar();
|
||||
EntityAirplaneWithRadar.Init(speed, weight, bodyColor, additionalColor, radar, dopbak);
|
||||
return true;
|
||||
}
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if(x < 0 || y < 0 ||x+_airplaneWidth >= _pictureWidth|| y + _airplaneHeight >= _pictureHeight)
|
||||
if (EntityAirplane != null)
|
||||
{
|
||||
x = y = 10;
|
||||
_startPosX = x;
|
||||
_startPosY=y;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
EntityAirplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, additionalColor, radar, dopbak);
|
||||
}
|
||||
}
|
||||
public void MoveTransport(Direction direction)
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAirplaneWithRadar == null)
|
||||
if (EntityAirplane is not EntityAirplaneWithRadar airplaneWithRadar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Left:
|
||||
if (_startPosX - EntityAirplaneWithRadar.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityAirplaneWithRadar.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.Up:
|
||||
if (_startPosY - EntityAirplaneWithRadar.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAirplaneWithRadar.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.Right:
|
||||
if (_startPosX + EntityAirplaneWithRadar.Step+_airplaneWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityAirplaneWithRadar.Step;
|
||||
}
|
||||
break;
|
||||
case Direction.Down:
|
||||
if (_startPosY + EntityAirplaneWithRadar.Step+_airplaneHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAirplaneWithRadar.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if(EntityAirplaneWithRadar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new Pen(Color.Black, 3);
|
||||
Brush additionalBrush = new SolidBrush(EntityAirplaneWithRadar.AdditionalColor);
|
||||
// корпус
|
||||
Brush br = new SolidBrush(EntityAirplaneWithRadar.BodyColor);
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY+25,180, 30) ;
|
||||
g.FillEllipse(br, _startPosX, _startPosY+25, 180, 30);
|
||||
// крыло
|
||||
Brush blackBrush = new SolidBrush(Color.Black);
|
||||
g.FillEllipse(blackBrush, _startPosX + 70, _startPosY + 35, 80, 10);
|
||||
// стекла
|
||||
base.DrawTransport(g);
|
||||
Pen blackPen = new Pen(Color.Black, 2);
|
||||
Brush blueBrush = new SolidBrush(Color.LightBlue);
|
||||
Point point1 = new Point(_startPosX+170, _startPosY+30);
|
||||
Point point2 = new Point(_startPosX+200, _startPosY+40);
|
||||
Point point3 = new Point(_startPosX+170, _startPosY + 50);
|
||||
Point[] curvePoints =
|
||||
{
|
||||
point1,
|
||||
point2,
|
||||
point3,
|
||||
};
|
||||
g.FillPolygon(blueBrush, curvePoints);
|
||||
g.DrawPolygon(blackPen, curvePoints);
|
||||
g.DrawLine(blackPen, _startPosX + 170, _startPosY + 40, _startPosX + 200, _startPosY + 40);
|
||||
// хвост
|
||||
Point point4 = new Point(_startPosX, _startPosY + 35);
|
||||
Point point5 = new Point(_startPosX, _startPosY +5 );
|
||||
Point point6 = new Point(_startPosX + 30, _startPosY + 35);
|
||||
Point[] curvePoints2 =
|
||||
{
|
||||
point4,
|
||||
point5,
|
||||
point6,
|
||||
};
|
||||
g.FillPolygon(br, curvePoints2);
|
||||
g.DrawPolygon(blackPen, curvePoints2);
|
||||
// шасси
|
||||
g.DrawLine(blackPen, _startPosX + 50, _startPosY + 55, _startPosX + 50, _startPosY + 70);
|
||||
g.DrawLine(blackPen, _startPosX + 150, _startPosY + 51, _startPosX + 150, _startPosY + 70);
|
||||
g.FillEllipse(blackBrush, _startPosX + 40, _startPosY + 65, 10, 10);
|
||||
g.FillEllipse(blackBrush, _startPosX + 50, _startPosY + 65, 10, 10);
|
||||
g.FillEllipse(blackBrush, _startPosX + 145, _startPosY + 65, 10, 10);
|
||||
if (EntityAirplaneWithRadar.DopBak)
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(airplaneWithRadar.AdditionalColor);
|
||||
if (airplaneWithRadar.DopBak)
|
||||
{
|
||||
//бак
|
||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY + 45, 40, 20);
|
||||
g.DrawEllipse(blackPen, _startPosX, _startPosY + 45, 40, 20);
|
||||
}
|
||||
if (EntityAirplaneWithRadar.Radar)
|
||||
if (airplaneWithRadar.Radar)
|
||||
{
|
||||
//радар
|
||||
g.DrawLine(blackPen, _startPosX + 60, _startPosY + 25, _startPosX + 60, _startPosY + 15);
|
||||
g.DrawLine(blackPen, _startPosX + 60, _startPosY + 15, _startPosX + 67, _startPosY + 11);
|
||||
Point point7 = new Point(_startPosX + 60, _startPosY + 15);
|
||||
@ -138,10 +45,10 @@ namespace ProjectAirplaneWithRadar
|
||||
Point point9 = new Point(_startPosX + 70, _startPosY + 25);
|
||||
Point[] curvePoints3 =
|
||||
{
|
||||
point7,
|
||||
point8,
|
||||
point9,
|
||||
};
|
||||
point7,
|
||||
point8,
|
||||
point9,
|
||||
};
|
||||
g.FillPolygon(additionalBrush, curvePoints3);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||
{
|
||||
public class DrawningObjectAirplane : IMoveableObject
|
||||
{
|
||||
private readonly DrawningAirplane? _drawningAirplane = null;
|
||||
public DrawningObjectAirplane(DrawningAirplane drawningCar)
|
||||
{
|
||||
_drawningAirplane = drawningCar;
|
||||
}
|
||||
public ObjectParameteres? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningAirplane == null || _drawningAirplane.EntityAirplane ==null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameteres(_drawningAirplane.GetPosX,
|
||||
_drawningAirplane.GetPosY, _drawningAirplane.GetWidth, _drawningAirplane.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningAirplane?.EntityAirplane?.Step ?? 0);
|
||||
public bool CheckCanMove(Direction direction) =>
|
||||
_drawningAirplane?.CanMove(direction) ?? false;
|
||||
public void MoveObject(Direction direction) =>
|
||||
_drawningAirplane?.MoveTransport(direction);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.Entities
|
||||
{
|
||||
public class EntityAirplane
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
public EntityAirplane(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -5,32 +5,18 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar
|
||||
namespace ProjectAirplaneWithRadar.Entities
|
||||
{
|
||||
public class EntityAirplaneWithRadar
|
||||
public class EntityAirplaneWithRadar : EntityAirplane
|
||||
{
|
||||
//скорость
|
||||
public int Speed { get; private set; }
|
||||
// вес
|
||||
public double Weight { get; private set; }
|
||||
// основной цвет
|
||||
public Color BodyColor { get; private set; }
|
||||
// доп цвет
|
||||
public Color AdditionalColor { get; private set; }
|
||||
// наличие радара
|
||||
public bool Radar{ get; private set; }
|
||||
// наличие дополнительных топливных баков
|
||||
public bool DopBak{ get; private set; }
|
||||
//шаг перемещения самолета
|
||||
public double Step => (double)Speed*100/Weight;
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool dopbak)
|
||||
public bool Radar { get; private set; }
|
||||
public bool DopBak { get; private set; }
|
||||
public EntityAirplaneWithRadar(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool dopbak) : base(speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Radar = radar;
|
||||
DopBak = dopbak;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,12 @@
|
||||
partial class FormAirplaneWithRadar
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// 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)
|
||||
@ -23,17 +23,21 @@
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxAirplaneWithRadar = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateAirplaneWithRadar = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreateAirplane = new Button();
|
||||
comboBoxAirplane = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
buttonSelectAirplane = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -42,47 +46,50 @@
|
||||
pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill;
|
||||
pictureBoxAirplaneWithRadar.Location = new Point(0, 0);
|
||||
pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar";
|
||||
pictureBoxAirplaneWithRadar.Size = new Size(882, 453);
|
||||
pictureBoxAirplaneWithRadar.Size = new Size(887, 454);
|
||||
pictureBoxAirplaneWithRadar.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxAirplaneWithRadar.TabIndex = 0;
|
||||
pictureBoxAirplaneWithRadar.TabStop = false;
|
||||
pictureBoxAirplaneWithRadar.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
// buttonCreateAirplaneWithRadar
|
||||
//
|
||||
buttonCreate.Location = new Point(12, 412);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(94, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Create";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Location = new Point(766, 396);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(49, 45);
|
||||
buttonDown.TabIndex = 2;
|
||||
buttonDown.Text = "↓";
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
buttonCreateAirplaneWithRadar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateAirplaneWithRadar.Location = new Point(12, 387);
|
||||
buttonCreateAirplaneWithRadar.Name = "buttonCreateAirplaneWithRadar";
|
||||
buttonCreateAirplaneWithRadar.Size = new Size(195, 55);
|
||||
buttonCreateAirplaneWithRadar.TabIndex = 1;
|
||||
buttonCreateAirplaneWithRadar.Text = "Create Airplane With Radar";
|
||||
buttonCreateAirplaneWithRadar.UseVisualStyleBackColor = true;
|
||||
buttonCreateAirplaneWithRadar.Click += buttonCreateAirplaneWithRadar_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Location = new Point(821, 396);
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.Location = new Point(825, 402);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(49, 45);
|
||||
buttonRight.TabIndex = 3;
|
||||
buttonRight.Size = new Size(50, 40);
|
||||
buttonRight.TabIndex = 2;
|
||||
buttonRight.Text = "→";
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.Location = new Point(769, 402);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(50, 40);
|
||||
buttonDown.TabIndex = 3;
|
||||
buttonDown.Text = "↓";
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Location = new Point(711, 396);
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.Location = new Point(713, 402);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(49, 45);
|
||||
buttonLeft.Size = new Size(50, 40);
|
||||
buttonLeft.TabIndex = 4;
|
||||
buttonLeft.Text = "←";
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
@ -90,24 +97,72 @@
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Location = new Point(766, 345);
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.Location = new Point(769, 356);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(49, 45);
|
||||
buttonUp.Size = new Size(50, 40);
|
||||
buttonUp.TabIndex = 5;
|
||||
buttonUp.Text = "↑";
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonCreateAirplane
|
||||
//
|
||||
buttonCreateAirplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateAirplane.Location = new Point(213, 387);
|
||||
buttonCreateAirplane.Name = "buttonCreateAirplane";
|
||||
buttonCreateAirplane.Size = new Size(203, 55);
|
||||
buttonCreateAirplane.TabIndex = 6;
|
||||
buttonCreateAirplane.Text = "Create Airplane";
|
||||
buttonCreateAirplane.UseVisualStyleBackColor = true;
|
||||
buttonCreateAirplane.Click += buttonCreateAirplane_Click;
|
||||
//
|
||||
// comboBoxAirplane
|
||||
//
|
||||
comboBoxAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxAirplane.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxAirplane.FormattingEnabled = true;
|
||||
comboBoxAirplane.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
|
||||
comboBoxAirplane.Location = new Point(724, 12);
|
||||
comboBoxAirplane.Name = "comboBoxAirplane";
|
||||
comboBoxAirplane.Size = new Size(151, 28);
|
||||
comboBoxAirplane.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonStep.Location = new Point(724, 46);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(151, 29);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Step";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
//
|
||||
// buttonSelectAirplane
|
||||
//
|
||||
buttonSelectAirplane.Location = new Point(724, 81);
|
||||
buttonSelectAirplane.Name = "buttonSelectAirplane";
|
||||
buttonSelectAirplane.Size = new Size(151, 29);
|
||||
buttonSelectAirplane.TabIndex = 9;
|
||||
buttonSelectAirplane.Text = "Select Airplane";
|
||||
buttonSelectAirplane.UseVisualStyleBackColor = true;
|
||||
buttonSelectAirplane.Click += buttonSelectAirplane_Click;
|
||||
//
|
||||
// FormAirplaneWithRadar
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
ClientSize = new Size(887, 454);
|
||||
Controls.Add(buttonSelectAirplane);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxAirplane);
|
||||
Controls.Add(buttonCreateAirplane);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonCreateAirplaneWithRadar);
|
||||
Controls.Add(pictureBoxAirplaneWithRadar);
|
||||
Name = "FormAirplaneWithRadar";
|
||||
Text = "FormAirplaneWithRadar";
|
||||
@ -119,10 +174,14 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxAirplaneWithRadar;
|
||||
private Button buttonCreate;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateAirplaneWithRadar;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateAirplane;
|
||||
private ComboBox comboBoxAirplane;
|
||||
private Button buttonStep;
|
||||
private Button buttonSelectAirplane;
|
||||
}
|
||||
}
|
@ -1,53 +1,31 @@
|
||||
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 ProjectAirplaneWithRadar.DrawningObjects;
|
||||
using ProjectAirplaneWithRadar.MovementStrategy;
|
||||
|
||||
namespace ProjectAirplaneWithRadar
|
||||
{
|
||||
public partial class FormAirplaneWithRadar : Form
|
||||
{
|
||||
private DrawningAirplaneWithRadar? _drawningAirplaneWithRadar;
|
||||
private DrawningAirplane _drawningAirplane;
|
||||
private AbstractStrategy _abstractStrategy;
|
||||
public DrawningAirplane? SelectedAirplane { get; private set; }
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAirplaneWithRadar == null)
|
||||
if (_drawningAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new Bitmap(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAirplaneWithRadar.DrawTransport(gr);
|
||||
_drawningAirplane.DrawTransport(gr);
|
||||
pictureBoxAirplaneWithRadar.Image = bmp;
|
||||
}
|
||||
public FormAirplaneWithRadar()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
_drawningAirplaneWithRadar = new DrawningAirplaneWithRadar();
|
||||
if (_drawningAirplaneWithRadar.Init
|
||||
(random.Next(100, 300), // speed
|
||||
random.Next(1000, 3000),// weight
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),// bodycolor
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), //additionalColor
|
||||
Convert.ToBoolean(random.Next(0, 2)), // radar
|
||||
Convert.ToBoolean(random.Next(0, 2)), //dopbak
|
||||
pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height))
|
||||
{
|
||||
_drawningAirplaneWithRadar.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAirplaneWithRadar == null)
|
||||
if (_drawningAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -55,19 +33,98 @@ namespace ProjectAirplaneWithRadar
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Up);
|
||||
_drawningAirplane.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Down);
|
||||
_drawningAirplane.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Left);
|
||||
_drawningAirplane.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningAirplaneWithRadar.MoveTransport(Direction.Right);
|
||||
_drawningAirplane.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
private void buttonCreateAirplaneWithRadar_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
bodyColor = dialog.Color;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
additionalColor = dialog.Color;
|
||||
|
||||
_drawningAirplane = new DrawningAirplaneWithRadar(random.Next(100, 300), random.Next(1000, 3000),
|
||||
bodyColor, additionalColor, true, true,
|
||||
pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
||||
Draw();
|
||||
}
|
||||
private void buttonCreateAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
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;
|
||||
}
|
||||
_drawningAirplane = new DrawningAirplane(random.Next(100, 300),
|
||||
random.Next(1000, 3000), color,
|
||||
pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
||||
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxAirplane.Enabled)
|
||||
{
|
||||
switch (comboBoxAirplane.SelectedIndex)
|
||||
{
|
||||
case 0:
|
||||
_abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_abstractStrategy = new MoveToBorder();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawningObjectAirplane(_drawningAirplane), pictureBoxAirplaneWithRadar.Width,
|
||||
pictureBoxAirplaneWithRadar.Height);
|
||||
comboBoxAirplane.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxAirplane.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
private void buttonSelectAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedAirplane = _drawningAirplane;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
126
ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.Designer.cs
generated
Normal file
126
ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.Designer.cs
generated
Normal file
@ -0,0 +1,126 @@
|
||||
namespace ProjectAirplaneWithRadar
|
||||
{
|
||||
partial class FormAirplanesCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
pictureBoxAirplanesCollection = new PictureBox();
|
||||
groupBoxAirplaneWithRadar = new GroupBox();
|
||||
buttonUpdateCollection = new Button();
|
||||
buttonDeleteAirplane = new Button();
|
||||
buttonAddAirplane = new Button();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirplanesCollection).BeginInit();
|
||||
groupBoxAirplaneWithRadar.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxAirplanesCollection
|
||||
//
|
||||
pictureBoxAirplanesCollection.Location = new Point(-9, 0);
|
||||
pictureBoxAirplanesCollection.Name = "pictureBoxAirplanesCollection";
|
||||
pictureBoxAirplanesCollection.Size = new Size(650, 454);
|
||||
pictureBoxAirplanesCollection.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxAirplanesCollection.TabIndex = 0;
|
||||
pictureBoxAirplanesCollection.TabStop = false;
|
||||
//
|
||||
// groupBoxAirplaneWithRadar
|
||||
//
|
||||
groupBoxAirplaneWithRadar.Controls.Add(buttonUpdateCollection);
|
||||
groupBoxAirplaneWithRadar.Controls.Add(buttonDeleteAirplane);
|
||||
groupBoxAirplaneWithRadar.Controls.Add(buttonAddAirplane);
|
||||
groupBoxAirplaneWithRadar.Controls.Add(maskedTextBoxNumber);
|
||||
groupBoxAirplaneWithRadar.Dock = DockStyle.Right;
|
||||
groupBoxAirplaneWithRadar.Location = new Point(637, 0);
|
||||
groupBoxAirplaneWithRadar.Name = "groupBoxAirplaneWithRadar";
|
||||
groupBoxAirplaneWithRadar.Size = new Size(250, 454);
|
||||
groupBoxAirplaneWithRadar.TabIndex = 1;
|
||||
groupBoxAirplaneWithRadar.TabStop = false;
|
||||
groupBoxAirplaneWithRadar.Text = "Инструменты";
|
||||
//
|
||||
// buttonUpdateCollection
|
||||
//
|
||||
buttonUpdateCollection.Location = new Point(6, 275);
|
||||
buttonUpdateCollection.Name = "buttonUpdateCollection";
|
||||
buttonUpdateCollection.Size = new Size(238, 29);
|
||||
buttonUpdateCollection.TabIndex = 3;
|
||||
buttonUpdateCollection.Text = "Обновить коллекцию";
|
||||
buttonUpdateCollection.UseVisualStyleBackColor = true;
|
||||
buttonUpdateCollection.Click += buttonUpdateCollection_Click;
|
||||
//
|
||||
// buttonDeleteAirplane
|
||||
//
|
||||
buttonDeleteAirplane.Location = new Point(6, 208);
|
||||
buttonDeleteAirplane.Name = "buttonDeleteAirplane";
|
||||
buttonDeleteAirplane.Size = new Size(238, 29);
|
||||
buttonDeleteAirplane.TabIndex = 2;
|
||||
buttonDeleteAirplane.Text = "Удалить самолет";
|
||||
buttonDeleteAirplane.UseVisualStyleBackColor = true;
|
||||
buttonDeleteAirplane.Click += buttonDeleteAirplane_Click;
|
||||
//
|
||||
// buttonAddAirplane
|
||||
//
|
||||
buttonAddAirplane.Location = new Point(6, 26);
|
||||
buttonAddAirplane.Name = "buttonAddAirplane";
|
||||
buttonAddAirplane.Size = new Size(238, 29);
|
||||
buttonAddAirplane.TabIndex = 1;
|
||||
buttonAddAirplane.Text = "Добавить самолет";
|
||||
buttonAddAirplane.UseVisualStyleBackColor = true;
|
||||
buttonAddAirplane.Click += buttonAddAirplane_Click;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(67, 92);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(125, 27);
|
||||
maskedTextBoxNumber.TabIndex = 0;
|
||||
//
|
||||
// FormAirplanesCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(887, 454);
|
||||
Controls.Add(groupBoxAirplaneWithRadar);
|
||||
Controls.Add(pictureBoxAirplanesCollection);
|
||||
Name = "FormAirplanesCollection";
|
||||
Text = "FormAirplaneWithRadar";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirplanesCollection).EndInit();
|
||||
groupBoxAirplaneWithRadar.ResumeLayout(false);
|
||||
groupBoxAirplaneWithRadar.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxAirplanesCollection;
|
||||
private GroupBox groupBoxAirplaneWithRadar;
|
||||
private Button buttonDeleteAirplane;
|
||||
private Button buttonAddAirplane;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private Button buttonUpdateCollection;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||
using ProjectAirplaneWithRadar.MovementStrategy;
|
||||
using ProjectAirplaneWithRadar.Generics;
|
||||
|
||||
namespace ProjectAirplaneWithRadar
|
||||
{
|
||||
public partial class FormAirplanesCollection : System.Windows.Forms.Form
|
||||
{
|
||||
private readonly AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane> _Airplanes;
|
||||
public FormAirplanesCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_Airplanes = new AirplanesGenericCollection<DrawningAirplane,
|
||||
DrawningObjectAirplane>(pictureBoxAirplanesCollection.Width, pictureBoxAirplanesCollection.Height);
|
||||
}
|
||||
private void buttonAddAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormAirplaneWithRadar form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_Airplanes + form.SelectedAirplane != null)
|
||||
{
|
||||
MessageBox.Show("Îáúåêò äîáàâëåí");
|
||||
pictureBoxAirplanesCollection.Image = _Airplanes.ShowAirplanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Íå óäàëîñü äîáàâèòü îáúåêò");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void buttonDeleteAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Óäàëèòü îáúåêò?", "Óäàëåíèå", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_Airplanes - pos != null)
|
||||
{
|
||||
MessageBox.Show("Îáúåêò óäàëåí");
|
||||
pictureBoxAirplanesCollection.Image = _Airplanes.ShowAirplanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Íå óäàëîñü óäàëèòü îáúåêò");
|
||||
}
|
||||
|
||||
}
|
||||
private void buttonUpdateCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxAirplanesCollection.Image = _Airplanes.ShowAirplanes();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||
{
|
||||
public interface IMoveableObject
|
||||
{
|
||||
ObjectParameteres? GetObjectPosition { get; }
|
||||
int GetStep { get; }
|
||||
bool CheckCanMove(Direction direction);
|
||||
void MoveObject(Direction direction);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||
{
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = FieldWidth - objParams.RightBorder;
|
||||
if (diffX > GetStep())
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
var diffY = FieldHeight - objParams.DownBorder;
|
||||
if (diffY > GetStep())
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||
{
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||
{
|
||||
public class ObjectParameteres
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
public int LeftBorder => _x;
|
||||
public int TopBorder => _y;
|
||||
public int RightBorder => _x + _width;
|
||||
public int DownBorder => _y + _height;
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
public ObjectParameteres(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectAirplaneWithRadar
|
||||
{
|
||||
internal static class Program
|
||||
@ -14,9 +8,10 @@ namespace ProjectAirplaneWithRadar
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormAirplaneWithRadar());
|
||||
Application.Run(new FormAirplanesCollection());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
using System.CodeDom;
|
||||
using System.ComponentModel;
|
||||
using System.Numerics;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.Generics
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly T?[] _places;
|
||||
public int Count => _places.Length;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
public int Insert(T airplane)
|
||||
{
|
||||
if (_places[Count - 1] != null)
|
||||
return -1;
|
||||
return Insert(airplane, 0);
|
||||
}
|
||||
public int Insert(T airplane, int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return -1;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int ind = position;
|
||||
while (ind < Count && _places[ind] != null)
|
||||
ind++;
|
||||
if (ind == Count)
|
||||
return -1;
|
||||
for (int i = ind - 1; i >= position; i--)
|
||||
_places[i + 1] = _places[i];
|
||||
}
|
||||
_places[position] = airplane;
|
||||
return position;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count) || _places[position] == null)
|
||||
return false;
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
15
ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/Status.cs
Normal file
15
ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/Status.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.MovementStrategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user