diff --git a/ProjectMachine/ProjectMachine/AbstractMap.cs b/ProjectMachine/ProjectMachine/AbstractMap.cs new file mode 100644 index 0000000..bdc975c --- /dev/null +++ b/ProjectMachine/ProjectMachine/AbstractMap.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectMachine +{ + internal abstract class AbstractMap + { + private IDrawningObject _drawningObject = 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, IDrawningObject drawningObject) + { + _width = width; + _height = height; + _drawningObject = drawningObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + + public (int LeftCoord, int TopCoord, int RightCoord, int BottomCoord) GetCoord() + { + return ((int)(_drawningObject.GetCurrentPosition().Left / _size_x), (int)(_drawningObject.GetCurrentPosition().Top / _size_y), (int)(_drawningObject.GetCurrentPosition().Right / _size_x), (int)(_drawningObject.GetCurrentPosition().Bottom / _size_y)); + } + + public bool CheckMove(Direction dir) + { + switch (dir) + { + case Direction.Left: + if (GetCoord().LeftCoord <= 0) + { + return false; + } + break; + case Direction.Right: + if (GetCoord().RightCoord + 1 > _map.GetLength(1)) + { + return false; + } + break; + case Direction.Up: + if (GetCoord().TopCoord <= 0) + { + return false; + } + break; + case (Direction.Down): + if (GetCoord().BottomCoord -1 > _map.GetLength(0)) + { + return false; + } + break; + } + switch (dir) + { + case Direction.Left: + for (int i = GetCoord().TopCoord; i <= GetCoord().BottomCoord; i++) + { + if (_map[GetCoord().LeftCoord - 1, i] == _barrier) + return false; + } + break; + case Direction.Right: + for (int i = GetCoord().TopCoord; i < GetCoord().BottomCoord; i++) + { + if (_map[GetCoord().RightCoord + 1, i] == _barrier) + return false; + } + break; + case Direction.Up: + for (int i = GetCoord().LeftCoord; i < GetCoord().RightCoord; i++) + { + if (_map[i, GetCoord().TopCoord - 1] == _barrier) + return false; + } + break; + case Direction.Down: + for (int i = GetCoord().LeftCoord; i < GetCoord().RightCoord; i++) + { + if (_map[i, GetCoord().BottomCoord + 1] == _barrier) + return false; + } + break; + } + return true; + } + public Bitmap MoveObject(Direction direction) + { + if (CheckMove(direction)) + { + _drawningObject.MoveObject(direction); + } + return DrawMapWithObject(); + } + private bool SetObjectOnMap() + { + if (_drawningObject == null || _map == null) + { + return false; + } + int x = _random.Next(0, 10); + int y = _random.Next(0, 10); + _drawningObject.SetObject(x, y, _width, _height); + for (int i = GetCoord().LeftCoord; i <= GetCoord().RightCoord; i++) + { + for (int j = GetCoord().TopCoord; j <= GetCoord().BottomCoord; j++) + { + if (_map[i, j] == _barrier) + { + return false; + } + } + } + return true; + } + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + if (_drawningObject == 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); + } + } + } + _drawningObject.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); + } +} \ No newline at end of file diff --git a/ProjectMachine/ProjectMachine/Direction.cs b/ProjectMachine/ProjectMachine/Direction.cs index a6156bc..9688957 100644 --- a/ProjectMachine/ProjectMachine/Direction.cs +++ b/ProjectMachine/ProjectMachine/Direction.cs @@ -11,6 +11,7 @@ namespace ProjectMachine /// internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/ProjectMachine/ProjectMachine/DrawningMachine.cs b/ProjectMachine/ProjectMachine/DrawningMachine.cs index de6dff6..b7ab6f2 100644 --- a/ProjectMachine/ProjectMachine/DrawningMachine.cs +++ b/ProjectMachine/ProjectMachine/DrawningMachine.cs @@ -175,7 +175,7 @@ namespace ProjectMachine /// public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { - return (_startPosX, _startPosY, _startPosX + _machineWidth, _startPosY + _machineHeight); + return (_startPosX, _startPosX + _machineWidth, _startPosY, _startPosY + _machineHeight); } } } diff --git a/ProjectMachine/ProjectMachine/DrawningObject.cs b/ProjectMachine/ProjectMachine/DrawningObject.cs index 2b28821..64d03d3 100644 --- a/ProjectMachine/ProjectMachine/DrawningObject.cs +++ b/ProjectMachine/ProjectMachine/DrawningObject.cs @@ -34,8 +34,7 @@ namespace ProjectMachine void IDrawningObject.DrawningObject(Graphics g) { - if (_machine != null) - _machine.DrawTransport(g); + _machine.DrawTransport(g); } } } diff --git a/ProjectMachine/ProjectMachine/DrawningTank.cs b/ProjectMachine/ProjectMachine/DrawningTank.cs index baa6ee6..0adccfd 100644 --- a/ProjectMachine/ProjectMachine/DrawningTank.cs +++ b/ProjectMachine/ProjectMachine/DrawningTank.cs @@ -19,7 +19,7 @@ namespace ProjectMachine /// Признак наличия башни с орудием /// Признак наличия зенитного пулемета public DrawningTank(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool turret, bool gun) : - base(speed, weight, bodyColor, 110, 60) + base(speed, weight, bodyColor, 90, 50) { Machine = new EntityTank(speed, weight, bodyColor, dopColor, bodyKit, turret, gun); } diff --git a/ProjectMachine/ProjectMachine/FormMachine.resx b/ProjectMachine/ProjectMachine/FormMachine.resx index 5cb320f..87c950d 100644 --- a/ProjectMachine/ProjectMachine/FormMachine.resx +++ b/ProjectMachine/ProjectMachine/FormMachine.resx @@ -60,4 +60,7 @@ 17, 17 + + 36 + \ No newline at end of file diff --git a/ProjectMachine/ProjectMachine/FormMap.Designer.cs b/ProjectMachine/ProjectMachine/FormMap.Designer.cs new file mode 100644 index 0000000..a4d9ad3 --- /dev/null +++ b/ProjectMachine/ProjectMachine/FormMap.Designer.cs @@ -0,0 +1,215 @@ +namespace ProjectMachine +{ + 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.pictureBoxMachine = 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.ButtonCreate = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxMachine)).BeginInit(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxMachine + // + this.pictureBoxMachine.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxMachine.Location = new System.Drawing.Point(0, 0); + this.pictureBoxMachine.MinimumSize = new System.Drawing.Size(1, 1); + this.pictureBoxMachine.Name = "pictureBoxMachine"; + this.pictureBoxMachine.Size = new System.Drawing.Size(732, 441); + this.pictureBoxMachine.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxMachine.TabIndex = 0; + this.pictureBoxMachine.TabStop = false; + // + // statusStrip1 + // + this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor}); + this.statusStrip1.Location = new System.Drawing.Point(0, 441); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(732, 26); + this.statusStrip1.TabIndex = 1; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20); + this.toolStripStatusLabelSpeed.Text = "Скорость:"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20); + this.toolStripStatusLabelWeight.Text = "Вес:"; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20); + this.toolStripStatusLabelBodyColor.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, 385); + this.ButtonCreate.Name = "ButtonCreate"; + this.ButtonCreate.Size = new System.Drawing.Size(94, 29); + this.ButtonCreate.TabIndex = 2; + this.ButtonCreate.Text = "Создать"; + this.ButtonCreate.UseVisualStyleBackColor = true; + this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::ProjectMachine.Properties.Resources.вниз; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(651, 384); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 3; + this.buttonDown.Text = " \r\n\r\n"; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.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::ProjectMachine.Properties.Resources.право; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(687, 384); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 4; + this.buttonRight.Text = " \r\n\r\n"; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.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::ProjectMachine.Properties.Resources.вверх; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(651, 348); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 5; + this.buttonUp.Text = " \r\n\r\n"; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::ProjectMachine.Properties.Resources.лево; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(615, 384); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 6; + this.buttonLeft.Text = " \r\n\r\n"; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonCreateModif + // + this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreateModif.Location = new System.Drawing.Point(124, 385); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(130, 29); + 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(12, 12); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28); + this.comboBoxSelectorMap.TabIndex = 8; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + // + // FormMap + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(732, 467); + this.Controls.Add(this.comboBoxSelectorMap); + this.Controls.Add(this.buttonCreateModif); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.ButtonCreate); + this.Controls.Add(this.pictureBoxMachine); + this.Controls.Add(this.statusStrip1); + this.Name = "FormMap"; + this.Text = "Карта"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxMachine)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxMachine; + private StatusStrip statusStrip1; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private Button ButtonCreate; + private Button buttonDown; + private Button buttonRight; + private Button buttonUp; + private Button buttonLeft; + private Button buttonCreateModif; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/ProjectMachine/ProjectMachine/FormMap.cs b/ProjectMachine/ProjectMachine/FormMap.cs new file mode 100644 index 0000000..da73052 --- /dev/null +++ b/ProjectMachine/ProjectMachine/FormMap.cs @@ -0,0 +1,101 @@ +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 ProjectMachine +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + + public FormMap() + { + InitializeComponent(); + _abstractMap = new SimpleMap(); + } + /// + /// Заполнение информации по объекту + /// + /// + private void SetData(DrawningMachine machine) + { + toolStripStatusLabelSpeed.Text = $"Скорость: {machine.Machine.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {machine.Machine.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {machine.Machine.BodyColor.Name}"; + pictureBoxMachine.Image = _abstractMap.CreateMap(pictureBoxMachine.Width, pictureBoxMachine.Height, + new DrawningObject(machine)); + } + /// + /// Обработка нажатия кнопки "Создать" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + var machine = new DrawningMachine(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(machine); + } + /// + /// Изменение размеров формы + /// + /// + /// + 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; + } + pictureBoxMachine.Image = _abstractMap?.MoveObject(dir); + } + /// + /// Обработка нажатия кнопки "Модификация" + /// + /// + /// + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + var machine = new DrawningTank(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(machine); + } + /// + /// Смена карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + case "Город": + _abstractMap = new TownMap(); + break; + } + } + } +} diff --git a/ProjectMachine/ProjectMachine/FormMap.resx b/ProjectMachine/ProjectMachine/FormMap.resx new file mode 100644 index 0000000..ba3508b --- /dev/null +++ b/ProjectMachine/ProjectMachine/FormMap.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 33 + + \ No newline at end of file diff --git a/ProjectMachine/ProjectMachine/Program.cs b/ProjectMachine/ProjectMachine/Program.cs index b8ffc19..4d6e0f6 100644 --- a/ProjectMachine/ProjectMachine/Program.cs +++ b/ProjectMachine/ProjectMachine/Program.cs @@ -11,7 +11,7 @@ namespace ProjectMachine // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMachine()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/ProjectMachine/ProjectMachine/SimpleMap.cs b/ProjectMachine/ProjectMachine/SimpleMap.cs new file mode 100644 index 0000000..d07049e --- /dev/null +++ b/ProjectMachine/ProjectMachine/SimpleMap.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectMachine +{ + /// + /// Простая реализация абсрактного класса 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, _size_x, _size_y); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + 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/ProjectMachine/ProjectMachine/TownMap.cs b/ProjectMachine/ProjectMachine/TownMap.cs new file mode 100644 index 0000000..f7aeae6 --- /dev/null +++ b/ProjectMachine/ProjectMachine/TownMap.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectMachine +{ + internal class TownMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierTreeColor = new SolidBrush(Color.Plum); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.LightGoldenrodYellow); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierTreeColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + protected override void GenerateMap() + { + _map = new int[15, 15]; + _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, 15); + int y = _random.Next(0, 15); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +}