2 Commits

12 changed files with 157 additions and 1068 deletions

View File

@@ -53,11 +53,7 @@ namespace ArmoredVehicle
_ArmoredVehicleHeight = ArmoredVehicleHeight + 50;
_ArmoredVehicleWidth = ArmoredVehicleWidth + 150;
}
public DrawingArmoredVehicle Copy(int? speed = null, float? weight = null, Color? bodyColor = null)
{
return new DrawingArmoredVehicle(speed ?? ArmoredVehicle.Speed, weight ?? ArmoredVehicle.Weight, bodyColor ?? ArmoredVehicle.BodyColor);
}
/// <summary>
/// Установка позиции

View File

@@ -8,19 +8,12 @@ namespace ArmoredVehicle
{
internal class DrawingTank : DrawingArmoredVehicle
{
public DrawingTank(int speed, float weight, Color bodyColor, Color dopColor, bool machineGun, bool tower)
public DrawingTank(int speed, float weight, Color bodyColor, Color dopColor, bool machineGun, bool tower, bool gun)
: base(speed, weight, bodyColor, 200, 60)
{
ArmoredVehicle = new TankEnity(speed, weight, bodyColor, dopColor, machineGun, tower);
}
public DrawingTank Copy(int? speed = null, float? weight = null, Color? bodyColor = null,
Color? dopColor = null, bool? machineGun = null, bool? tower = null)
{
var e = (TankEnity)ArmoredVehicle;
return new DrawingTank(speed ?? e.Speed, weight ?? e.Weight, bodyColor ?? e.BodyColor, dopColor ?? e.DopColor,
machineGun ?? e.MachineGun, tower ?? e.Tower);
ArmoredVehicle = new TankEnity(speed, weight, bodyColor, dopColor, machineGun, tower, gun);
}
public override void DrawTransport(Graphics g)
{

View File

@@ -1,389 +0,0 @@
namespace ArmoredVehicle
{
partial class FormMachineConfig
{
/// <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.groupBoxConfig = new System.Windows.Forms.GroupBox();
this.labelHard = new System.Windows.Forms.Label();
this.labelSimple = new System.Windows.Forms.Label();
this.checkBoxMachineGun = new System.Windows.Forms.CheckBox();
this.checkBoxTower = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelWeight = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelPale = new System.Windows.Forms.Panel();
this.panelOrange = new System.Windows.Forms.Panel();
this.panelLightGreen = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.panelIndigo = new System.Windows.Forms.Panel();
this.panelCoral = new System.Windows.Forms.Panel();
this.panelObject = new System.Windows.Forms.Panel();
this.labelDopColor = new System.Windows.Forms.Label();
this.labelColor = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxConfig.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.groupBoxColors.SuspendLayout();
this.panelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.SuspendLayout();
//
// groupBoxConfig
//
this.groupBoxConfig.Controls.Add(this.labelHard);
this.groupBoxConfig.Controls.Add(this.labelSimple);
this.groupBoxConfig.Controls.Add(this.checkBoxMachineGun);
this.groupBoxConfig.Controls.Add(this.checkBoxTower);
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
this.groupBoxConfig.Controls.Add(this.labelWeight);
this.groupBoxConfig.Controls.Add(this.labelSpeed);
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
this.groupBoxConfig.Location = new System.Drawing.Point(8, 14);
this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Size = new System.Drawing.Size(667, 440);
this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Параметры";
//
// labelHard
//
this.labelHard.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelHard.Location = new System.Drawing.Point(507, 318);
this.labelHard.Name = "labelHard";
this.labelHard.Size = new System.Drawing.Size(134, 38);
this.labelHard.TabIndex = 9;
this.labelHard.Text = "Продвинутый";
this.labelHard.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelHard.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
//
// labelSimple
//
this.labelSimple.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimple.Location = new System.Drawing.Point(292, 318);
this.labelSimple.Name = "labelSimple";
this.labelSimple.Size = new System.Drawing.Size(121, 38);
this.labelSimple.TabIndex = 8;
this.labelSimple.Text = "Простой";
this.labelSimple.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelObject_MouseDown);
//
// checkBoxMachineGun
//
this.checkBoxMachineGun.AutoSize = true;
this.checkBoxMachineGun.Location = new System.Drawing.Point(5, 235);
this.checkBoxMachineGun.Name = "checkBoxMachineGun";
this.checkBoxMachineGun.Size = new System.Drawing.Size(260, 29);
this.checkBoxMachineGun.TabIndex = 6;
this.checkBoxMachineGun.Text = "Признак наличия пулемета";
this.checkBoxMachineGun.UseVisualStyleBackColor = true;
//
// checkBoxTower
//
this.checkBoxTower.AutoSize = true;
this.checkBoxTower.Location = new System.Drawing.Point(5, 202);
this.checkBoxTower.Name = "checkBoxTower";
this.checkBoxTower.Size = new System.Drawing.Size(238, 29);
this.checkBoxTower.TabIndex = 5;
this.checkBoxTower.Text = "Признак наличия башни";
this.checkBoxTower.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(96, 135);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
100000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(106, 31);
this.numericUpDownWeight.TabIndex = 4;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(97, 94);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
100000,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(105, 31);
this.numericUpDownSpeed.TabIndex = 3;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(6, 134);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(39, 25);
this.labelWeight.TabIndex = 2;
this.labelWeight.Text = "Вес";
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(6, 91);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(89, 25);
this.labelSpeed.TabIndex = 1;
this.labelSpeed.Text = "Скорость";
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.panelPale);
this.groupBoxColors.Controls.Add(this.panelOrange);
this.groupBoxColors.Controls.Add(this.panelLightGreen);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Controls.Add(this.panelIndigo);
this.groupBoxColors.Controls.Add(this.panelCoral);
this.groupBoxColors.Location = new System.Drawing.Point(292, 91);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(349, 205);
this.groupBoxColors.TabIndex = 0;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
//
// panelPale
//
this.panelPale.BackColor = System.Drawing.Color.PaleTurquoise;
this.panelPale.Location = new System.Drawing.Point(183, 111);
this.panelPale.Name = "panelPale";
this.panelPale.Size = new System.Drawing.Size(64, 57);
this.panelPale.TabIndex = 1;
this.panelPale.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelOrange
//
this.panelOrange.BackColor = System.Drawing.Color.Orange;
this.panelOrange.Location = new System.Drawing.Point(101, 111);
this.panelOrange.Name = "panelOrange";
this.panelOrange.Size = new System.Drawing.Size(64, 57);
this.panelOrange.TabIndex = 1;
this.panelOrange.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelLightGreen
//
this.panelLightGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
this.panelLightGreen.Location = new System.Drawing.Point(19, 111);
this.panelLightGreen.Name = "panelLightGreen";
this.panelLightGreen.Size = new System.Drawing.Size(64, 57);
this.panelLightGreen.TabIndex = 1;
this.panelLightGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(262, 31);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(64, 57);
this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(183, 30);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(64, 57);
this.panelBlue.TabIndex = 1;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(101, 31);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(64, 57);
this.panelRed.TabIndex = 1;
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelIndigo
//
this.panelIndigo.BackColor = System.Drawing.Color.Indigo;
this.panelIndigo.Location = new System.Drawing.Point(262, 111);
this.panelIndigo.Name = "panelIndigo";
this.panelIndigo.Size = new System.Drawing.Size(64, 57);
this.panelIndigo.TabIndex = 1;
this.panelIndigo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelCoral
//
this.panelCoral.BackColor = System.Drawing.Color.Coral;
this.panelCoral.Location = new System.Drawing.Point(19, 31);
this.panelCoral.Name = "panelCoral";
this.panelCoral.Size = new System.Drawing.Size(64, 57);
this.panelCoral.TabIndex = 0;
this.panelCoral.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown);
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.labelDopColor);
this.panelObject.Controls.Add(this.labelColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(695, 27);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(475, 399);
this.panelObject.TabIndex = 1;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter);
//
// labelDopColor
//
this.labelDopColor.AllowDrop = true;
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelDopColor.Location = new System.Drawing.Point(303, 14);
this.labelDopColor.Name = "labelDopColor";
this.labelDopColor.Size = new System.Drawing.Size(121, 38);
this.labelDopColor.TabIndex = 10;
this.labelDopColor.Text = "Доп. цвет";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelDopColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelDopColor_DragEnter);
//
// labelColor
//
this.labelColor.AllowDrop = true;
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelColor.Location = new System.Drawing.Point(78, 14);
this.labelColor.Name = "labelColor";
this.labelColor.Size = new System.Drawing.Size(121, 38);
this.labelColor.TabIndex = 9;
this.labelColor.Text = "Цвет";
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop);
this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter);
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(17, 59);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(441, 321);
this.pictureBoxObject.TabIndex = 0;
this.pictureBoxObject.TabStop = false;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(695, 432);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(138, 34);
this.buttonAdd.TabIndex = 2;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(862, 433);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(133, 34);
this.buttonCancel.TabIndex = 3;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// FormMachineConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1182, 478);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxConfig);
this.Name = "FormMachineConfig";
this.Text = "Создание объектов";
this.groupBoxConfig.ResumeLayout(false);
this.groupBoxConfig.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.groupBoxColors.ResumeLayout(false);
this.panelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private Label labelWeight;
private Label labelSpeed;
private GroupBox groupBoxColors;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private CheckBox checkBoxMachineGun;
private CheckBox checkBoxTower;
private Label labelHard;
private Label labelSimple;
private Panel panelPale;
private Panel panelOrange;
private Panel panelLightGreen;
private Panel panelGreen;
private Panel panelBlue;
private Panel panelRed;
private Panel panelIndigo;
private Panel panelCoral;
private Panel panelObject;
private Label labelDopColor;
private Label labelColor;
private PictureBox pictureBoxObject;
private Button buttonAdd;
private Button buttonCancel;
}
}

