diff --git a/Stormtrooper/Stormtrooper/DrawningObject.cs b/Stormtrooper/Stormtrooper/DrawningObject.cs index d7ac06d..bf786ae 100644 --- a/Stormtrooper/Stormtrooper/DrawningObject.cs +++ b/Stormtrooper/Stormtrooper/DrawningObject.cs @@ -8,8 +8,8 @@ namespace Stormtrooper { internal class DrawningObjectStormtrooper : IDrawningObject { - private DrowningStormtrooper _stormtrooper = null; - public DrawningObjectStormtrooper(DrowningStormtrooper stormtrooper) + private DrawningStormtrooper _stormtrooper = null; + public DrawningObjectStormtrooper(DrawningStormtrooper stormtrooper) { _stormtrooper = stormtrooper; } diff --git a/Stormtrooper/Stormtrooper/DrowningStormtrooper.cs b/Stormtrooper/Stormtrooper/DrawningStormtrooper.cs similarity index 98% rename from Stormtrooper/Stormtrooper/DrowningStormtrooper.cs rename to Stormtrooper/Stormtrooper/DrawningStormtrooper.cs index dc79d38..f72a163 100644 --- a/Stormtrooper/Stormtrooper/DrowningStormtrooper.cs +++ b/Stormtrooper/Stormtrooper/DrawningStormtrooper.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Stormtrooper { - public class DrowningStormtrooper + public class DrawningStormtrooper { /// /// Класс-сущность @@ -42,11 +42,11 @@ namespace Stormtrooper /// Скорость /// Вес автомобиля /// Цвет кузова - public DrowningStormtrooper(int speed, float weight, Color bodyColor) + public DrawningStormtrooper(int speed, float weight, Color bodyColor) { Stormtrooper = new EntityStormtrooper(speed, weight, bodyColor); } - protected DrowningStormtrooper(int speed, float weight, Color bodyColor, int StormtrooperWidth, int StormtrooperHeight) : + protected DrawningStormtrooper(int speed, float weight, Color bodyColor, int StormtrooperWidth, int StormtrooperHeight) : this(speed, weight, bodyColor) { _stormtrooperWidth = StormtrooperWidth; diff --git a/Stormtrooper/Stormtrooper/DrowningSuperStormtrooper.cs b/Stormtrooper/Stormtrooper/DrawningSuperStormtrooper.cs similarity index 96% rename from Stormtrooper/Stormtrooper/DrowningSuperStormtrooper.cs rename to Stormtrooper/Stormtrooper/DrawningSuperStormtrooper.cs index dea7073..9d0e241 100644 --- a/Stormtrooper/Stormtrooper/DrowningSuperStormtrooper.cs +++ b/Stormtrooper/Stormtrooper/DrawningSuperStormtrooper.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace Stormtrooper { - internal class DrowningSuperStormtrooper : DrowningStormtrooper + internal class DrawningSuperStormtrooper : DrawningStormtrooper { - public DrowningSuperStormtrooper(int speed, float weight, Color bodyColor, Color dopColor, bool bombs, bool rockets, bool sportLine) : base(speed, weight, bodyColor, 90, 120) + public DrawningSuperStormtrooper(int speed, float weight, Color bodyColor, Color dopColor, bool bombs, bool rockets, bool sportLine) : base(speed, weight, bodyColor, 90, 120) { Stormtrooper = new EntitySuperStormtrooper(speed, weight, bodyColor, dopColor, bombs, rockets, sportLine); } @@ -19,7 +19,7 @@ namespace Stormtrooper return; } - Brush redBrush = new SolidBrush(Color.Red); + Brush redBrush = new SolidBrush(superStormtrooper.BodyColor); Brush dopBrush = new SolidBrush(superStormtrooper.DopColor); if (superStormtrooper.Bombs) diff --git a/Stormtrooper/Stormtrooper/FormMapWithSetStormtroopers.Designer.cs b/Stormtrooper/Stormtrooper/FormMapWithSetStormtroopers.Designer.cs index 8e39ab6..0e0b0d3 100644 --- a/Stormtrooper/Stormtrooper/FormMapWithSetStormtroopers.Designer.cs +++ b/Stormtrooper/Stormtrooper/FormMapWithSetStormtroopers.Designer.cs @@ -35,13 +35,12 @@ this.buttonDeleteMap = new System.Windows.Forms.Button(); this.buttonAddMap = new System.Windows.Forms.Button(); this.textBoxNewMap = new System.Windows.Forms.TextBox(); - this.comboBoxSelector = new System.Windows.Forms.ComboBox(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.buttonShowOnMap = new System.Windows.Forms.Button(); this.buttonShowStorage = new System.Windows.Forms.Button(); this.buttonRemoveStormtrooper = new System.Windows.Forms.Button(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonAddStormtrooper = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); @@ -60,7 +59,6 @@ this.groupBox1.Controls.Add(this.buttonRemoveStormtrooper); this.groupBox1.Controls.Add(this.maskedTextBoxPosition); this.groupBox1.Controls.Add(this.buttonAddStormtrooper); - this.groupBox1.Controls.Add(this.comboBoxSelectorMap); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox1.Location = new System.Drawing.Point(637, 0); this.groupBox1.Name = "groupBox1"; @@ -75,7 +73,7 @@ this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); this.groupBoxMaps.Controls.Add(this.buttonAddMap); this.groupBoxMaps.Controls.Add(this.textBoxNewMap); - this.groupBoxMaps.Controls.Add(this.comboBoxSelector); + this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); this.groupBoxMaps.Location = new System.Drawing.Point(23, 26); this.groupBoxMaps.Name = "groupBoxMaps"; this.groupBoxMaps.Size = new System.Drawing.Size(203, 290); @@ -120,18 +118,15 @@ this.textBoxNewMap.Size = new System.Drawing.Size(179, 27); this.textBoxNewMap.TabIndex = 1; // - // comboBoxSelector + // comboBoxSelectorMap // - this.comboBoxSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxSelector.FormattingEnabled = true; - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта", - "Собственная карта"}); - this.comboBoxSelector.Location = new System.Drawing.Point(18, 59); - this.comboBoxSelector.Name = "comboBoxSelector"; - this.comboBoxSelector.Size = new System.Drawing.Size(179, 28); - this.comboBoxSelector.TabIndex = 0; - this.comboBoxSelector.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelector_SelectedIndexChanged); + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Location = new System.Drawing.Point(18, 59); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(179, 28); + this.comboBoxSelectorMap.TabIndex = 0; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelector_SelectedIndexChanged); // // buttonShowOnMap // @@ -181,8 +176,6 @@ this.buttonAddStormtrooper.Text = "Добавить"; this.buttonAddStormtrooper.UseVisualStyleBackColor = true; this.buttonAddStormtrooper.Click += new System.EventHandler(this.ButtonAddStormtrooper_Click); - // - // // buttonDown // @@ -271,7 +264,6 @@ private Button buttonRemoveStormtrooper; private MaskedTextBox maskedTextBoxPosition; private Button buttonAddStormtrooper; - private ComboBox comboBoxSelectorMap; private PictureBox pictureBox; private Button buttonRight; private Button buttonLeft; @@ -282,6 +274,6 @@ private Button buttonDeleteMap; private Button buttonAddMap; private TextBox textBoxNewMap; - private ComboBox comboBoxSelector; + private ComboBox comboBoxSelectorMap; } } \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/FormMapWithSetStormtroopers.cs b/Stormtrooper/Stormtrooper/FormMapWithSetStormtroopers.cs index 5f0c495..8db5e4f 100644 --- a/Stormtrooper/Stormtrooper/FormMapWithSetStormtroopers.cs +++ b/Stormtrooper/Stormtrooper/FormMapWithSetStormtroopers.cs @@ -68,18 +68,18 @@ namespace Stormtrooper /// private void ButtonAddStormtrooper_Click(object sender, EventArgs e) { - if (_mapCarsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } FormStormtrooper form = new(); if (form.ShowDialog() == DialogResult.OK) { - DrawningObjectStormtrooper stormtrooper = new(form.SelectedStormtrooper); - if (_mapCarsCollectionGeneric + stormtrooper != -1) + DrawningObjectStormtrooper car = new(form.SelectedStormtrooper); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + car != -1) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -124,11 +124,11 @@ namespace Stormtrooper /// private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapCarsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } /// /// Вывод карты @@ -137,11 +137,11 @@ namespace Stormtrooper /// private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapCarsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapCarsCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } /// /// Перемещение @@ -150,7 +150,8 @@ namespace Stormtrooper /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapCarsCollectionGeneric == null) + + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -172,7 +173,8 @@ namespace Stormtrooper dir = Direction.Right; break; } - pictureBox.Image = _mapCarsCollectionGeneric.MoveObject(dir); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? + string.Empty].MoveObject(dir); } private void buttonAddMap_Click(object sender, EventArgs e) @@ -213,5 +215,7 @@ namespace Stormtrooper { } + + } } diff --git a/Stormtrooper/Stormtrooper/FormStormtrooper.cs b/Stormtrooper/Stormtrooper/FormStormtrooper.cs index 2df54a5..46eea12 100644 --- a/Stormtrooper/Stormtrooper/FormStormtrooper.cs +++ b/Stormtrooper/Stormtrooper/FormStormtrooper.cs @@ -13,9 +13,9 @@ namespace Stormtrooper public partial class FormStormtrooper : Form { - private DrowningStormtrooper _stormtrooper; + private DrawningStormtrooper _stormtrooper; - public DrowningStormtrooper SelectedStormtrooper { get; private set; } + public DrawningStormtrooper SelectedStormtrooper { get; private set; } public FormStormtrooper() { @@ -46,8 +46,15 @@ namespace Stormtrooper private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _stormtrooper = new DrowningStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), + rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _stormtrooper = new DrawningStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000), + color); _stormtrooper.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); SetData(); @@ -70,7 +77,7 @@ namespace Stormtrooper { dopColor = dialogDop.Color; } - _stormtrooper = new DrowningSuperStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000), + _stormtrooper = new DrawningSuperStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); diff --git a/Stormtrooper/Stormtrooper/MapWithSetStormtroopersGeneric.cs b/Stormtrooper/Stormtrooper/MapWithSetStormtroopersGeneric.cs index 4a2f23e..488025c 100644 --- a/Stormtrooper/Stormtrooper/MapWithSetStormtroopersGeneric.cs +++ b/Stormtrooper/Stormtrooper/MapWithSetStormtroopersGeneric.cs @@ -161,17 +161,17 @@ namespace Stormtrooper /// private void DrawCars(Graphics g) { - int x = 5; + int x = (_pictureWidth / _placeSizeWidth) * _placeSizeWidth - _placeSizeWidth; int y = 5; foreach (var boat in _setStormtroopers.GetStormtroopers()) { boat?.SetObject(x, y, _pictureWidth, _pictureHeight); boat?.DrawningObject(g); - x += _placeSizeWidth; - if (x + _placeSizeWidth > _pictureWidth) + x -= _placeSizeWidth; + if (x < 0) { y += _placeSizeHeight; - x = 5; + x = (_pictureWidth / _placeSizeWidth) * _placeSizeWidth - _placeSizeWidth; } } } diff --git a/Stormtrooper/Stormtrooper/MySecondMap.cs b/Stormtrooper/Stormtrooper/MySecondMap.cs index 3176963..59916d2 100644 --- a/Stormtrooper/Stormtrooper/MySecondMap.cs +++ b/Stormtrooper/Stormtrooper/MySecondMap.cs @@ -11,7 +11,7 @@ namespace Stormtrooper /// /// Цвет участка закрытого /// - private readonly Brush barrierColor = new SolidBrush(Color.Red); + private readonly Brush barrierColor = new SolidBrush(Color.Blue); /// /// Цвет участка открытого /// @@ -41,11 +41,15 @@ namespace Stormtrooper } while (counter < 10) { - int x = _random.Next(0, _map.GetLength(0)); - int y = _random.Next(0, _map.GetLength(1)); + int x = _random.Next(2, _map.GetLength(0)); + int y = _random.Next(2, _map.GetLength(1)); if (_map[x, y] == _freeRoad) { _map[x, y] = _barrier; + _map[x - 1, y] = _barrier; + _map[x, y - 1] = _barrier; + _map[x - 1, y - 1] = _barrier; + counter++; } }