Добавлена новая форма

This commit is contained in:
Сергей Полевой 2022-10-02 16:55:05 +04:00
parent 5965acca14
commit ccd57fad9b
6 changed files with 291 additions and 226 deletions

View File

@ -1,88 +0,0 @@
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 Artilleries
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
private void SetData(DrawingArtillery artillery)
{
Random rnd = new();
artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
SpeedStatusLabel.Text = $"Скорость: {artillery.Artillery.Speed}";
WeightStatusLabel.Text = $"Вес: {artillery.Artillery.Weight}";
ColorStatusLabel.Text = $"Цвет: {artillery.Artillery.BodyColor.Name}";
pictureBoxArtilleries.Image = _abstractMap.CreateMap(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height, new DrawingObjectArtillery(artillery));
}
private void createAdvancedButton_Click(object sender, EventArgs e)
{
Random rnd = new();
var artillery = new DrawingAdvancedArtillery(
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)),
rnd.Next(0, 2) == 1, rnd.Next(0, 2) == 1
);
SetData(artillery);
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
var artillery = new DrawingArtillery(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetData(artillery);
}
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;
}
pictureBoxArtilleries.Image = _abstractMap?.MoveObject(dir);
}
private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Лесная карта":
_abstractMap = new ForestMap();
break;
}
}
}
}

View File