View File

@@ -1,204 +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 ArmoredVehicle
{
public partial class FormMachineConfig : Form
{
/// <summary>
/// Переменная-выбранная машина
/// </summary>
DrawingArmoredVehicle _machine = null;
/// <summary>
/// Событие
/// </summary>
public event Action<DrawingArmoredVehicle> EventAddMachine;
/// <summary>
/// Конструктор
/// </summary>
public FormMachineConfig()
{
InitializeComponent();
panelCoral.MouseDown += panelColor_MouseDown;
panelRed.MouseDown += panelColor_MouseDown;
panelBlue.MouseDown += panelColor_MouseDown;
panelOrange.MouseDown += panelColor_MouseDown;
panelPale.MouseDown += panelColor_MouseDown;
panelGreen.MouseDown += panelColor_MouseDown;
panelIndigo.MouseDown += panelColor_MouseDown;
panelLightGreen.MouseDown += panelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
/// <summary>
/// Отрисовать машину
/// </summary>
private void DrawMachine()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_machine?.SetPosition(5, 5, pictureBoxObject.Width,
pictureBoxObject.Height);
_machine?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev"></param>
public void AddEvent(Action<DrawingArmoredVehicle> ev)
{
if(EventAddMachine == null)
{
EventAddMachine = new (ev);
}
else
{
EventAddMachine += ev;
}
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "labelSimple":
_machine = new DrawingArmoredVehicle((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White);
break;
case "labelHard":
_machine = new DrawingTank((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxMachineGun.Checked, checkBoxTower.Checked);
break;
}
DrawMachine();
}
/// <summary>
/// Отправляем цвет с панели
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Принимаем основной цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
if (_machine is DrawingTank)
{
_machine = ((DrawingTank)_machine).Copy(bodyColor: color);
}
else if (_machine is DrawingArmoredVehicle)
{
_machine = _machine.Copy(bodyColor: color);
}
DrawMachine();
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelDopColor_DragEnter(object sender, DragEventArgs e)
{
if(_machine is DrawingTank)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
/// <summary>
/// Принимаем дополнительный цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelDopColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
var machine = _machine as DrawingTank;
if (machine != null)
{
_machine = machine.Copy(dopColor: color);
}
DrawMachine();
}
/// <summary>
/// Добавление машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAdd_Click(object sender, EventArgs e)
{
EventAddMachine?.Invoke(_machine);
Close();
}
}
}

View File

@@ -1,60 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -30,12 +30,6 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMapWithSetMachine));
this.groupBoxInstruments = new System.Windows.Forms.GroupBox();
this.groupBoxMap = new System.Windows.Forms.GroupBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonAddMap = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.ButtonDown = new System.Windows.Forms.Button();
this.ButtonRight = new System.Windows.Forms.Button();
@@ -45,15 +39,14 @@
this.buttonStore = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.comboBoxMap = new System.Windows.Forms.ComboBox();
this.pictureBoxImage = new System.Windows.Forms.PictureBox();
this.groupBoxInstruments.SuspendLayout();
this.groupBoxMap.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxImage)).BeginInit();
this.SuspendLayout();
//
// groupBoxInstruments
//
this.groupBoxInstruments.Controls.Add(this.groupBoxMap);
this.groupBoxInstruments.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxInstruments.Controls.Add(this.ButtonDown);
this.groupBoxInstruments.Controls.Add(this.ButtonRight);
@@ -63,84 +56,18 @@
this.groupBoxInstruments.Controls.Add(this.buttonStore);
this.groupBoxInstruments.Controls.Add(this.buttonDelete);
this.groupBoxInstruments.Controls.Add(this.buttonAdd);
this.groupBoxInstruments.Controls.Add(this.comboBoxMap);
this.groupBoxInstruments.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxInstruments.Location = new System.Drawing.Point(964, 0);
this.groupBoxInstruments.Location = new System.Drawing.Point(728, 0);
this.groupBoxInstruments.Name = "groupBoxInstruments";
this.groupBoxInstruments.Size = new System.Drawing.Size(300, 910);
this.groupBoxInstruments.Size = new System.Drawing.Size(300, 644);
this.groupBoxInstruments.TabIndex = 0;
this.groupBoxInstruments.TabStop = false;
this.groupBoxInstruments.Text = "Инструменты";
//
// groupBoxMap
//
this.groupBoxMap.Controls.Add(this.buttonDeleteMap);
this.groupBoxMap.Controls.Add(this.listBoxMaps);
this.groupBoxMap.Controls.Add(this.buttonAddMap);
this.groupBoxMap.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMap.Controls.Add(this.textBoxNewMapName);
this.groupBoxMap.Location = new System.Drawing.Point(13, 30);
this.groupBoxMap.Name = "groupBoxMap";
this.groupBoxMap.Size = new System.Drawing.Size(267, 408);
this.groupBoxMap.TabIndex = 19;
this.groupBoxMap.TabStop = false;
this.groupBoxMap.Text = "Карты";
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(5, 330);
this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(250, 58);
this.buttonDeleteMap.TabIndex = 6;
this.buttonDeleteMap.Text = "Удалить карту";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 25;
this.listBoxMaps.Location = new System.Drawing.Point(5, 189);
this.listBoxMaps.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(248, 129);
this.listBoxMaps.TabIndex = 5;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(5, 121);
this.buttonAddMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(250, 58);
this.buttonAddMap.TabIndex = 4;
this.buttonAddMap.Text = "Добавить карту";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(5, 73);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(248, 33);
this.comboBoxSelectorMap.TabIndex = 3;
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(5, 32);
this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(248, 31);
this.textBoxNewMapName.TabIndex = 1;
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 506);
this.maskedTextBoxPosition.Location = new System.Drawing.Point(18, 179);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(270, 31);
@@ -151,7 +78,7 @@
this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("ButtonDown.BackgroundImage")));
this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ButtonDown.Location = new System.Drawing.Point(129, 823);
this.ButtonDown.Location = new System.Drawing.Point(139, 555);
this.ButtonDown.Name = "ButtonDown";
this.ButtonDown.Size = new System.Drawing.Size(40, 36);
this.ButtonDown.TabIndex = 17;
@@ -163,7 +90,7 @@
this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("ButtonRight.BackgroundImage")));
this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ButtonRight.Location = new System.Drawing.Point(172, 776);
this.ButtonRight.Location = new System.Drawing.Point(182, 508);
this.ButtonRight.Name = "ButtonRight";
this.ButtonRight.Size = new System.Drawing.Size(40, 36);
this.ButtonRight.TabIndex = 16;
@@ -175,7 +102,7 @@
this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("ButtonLeft.BackgroundImage")));
this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ButtonLeft.Location = new System.Drawing.Point(89, 778);
this.ButtonLeft.Location = new System.Drawing.Point(99, 510);
this.ButtonLeft.Name = "ButtonLeft";
this.ButtonLeft.Size = new System.Drawing.Size(40, 36);
this.ButtonLeft.TabIndex = 15;
@@ -187,7 +114,7 @@
this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("ButtonUp.BackgroundImage")));
this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ButtonUp.Location = new System.Drawing.Point(129, 728);
this.ButtonUp.Location = new System.Drawing.Point(139, 460);
this.ButtonUp.Name = "ButtonUp";
this.ButtonUp.Size = new System.Drawing.Size(40, 36);
this.ButtonUp.TabIndex = 14;
@@ -196,50 +123,63 @@
//
// buttonMap
//
this.buttonMap.Location = new System.Drawing.Point(18, 680);
this.buttonMap.Location = new System.Drawing.Point(26, 373);
this.buttonMap.Name = "buttonMap";
this.buttonMap.Size = new System.Drawing.Size(262, 34);
this.buttonMap.TabIndex = 5;
this.buttonMap.Text = "Посмотреть карту";
this.buttonMap.UseVisualStyleBackColor = true;
this.buttonMap.Click += new System.EventHandler(this.ButtonMap_Click);
this.buttonMap.Click += new System.EventHandler(this.buttonMap_Click);
//
// buttonStore
//
this.buttonStore.Location = new System.Drawing.Point(16, 614);
this.buttonStore.Location = new System.Drawing.Point(24, 307);
this.buttonStore.Name = "buttonStore";
this.buttonStore.Size = new System.Drawing.Size(264, 34);
this.buttonStore.TabIndex = 4;
this.buttonStore.Text = "Посмотреть хранилище";
this.buttonStore.UseVisualStyleBackColor = true;
this.buttonStore.Click += new System.EventHandler(this.ButtonStore_Click);
this.buttonStore.Click += new System.EventHandler(this.buttonStore_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(12, 561);
this.buttonDelete.Location = new System.Drawing.Point(20, 234);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(268, 34);
this.buttonDelete.TabIndex = 3;
this.buttonDelete.Text = "Удалить машину";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(5, 444);
this.buttonAdd.Location = new System.Drawing.Point(13, 117);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(275, 34);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить машину";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// comboBoxMap
//
this.comboBoxMap.FormattingEnabled = true;
this.comboBoxMap.Items.AddRange(new object[] {
"Простая карта",
"Горизонтальная карта",
"Вертикальная карта"});
this.comboBoxMap.Location = new System.Drawing.Point(9, 41);
this.comboBoxMap.Name = "comboBoxMap";
this.comboBoxMap.Size = new System.Drawing.Size(279, 33);
this.comboBoxMap.TabIndex = 0;
this.comboBoxMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxMap_SelectedIndexChanged);
//
// pictureBoxImage
//
this.pictureBoxImage.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxImage.Location = new System.Drawing.Point(0, 0);
this.pictureBoxImage.Name = "pictureBoxImage";
this.pictureBoxImage.Size = new System.Drawing.Size(964, 910);
this.pictureBoxImage.Size = new System.Drawing.Size(728, 644);
this.pictureBoxImage.TabIndex = 1;
this.pictureBoxImage.TabStop = false;
//
@@ -247,15 +187,13 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1264, 910);
this.ClientSize = new System.Drawing.Size(1028, 644);
this.Controls.Add(this.pictureBoxImage);
this.Controls.Add(this.groupBoxInstruments);
this.Name = "FormMapWithSetMachine";
this.Text = "Карта с набором объектов";
this.groupBoxInstruments.ResumeLayout(false);
this.groupBoxInstruments.PerformLayout();
this.groupBoxMap.ResumeLayout(false);
this.groupBoxMap.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxImage)).EndInit();
this.ResumeLayout(false);
@@ -268,17 +206,12 @@
private Button buttonStore;
private Button buttonDelete;
private Button buttonAdd;
private ComboBox comboBoxMap;
private PictureBox pictureBoxImage;
private MaskedTextBox maskedTextBoxPosition;
private Button ButtonDown;
private Button ButtonRight;
private Button ButtonLeft;
private Button ButtonUp;
private GroupBox groupBoxMap;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
private Button buttonAddMap;
private ComboBox comboBoxSelectorMap;
private TextBox textBoxNewMapName;
}
}

