Polevoy S.V Lab_work3 #3

Merged
eegov merged 11 commits from LabWork03 into LabWork02 2022-10-07 09:57:40 +04:00
12 changed files with 576 additions and 230 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Artilleries
{
internal enum Direction
public enum Direction
{
Up = 1,
Down = 2,

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Artilleries
{
internal class DrawingArtillery
public class DrawingArtillery
{
public EntityArtillery Artillery { protected set; get; }
protected float _startPosX;

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Artilleries
{
internal class EntityArtillery
public class EntityArtillery
{
public int Speed { get; private set; }
public float Weight { get; private set; }

View File

@ -39,6 +39,8 @@
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.createAdvancedButton = new System.Windows.Forms.Button();
this.selectArtilleryButton = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit();
this.SuspendLayout();
@ -147,11 +149,35 @@
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
//
// createAdvancedButton
//
this.createAdvancedButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.createAdvancedButton.Location = new System.Drawing.Point(106, 382);
this.createAdvancedButton.Name = "createAdvancedButton";
this.createAdvancedButton.Size = new System.Drawing.Size(113, 23);
this.createAdvancedButton.TabIndex = 7;
this.createAdvancedButton.Text = "Модифицировать";
this.createAdvancedButton.UseVisualStyleBackColor = true;
this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_Click);
//
// selectArtilleryButton
//
this.selectArtilleryButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.selectArtilleryButton.Location = new System.Drawing.Point(410, 379);
this.selectArtilleryButton.Name = "selectArtilleryButton";
this.selectArtilleryButton.Size = new System.Drawing.Size(75, 23);
this.selectArtilleryButton.TabIndex = 8;
this.selectArtilleryButton.Text = "Выбрать";
this.selectArtilleryButton.UseVisualStyleBackColor = true;
this.selectArtilleryButton.Click += new System.EventHandler(this.selectArtilleryButton_Click);
//
// FormArtillery
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(624, 441);
this.Controls.Add(this.selectArtilleryButton);
this.Controls.Add(this.createAdvancedButton);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp);
@ -183,5 +209,7 @@
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
private Button createAdvancedButton;
private Button selectArtilleryButton;
}
}

View File

@ -4,6 +4,8 @@ namespace Artilleries
{
private DrawingArtillery _artillery;
public DrawingArtillery SelectedArtillery { get; private set; }
public FormArtillery()
{
InitializeComponent();
@ -17,14 +19,53 @@ namespace Artilleries
pictureBoxArtilleries.Image = bmp;
}
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}";
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_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)));
_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}";
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;
}
_artillery = new DrawingArtillery(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData(_artillery);
Draw();
}
private void createAdvancedButton_Click(object sender, EventArgs e)
{
Random rnd = new();
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;
}
_artillery = new DrawingAdvancedArtillery(
rnd.Next(100, 300),
rnd.Next(1000, 2000),
color,
dopColor,
rnd.Next(0, 2) == 1, rnd.Next(0, 2) == 1
);
SetData(_artillery);
Draw();
}
@ -54,5 +95,11 @@ namespace Artilleries
_artillery?.ChangeBorders(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height);
Draw();
}
private void selectArtilleryButton_Click(object sender, EventArgs e)
{
SelectedArtillery = _artillery;
DialogResult = DialogResult.OK;
}
}
}

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
{
partial class FormMap
partial class FormMapWithSetArtilleries
{
/// <summary>
/// Required designer variable.
@ -28,130 +28,89 @@
/// </summary>
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.buttonDown = new System.Windows.Forms.Button();
this.buttonUp = 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.statusStrip1 = new System.Windows.Forms.StatusStrip();
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();
this.toolsGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// createAdvancedButton
// toolsGroupBox
//
this.createAdvancedButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.createAdvancedButton.Location = new System.Drawing.Point(105, 382);
this.createAdvancedButton.Name = "createAdvancedButton";
this.createAdvancedButton.Size = new System.Drawing.Size(95, 23);
this.createAdvancedButton.TabIndex = 15;
this.createAdvancedButton.Text = "Модификация";
this.createAdvancedButton.UseVisualStyleBackColor = true;
this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_Click);
this.toolsGroupBox.Controls.Add(this.buttonShowOnMap);
this.toolsGroupBox.Controls.Add(this.buttonShowStorage);
this.toolsGroupBox.Controls.Add(this.buttonRemoveArtillery);
this.toolsGroupBox.Controls.Add(this.maskedTextBoxPosition);
this.toolsGroupBox.Controls.Add(this.buttonAddArtillery);
this.toolsGroupBox.Controls.Add(this.comboBoxSelectorMap);
this.toolsGroupBox.Controls.Add(this.buttonRight);
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.buttonRight.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(579, 375);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 14;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
this.buttonShowOnMap.Location = new System.Drawing.Point(13, 315);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 32);
this.buttonShowOnMap.TabIndex = 24;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
//
// buttonDown
// buttonShowStorage
//
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(543, 375);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 13;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
this.buttonShowStorage.Location = new System.Drawing.Point(13, 249);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(175, 32);
this.buttonShowStorage.TabIndex = 23;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
//
// buttonUp
// buttonRemoveArtillery
//
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(543, 342);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 12;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
this.buttonRemoveArtillery.Location = new System.Drawing.Point(13, 177);
this.buttonRemoveArtillery.Name = "buttonRemoveArtillery";
this.buttonRemoveArtillery.Size = new System.Drawing.Size(175, 32);
this.buttonRemoveArtillery.TabIndex = 22;
this.buttonRemoveArtillery.Text = "Удалить артиллерию";
this.buttonRemoveArtillery.UseVisualStyleBackColor = true;
this.buttonRemoveArtillery.Click += new System.EventHandler(this.buttonRemoveArtillery_Click);
//
// buttonLeft
// maskedTextBoxPosition
//
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(509, 375);
this.buttonLeft.Name = "buttonLeft";
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);
this.maskedTextBoxPosition.Location = new System.Drawing.Point(13, 148);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
this.maskedTextBoxPosition.TabIndex = 21;
//
// buttonCreate
// buttonAddArtillery
//
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 = 10;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
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 = "Цвет:";
this.buttonAddArtillery.Location = new System.Drawing.Point(13, 83);
this.buttonAddArtillery.Name = "buttonAddArtillery";
this.buttonAddArtillery.Size = new System.Drawing.Size(175, 32);
this.buttonAddArtillery.TabIndex = 20;
this.buttonAddArtillery.Text = "Добавить артиллерию";
this.buttonAddArtillery.UseVisualStyleBackColor = true;
this.buttonAddArtillery.Click += new System.EventHandler(this.buttonAddArtillery_Click);
//
// comboBoxSelectorMap
//
@ -160,49 +119,98 @@
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.Size = new System.Drawing.Size(121, 23);
this.comboBoxSelectorMap.TabIndex = 16;
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
this.comboBoxSelectorMap.TabIndex = 19;
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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(624, 441);
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.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.pictureBoxArtilleries);
this.Controls.Add(this.statusStrip1);
this.Name = "FormMap";
this.Controls.Add(this.toolsGroupBox);
this.Name = "FormMapWithSetArtilleries";
this.Text = "Artillery";
this.toolsGroupBox.ResumeLayout(false);
this.toolsGroupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button createAdvancedButton;
private GroupBox toolsGroupBox;
private PictureBox pictureBoxArtilleries;
private Button buttonRight;
private Button buttonDown;
private Button buttonUp;
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 Button buttonShowOnMap;
private Button buttonShowStorage;
private Button buttonRemoveArtillery;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddArtillery;
}
}

