Параметрические классы и форма для них

This commit is contained in:
ityurner02@mail.ru 2022-10-01 15:59:56 +04:00
parent ee29601886
commit 2cea7ab205
13 changed files with 664 additions and 320 deletions

View File

@ -9,7 +9,7 @@ namespace AntiAircraftGun
/// <summary> /// <summary>
/// Направление перемещения /// Направление перемещения
/// </summary> /// </summary>
internal enum Direction public enum Direction
{ {
None = 0, None = 0,
Up = 1, Up = 1,

View File

@ -9,7 +9,7 @@ namespace AntiAircraftGun
/// <summary> /// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary> /// </summary>
internal class DrawingAntiAircraftGun public class DrawingAntiAircraftGun
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AntiAircraftGun namespace AntiAircraftGun
{ {
internal class EntityAntiAircraftGun public class EntityAntiAircraftGun
{ {
/// <summary> /// <summary>
/// Скорость /// Скорость

View File

@ -39,6 +39,7 @@
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.buttonCreareModif = new System.Windows.Forms.Button(); this.buttonCreareModif = new System.Windows.Forms.Button();
this.buttonSelect = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit();
this.statusStrip.SuspendLayout(); this.statusStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -154,11 +155,23 @@
this.buttonCreareModif.UseVisualStyleBackColor = true; this.buttonCreareModif.UseVisualStyleBackColor = true;
this.buttonCreareModif.Click += new System.EventHandler(this.ButtonCreareModif_Click); this.buttonCreareModif.Click += new System.EventHandler(this.ButtonCreareModif_Click);
// //
// buttonSelect
//
this.buttonSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonSelect.Location = new System.Drawing.Point(578, 379);
this.buttonSelect.Name = "buttonSelect";
this.buttonSelect.Size = new System.Drawing.Size(94, 29);
this.buttonSelect.TabIndex = 8;
this.buttonSelect.Text = "Выбрать";
this.buttonSelect.UseVisualStyleBackColor = true;
this.buttonSelect.Click += new System.EventHandler(this.ButtonSelect_Click);
//
// FormAntiAircraftGun // FormAntiAircraftGun
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 451); this.ClientSize = new System.Drawing.Size(800, 451);
this.Controls.Add(this.buttonSelect);
this.Controls.Add(this.buttonCreareModif); this.Controls.Add(this.buttonCreareModif);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonRight);
@ -192,5 +205,6 @@
private Button buttonRight; private Button buttonRight;
private Button buttonDown; private Button buttonDown;
private Button buttonCreareModif; private Button buttonCreareModif;
private Button buttonSelect;
} }
} }

View File

@ -5,6 +5,10 @@ namespace AntiAircraftGun
public partial class FormAntiAircraftGun : Form public partial class FormAntiAircraftGun : Form
{ {
private DrawingAntiAircraftGun _antiAircrafGun; private DrawingAntiAircraftGun _antiAircrafGun;
/// <summary>
/// Âûáðàííîå îáúåêò
/// </summary>
public DrawingAntiAircraftGun SelectedAntiAircraftGun { get; private set; }
public FormAntiAircraftGun() public FormAntiAircraftGun()
{ {
@ -99,5 +103,11 @@ namespace AntiAircraftGun
SetData(); SetData();
Draw(); Draw();
} }
private void ButtonSelect_Click(object sender, EventArgs e)
{
SelectedAntiAircraftGun = _antiAircrafGun;
DialogResult = DialogResult.OK;
}
} }
} }

View File

@ -1,210 +0,0 @@
namespace AntiAircraftGun
{
partial class FormMap
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBoxAntiAircraftGun = new System.Windows.Forms.PictureBox();
this.statusStrip = 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.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonCreareModif = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxAntiAircraftGun
//
this.pictureBoxAntiAircraftGun.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxAntiAircraftGun.Location = new System.Drawing.Point(0, 0);
this.pictureBoxAntiAircraftGun.Name = "pictureBoxAntiAircraftGun";
this.pictureBoxAntiAircraftGun.Size = new System.Drawing.Size(800, 425);
this.pictureBoxAntiAircraftGun.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxAntiAircraftGun.TabIndex = 0;
this.pictureBoxAntiAircraftGun.TabStop = false;
//
// statusStrip
//
this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip.Location = new System.Drawing.Point(0, 425);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 26);
this.statusStrip.TabIndex = 1;
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(73, 20);
this.toolStripStatusLabelSpeed.Text = "Скорость";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(33, 20);
this.toolStripStatusLabelWeight.Text = "Вес";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(42, 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(11, 381);
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);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(725, 341);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 29);
this.buttonUp.TabIndex = 3;
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::AntiAircraftGun.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(688, 379);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 29);
this.buttonLeft.TabIndex = 4;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.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::AntiAircraftGun.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(760, 379);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 29);
this.buttonRight.TabIndex = 5;
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::AntiAircraftGun.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(725, 379);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 29);
this.buttonDown.TabIndex = 6;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonCreareModif
//
this.buttonCreareModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreareModif.Location = new System.Drawing.Point(111, 381);
this.buttonCreareModif.Name = "buttonCreareModif";
this.buttonCreareModif.Size = new System.Drawing.Size(125, 29);
this.buttonCreareModif.TabIndex = 7;
this.buttonCreareModif.Text = "Модификация";
this.buttonCreareModif.UseVisualStyleBackColor = true;
this.buttonCreareModif.Click += new System.EventHandler(this.ButtonCreareModif_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Простая карта 2"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(11, 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(800, 451);
this.Controls.Add(this.comboBoxSelectorMap);
this.Controls.Add(this.buttonCreareModif);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxAntiAircraftGun);
this.Controls.Add(this.statusStrip);
this.MinimumSize = new System.Drawing.Size(50, 80);
this.Name = "FormMap";
this.Text = "Карта";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxAntiAircraftGun;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate;
private Button buttonUp;
private Button buttonLeft;
private Button buttonRight;
private Button buttonDown;
private Button buttonCreareModif;
private ComboBox comboBoxSelectorMap;
}
}

