diff --git a/ProjectPlane/ProjectPlane/AbstractMap.cs b/ProjectPlane/ProjectPlane/AbstractMap.cs new file mode 100644 index 0000000..4b9b93e --- /dev/null +++ b/ProjectPlane/ProjectPlane/AbstractMap.cs @@ -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); + } +} diff --git a/ProjectPlane/ProjectPlane/Direction.cs b/ProjectPlane/ProjectPlane/Direction.cs index ae7d03e..45ee136 100644 --- a/ProjectPlane/ProjectPlane/Direction.cs +++ b/ProjectPlane/ProjectPlane/Direction.cs @@ -8,6 +8,7 @@ namespace ProjectPlane { internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/ProjectPlane/ProjectPlane/DrawingObject.cs b/ProjectPlane/ProjectPlane/DrawingObject.cs new file mode 100644 index 0000000..18e6766 --- /dev/null +++ b/ProjectPlane/ProjectPlane/DrawingObject.cs @@ -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); + } + } +} diff --git a/ProjectPlane/ProjectPlane/DrawingWarPlane.cs b/ProjectPlane/ProjectPlane/DrawingWarPlane.cs new file mode 100644 index 0000000..7dfe2d2 --- /dev/null +++ b/ProjectPlane/ProjectPlane/DrawingWarPlane.cs @@ -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 + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + 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); + } + + } + } +} diff --git a/ProjectPlane/ProjectPlane/DrawningPlane.cs b/ProjectPlane/ProjectPlane/DrawningPlane.cs index 18ee68f..61d0386 100644 --- a/ProjectPlane/ProjectPlane/DrawningPlane.cs +++ b/ProjectPlane/ProjectPlane/DrawningPlane.cs @@ -12,15 +12,15 @@ namespace ProjectPlane /// /// Класс-сущность /// - public EntityPlane Plane { get; private set; } + public EntityPlane Plane { get; protected set; } /// /// Левая координата отрисовки самолета /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки самолета - /// - private float _startPosY; + /// + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -32,47 +32,58 @@ namespace ProjectPlane /// /// Ширина отрисовки самолета /// - private readonly int _planeWidth = 120; + private readonly int _planeWidth = 125; /// /// Высота отрисовки самолета /// - private readonly int _planeHeight = 50; - /// - /// Левый край - /// - private readonly int _minX = 5; - /// - /// Верхний край - /// - private readonly int _minY = 40; + private readonly int _planeHeight = 45; /// /// Инициализация свойств /// /// Скорость /// Вес самолета /// Цвет корпуса - 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); } /// - /// Установка позиции самолета + /// Инициализация свойств /// - /// Координата X - /// Координата Y - /// Ширина картинки - /// Высота картинки - public void SetPosition(int x, int y, int width, int height) + /// Скорость + /// Вес самолета + /// Цвет корпуса + /// Ширина отрисовки самолета + /// Высота отрисовки самолета + 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; + } + /// + /// Установка позиции самолета + /// + /// Координата X + /// Координата Y + /// Ширина картинки + /// Высота картинки + /// + + 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; } /// /// Изменение направления пермещения @@ -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 /// Отрисовка самолета /// /// - 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); } /// /// Смена границ формы отрисовки @@ -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); + } } } \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/EntityPlane.cs b/ProjectPlane/ProjectPlane/EntityPlane.cs index cab3959..856c101 100644 --- a/ProjectPlane/ProjectPlane/EntityPlane.cs +++ b/ProjectPlane/ProjectPlane/EntityPlane.cs @@ -32,7 +32,7 @@ namespace ProjectPlane /// /// /// - 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; diff --git a/ProjectPlane/ProjectPlane/EntityWarPlane.cs b/ProjectPlane/ProjectPlane/EntityWarPlane.cs new file mode 100644 index 0000000..7346267 --- /dev/null +++ b/ProjectPlane/ProjectPlane/EntityWarPlane.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectPlane +{ + /// + /// Класс-сущность "Военный самолет" + /// + internal class EntityWarPlane : EntityPlane + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + + /// + /// доп отсек + /// + public bool extraCell { get; private set; } + /// + /// наличие супертурбины + /// + public bool SuperTurbine { get; private set; } + + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолета + /// Цвет корпуса + /// Дополнительный цвет + /// Признак наличия доп остсека> + /// + public EntityWarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool cell, bool superturbine) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + extraCell = cell; + SuperTurbine = superturbine; + } + } +} diff --git a/ProjectPlane/ProjectPlane/FormMap.Designer.cs b/ProjectPlane/ProjectPlane/FormMap.Designer.cs new file mode 100644 index 0000000..c368940 --- /dev/null +++ b/ProjectPlane/ProjectPlane/FormMap.Designer.cs @@ -0,0 +1,206 @@ +namespace ProjectPlane +{ + partial class FormMap + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + 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 + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + /// + 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; + } +} \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/FormMap.cs b/ProjectPlane/ProjectPlane/FormMap.cs new file mode 100644 index 0000000..4ba845e --- /dev/null +++ b/ProjectPlane/ProjectPlane/FormMap.cs @@ -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; + } + } + /// + 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)); + } + + /// + /// "Обработка нажатия на кнопки движения" + /// + /// + /// + 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); + + } + + /// + /// Обработка нажатия кнопки "Модификация" + /// + /// + /// + 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); + } + + + } +} + diff --git a/ProjectPlane/ProjectPlane/FormMap.resx b/ProjectPlane/ProjectPlane/FormMap.resx new file mode 100644 index 0000000..5cb320f --- /dev/null +++ b/ProjectPlane/ProjectPlane/FormMap.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/FormPlane.Designer.cs b/ProjectPlane/ProjectPlane/FormPlane.Designer.cs index 1b715aa..06e5038 100644 --- a/ProjectPlane/ProjectPlane/FormPlane.Designer.cs +++ b/ProjectPlane/ProjectPlane/FormPlane.Designer.cs @@ -19,7 +19,10 @@ } base.Dispose(disposing); } + private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) + { + } #region Windows Form Designer generated code /// @@ -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; } } \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/FormPlane.cs b/ProjectPlane/ProjectPlane/FormPlane.cs index ab28350..35aa65e 100644 --- a/ProjectPlane/ProjectPlane/FormPlane.cs +++ b/ProjectPlane/ProjectPlane/FormPlane.cs @@ -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}"; + } /// - /// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü" + /// "Обработка нажатия на кнопки движения" /// /// /// @@ -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(); } + /// + /// Обработка нажатия кнопки "Модификация" + /// + /// + /// + 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(); + } + + } } \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/IDrawingObject.cs b/ProjectPlane/ProjectPlane/IDrawingObject.cs new file mode 100644 index 0000000..7e27543 --- /dev/null +++ b/ProjectPlane/ProjectPlane/IDrawingObject.cs @@ -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 + { + /// + /// Шаг перемещения объекта + /// + public float Step { get; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + void SetObject(int x, int y, int width, int height); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + /// + void MoveObject(Direction direction); + /// + /// Отрисовка объекта + /// + /// + void DrawingObject(Graphics g); + /// + /// Получение текущей позиции объекта + /// + /// + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } +} diff --git a/ProjectPlane/ProjectPlane/Program.cs b/ProjectPlane/ProjectPlane/Program.cs index 23d8582..bce2d5a 100644 --- a/ProjectPlane/ProjectPlane/Program.cs +++ b/ProjectPlane/ProjectPlane/Program.cs @@ -9,7 +9,7 @@ namespace ProjectPlane static void Main() { ApplicationConfiguration.Initialize(); - Application.Run(new FormPlane()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/SimpleMap.cs b/ProjectPlane/ProjectPlane/SimpleMap.cs new file mode 100644 index 0000000..8752b0b --- /dev/null +++ b/ProjectPlane/ProjectPlane/SimpleMap.cs @@ -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 + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// + /// Цвет участка открытого + /// + 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++; + } + } + } + } +} diff --git a/ProjectPlane/ProjectPlane/SkyMap.cs b/ProjectPlane/ProjectPlane/SkyMap.cs new file mode 100644 index 0000000..b58bbdf --- /dev/null +++ b/ProjectPlane/ProjectPlane/SkyMap.cs @@ -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 + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// + /// Цвет участка открытого + /// + 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++; + } + } + } + } +}