View File

@ -0,0 +1,134 @@
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 != -1)
{
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 != null)
{
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">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</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>

View File

@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Artilleries
{
internal class MapWithSetArtilleriesGeneric<T, U>
where T : class, IDrawingObject
where U : AbstractMap
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeHeight = 90;
private readonly SetArtilleriesGeneric<T> _setArtilleries;
private readonly U _map;
public MapWithSetArtilleriesGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setArtilleries = new SetArtilleriesGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
public static int operator +(MapWithSetArtilleriesGeneric<T, U> map, T artillery)
{
return map._setArtilleries.Insert(artillery);
}
public static T operator -(MapWithSetArtilleriesGeneric<T, U> map, int position)
{
return map._setArtilleries.Remove(position);
}
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawArtilleries(gr);
return bmp;
}
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setArtilleries.Count; i++)
{
var car = _setArtilleries.Get(i);
if (car != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
}
}
return new(_pictureWidth, _pictureHeight);
}
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new(_pictureWidth, _pictureHeight);
}
private void Shaking()
{
int j = _setArtilleries.Count - 1;
for (int i = 0; i < _setArtilleries.Count; i++)
{
if (_setArtilleries.Get(i) == null)
{
for (; j > i; j--)
{
var car = _setArtilleries.Get(j);
if (car != null)
{
_setArtilleries.Insert(car, i);
_setArtilleries.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
Brush boxBrush = new SolidBrush(Color.DarkGreen);
Pen thinPen = new Pen(Color.Black, 2);
Brush flagBrush = new SolidBrush(Color.Red);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
g.FillRectangle(boxBrush, i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5, _placeSizeWidth / 3 - 5, _placeSizeHeight / 3 - 5);
g.DrawLine(thinPen, i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 + _placeSizeHeight / 3 - 10);
g.DrawLine(thinPen, i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 + _placeSizeHeight / 3 - 10, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5);
g.FillRectangle(flagBrush, i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight * 5 / 8 - 5, _placeSizeWidth / 5, _placeSizeHeight / 5);
g.DrawLine(thinPen, i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight - 5, i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight * 5 / 8 - 5);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
private void DrawArtilleries(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _setArtilleries.Count; i++)
{
var artillery = _setArtilleries.Get(i);
if (artillery != null)
{
artillery.SetObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
artillery.DrawingObject(g);
}
}
}
}
}

View File

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

View File

@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Artilleries
{
internal class SetArtilleriesGeneric<T>
where T : class
{
private readonly T[] _places;
public int Count => _places.Length;
public SetArtilleriesGeneric(int count)
{
_places = new T[count];
}
public int Insert(T artillery)
{
return Insert(artillery, 0);
}
public int Insert(T artillery, int position)
{
if (position < 0 || position >= Count)
{
return -1;
}
if (_places[position] == null)
{
_places[position] = artillery;
return position;
}
int firstNull = -1;
for (int i = position + 1; i < Count; i++)
{
if (_places[i] == null)
{
firstNull = i;
break;
}
}
if (firstNull == -1)
{
return -1;
}
for (int i = firstNull; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = artillery;
return position;
}
public T Remove(int position)
{
if (position < 0 || position >= Count)
{
return null;
}
var result = _places[position];
_places[position] = null;
return result;
}
public T Get(int position)
{
if (position < 0 || position >= Count)
{
return null;
}
return _places[position];
}
}
}