View File

@@ -11,76 +11,17 @@ using System.Windows.Forms;
namespace ArmoredVehicle
{
public partial class FormMapWithSetMachine : Form
{
{
/// <summary>
/// Словарь для выпадающего списка
/// </summary>
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{ "Вертикальная карта", new VerticalMap() },
{ "Горизонтальная карта", new HorizontalMap() }
};
/// <summary>
/// Объект от коллекции карт
/// </summary>
private readonly MapsCollection _mapsCollection;
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetMachineGeneric<DrawningObject, AbstractMap> _mapCarsCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetMachine()
{
InitializeComponent();
_mapsCollection = new MapsCollection(pictureBoxImage.Width, pictureBoxImage.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
/// <summary>
/// Заполнение listBoxMaps
/// </summary>
private void ReloadMaps()
{
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
}
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{
listBoxMaps.SelectedIndex = index;
}
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddMap_Click(object sender, EventArgs e)
{
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
}
/// <summary>
@@ -88,73 +29,72 @@ namespace ArmoredVehicle
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
private void comboBoxMap_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
AbstractMap map = null;
switch (comboBoxMap.Text)
{
return;
case "Простая карта":
map = new SimpleMap();
break;
case "Горизонтальная карта":
map = new HorizontalMap();
break;
case "Вертикальная карта":
map = new VerticalMap();
break;
}
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if (map != null)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAdd_Click(object sender, EventArgs e)
{
FormMachineConfig formMachine = new();
formMachine.AddEvent(new(AddMachine));
formMachine.Show();
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="machine"></param>
private void AddMachine(DrawingArmoredVehicle machine)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if(machine == null)
{
MessageBox.Show("Необходимо выбрать объект перед добавлением!");
return;
}
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObject(machine) != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
_mapCarsCollectionGeneric = new MapWithSetMachineGeneric<DrawningObject, AbstractMap>(
pictureBoxImage.Width, pictureBoxImage.Height, map);
}
else
{
MessageBox.Show("Не удалось добавить объект");
_mapCarsCollectionGeneric = null;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAdd_Click(object sender, EventArgs e)
{
if (_mapCarsCollectionGeneric == null)
{
return;
}
MainForm form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (form.SelectedMachine == null)
{
MessageBox.Show("Вы не создали объект");
return;
}
DrawningObject machine = new(form.SelectedMachine);
if (_mapCarsCollectionGeneric + machine != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxImage.Image = _mapCarsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
///<summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonDelete_Click(object sender, EventArgs e)
private void buttonDelete_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
@@ -165,10 +105,10 @@ namespace ArmoredVehicle
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
if (_mapCarsCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
pictureBoxImage.Image = _mapCarsCollectionGeneric.ShowSet();
}
else
{
@@ -181,13 +121,13 @@ namespace ArmoredVehicle
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonStore_Click(object sender, EventArgs e)
private void buttonStore_Click(object sender, EventArgs e)
{
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] == null)
if (_mapCarsCollectionGeneric == null)
{
return;
}
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
pictureBoxImage.Image = _mapCarsCollectionGeneric.ShowSet();
}
/// <summary>
@@ -195,13 +135,13 @@ namespace ArmoredVehicle
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMap_Click(object sender, EventArgs e)
private void buttonMap_Click(object sender, EventArgs e)
{
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] == null)
if (_mapCarsCollectionGeneric == null)
{
return;
}
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
pictureBoxImage.Image = _mapCarsCollectionGeneric.ShowOnMap();
}
/// <summary>
@@ -211,7 +151,7 @@ namespace ArmoredVehicle
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] == null)
if (_mapCarsCollectionGeneric == null)
{
return;
}
@@ -233,7 +173,7 @@ namespace ArmoredVehicle
dir = Direction.Right;
break;
}
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
pictureBoxImage.Image = _mapCarsCollectionGeneric.MoveObject(dir);
}
}
}

