Dolgov D.A. Lab Work 2 #2
164
ProjectPlane/ProjectPlane/AbstractMap.cs
Normal file
164
ProjectPlane/ProjectPlane/AbstractMap.cs
Normal file
@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPlane
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
{
|
||||
private IDrawingObject _drawingObject = null;
|
||||
protected int[,] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected readonly Random _random = new();
|
||||
protected readonly int _freeRoad = 0;
|
||||
protected readonly int _barrier = 1;
|
||||
|
||||
public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawingObject = drawingObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
int _objWidth = Convert.ToInt32(_drawingObject.GetCurrentPosition().Right / _size_x);
|
||||
int _startX = Convert.ToInt32(_drawingObject.GetCurrentPosition().Left / _size_x);
|
||||
int _startY = Convert.ToInt32(_drawingObject.GetCurrentPosition().Top / _size_y);
|
||||
int _objHeight = Convert.ToInt32(_drawingObject.GetCurrentPosition().Bottom / _size_y);
|
||||
|
||||
bool isMoveable = true;
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Right:
|
||||
for (int i = _startX; i <= _objWidth + Convert.ToInt32(_drawingObject.Step / _size_x); i++)
|
||||
{
|
||||
for (int j = _startY; j <= _objHeight; j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
isMoveable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Direction.Left:
|
||||
for (int i = _startX; i >= _startX - Convert.ToInt32(_drawingObject.Step / _size_x); i--)
|
||||
{
|
||||
for (int j = _startY; j <= _objHeight; j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
isMoveable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Direction.Up:
|
||||
for (int i = _startX; i <= _objWidth; i++)
|
||||
{
|
||||
for (int j = _startY; j >= _startY - Convert.ToInt32(_drawingObject.Step / _size_y); j--)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
isMoveable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Direction.Down:
|
||||
for (int i = _startX; i <= _objWidth; i++)
|
||||
{
|
||||
for (int j = _objHeight; j <= _objHeight + Convert.ToInt32(_drawingObject.Step / _size_y); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
isMoveable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (isMoveable)
|
||||
{
|
||||
_drawingObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.Next(0, 10);
|
||||
int y = _random.Next(0, 10);
|
||||
_drawingObject.SetObject(x, y, _width, _height);
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (i * _size_x >= x && j * _size_y >= y &&
|
||||
i * _size_x <= x + _drawingObject.GetCurrentPosition().Right &&
|
||||
j * _size_y <= j + _drawingObject.GetCurrentPosition().Bottom)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private Bitmap DrawMapWithObject()
|
||||
{
|
||||
Bitmap bmp = new(_width, _height);
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i, j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i, j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawingObject.DrawingObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ namespace ProjectPlane
|
||||
{
|
||||
internal enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
|
40
ProjectPlane/ProjectPlane/DrawingObject.cs
Normal file
40
ProjectPlane/ProjectPlane/DrawingObject.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPlane
|
||||
{
|
||||
internal class DrawingObject : IDrawingObject
|
||||
|
||||
{
|
||||
private DrawingPlane _plane = null;
|
||||
|
||||
public DrawingObject(DrawingPlane plane)
|
||||
{
|
||||
_plane = plane;
|
||||
}
|
||||
|
||||
public float Step => _plane?.Plane?.Step ?? 0;
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _plane?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_plane?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_plane.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
void IDrawingObject.DrawingObject(Graphics g)
|
||||
{
|
||||
_plane.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
73
ProjectPlane/ProjectPlane/DrawingWarPlane.cs
Normal file
73
ProjectPlane/ProjectPlane/DrawingWarPlane.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPlane
|
||||
{
|
||||
internal class DrawingWarPlane : DrawingPlane
|
||||
eegov
commented
Имя класса не соответствует указаному в задании Имя класса не соответствует указаному в задании
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public DrawingWarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool isBomber, bool isFighter, bool superTurbine) :
|
||||
base(speed, weight, bodyColor, 110, 60)
|
||||
{
|
||||
Plane = new EntityWarPlane(speed, weight, bodyColor, dopColor, isFighter, superTurbine);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
|
||||
|
||||
if (Plane is not EntityWarPlane warplane)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(warplane.DopColor);
|
||||
Brush Brush = new SolidBrush(warplane.BodyColor);
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
|
||||
if (warplane.SuperTurbine)
|
||||
{
|
||||
|
||||
g.FillRectangle(dopBrush, _startPosX, _startPosY + 20, 30, 22);
|
||||
g.DrawLine(pen, _startPosX, _startPosY + 42, _startPosX + 30, _startPosY + 42);
|
||||
g.DrawLine(pen, _startPosX, _startPosY + 20, _startPosX + 30, _startPosY + 20);
|
||||
}
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
|
||||
if (warplane.extraCell)
|
||||
{
|
||||
Point[] Nose = new Point[4];
|
||||
Nose[0].X = Convert.ToInt32(_startPosX + 118); Nose[0].Y = Convert.ToInt32(_startPosY + 22);
|
||||
Nose[1].X = Convert.ToInt32(_startPosX + 155); Nose[1].Y = Convert.ToInt32(_startPosY + 22);
|
||||
Nose[2].X = Convert.ToInt32(_startPosX + 118); Nose[2].Y = Convert.ToInt32(_startPosY + 45);
|
||||
Nose[3].X = Convert.ToInt32(_startPosX + 98); Nose[3].Y = Convert.ToInt32(_startPosY + 45);
|
||||
g.FillPolygon(Brush, Nose);
|
||||
|
||||
Point[] NoseWin = new Point[3];
|
||||
NoseWin[0].X = Convert.ToInt32(_startPosX + 120); NoseWin[0].Y = Convert.ToInt32(_startPosY + 24);
|
||||
NoseWin[1].X = Convert.ToInt32(_startPosX + 148); NoseWin[1].Y = Convert.ToInt32(_startPosY + 24);
|
||||
NoseWin[2].X = Convert.ToInt32(_startPosX + 132); NoseWin[2].Y = Convert.ToInt32(_startPosY + 34);
|
||||
g.FillPolygon(brBlue, NoseWin);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -12,15 +12,15 @@ namespace ProjectPlane
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityPlane Plane { get; private set; }
|
||||
public EntityPlane Plane { get; protected set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки самолета
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки самолета
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
/// </summary>
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -32,47 +32,58 @@ namespace ProjectPlane
|
||||
/// <summary>
|
||||
/// Ширина отрисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _planeWidth = 120;
|
||||
private readonly int _planeWidth = 125;
|
||||
/// <summary>
|
||||
/// Высота отрисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _planeHeight = 50;
|
||||
/// <summary>
|
||||
/// Левый край
|
||||
/// </summary>
|
||||
private readonly int _minX = 5;
|
||||
/// <summary>
|
||||
/// Верхний край
|
||||
/// </summary>
|
||||
private readonly int _minY = 40;
|
||||
private readonly int _planeHeight = 45;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawingPlane(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Plane = new EntityPlane();
|
||||
Plane.Init(speed, weight, bodyColor);
|
||||
Plane = new EntityPlane(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции самолета
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
/// <param name="planeWidth">Ширина отрисовки самолета</param>
|
||||
/// <param name="planeHeight">Высота отрисовки самолета</param>
|
||||
protected DrawingPlane(int speed, float weight, Color bodyColor, int planeWidth, int planeHeight)
|
||||
: this(speed, weight, bodyColor)
|
||||
{
|
||||
if (x >= _minX && x <= width && y >= _minY && y <= height)
|
||||
_planeWidth = planeWidth;
|
||||
_planeHeight = planeHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции самолета
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
///
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x < 0 || x + _planeWidth >= width)
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return;
|
||||
}
|
||||
else SetPosition(_minX, _minY, width, height);
|
||||
if (y < 0 || y + _planeHeight >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения
|
||||
@ -99,21 +110,22 @@ namespace ProjectPlane
|
||||
{
|
||||
_startPosX -= Plane.Step;
|
||||
}
|
||||
else _startPosX = 0;
|
||||
break;
|
||||
//вверх
|
||||
case Direction.Up:
|
||||
if (_startPosY - Plane.Step > 35)
|
||||
if (_startPosY - Plane.Step > 0)
|
||||
{
|
||||
_startPosY -= Plane.Step;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
//вниз
|
||||
case Direction.Down:
|
||||
if (_startPosY + _planeHeight + Plane.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += Plane.Step;
|
||||
}
|
||||
else _startPosY = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -121,7 +133,7 @@ namespace ProjectPlane
|
||||
/// Отрисовка самолета
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
@ -131,75 +143,73 @@ namespace ProjectPlane
|
||||
//границы самолета
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY + 20, 20, 20);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX + 8, _startPosY, 100, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 8, _startPosY + 20, 100, 20);
|
||||
|
||||
Point[] Triangle0 = new Point[3];
|
||||
Triangle0[0].X = Convert.ToInt32(_startPosX + 108); Triangle0[0].Y = Convert.ToInt32(_startPosY - 2);
|
||||
Triangle0[1].X = Convert.ToInt32(_startPosX + 125); Triangle0[1].Y = Convert.ToInt32(_startPosY + 10);
|
||||
Triangle0[2].X = Convert.ToInt32(_startPosX + 108); Triangle0[2].Y = Convert.ToInt32(_startPosY + 10);
|
||||
Triangle0[0].X = Convert.ToInt32(_startPosX + 108); Triangle0[0].Y = Convert.ToInt32(_startPosY + 18);
|
||||
Triangle0[1].X = Convert.ToInt32(_startPosX + 125); Triangle0[1].Y = Convert.ToInt32(_startPosY + 30);
|
||||
Triangle0[2].X = Convert.ToInt32(_startPosX + 108); Triangle0[2].Y = Convert.ToInt32(_startPosY + 30);
|
||||
g.DrawPolygon(pen, Triangle0);
|
||||
|
||||
Point[] Triangle1 = new Point[3];
|
||||
Triangle1[0].X = Convert.ToInt32(_startPosX + 108); Triangle1[0].Y = Convert.ToInt32(_startPosY + 10);
|
||||
Triangle1[1].X = Convert.ToInt32(_startPosX + 125); Triangle1[1].Y = Convert.ToInt32(_startPosY + 10);
|
||||
Triangle1[2].X = Convert.ToInt32(_startPosX + 108); Triangle1[2].Y = Convert.ToInt32(_startPosY + 22);
|
||||
Triangle1[0].X = Convert.ToInt32(_startPosX + 108); Triangle1[0].Y = Convert.ToInt32(_startPosY + 30);
|
||||
Triangle1[1].X = Convert.ToInt32(_startPosX + 125); Triangle1[1].Y = Convert.ToInt32(_startPosY + 30);
|
||||
Triangle1[2].X = Convert.ToInt32(_startPosX + 108); Triangle1[2].Y = Convert.ToInt32(_startPosY + 42);
|
||||
g.DrawPolygon(pen, Triangle1);
|
||||
|
||||
Point[] Triangle = new Point[3];
|
||||
Triangle[0].X = Convert.ToInt32(_startPosX + 5); Triangle[0].Y = Convert.ToInt32(_startPosY);
|
||||
Triangle[1].X = Convert.ToInt32(_startPosX + 5); Triangle[1].Y = Convert.ToInt32(_startPosY - 20);
|
||||
Triangle[2].X = Convert.ToInt32(_startPosX + 35); Triangle[2].Y = Convert.ToInt32(_startPosY);
|
||||
Triangle[0].X = Convert.ToInt32(_startPosX + 5); Triangle[0].Y = Convert.ToInt32(_startPosY + 20);
|
||||
Triangle[1].X = Convert.ToInt32(_startPosX + 5); Triangle[1].Y = Convert.ToInt32(_startPosY);
|
||||
Triangle[2].X = Convert.ToInt32(_startPosX + 35); Triangle[2].Y = Convert.ToInt32(_startPosY + 20);
|
||||
g.DrawPolygon(pen, Triangle);
|
||||
|
||||
////корпус
|
||||
|
||||
Brush br = new SolidBrush(Plane?.BodyColor ?? Color.Black);
|
||||
|
||||
g.FillEllipse(br, _startPosX, _startPosY, 20, 20);
|
||||
g.FillEllipse(br, _startPosX, _startPosY + 20, 20, 20);
|
||||
|
||||
g.FillRectangle(br, _startPosX + 8, _startPosY, 100, 20);
|
||||
g.FillRectangle(br, _startPosX + 8, _startPosY + 20, 100, 20);
|
||||
|
||||
Point[] Triangle2 = new Point[3];
|
||||
Triangle2[0].X = Convert.ToInt32(_startPosX + 5); Triangle2[0].Y = Convert.ToInt32(_startPosY);
|
||||
Triangle2[1].X = Convert.ToInt32(_startPosX + 5); Triangle2[1].Y = Convert.ToInt32(_startPosY - 20);
|
||||
Triangle2[2].X = Convert.ToInt32(_startPosX + 35); Triangle2[2].Y = Convert.ToInt32(_startPosY);
|
||||
Triangle2[0].X = Convert.ToInt32(_startPosX + 5); Triangle2[0].Y = Convert.ToInt32(_startPosY + 20);
|
||||
Triangle2[1].X = Convert.ToInt32(_startPosX + 5); Triangle2[1].Y = Convert.ToInt32(_startPosY); //the highest point
|
||||
Triangle2[2].X = Convert.ToInt32(_startPosX + 35); Triangle2[2].Y = Convert.ToInt32(_startPosY + 20);
|
||||
g.FillPolygon(br, Triangle2);
|
||||
|
||||
Point[] Triangle4 = new Point[3];
|
||||
Triangle4[0].X = Convert.ToInt32(_startPosX + 108); Triangle4[0].Y = Convert.ToInt32(_startPosY + 10);
|
||||
Triangle4[1].X = Convert.ToInt32(_startPosX + 125); Triangle4[1].Y = Convert.ToInt32(_startPosY + 10);
|
||||
Triangle4[2].X = Convert.ToInt32(_startPosX + 108); Triangle4[2].Y = Convert.ToInt32(_startPosY + 22);
|
||||
Triangle4[0].X = Convert.ToInt32(_startPosX + 108); Triangle4[0].Y = Convert.ToInt32(_startPosY + 30);
|
||||
Triangle4[1].X = Convert.ToInt32(_startPosX + 125); Triangle4[1].Y = Convert.ToInt32(_startPosY + 30);
|
||||
Triangle4[2].X = Convert.ToInt32(_startPosX + 108); Triangle4[2].Y = Convert.ToInt32(_startPosY + 42);
|
||||
g.FillPolygon(br, Triangle4);
|
||||
|
||||
// window
|
||||
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
|
||||
Point[] Triangle3 = new Point[3];
|
||||
Triangle3[0].X = Convert.ToInt32(_startPosX + 108); Triangle3[0].Y = Convert.ToInt32(_startPosY - 2);
|
||||
Triangle3[1].X = Convert.ToInt32(_startPosX + 125); Triangle3[1].Y = Convert.ToInt32(_startPosY + 10);
|
||||
Triangle3[2].X = Convert.ToInt32(_startPosX + 108); Triangle3[2].Y = Convert.ToInt32(_startPosY + 10);
|
||||
g.FillPolygon(brBlue, Triangle3);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 37, _startPosY + 20, _startPosX + 37, _startPosY + 25);
|
||||
g.DrawLine(pen, _startPosX + 32, _startPosY + 25, _startPosX + 40, _startPosY + 25);
|
||||
g.DrawRectangle(pen, _startPosX + 32, _startPosY + 25, 3, 3);
|
||||
g.DrawRectangle(pen, _startPosX + 39, _startPosY + 25, 3, 3);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 102, _startPosY + 20, _startPosX + 102, _startPosY + 25);
|
||||
g.DrawRectangle(pen, _startPosX + 101, _startPosY + 25, 3, 3);
|
||||
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
|
||||
g.FillRectangle(brBlack, _startPosX + 5, _startPosY - 2, 18, 7);
|
||||
g.FillEllipse(brBlack, _startPosX, _startPosY - 2, 7, 7);
|
||||
g.FillEllipse(brBlack, _startPosX + 20, _startPosY - 2, 7, 7);
|
||||
Point[] Triangle3 = new Point[3];
|
||||
Triangle3[0].X = Convert.ToInt32(_startPosX + 108); Triangle3[0].Y = Convert.ToInt32(_startPosY + 18);
|
||||
Triangle3[1].X = Convert.ToInt32(_startPosX + 125); Triangle3[1].Y = Convert.ToInt32(_startPosY + 30);
|
||||
Triangle3[2].X = Convert.ToInt32(_startPosX + 108); Triangle3[2].Y = Convert.ToInt32(_startPosY + 30);
|
||||
g.FillPolygon(brBlue, Triangle3);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 37, _startPosY + 40, _startPosX + 37, _startPosY + 45);
|
||||
g.DrawLine(pen, _startPosX + 32, _startPosY + 45, _startPosX + 40, _startPosY + 45);
|
||||
g.FillRectangle(brBlack, _startPosX + 32, _startPosY + 45, 3, 3);
|
||||
g.FillRectangle(brBlack, _startPosX + 39, _startPosY + 45, 3, 3);
|
||||
|
||||
g.DrawLine(pen, _startPosX + 102, _startPosY + 40, _startPosX + 102, _startPosY + 45);
|
||||
g.FillRectangle(brBlack, _startPosX + 101, _startPosY + 45, 3, 3);
|
||||
|
||||
g.FillRectangle(brBlack, _startPosX + 5, _startPosY + 18, 18, 7);
|
||||
g.FillEllipse(brBlack, _startPosX, _startPosY + 18, 7, 7);
|
||||
g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 18, 7, 7);
|
||||
|
||||
g.FillRectangle(brBlack, _startPosX + 41, _startPosY + 28, 42, 4);
|
||||
g.FillEllipse(brBlack, _startPosX + 39, _startPosY + 28, 4, 4);
|
||||
g.FillEllipse(brBlack, _startPosX + 81, _startPosY + 28, 4, 4);
|
||||
|
||||
g.FillRectangle(brBlack, _startPosX + 41, _startPosY + 8, 42, 4);
|
||||
g.FillEllipse(brBlack, _startPosX + 39, _startPosY + 8, 4, 4);
|
||||
g.FillEllipse(brBlack, _startPosX + 81, _startPosY + 8, 4, 4);
|
||||
}
|
||||
/// <summary>
|
||||
/// Смена границ формы отрисовки
|
||||
@ -225,5 +235,9 @@ namespace ProjectPlane
|
||||
_startPosY = _pictureHeight.Value - _planeHeight;
|
||||
}
|
||||
}
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosX + _planeWidth, _startPosY , _startPosY + _planeHeight);
|
||||
}
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ namespace ProjectPlane
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityPlane(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(350, 550) : speed;
|
||||
|
45
ProjectPlane/ProjectPlane/EntityWarPlane.cs
Normal file
45
ProjectPlane/ProjectPlane/EntityWarPlane.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Военный самолет"
|
||||
/// </summary>
|
||||
internal class EntityWarPlane : EntityPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// доп отсек
|
||||
/// </summary>
|
||||
public bool extraCell { get; private set; }
|
||||
/// <summary>
|
||||
/// наличие супертурбины
|
||||
/// </summary>
|
||||
public bool SuperTurbine { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="cell">Признак наличия доп остсека>
|
||||
///
|
||||
public EntityWarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool cell, bool superturbine) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
extraCell = cell;
|
||||
SuperTurbine = superturbine;
|
||||
}
|
||||
}
|
||||
}
|
206
ProjectPlane/ProjectPlane/FormMap.Designer.cs
generated
Normal file
206
ProjectPlane/ProjectPlane/FormMap.Designer.cs
generated
Normal file
@ -0,0 +1,206 @@
|
||||
namespace ProjectPlane
|
||||
{
|
||||
partial class FormMap
|
||||
{
|
||||
/// <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);
|
||||
}
|
||||
|
||||
private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
#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.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.pictureBoxPlane = new System.Windows.Forms.PictureBox();
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.comboMapSelector = new System.Windows.Forms.ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.BackgroundImage = global::ProjectPlane.Properties.Resources.up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(686, 323);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(48, 47);
|
||||
this.buttonUp.TabIndex = 8;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.BackgroundImage = global::ProjectPlane.Properties.Resources.right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(740, 372);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(48, 47);
|
||||
this.buttonRight.TabIndex = 7;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.BackgroundImage = global::ProjectPlane.Properties.Resources.down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(686, 372);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(48, 47);
|
||||
this.buttonDown.TabIndex = 6;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.BackgroundImage = global::ProjectPlane.Properties.Resources.left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(632, 372);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(48, 47);
|
||||
this.buttonLeft.TabIndex = 5;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.BackColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.buttonCreate.Location = new System.Drawing.Point(12, 376);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(120, 47);
|
||||
this.buttonCreate.TabIndex = 4;
|
||||
this.buttonCreate.Text = "New Plane";
|
||||
this.buttonCreate.UseVisualStyleBackColor = false;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
//
|
||||
// pictureBoxPlane
|
||||
//
|
||||
this.pictureBoxPlane.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxPlane.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxPlane.Name = "pictureBoxPlane";
|
||||
this.pictureBoxPlane.Size = new System.Drawing.Size(800, 450);
|
||||
this.pictureBoxPlane.TabIndex = 5;
|
||||
this.pictureBoxPlane.TabStop = false;
|
||||
|
||||
//
|
||||
// statusStrip1
|
||||
//
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelBodyColor});
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 428);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Size = new System.Drawing.Size(800, 22);
|
||||
this.statusStrip1.TabIndex = 9;
|
||||
this.statusStrip1.Text = "statusStrip1";
|
||||
this.statusStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.statusStrip1_ItemClicked);
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(39, 17);
|
||||
this.toolStripStatusLabelSpeed.Text = "Speed";
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(45, 17);
|
||||
this.toolStripStatusLabelWeight.Text = "Weight";
|
||||
//
|
||||
// toolStripStatusLabelBodyColor
|
||||
//
|
||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Color";
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.BackColor = System.Drawing.SystemColors.ControlLight;
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(138, 376);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(115, 47);
|
||||
this.buttonCreateModif.TabIndex = 10;
|
||||
this.buttonCreateModif.Text = "Modificate";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = false;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||
//
|
||||
// comboMapSelector
|
||||
//
|
||||
this.comboMapSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboMapSelector.FormattingEnabled = true;
|
||||
this.comboMapSelector.Items.AddRange(new object[] {
|
||||
"Simple Map",
|
||||
"Sky Map"});
|
||||
this.comboMapSelector.Location = new System.Drawing.Point(12, 12);
|
||||
this.comboMapSelector.Name = "comboMapSelector";
|
||||
this.comboMapSelector.Size = new System.Drawing.Size(121, 23);
|
||||
this.comboMapSelector.TabIndex = 11;
|
||||
this.comboMapSelector.SelectedIndexChanged += new System.EventHandler(this.comboMapSelector_SelectedIndexChanged);
|
||||
//
|
||||
// FormMap
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.comboMapSelector);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Controls.Add(this.pictureBoxPlane);
|
||||
this.Name = "FormMap";
|
||||
this.Text = "FormMap";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).EndInit();
|
||||
this.statusStrip1.ResumeLayout(false);
|
||||
this.statusStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonCreate;
|
||||
private PictureBox pictureBoxPlane;
|
||||
private StatusStrip statusStrip1;
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private Button buttonCreateModif;
|
||||
private ComboBox comboMapSelector;
|
||||
}
|
||||
}
|
97
ProjectPlane/ProjectPlane/FormMap.cs
Normal file
97
ProjectPlane/ProjectPlane/FormMap.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectPlane
|
||||
{
|
||||
public partial class FormMap : Form
|
||||
{
|
||||
private AbstractMap _abstractMap;
|
||||
public FormMap()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
|
||||
private void comboMapSelector_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboMapSelector.SelectedIndex)
|
||||
{
|
||||
case 0:
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case 1:
|
||||
_abstractMap = new SkyMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <param name="plane"></param>
|
||||
private void SetData(DrawingPlane plane)
|
||||
{
|
||||
toolStripStatusLabelSpeed.Text = $"Speed: {plane.Plane.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Weight: {plane.Plane.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Color: {plane.Plane.BodyColor.Name}";
|
||||
pictureBoxPlane.Image = _abstractMap.CreateMap(pictureBoxPlane.Width, pictureBoxPlane.Height,
|
||||
new DrawingObject(plane));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "Обработка нажатия на кнопки движения"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBoxPlane.Image = _abstractMap?.MoveObject(dir);
|
||||
}
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var plane = new DrawingPlane(rnd.Next(300, 400), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
SetData(plane);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Модификация"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var _plane = new DrawingWarPlane(rnd.Next(300, 400), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData(_plane);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
63
ProjectPlane/ProjectPlane/FormMap.resx
Normal file
63
ProjectPlane/ProjectPlane/FormMap.resx
Normal file
@ -0,0 +1,63 @@
|
||||
<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>
|
||||
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
18
ProjectPlane/ProjectPlane/FormPlane.Designer.cs
generated
18
ProjectPlane/ProjectPlane/FormPlane.Designer.cs
generated
@ -19,7 +19,10 @@
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
@ -38,6 +41,7 @@
|
||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -113,6 +117,7 @@
|
||||
this.statusStrip1.Size = new System.Drawing.Size(800, 22);
|
||||
this.statusStrip1.TabIndex = 9;
|
||||
this.statusStrip1.Text = "statusStrip1";
|
||||
this.statusStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.statusStrip1_ItemClicked);
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
@ -132,11 +137,23 @@
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Color";
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.BackColor = System.Drawing.SystemColors.ControlLight;
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(138, 376);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(115, 47);
|
||||
this.buttonCreateModif.TabIndex = 10;
|
||||
this.buttonCreateModif.Text = "Modificate";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = false;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||
//
|
||||
// FormPlane
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
@ -167,5 +184,6 @@
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -19,8 +19,17 @@
|
||||
_plane?.DrawTransport(gr);
|
||||
pictureBoxPlane.Image = bmp;
|
||||
}
|
||||
private void SetData()
|
||||
{
|
||||
Random rand = new();
|
||||
_plane.SetPosition(rand.Next(5, 100), rand.Next(40, 100),
|
||||
pictureBoxPlane.Width, pictureBoxPlane.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Speed: {_plane.Plane.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Weiht: {_plane.Plane.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Color: {_plane.Plane.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// "Обработка нажатия на кнопки движения"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
@ -48,14 +57,9 @@
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rand = new Random();
|
||||
_plane = new DrawingPlane();
|
||||
_plane.Init(rand.Next(200, 500), rand.Next(2000, 3000),
|
||||
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)));
|
||||
_plane.SetPosition(rand.Next(5, 100), rand.Next(40, 100),
|
||||
pictureBoxPlane.Width, pictureBoxPlane.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Speed: {_plane.Plane.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Weiht: {_plane.Plane.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Color: {_plane.Plane.BodyColor.Name}";
|
||||
_plane = new DrawingPlane(rand.Next(200, 500), rand.Next(2000, 3000),
|
||||
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
private void PictureBoxCar_Resize(object sender, EventArgs e)
|
||||
@ -63,5 +67,22 @@
|
||||
_plane?.ChangeBorders(pictureBoxPlane.Width, pictureBoxPlane.Height);
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Модификация"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_plane = new DrawingWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
40
ProjectPlane/ProjectPlane/IDrawingObject.cs
Normal file
40
ProjectPlane/ProjectPlane/IDrawingObject.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPlane
|
||||
{
|
||||
internal interface IDrawingObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
/// </summary>
|
||||
public float Step { get; }
|
||||
/// <summary>
|
||||
/// Установка позиции объекта
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина полотна</param>
|
||||
/// <param name="height">Высота полотна</param>
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns></returns>
|
||||
void MoveObject(Direction direction);
|
||||
/// <summary>
|
||||
/// Отрисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
void DrawingObject(Graphics g);
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ namespace ProjectPlane
|
||||
static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormPlane());
|
||||
Application.Run(new FormMap());
|
||||
}
|
||||
}
|
||||
}
|
53
ProjectPlane/ProjectPlane/SimpleMap.cs
Normal file
53
ProjectPlane/ProjectPlane/SimpleMap.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPlane
|
||||
{
|
||||
internal class SimpleMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
ProjectPlane/ProjectPlane/SkyMap.cs
Normal file
57
ProjectPlane/ProjectPlane/SkyMap.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPlane
|
||||
{
|
||||
internal class SkyMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush skyColor = new SolidBrush(Color.AliceBlue);
|
||||
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
Point[] Triangle = new Point[3];
|
||||
Triangle[0].X = i * (int)_size_x; Triangle[0].Y = j * (int)_size_y;
|
||||
Triangle[1].X = i * (int)_size_x + 8; Triangle[1].Y = j * (int)_size_y - 5;
|
||||
Triangle[2].X = i * (int)_size_x + 8; Triangle[2].Y = j * (int)_size_y + 5;
|
||||
g.FillPolygon(barrierColor, Triangle);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(skyColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 30)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Имя класса не соответствует указаному в задании