diff --git a/Warship/Warship.sln b/Warship/Warship.sln index e4e7043..82429d8 100644 --- a/Warship/Warship.sln +++ b/Warship/Warship.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32901.215 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Warship", "Warship\Warship.csproj", "{9CFF4FD7-9721-45C9-84DC-020B509D6024}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AircraftCarrier", "Warship\AircraftCarrier.csproj", "{9CFF4FD7-9721-45C9-84DC-020B509D6024}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Warship/Warship/AbstractMap.cs b/Warship/Warship/AbstractMap.cs new file mode 100644 index 0000000..b6a9911 --- /dev/null +++ b/Warship/Warship/AbstractMap.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + internal abstract class AbstractMap + { + private IDrawingObject _drawingObjectWarship = 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 drawingObjectWarship) + { + _width = width; + _height = height; + _drawingObjectWarship = drawingObjectWarship; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + public Bitmap MoveObject(Direction direction) + { + // TODO проверка, что объект может переместится в требуемом направлении + if (true) + { + _drawingObjectWarship.MoveObject(direction); + } + return DrawMapWithObject(); + } + private bool SetObjectOnMap() + { + if (_drawingObjectWarship == null || _map == null) + { + return false; + } + int x = _random.Next(0, 10); + int y = _random.Next(0, 10); + _drawingObjectWarship.SetObject(x, y, _width, _height); + // TODO првоерка, что объект не "накладывается" на закрытые участки + return true; + } + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + if (_drawingObjectWarship == 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); + } + } + } + _drawingObjectWarship.DrawningObject(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/Warship/Warship/Warship.csproj b/Warship/Warship/AircraftCarrier.csproj similarity index 100% rename from Warship/Warship/Warship.csproj rename to Warship/Warship/AircraftCarrier.csproj diff --git a/Warship/Warship/Direction.cs b/Warship/Warship/Direction.cs index 83590ab..29854e5 100644 --- a/Warship/Warship/Direction.cs +++ b/Warship/Warship/Direction.cs @@ -4,13 +4,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Warship +namespace AircraftCarrier { /// /// Направление перемещения /// internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/Warship/Warship/DrawingObjectWarship.cs b/Warship/Warship/DrawingObjectWarship.cs new file mode 100644 index 0000000..439f636 --- /dev/null +++ b/Warship/Warship/DrawingObjectWarship.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + internal class DrawingObjectWarship : IDrawingObject + { + private DrawingWarship _ship = null; + public DrawingObjectWarship(DrawingWarship ship) + { + _ship = ship; + } + public float Step => _ship?.Ship?.Step ?? 0; + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _ship?.GetCurrentPosition() ?? default; + } + public void MoveObject(Direction direction) + { + _ship?.MoveTransport(direction); + } + public void SetObject(int x, int y, int width, int height) + { + _ship.SetPosition(x, y, width, height); + } + public void DrawningObject(Graphics g) + { + // TODO + } + } +} diff --git a/Warship/Warship/DrawingPlaneWarship.cs b/Warship/Warship/DrawingPlaneWarship.cs new file mode 100644 index 0000000..6d71221 --- /dev/null +++ b/Warship/Warship/DrawingPlaneWarship.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + /// + /// Класс, отвечающий за прорисовку и перемещение объекта-сущности + /// + internal class DrawingPlaneWarship : DrawingWarship + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес корабля + /// Цвет + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия рубки управления + /// Признак наличия взлетной полосы + public DrawingPlaneWarship(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool controlplace, bool runway) : + base(speed, weight, bodyColor, 244, 100) + { + Ship = new EntityPlaneWarship(speed, weight, bodyColor, dopColor, bodyKit, controlplace, runway); + } + public override void DrawTransport(Graphics g) + { + if (Ship is not EntityPlaneWarship planeWarship) + { + return; + } + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(planeWarship.DopColor); + Brush brYellow = new SolidBrush(Color.Yellow); + Brush br = new SolidBrush(Ship?.BodyColor ?? Color.White); + if (planeWarship.BodyKit) + { + // броня носовой части корабля + PointF pointShipArmor1 = new PointF(_startPosX + 167, _startPosY + 25); + PointF pointShipArmor2 = new PointF(_startPosX + 237, _startPosY + 40); + PointF pointShipArmor3 = new PointF(_startPosX + 167, _startPosY + 75); + PointF pointShipArmor4 = new PointF(_startPosX + 237, _startPosY + 55); + PointF[] PointsShipArmor = + { + pointShipArmor1, pointShipArmor2, pointShipArmor3, pointShipArmor4, + }; + g.FillPolygon(br, PointsShipArmor); + g.DrawPolygon(pen, PointsShipArmor); + g.DrawEllipse(pen, _startPosX + 224, _startPosY + 37, 20, 20); + g.FillEllipse(br, _startPosX + 224, _startPosY + 37, 20, 20); + } + + if (planeWarship.RunWay) + { + //взлетная полоса + g.DrawRectangle(pen, _startPosX + 27, _startPosY + 75, 140, 25); + g.DrawRectangle(pen, _startPosX + 32, _startPosY + 87, 25, 5); + g.DrawRectangle(pen, _startPosX + 82, _startPosY + 87, 25, 5); + g.DrawRectangle(pen, _startPosX + 132, _startPosY + 87, 25, 5); + g.FillRectangle(brYellow, _startPosX + 32, _startPosY + 87, 25, 5); + g.FillRectangle(brYellow, _startPosX + 82, _startPosY + 87, 25, 5); + g.FillRectangle(brYellow, _startPosX + 132, _startPosY + 87, 25, 5); + } + + _startPosX += 22; + _startPosY += 25; + base.DrawTransport(g); + _startPosX -= 22; + _startPosY -= 25; + + if (planeWarship.СontrolPlace) + { + g.FillEllipse(dopBrush, _startPosX + 127, _startPosY + 30, 10, 10); + g.DrawEllipse(pen, _startPosX + 127, _startPosY + 30, 10, 10); + + g.FillEllipse(dopBrush, _startPosX + 137, _startPosY + 30, 10, 10); + g.DrawEllipse(pen, _startPosX + 137, _startPosY + 30, 10, 10); + + g.FillRectangle(dopBrush, _startPosX + 132, _startPosY + 30, 10, 10); + g.DrawRectangle(pen, _startPosX + 132, _startPosY + 30, 10, 10); + } + } + } +} diff --git a/Warship/Warship/DrawingWarship.cs b/Warship/Warship/DrawingWarship.cs index 5f28a1e..ca377a2 100644 --- a/Warship/Warship/DrawingWarship.cs +++ b/Warship/Warship/DrawingWarship.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Warship +namespace AircraftCarrier { /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности @@ -14,15 +14,15 @@ namespace Warship /// /// Класс-сущность /// - public EntityWarship Ship { private set; get; } + public EntityWarship Ship { protected set; get; } /// /// Левая координата отрисовки корабля /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки корабля /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -45,10 +45,24 @@ namespace Warship /// Скорость /// Вес корабля /// Цвет - public void Init(int speed, float weight, Color bodyColor) + public DrawingWarship(int speed, float weight, Color bodyColor) { - Ship = new EntityWarship(); - Ship.Init(speed, weight, bodyColor); + Ship = new EntityWarship(speed, weight, bodyColor); + } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес корабля + /// Цвет кузова + /// Ширина отрисовки корабля + /// Высота отрисовки корабля + protected DrawingWarship(int speed, float weight, Color bodyColor, int + shipWidth, int shipHeight) : + this(speed, weight, bodyColor) + { + _shipWidth = shipWidth; + _shipHeight = shipHeight; } /// /// Установка позиции корабля @@ -120,7 +134,7 @@ namespace Warship /// Отрисовка корабля /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) @@ -171,6 +185,15 @@ namespace Warship _startPosY = _pictureHeight.Value - _shipHeight; } } + /// + /// Получение текущей позиции объекта + /// + /// + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + + _shipHeight); + } } } diff --git a/Warship/Warship/EntityPlaneWarship.cs b/Warship/Warship/EntityPlaneWarship.cs new file mode 100644 index 0000000..1d7a3b8 --- /dev/null +++ b/Warship/Warship/EntityPlaneWarship.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + /// + /// Класс-сущность "Авианосец" + /// + internal class EntityPlaneWarship : EntityWarship + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия обвеса + /// + public bool BodyKit { get; private set; } + /// + /// Признак наличия рубки управления + /// + public bool СontrolPlace { get; private set; } + /// + /// Признак наличия взлетной полосы + /// + public bool RunWay { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес корабля + /// Цвет + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия рубки управления + /// Признак наличия взлетной полосы + public EntityPlaneWarship(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool controlplace, bool runway) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + BodyKit = bodyKit; + СontrolPlace = controlplace; + RunWay = runway; + } + + } +} diff --git a/Warship/Warship/EntityWarship.cs b/Warship/Warship/EntityWarship.cs index 74a511d..cc726d6 100644 --- a/Warship/Warship/EntityWarship.cs +++ b/Warship/Warship/EntityWarship.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Warship +namespace AircraftCarrier { /// /// Класс-сущность "Военный корабль" @@ -34,7 +34,7 @@ namespace Warship /// /// /// - public void Init(int speed, float weight, Color bodyColor) + public EntityWarship(int speed, float weight, Color bodyColor) { Random rnd = new Random(); Speed = speed <= 0 ? rnd.Next(50, 100) : speed; diff --git a/Warship/Warship/FormMap.Designer.cs b/Warship/Warship/FormMap.Designer.cs new file mode 100644 index 0000000..fc1df6a --- /dev/null +++ b/Warship/Warship/FormMap.Designer.cs @@ -0,0 +1,205 @@ +namespace AircraftCarrier +{ + 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); + } + + #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.pictureBoxShip = 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.toolStripStatusLabelColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxShip + // + this.pictureBoxShip.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxShip.Location = new System.Drawing.Point(0, 0); + this.pictureBoxShip.Name = "pictureBoxShip"; + this.pictureBoxShip.Size = new System.Drawing.Size(800, 450); + this.pictureBoxShip.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxShip.TabIndex = 0; + this.pictureBoxShip.TabStop = false; + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelColor}); + 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 = 1; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17); + this.toolStripStatusLabelSpeed.Text = " Скорость"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(26, 17); + this.toolStripStatusLabelWeight.Text = "Вес"; + // + // toolStripStatusLabelColor + // + this.toolStripStatusLabelColor.Name = "toolStripStatusLabelColor"; + this.toolStripStatusLabelColor.Size = new System.Drawing.Size(33, 17); + this.toolStripStatusLabelColor.Text = "Цвет"; + // + // buttonCreate + // + this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreate.Location = new System.Drawing.Point(12, 382); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелка; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(657, 375); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 3; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелкаbott; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(693, 375); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 4; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелкаtop; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(693, 339); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 5; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелкаright; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(729, 375); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 6; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(107, 382); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(130, 23); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(8, 8); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); + this.comboBoxSelectorMap.TabIndex = 8; + // + // 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.comboBoxSelectorMap); + this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.buttonCreateModif); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.pictureBoxShip); + this.Name = "FormMap"; + this.Text = "FormMap"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxShip; + private StatusStrip statusStrip1; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelColor; + private Button buttonCreate; + private Button buttonLeft; + private Button buttonDown; + private Button buttonUp; + private Button buttonRight; + private Button buttonCreateModif; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/Warship/Warship/FormMap.cs b/Warship/Warship/FormMap.cs new file mode 100644 index 0000000..1722865 --- /dev/null +++ b/Warship/Warship/FormMap.cs @@ -0,0 +1,102 @@ +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 AircraftCarrier +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + public FormMap() + { + InitializeComponent(); + _abstractMap = new SimpleMap(); + } + /// + /// Заполнение информации по объекту + /// + /// + private void SetData(DrawingWarship ship) + { + toolStripStatusLabelSpeed.Text = $"Скорость: {ship.Ship.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {ship.Ship.Weight}"; + toolStripStatusLabelColor.Text = $"Цвет: {ship.Ship.BodyColor.Name}"; + pictureBoxShip.Image = _abstractMap.CreateMap(pictureBoxShip.Width, pictureBoxShip.Height, + new DrawingObjectWarship(ship)); + } + /// + /// Обработка нажатия кнопки "Создать" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + var ship = new DrawingWarship(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(ship); + } + /// + /// Изменение размеров формы + /// + /// + /// + 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; + } + pictureBoxShip.Image = _abstractMap?.MoveObject(dir); + } + /// + /// Обработка нажатия кнопки "Модификация" + /// + /// + /// + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + var ship = new DrawingPlaneWarship(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(ship); + } + /// + /// Смена карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + } + } + + } +} diff --git a/Warship/Warship/FormMap.resx b/Warship/Warship/FormMap.resx new file mode 100644 index 0000000..5cb320f --- /dev/null +++ b/Warship/Warship/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/Warship/Warship/FormShip.Designer.cs b/Warship/Warship/FormShip.Designer.cs index 77b08e2..07d3c4f 100644 --- a/Warship/Warship/FormShip.Designer.cs +++ b/Warship/Warship/FormShip.Designer.cs @@ -1,4 +1,4 @@ -namespace Warship +namespace AircraftCarrier { partial class FormShip { @@ -38,6 +38,7 @@ this.buttonDown = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -96,7 +97,7 @@ // buttonLeft // this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeft.BackgroundImage = global::Warship.Properties.Resources.стрелка; + this.buttonLeft.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелка; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.Location = new System.Drawing.Point(657, 375); this.buttonLeft.Name = "buttonLeft"; @@ -108,7 +109,7 @@ // buttonDown // this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDown.BackgroundImage = global::Warship.Properties.Resources.стрелкаbott; + this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелкаbott; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.Location = new System.Drawing.Point(693, 375); this.buttonDown.Name = "buttonDown"; @@ -120,7 +121,7 @@ // buttonUp // this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::Warship.Properties.Resources.стрелкаtop; + this.buttonUp.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелкаtop; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.Location = new System.Drawing.Point(693, 339); this.buttonUp.Name = "buttonUp"; @@ -132,7 +133,7 @@ // buttonRight // this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::Warship.Properties.Resources.стрелкаright; + this.buttonRight.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелкаright; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.Location = new System.Drawing.Point(729, 375); this.buttonRight.Name = "buttonRight"; @@ -141,11 +142,22 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(107, 382); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(130, 23); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // // FormShip // 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.buttonRight); this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonDown); @@ -175,5 +187,6 @@ private Button buttonDown; private Button buttonUp; private Button buttonRight; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/Warship/Warship/FormShip.cs b/Warship/Warship/FormShip.cs index 66f5862..1e40c7d 100644 --- a/Warship/Warship/FormShip.cs +++ b/Warship/Warship/FormShip.cs @@ -1,4 +1,4 @@ -namespace Warship +namespace AircraftCarrier { public partial class FormShip : Form { @@ -8,7 +8,7 @@ namespace Warship InitializeComponent(); } /// - /// + /// /// private void Draw() { @@ -18,6 +18,17 @@ namespace Warship pictureBoxShip.Image = bmp; } /// + /// + /// + private void Setdata() + { + Random rnd = new(); + _ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height); + toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}"; + toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}"; + toolStripStatusLabelColor.Text = $": {_ship.Ship.BodyColor.Name}"; + } + /// /// "" /// /// @@ -25,14 +36,9 @@ namespace Warship private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _ship = new DrawingWarship(); - _ship.Init(rnd.Next(50, 100), rnd.Next(20000, 30000), + _ship = new DrawingWarship(rnd.Next(50, 100), rnd.Next(20000, 30000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), - pictureBoxShip.Width, pictureBoxShip.Height); - toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}"; - toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}"; - toolStripStatusLabelColor.Text = $": {_ship.Ship.BodyColor.Name}"; + Setdata(); Draw(); } private void ButtonMove_Click(object sender, EventArgs e) @@ -62,6 +68,21 @@ namespace Warship _ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height); Draw(); } + /// + /// "" + /// + /// + /// + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _ship = new DrawingPlaneWarship(rnd.Next(50, 100), rnd.Next(20000, 30000), + 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(); + } } } diff --git a/Warship/Warship/IDrawingObject.cs b/Warship/Warship/IDrawingObject.cs new file mode 100644 index 0000000..284bbbb --- /dev/null +++ b/Warship/Warship/IDrawingObject.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + /// + /// Интерфейс для работы с объектом, прорисовываемым на форме + /// + internal interface IDrawingObject + { + /// + /// Шаг перемещения объекта + /// + public float Step { get; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + void SetObject(int x, int y, int width, int height); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + void MoveObject(Direction direction); + /// + /// Отрисовка объекта + /// + /// + void DrawningObject(Graphics g); + /// + /// Получение текущей позиции объекта + /// + /// + (float Left, float Right, float Top, float Bottom) + GetCurrentPosition(); + } +} diff --git a/Warship/Warship/Program.cs b/Warship/Warship/Program.cs index 3eef74f..4080ebd 100644 --- a/Warship/Warship/Program.cs +++ b/Warship/Warship/Program.cs @@ -1,4 +1,4 @@ -namespace Warship +namespace AircraftCarrier { internal static class Program { @@ -11,7 +11,7 @@ namespace Warship // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormShip()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/Warship/Warship/Properties/Resources.Designer.cs b/Warship/Warship/Properties/Resources.Designer.cs index 0a27005..6a559e2 100644 --- a/Warship/Warship/Properties/Resources.Designer.cs +++ b/Warship/Warship/Properties/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Warship.Properties { +namespace AircraftCarrier.Properties { using System; @@ -39,7 +39,7 @@ namespace Warship.Properties { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Warship.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AircraftCarrier.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Warship/Warship/SimpleMap.cs b/Warship/Warship/SimpleMap.cs new file mode 100644 index 0000000..fc3dd29 --- /dev/null +++ b/Warship/Warship/SimpleMap.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + /// + /// Простая реализация абсрактного класса AbstractMap + /// + 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++; + } + } + } + } +}