View File

@@ -51,7 +51,7 @@ namespace ArmoredVehicle
private void SetData()
{
Random rnd = new();
_ArmoredVehicle.SetPosition(/*rnd.Next(0, 100)*/ -10, rnd.Next(0, 100), DrawingPictureBox.Width, DrawingPictureBox.Height);
_ArmoredVehicle.SetPosition( -10, rnd.Next(0, 100), DrawingPictureBox.Width, DrawingPictureBox.Height);
toolStripStatusLabelSpeed.Text = $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {_ArmoredVehicle.ArmoredVehicle.Speed}";
toolStripStatusLabelWeight.Text = $"<22><><EFBFBD>: {_ArmoredVehicle.ArmoredVehicle.Weight}";
toolStripStatusLabelColor.Text = $"<22><><EFBFBD><EFBFBD>: {_ArmoredVehicle.ArmoredVehicle.BodyColor.Name}";
@@ -114,6 +114,7 @@ namespace ArmoredVehicle
color,
dopColor,
Convert.ToBoolean(rnd.Next(0, 2)),
Convert.ToBoolean(rnd.Next(0, 2)),
Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();

View File

@@ -49,6 +49,10 @@
_map = map;
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
@@ -88,9 +92,13 @@
public Bitmap ShowOnMap()
{
Shaking();
foreach (var machine in _setMachines.GetMachine())
for (int i = 0; i < _setMachines.Count; i++)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, machine);
var car = _setMachines.Get(i);
if (car != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
}
}
return new(_pictureWidth, _pictureHeight);
}
@@ -115,11 +123,11 @@
int j = _setMachines.Count - 1;
for (int i = 0; i < _setMachines.Count; i++)
{
if (_setMachines[i] == null)
if (_setMachines.Get(i) == null)
{
for (; j > i; j--)
{
var car = _setMachines[j];
var car = _setMachines.Get(j);
if (car != null)
{
_setMachines.Insert(car, i);
@@ -166,18 +174,18 @@
int currentWidth = 0;
int currentHeight = 0;
foreach (var machine in _setMachines.GetMachine())
for (int i = 0; i < _setMachines.Count; i++)
{
int dop = 0;
if (currentWidth > 0 && currentHeight > 0)
if(currentWidth > 0 && currentHeight > 0)
{
dop = 30;
}
machine.SetObject(currentWidth * _placeSizeWidth + dop,
_setMachines.Get(i)?.SetObject(currentWidth * _placeSizeWidth + dop,
currentHeight * _placeSizeHeight + dop,
_pictureWidth, _pictureHeight);
machine?.DrawningObject(g);
_setMachines.Get(i)?.DrawningObject(g);
if (currentWidth < width - 1)
{
currentWidth++;
@@ -189,7 +197,7 @@
}
if (currentHeight > height) return;
}
}
}
}

View File

@@ -1,97 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ArmoredVehicle
{
/// <summary>
/// Класс для хранения коллекции карт
/// </summary>
internal class MapsCollection
{
/// <summary>
/// Словарь (хранилище) с картами
/// </summary>
readonly Dictionary<string, MapWithSetMachineGeneric<DrawningObject,
AbstractMap>> _mapStorages;
/// <summary>
/// Возвращение списка названий карт
/// </summary>
public List<string> Keys => _mapStorages.Keys.ToList();
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string,
MapWithSetMachineGeneric<DrawningObject, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="name">Название карты</param>
/// <param name="map">Карта</param>
public void AddMap(string name, AbstractMap map)
{
if (Keys.Contains(name))
{
MessageBox.Show("Такая карта уже есть");
return;
}
else
{
var NewElem = new MapWithSetMachineGeneric<DrawningObject, AbstractMap>(
_pictureWidth, _pictureHeight, map);
_mapStorages.Add(name, NewElem);
}
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="name">Название карты</param>
public void DelMap(string name)
{
if (Keys.Contains(name))
{
_mapStorages.Remove(name);
}
else
{
MessageBox.Show("Такой карты нет");
return;
}
}
/// <summary>
/// Доступ к парковке
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public MapWithSetMachineGeneric<DrawningObject, AbstractMap> this[string ind]
{
get
{
if(Keys.Contains(ind))
{
return _mapStorages[ind];
}
MessageBox.Show("Такой карты нет");
return null;
}
}
}
}

View File

@@ -8,14 +8,13 @@
where T : class
{
/// <summary>
/// Список объектов, которые храним
/// Массив объектов, которые храним
/// </summary>
private readonly List<T> _places;
private readonly int _maxCount;
private readonly T[] _places;
/// <summary>
/// Количество объектов в списке
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Count;
public int Count => _places.Length;
private int BusyPlaces = 0;
/// <summary>
/// Конструктор
@@ -23,9 +22,7 @@
/// <param name="count"></param>
public SetMachineGeneric(int count)
{
_maxCount = count;
_places = new List<T>();
_places = new T[count];
}
/// <summary>
/// Добавление объекта в набор
@@ -34,8 +31,7 @@
/// <returns></returns>
public int Insert(T machine)
{
if (Count + 1 <= _maxCount) return Insert(machine, 0);
else return -1;
return Insert(machine, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
@@ -45,13 +41,21 @@
/// <returns></returns>
public int Insert(T machine, int position)
{
if (position >= _maxCount && position < 0)
if (position < 0 || position >= _places.Length || BusyPlaces == _places.Length) return -1;
BusyPlaces++;
while (_places[position] != null)
{
return -1;
for (int i = _places.Length - 1; i > 0; --i)
{
if (_places[i] == null && _places[i - 1] != null)
{
_places[i] = _places[i - 1];
_places[i - 1] = null;
}
}
}
_places.Insert(position, machine);
_places[position] = machine;
return position;
}
/// <summary>
@@ -61,63 +65,21 @@
/// <returns></returns>
public T Remove(int position)
{
if (position < _maxCount && position >= 0)
{
if (_places.ElementAt(position) != null)
{
T result = _places.ElementAt(position);
_places.RemoveAt(position);
return result;
}
return null;
}
return null;
if (position < 0 || position >= _places.Length) return null;
T deletemashine = _places[position];
_places[position] = null;
return deletemashine;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T this[int position]
public T Get(int position)
{
get
{
if (position < _maxCount && position >= 0)
{
return _places.ElementAt(position);
}
return null;
}
set
{
if (position < _maxCount && position >= 0)
{
Insert(this[position], position);
}
}
if (position < 0 || position >= _places.Length) return null;
else if (_places[position] == null) return null;
return _places[position];
}
/// <summary>
/// Проход по набору до первого пустого
/// </summary>
/// <returns></returns>
public IEnumerable<T> GetMachine()
{
foreach (var machine in _places)
{
if (machine != null)
{
yield return machine;
}
else
{
yield break;
}
}
}
}
}

View File

@@ -17,12 +17,14 @@ namespace ArmoredVehicle
/// <param name="dopColor">Дополнительный цвет</param>
/// <param name="MachineGun">Признак наличия пулемета</param>
/// <param name="Tower">Признак наличия башни</param>
/// <param name="Gun">Признак наличия орудия</param>
public TankEnity(int speed, float weight, Color bodyColor, Color dopColor, bool machineGun, bool tower) : base(speed, weight, bodyColor)
public TankEnity(int speed, float weight, Color bodyColor, Color dopColor, bool machineGun, bool tower, bool gun) : base(speed, weight, bodyColor)
{
DopColor = dopColor;
MachineGun = machineGun;
Tower = tower;
Gun = gun;
}
/// <summary>
@@ -37,6 +39,10 @@ namespace ArmoredVehicle
/// Признак наличия башни
/// </summary>
public bool Tower { get; private set; }
/// <summary>
/// Признак наличия орудия
/// </summary>
public bool Gun { get; private set; }
}