View File

@ -1,103 +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 AntiAircraftGun
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
/// <summary>
/// Заполнение информации по объекту
/// </summary>
/// <param name="car"></param>
private void SetData(DrawingAntiAircraftGun antiAircraftGun)
{
toolStripStatusLabelSpeed.Text = $"Скорость: {antiAircraftGun.AntiAircraftGun.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {antiAircraftGun.AntiAircraftGun.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {antiAircraftGun.AntiAircraftGun.BodyColor.Name}";
pictureBoxAntiAircraftGun.Image = _abstractMap.CreateMap(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height,
new DrawingObjectAntiAircraftGun(antiAircraftGun));
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
var antiAircraftGun = new DrawingAntiAircraftGun(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetData(antiAircraftGun);
}
/// <summary>
/// Определение направления
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
pictureBoxAntiAircraftGun.Image = _abstractMap?.MoveObject(dir);
}
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreareModif_Click(object sender, EventArgs e)
{
Random rnd = new();
var antiAircraftGun = new DrawingUpdateAntiAircraftGun(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)));
SetData(antiAircraftGun);
}
/// <summary>
/// Смена карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Простая карта 2":
_abstractMap = new SimpleMap2();
break;
}
}
}
}

View File

@ -0,0 +1,216 @@
namespace AntiAircraftGun
{
partial class FormMapWithSetAntiAircraftGuns
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox = new System.Windows.Forms.GroupBox();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveAntiAircraftGun = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddAntiAircraftGun = 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();
this.buttonUp = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBox
//
this.groupBox.Controls.Add(this.buttonShowOnMap);
this.groupBox.Controls.Add(this.buttonShowStorage);
this.groupBox.Controls.Add(this.buttonRemoveAntiAircraftGun);
this.groupBox.Controls.Add(this.maskedTextBoxPosition);
this.groupBox.Controls.Add(this.buttonAddAntiAircraftGun);
this.groupBox.Controls.Add(this.comboBoxSelectorMap);
this.groupBox.Controls.Add(this.buttonDown);
this.groupBox.Controls.Add(this.buttonRight);
this.groupBox.Controls.Add(this.buttonLeft);
this.groupBox.Controls.Add(this.buttonUp);
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox.Location = new System.Drawing.Point(562, 0);
this.groupBox.Name = "groupBox";
this.groupBox.Size = new System.Drawing.Size(238, 450);
this.groupBox.TabIndex = 0;
this.groupBox.TabStop = false;
this.groupBox.Text = "Инструменты";
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(34, 309);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(194, 29);
this.buttonShowOnMap.TabIndex = 16;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(34, 245);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(194, 29);
this.buttonShowStorage.TabIndex = 15;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonRemoveAntiAircraftGun
//
this.buttonRemoveAntiAircraftGun.Location = new System.Drawing.Point(34, 177);
this.buttonRemoveAntiAircraftGun.Name = "buttonRemoveAntiAircraftGun";
this.buttonRemoveAntiAircraftGun.Size = new System.Drawing.Size(194, 29);
this.buttonRemoveAntiAircraftGun.TabIndex = 14;
this.buttonRemoveAntiAircraftGun.Text = "Удалить орудие";
this.buttonRemoveAntiAircraftGun.UseVisualStyleBackColor = true;
this.buttonRemoveAntiAircraftGun.Click += new System.EventHandler(this.ButtonRemoveAntiAircraftGun_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(34, 144);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(194, 27);
this.maskedTextBoxPosition.TabIndex = 13;
//
// buttonAddAntiAircraftGun
//
this.buttonAddAntiAircraftGun.Location = new System.Drawing.Point(34, 95);
this.buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun";
this.buttonAddAntiAircraftGun.Size = new System.Drawing.Size(194, 29);
this.buttonAddAntiAircraftGun.TabIndex = 12;
this.buttonAddAntiAircraftGun.Text = "Добавить орудие";
this.buttonAddAntiAircraftGun.UseVisualStyleBackColor = true;
this.buttonAddAntiAircraftGun.Click += new System.EventHandler(this.ButtonAddAntiAircraftGun_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Простая карта 2"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(34, 40);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(194, 28);
this.comboBoxSelectorMap.TabIndex = 11;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AntiAircraftGun.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(120, 408);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 29);
this.buttonDown.TabIndex = 10;
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::AntiAircraftGun.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(155, 408);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 29);
this.buttonRight.TabIndex = 9;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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::AntiAircraftGun.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(83, 408);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 29);
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::AntiAircraftGun.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(120, 370);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 29);
this.buttonUp.TabIndex = 7;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(562, 450);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetAntiAircraftGuns
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox);
this.Name = "FormMapWithSetAntiAircraftGuns";
this.Text = "FormMapWithSetAntiAircraftGuns";
this.groupBox.ResumeLayout(false);
this.groupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBox;
private PictureBox pictureBox;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private Button buttonUp;
private Button buttonShowOnMap;
private Button buttonShowStorage;
private Button buttonRemoveAntiAircraftGun;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddAntiAircraftGun;
private ComboBox comboBoxSelectorMap;
}
}

