diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 5ce80af..ae7c3fa 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -33,7 +33,13 @@ namespace AirBomber private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _airBomber = new DrawningBomber(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; + } + _airBomber = new DrawningBomber(rnd.Next(100, 300), rnd.Next(1000, 2000), color); SetData(); Draw(); } @@ -68,10 +74,19 @@ namespace AirBomber private void ButtonCreateModif_Click(object sender, EventArgs e) { Random rnd = new(); - _airBomber = new DrawningWarplane(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))); + 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; + } + Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } + _airBomber = new DrawningWarplane(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(); Draw(); } diff --git a/AirBomber/AirBomber/FormMapWithSetAirBomber.Designer.cs b/AirBomber/AirBomber/FormMapWithSetAirBomber.Designer.cs index 96b2687..a4477a6 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirBomber.Designer.cs @@ -29,17 +29,17 @@ private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); - this.buttonAddAirBomber = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - this.pictureBox = new System.Windows.Forms.PictureBox(); - this.buttonRemoveAirBomber = new System.Windows.Forms.Button(); - this.buttonShowStorage = new System.Windows.Forms.Button(); - this.buttonShowOnMap = 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.buttonUp = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveAirBomber = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonAddAirBomber = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); @@ -64,6 +64,84 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "Инструменты"; // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.ArrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(116, 404); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 10; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.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::AirBomber.Properties.Resources.ArrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(80, 404); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 9; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.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::AirBomber.Properties.Resources.ArrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(44, 404); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 8; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.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::AirBomber.Properties.Resources.ArrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(80, 368); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 7; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(22, 319); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(150, 33); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(22, 258); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(150, 36); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // buttonRemoveAirBomber + // + this.buttonRemoveAirBomber.Location = new System.Drawing.Point(22, 195); + this.buttonRemoveAirBomber.Name = "buttonRemoveAirBomber"; + this.buttonRemoveAirBomber.Size = new System.Drawing.Size(150, 36); + this.buttonRemoveAirBomber.TabIndex = 3; + this.buttonRemoveAirBomber.Text = "Удалить самолет"; + this.buttonRemoveAirBomber.UseVisualStyleBackColor = true; + this.buttonRemoveAirBomber.Click += new System.EventHandler(this.ButtonRemoveAirBomber_Click); + // // maskedTextBoxPosition // this.maskedTextBoxPosition.Location = new System.Drawing.Point(22, 166); @@ -80,14 +158,20 @@ this.buttonAddAirBomber.TabIndex = 1; this.buttonAddAirBomber.Text = "Добавить самолет"; this.buttonAddAirBomber.UseVisualStyleBackColor = true; + this.buttonAddAirBomber.Click += new System.EventHandler(this.ButtonAddAirBomber_Click); // // comboBoxSelectorMap // this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Вторая карта", + "Третья карта"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(22, 44); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(150, 23); this.comboBoxSelectorMap.TabIndex = 0; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); // // pictureBox // @@ -98,77 +182,6 @@ this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // - // buttonRemoveAirBomber - // - this.buttonRemoveAirBomber.Location = new System.Drawing.Point(22, 195); - this.buttonRemoveAirBomber.Name = "buttonRemoveAirBomber"; - this.buttonRemoveAirBomber.Size = new System.Drawing.Size(150, 36); - this.buttonRemoveAirBomber.TabIndex = 3; - this.buttonRemoveAirBomber.Text = "Удалить самолет"; - this.buttonRemoveAirBomber.UseVisualStyleBackColor = true; - // - // buttonShowStorage - // - this.buttonShowStorage.Location = new System.Drawing.Point(22, 258); - this.buttonShowStorage.Name = "buttonShowStorage"; - this.buttonShowStorage.Size = new System.Drawing.Size(150, 36); - this.buttonShowStorage.TabIndex = 4; - this.buttonShowStorage.Text = "Посмотреть хранилище"; - this.buttonShowStorage.UseVisualStyleBackColor = true; - // - // buttonShowOnMap - // - this.buttonShowOnMap.Location = new System.Drawing.Point(22, 319); - this.buttonShowOnMap.Name = "buttonShowOnMap"; - this.buttonShowOnMap.Size = new System.Drawing.Size(150, 33); - this.buttonShowOnMap.TabIndex = 5; - this.buttonShowOnMap.Text = "Посмотреть карту"; - this.buttonShowOnMap.UseVisualStyleBackColor = true; - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.ArrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(116, 404); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 10; - this.buttonRight.UseVisualStyleBackColor = true; - // - // buttonDown - // - this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.ArrowDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(80, 404); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(30, 30); - this.buttonDown.TabIndex = 9; - this.buttonDown.UseVisualStyleBackColor = true; - // - // buttonLeft - // - this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.ArrowLeft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(44, 404); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(30, 30); - this.buttonLeft.TabIndex = 8; - this.buttonLeft.UseVisualStyleBackColor = true; - // - // buttonUp - // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.ArrowUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(80, 368); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - this.buttonUp.TabIndex = 7; - this.buttonUp.UseVisualStyleBackColor = true; - // // FormMapWithSetAirBomber // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); diff --git a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs index 0541b16..3c13999 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs @@ -17,44 +17,19 @@ namespace AirBomber public FormMapWithSetAirBomber() { InitializeComponent(); - } + } - private void ComboBoxSelectorMap_SelectedIndexChanged(object sende, EventArgs e) - { - AbstractMap map = null; - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - map = new SimpleMap(); - break; - case "Вторая карта": - map = new SecondMap(); - break; - case "Третья карта": - map = new ThirdMap(); - break; - } - if (map != null) - { - _mapAirBomberCollectionGeneric = new MapWithSetAirBomberGeneric(pictureBox.Width, pictureBox.Height, map); - } - else - { - _mapAirBomberCollectionGeneric = null; - } - } - - private void ButtonAddCar_Click(object sender, EventArgs e) + private void ButtonAddAirBomber_Click(object sender, EventArgs e) { if (_mapAirBomberCollectionGeneric == null) { return; } FormAirBomber form = new(); - if(form.ShowDialog() == DialogResult.OK) + if (form.ShowDialog() == DialogResult.OK) { DrawningObjectBomber airBomber = new(form.SelectedAirBomber); - if(_mapAirBomberCollectionGeneric + airBomber) + if (_mapAirBomberCollectionGeneric + airBomber == 1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapAirBomberCollectionGeneric.ShowSet(); @@ -66,7 +41,7 @@ namespace AirBomber } } - private void ButtonRemoveCar_Click(object sender, EventArgs e) + private void ButtonRemoveAirBomber_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { @@ -77,7 +52,7 @@ namespace AirBomber return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapAirBomberCollectionGeneric - pos) + if (_mapAirBomberCollectionGeneric - pos == 1) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapAirBomberCollectionGeneric.ShowSet(); @@ -106,6 +81,31 @@ namespace AirBomber pictureBox.Image = _mapAirBomberCollectionGeneric.ShowOnMap(); } + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + case "Вторая карта": + map = new SecondMap(); + break; + case "Третья карта": + map = new ThirdMap(); + break; + } + if (map != null) + { + _mapAirBomberCollectionGeneric = new MapWithSetAirBomberGeneric(pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapAirBomberCollectionGeneric = null; + } + } + private void ButtonMove_Click(object sender, EventArgs e) { if (_mapAirBomberCollectionGeneric == null) @@ -116,20 +116,20 @@ namespace AirBomber Direction dir = Direction.None; switch (name) { - case "butttonUp": + case "buttonUp": dir = Direction.Up; break; - case "butttonDown": + case "buttonDown": dir = Direction.Down; break; - case "butttonLeft": + case "buttonLeft": dir = Direction.Left; break; - case "butttonRight": + case "buttonRight": dir = Direction.Right; break; } pictureBox.Image = _mapAirBomberCollectionGeneric.MoveObject(dir); - } + } } } diff --git a/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs b/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs index f18f006..bafc36e 100644 --- a/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs @@ -13,7 +13,7 @@ namespace AirBomber private readonly int _pictureWidth; private readonly int _pictureHeight; private readonly int _placeSizeWidth = 210; - private readonly int _placeSizeHeight = 90; + private readonly int _placeSizeHeight = 120; private readonly SetAirBomberGeneric _setAirBomber; private readonly U _map; @@ -27,12 +27,12 @@ namespace AirBomber _map = map; } - public static bool operator +(MapWithSetAirBomberGeneric map, T airBomber) + public static int operator +(MapWithSetAirBomberGeneric map, T airBomber) { return map._setAirBomber.Insert(airBomber); } - public static bool operator -(MapWithSetAirBomberGeneric map, int position) + public static int operator -(MapWithSetAirBomberGeneric map, int position) { return map._setAirBomber.Remove(position); } @@ -42,7 +42,7 @@ namespace AirBomber Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); DrawBackground(gr); - DrawCars(gr); + DrawAirBomber(gr); return bmp; } @@ -97,22 +97,28 @@ namespace AirBomber private void DrawBackground(Graphics g) { - Pen pen = new(Color.Black, 3); + Pen pen = new(Color.DarkGreen, 3); + SolidBrush brush = new(Color.DarkGreen); for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i) { for (int j = 0; j < _pictureHeight / _placeSizeHeight; ++j) { g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + g.DrawPie(pen, new Rectangle(i * _placeSizeWidth - 25, j * _placeSizeHeight, 50, 120), -90, 180); + g.FillPie(brush, new Rectangle((i + 1) * _placeSizeWidth - _placeSizeHeight - 10, j * _placeSizeHeight, 50, 120), -90, 180); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight); } } - private void DrawCars(Graphics g) + private void DrawAirBomber(Graphics g) { for (int i = 0; i < _setAirBomber.Count; ++i) { - _setAirBomber.Get(i)?.DrawningObject(g); + if (_setAirBomber.Get(i) != null) + { + _setAirBomber.Get(i).SetObject((_pictureWidth / _placeSizeWidth - (i % (_pictureWidth / _placeSizeWidth)) - 1) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight, _pictureWidth, _pictureHeight); + _setAirBomber.Get(i).DrawningObject(g); + } } } } diff --git a/AirBomber/AirBomber/SetAirBomberGeneric.cs b/AirBomber/AirBomber/SetAirBomberGeneric.cs index 11d1258..cb25d74 100644 --- a/AirBomber/AirBomber/SetAirBomberGeneric.cs +++ b/AirBomber/AirBomber/SetAirBomberGeneric.cs @@ -18,24 +18,68 @@ namespace AirBomber _places = new T[count]; } - public bool Insert(T car) + public int Insert(T airBomber) { - return true; + return Insert(airBomber, 0); } - public bool Insert(T car, int position) + public int Insert(T airBomber, int position) { - _places[position] = car; - return true; + if (position < 0 || position >= Count) + { + return 0; + } + int emptyPos = -1; + if (_places[position] == null) + { + _places[position] = airBomber; + return 1; + } + else + { + for (int i = position + 1; i < Count; ++i) + { + if (_places[i] == null) + { + emptyPos = i; + break; + } + } + if (emptyPos != -1) + { + for (int i = emptyPos; i > position; --i) + { + _places[i] = _places[i - 1]; + } + } + } + if (emptyPos != -1) + { + _places[position] = airBomber; + return 1; + } + else + { + return 0; + } } - public bool Remove(int position) + public int Remove(int position) { - return true; + if (position < 0 || position >= Count) + { + return 0; + } + _places[position] = null; + return 1; } public T Get(int position) { + if (position < 0 || position >= Count) + { + return null; + } return _places[position]; } }