@ -1,6 +1,6 @@
namespace Artilleries namespace Artilleries
{ {
partial class FormMap partial class FormMapWithSetArtilleries
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@ -28,130 +28,89 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.createAdvancedButton = new System.Windows.Forms.Button(); this.toolsGroupBox = new System.Windows.Forms.GroupBox();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveArtillery = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddArtillery = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.pictureBoxArtilleries = new System.Windows.Forms.PictureBox(); this.pictureBoxArtilleries = new System.Windows.Forms.PictureBox();
this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolsGroupBox.SuspendLayout();
this.SpeedStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.WeightStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.ColorStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// createAdvancedButton // toolsGroupBox
// //
this.createAdvancedButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.toolsGroupBox.Controls.Add(this.buttonShowOnMap);
this.createAdvancedButton.Location = new System.Drawing.Point(105, 382); this.toolsGroupBox.Controls.Add(this.buttonShowStorage);
this.createAdvancedButton.Name = "createAdvancedButton"; this.toolsGroupBox.Controls.Add(this.buttonRemoveArtillery);
this.createAdvancedButton.Size = new System.Drawing.Size(95, 23); this.toolsGroupBox.Controls.Add(this.maskedTextBoxPosition);
this.createAdvancedButton.TabIndex = 15; this.toolsGroupBox.Controls.Add(this.buttonAddArtillery);
this.createAdvancedButton.Text = "Модификация"; this.toolsGroupBox.Controls.Add(this.comboBoxSelectorMap);
this.createAdvancedButton.UseVisualStyleBackColor = true; this.toolsGroupBox.Controls.Add(this.buttonRight);
this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_Click); this.toolsGroupBox.Controls.Add(this.buttonDown);
this.toolsGroupBox.Controls.Add(this.buttonUp);
this.toolsGroupBox.Controls.Add(this.buttonLeft);
this.toolsGroupBox.Dock = System.Windows.Forms.DockStyle.Right;
this.toolsGroupBox.Location = new System.Drawing.Point(600, 0);
this.toolsGroupBox.Name = "toolsGroupBox";
this.toolsGroupBox.Size = new System.Drawing.Size(200, 450);
this.toolsGroupBox.TabIndex = 0;
this.toolsGroupBox.TabStop = false;
this.toolsGroupBox.Text = "Инструменты";
// //
// buttonRight // buttonShowOnMap
// //
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonShowOnMap.Location = new System.Drawing.Point(13, 315);
this.buttonRight.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowRight; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonShowOnMap.Size = new System.Drawing.Size(175, 32);
this.buttonRight.Location = new System.Drawing.Point(579, 375); this.buttonShowOnMap.TabIndex = 24;
this.buttonRight.Name = "buttonRight"; this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonRight.TabIndex = 14; this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
// //
// buttonDown // buttonShowStorage
// //
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonShowStorage.Location = new System.Drawing.Point(13, 249);
this.buttonDown.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowDown; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonShowStorage.Size = new System.Drawing.Size(175, 32);
this.buttonDown.Location = new System.Drawing.Point(543, 375); this.buttonShowStorage.TabIndex = 23;
this.buttonDown.Name = "buttonDown"; this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonDown.TabIndex = 13; this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
// //
// buttonUp // buttonRemoveArtillery
// //
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRemoveArtillery.Location = new System.Drawing.Point(13, 177);
this.buttonUp.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowUp; this.buttonRemoveArtillery.Name = "buttonRemoveArtillery";
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonRemoveArtillery.Size = new System.Drawing.Size(175, 32);
this.buttonUp.Location = new System.Drawing.Point(543, 342); this.buttonRemoveArtillery.TabIndex = 22;
this.buttonUp.Name = "buttonUp"; this.buttonRemoveArtillery.Text = "Удалить артиллерию";
this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonRemoveArtillery.UseVisualStyleBackColor = true;
this.buttonUp.TabIndex = 12; this.buttonRemoveArtillery.Click += new System.EventHandler(this.buttonRemoveArtillery_Click);
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
// //
// buttonLeft // maskedTextBoxPosition
// //
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.maskedTextBoxPosition.Location = new System.Drawing.Point(13, 148);
this.buttonLeft.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowLeft; this.maskedTextBoxPosition.Mask = "00";
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.buttonLeft.Location = new System.Drawing.Point(509, 375); this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
this.buttonLeft.Name = "buttonLeft"; this.maskedTextBoxPosition.TabIndex = 21;
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 11;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
// //
// buttonCreate // buttonAddArtillery
// //
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonAddArtillery.Location = new System.Drawing.Point(13, 83);
this.buttonCreate.Location = new System.Drawing.Point(12, 382); this.buttonAddArtillery.Name = "buttonAddArtillery";
this.buttonCreate.Name = "buttonCreate"; this.buttonAddArtillery.Size = new System.Drawing.Size(175, 32);
this.buttonCreate.Size = new System.Drawing.Size(75, 23); this.buttonAddArtillery.TabIndex = 20;
this.buttonCreate.TabIndex = 10; this.buttonAddArtillery.Text = "Добавить артиллерию";
this.buttonCreate.Text = "Создать"; this.buttonAddArtillery.UseVisualStyleBackColor = true;
this.buttonCreate.UseVisualStyleBackColor = true; this.buttonAddArtillery.Click += new System.EventHandler(this.buttonAddArtillery_Click);
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// pictureBoxArtilleries
//
this.pictureBoxArtilleries.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxArtilleries.Location = new System.Drawing.Point(0, 0);
this.pictureBoxArtilleries.Name = "pictureBoxArtilleries";
this.pictureBoxArtilleries.Size = new System.Drawing.Size(624, 419);
this.pictureBoxArtilleries.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxArtilleries.TabIndex = 9;
this.pictureBoxArtilleries.TabStop = false;
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SpeedStatusLabel,
this.WeightStatusLabel,
this.ColorStatusLabel});
this.statusStrip1.Location = new System.Drawing.Point(0, 419);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(624, 22);
this.statusStrip1.TabIndex = 8;
//
// SpeedStatusLabel
//
this.SpeedStatusLabel.Name = "SpeedStatusLabel";
this.SpeedStatusLabel.Size = new System.Drawing.Size(62, 17);
this.SpeedStatusLabel.Text = "Скорость:";
//
// WeightStatusLabel
//
this.WeightStatusLabel.Name = "WeightStatusLabel";
this.WeightStatusLabel.Size = new System.Drawing.Size(29, 17);
this.WeightStatusLabel.Text = "Вес:";
//
// ColorStatusLabel
//
this.ColorStatusLabel.Name = "ColorStatusLabel";
this.ColorStatusLabel.Size = new System.Drawing.Size(36, 17);
this.ColorStatusLabel.Text = "Цвет:";
// //
// comboBoxSelectorMap // comboBoxSelectorMap
// //
@ -160,49 +119,98 @@
this.comboBoxSelectorMap.Items.AddRange(new object[] { this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта", "Простая карта",
"Лесная карта"}); "Лесная карта"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 22);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
this.comboBoxSelectorMap.TabIndex = 16; this.comboBoxSelectorMap.TabIndex = 19;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged);
// //
// FormMap // buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(124, 399);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 18;
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::SelfPropelledArtilleryUnit.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(88, 399);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 17;
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::SelfPropelledArtilleryUnit.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(88, 366);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 16;
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::SelfPropelledArtilleryUnit.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(54, 399);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 15;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
//
// pictureBoxArtilleries
//
this.pictureBoxArtilleries.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxArtilleries.Location = new System.Drawing.Point(0, 0);
this.pictureBoxArtilleries.Name = "pictureBoxArtilleries";
this.pictureBoxArtilleries.Size = new System.Drawing.Size(600, 450);
this.pictureBoxArtilleries.TabIndex = 1;
this.pictureBoxArtilleries.TabStop = false;
//
// FormMapWithSetArtilleries
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(624, 441); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.comboBoxSelectorMap);
this.Controls.Add(this.createAdvancedButton);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxArtilleries); this.Controls.Add(this.pictureBoxArtilleries);
this.Controls.Add(this.statusStrip1); this.Controls.Add(this.toolsGroupBox);
this.Name = "FormMap"; this.Name = "FormMapWithSetArtilleries";
this.Text = "Artillery"; this.Text = "Artillery";
this.toolsGroupBox.ResumeLayout(false);
this.toolsGroupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
#endregion #endregion
private Button createAdvancedButton; private GroupBox toolsGroupBox;
private PictureBox pictureBoxArtilleries;
private Button buttonRight; private Button buttonRight;
private Button buttonDown; private Button buttonDown;
private Button buttonUp; private Button buttonUp;
private Button buttonLeft; private Button buttonLeft;
private Button buttonCreate;
private PictureBox pictureBoxArtilleries;
private StatusStrip statusStrip1;
private ToolStripStatusLabel SpeedStatusLabel;
private ToolStripStatusLabel WeightStatusLabel;
private ToolStripStatusLabel ColorStatusLabel;
private ComboBox comboBoxSelectorMap; private ComboBox comboBoxSelectorMap;
private Button buttonShowOnMap;
private Button buttonShowStorage;
private Button buttonRemoveArtillery;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddArtillery;
} }
} }