View File

@ -0,0 +1,165 @@
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 AntiAircraftGun
{
public partial class FormMapWithSetAntiAircraftGuns : Form
{
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap> _mapAntiAircraftGunsCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetAntiAircraftGuns()
{
InitializeComponent();
}
/// <summary>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Простая карта 2":
map = new SimpleMap2();
break;
}
if (map != null)
{
_mapAntiAircraftGunsCollectionGeneric = new MapWithSetAntiAircraftGunsGeneric<DrawingObjectAntiAircraftGun, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapAntiAircraftGunsCollectionGeneric = null;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
///
private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e)
{
if (_mapAntiAircraftGunsCollectionGeneric == null)
{
return;
}
FormAntiAircraftGun form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectAntiAircraftGun antiAircraftGun = new(form.SelectedAntiAircraftGun);
if (_mapAntiAircraftGunsCollectionGeneric + antiAircraftGun)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveAntiAircraftGun_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 (_mapAntiAircraftGunsCollectionGeneric - pos)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapAntiAircraftGunsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapAntiAircraftGunsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapAntiAircraftGunsCollectionGeneric == 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;
}
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.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="statusStrip.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

@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun
{
/// <summary>
/// Карта с набром объектов под нее
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class MapWithSetAntiAircraftGunsGeneric<T, U>
where T : class, IDrawingObject
where U : AbstractMap
{
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetAntiAircraftGunsGeneric<T> _setAntiAircraftGuns;
/// <summary>
/// Карта
/// </summary>
private readonly U _map;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="map"></param>
public MapWithSetAntiAircraftGunsGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setAntiAircraftGuns = new SetAntiAircraftGunsGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="map"></param>
/// <param name="car"></param>
/// <returns></returns>
public static bool operator +(MapWithSetAntiAircraftGunsGeneric<T, U> map, T antiAircraftGuns)
{
return map._setAntiAircraftGuns.Insert(antiAircraftGuns);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="map"></param>
/// <param name="position"></param>
/// <returns></returns>
public static bool operator -(MapWithSetAntiAircraftGunsGeneric<T, U> map, int position)
{
return map._setAntiAircraftGuns.Remove(position);
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawCars(gr);
return bmp;
}
/// <summary>
/// Просмотр объекта на карте
/// </summary>
/// <returns></returns>
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setAntiAircraftGuns.Count; i++)
{
var car = _setAntiAircraftGuns.Get(i);
if (car != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
}
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// Перемещение объекта по крате
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary>
private void Shaking()
{
int j = _setAntiAircraftGuns.Count - 1;
for (int i = 0; i < _setAntiAircraftGuns.Count; i++)
{
if (_setAntiAircraftGuns.Get(i) == null)
{
for (; j > i; j--)
{
var car = _setAntiAircraftGuns.Get(j);
if (car != null)
{
_setAntiAircraftGuns.Insert(car, i);
_setAntiAircraftGuns.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
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.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawCars(Graphics g)
{
for (int i = 0; i < _setAntiAircraftGuns.Count; i++)
{
// TODO установка позиции
_setAntiAircraftGuns.Get(i)?.DrawingObjectAntiAircraftGun(g);
}
}
}
}

View File

@ -11,7 +11,7 @@ namespace AntiAircraftGun
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormMap()); Application.Run(new FormMapWithSetAntiAircraftGuns());
} }
} }
} }

View File

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun
{
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T"></typeparam>
internal class SetAntiAircraftGunsGeneric<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private readonly T[] _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Length;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetAntiAircraftGunsGeneric(int count)
{
_places = new T[count];
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <returns></returns>
public bool Insert(T antiAircraftGun)
{
// TODO вставка в начало набора
return true;
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="antiAircraftGun">Добавляемое орудие</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T antiAircraftGun, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции
_places[position] = antiAircraftGun;
return true;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присовив элементу массива значение null
return true;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Get(int position)
{
// TODO проверка позиции
return _places[position];
}
}
}