View File

@ -0,0 +1,139 @@
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;
using static System.Windows.Forms.DataFormats;
namespace Artilleries
{
public partial class FormMapWithSetArtilleries : Form
{
private MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap>
_mapArtilleriesCollectionGeneric;
public FormMapWithSetArtilleries()
{
InitializeComponent();
}
private void comboBoxSelectorMap_SelectedIndexChanged(object sender,
EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Лесная карта":
map = new ForestMap();
break;
}
if (map != null)
{
_mapArtilleriesCollectionGeneric = new
MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap>(
pictureBoxArtilleries.Width, pictureBoxArtilleries.Height, map);
}
else
{
_mapArtilleriesCollectionGeneric = null;
}
}
private void buttonAddArtillery_Click(object sender, EventArgs e)
{
if (_mapArtilleriesCollectionGeneric == null)
{
return;
}
FormArtillery form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectArtillery car = new(form.SelectedArtillery);
if (_mapArtilleriesCollectionGeneric + car)
{
MessageBox.Show("Объект добавлен");
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void buttonRemoveArtillery_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapArtilleriesCollectionGeneric - pos)
{
MessageBox.Show("Объект удален");
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void buttonShowStorage_Click(object sender, EventArgs e)
{
if (_mapArtilleriesCollectionGeneric == null)
{
return;
}
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
}
private void buttonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapArtilleriesCollectionGeneric == null)
{
return;
}
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowOnMap();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_mapArtilleriesCollectionGeneric == null)
{
return;
}
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;
}
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.MoveObject(dir);
}
}
}

View File

@ -57,7 +57,4 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root> </root>

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Artilleries namespace Artilleries
{ {
internal class MapWithArtilleriesGeneric<T, U> internal class MapWithSetArtilleriesGeneric<T, U>
where T : class, IDrawingObject where T : class, IDrawingObject
where U : AbstractMap where U : AbstractMap
{ {
@ -17,7 +17,7 @@ namespace Artilleries
private readonly SetArtilleriesGeneric<T> _setArtilleries; private readonly SetArtilleriesGeneric<T> _setArtilleries;
private readonly U _map; private readonly U _map;
public MapWithArtilleriesGeneric(int picWidth, int picHeight, U map) public MapWithSetArtilleriesGeneric(int picWidth, int picHeight, U map)
{ {
int width = picWidth / _placeSizeWidth; int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight; int height = picHeight / _placeSizeHeight;
@ -27,16 +27,25 @@ namespace Artilleries
_map = map; _map = map;
} }
public static bool operator +(MapWithArtilleriesGeneric<T, U> map, T artillery) public static bool operator +(MapWithSetArtilleriesGeneric<T, U> map, T artillery)
{ {
return map._setArtilleries.Insert(artillery); // TODO return map._setArtilleries.Insert(artillery); // TODO
} }
public static bool operator -(MapWithArtilleriesGeneric<T, U> map, int position) public static bool operator -(MapWithSetArtilleriesGeneric<T, U> map, int position)
{ {
return map._setArtilleries.Remove(position); // TODO return map._setArtilleries.Remove(position); // TODO
} }
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawArtilleries(gr);
return bmp;
}
public Bitmap ShowOnMap() public Bitmap ShowOnMap()
{ {
Shaking(); Shaking();

View File

@ -6,7 +6,7 @@ namespace Artilleries
static void Main() static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormMap()); Application.Run(new FormMapWithSetArtilleries());
} }
} }
} }