5 Commits

Author SHA1 Message Date
Danil Kargin
d3d75cc1e3 Event work 2022-11-02 23:12:38 +04:00
Danil Kargin
5c3ed88317 Add config form 2022-11-02 23:06:30 +04:00
Danil Kargin
50baf3b05b Этап 3. Форма 2022-11-02 22:20:29 +04:00
Danil Kargin
66cf50c25a Этап 2. Класс MapsCollection 2022-11-02 22:04:03 +04:00
Danil Kargin
6550575acd Этап 1. Смена массива на список. 2022-11-02 22:00:08 +04:00
10 changed files with 1025 additions and 145 deletions

View File

@@ -41,5 +41,13 @@ namespace AirFighter
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor;
}
/// <summary>
/// Смена цвета
/// </summary>
/// <param name="color"></param>
public void ChangeColor(Color color)
{
BodyColor = color;
}
}
}

View File

@@ -39,5 +39,9 @@ namespace AirFighter
DopWing = dopWing;
Rocket = rocket;
}
public void ChangeDopColor(Color color)
{
DopColor = color;
}
}
}

View File

@@ -0,0 +1,368 @@
namespace AirFighter
{
partial class FormAirFighterConfig
{
/// <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.labelSimpleObject = new System.Windows.Forms.Label();
this.labelModifiedObject = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.checkBoxDopWing = new System.Windows.Forms.CheckBox();
this.checkBoxRocket = 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.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.panelObject = new System.Windows.Forms.Panel();
this.labelDopColor = new System.Windows.Forms.Label();
this.labelBaseColor = new System.Windows.Forms.Label();
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxConfig.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.panelObject.SuspendLayout();
this.SuspendLayout();
//
// groupBoxConfig
//
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
this.groupBoxConfig.Controls.Add(this.checkBoxDopWing);
this.groupBoxConfig.Controls.Add(this.checkBoxRocket);
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.Location = new System.Drawing.Point(0, 0);
this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Size = new System.Drawing.Size(602, 309);
this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Параметры";
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(357, 196);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(111, 50);
this.labelSimpleObject.TabIndex = 0;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelModifiedObject
//
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifiedObject.Location = new System.Drawing.Point(474, 196);
this.labelModifiedObject.Name = "labelModifiedObject";
this.labelModifiedObject.Size = new System.Drawing.Size(111, 50);
this.labelModifiedObject.TabIndex = 1;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.panelPurple);
this.groupBoxColors.Controls.Add(this.panelBlack);
this.groupBoxColors.Controls.Add(this.panelGray);
this.groupBoxColors.Controls.Add(this.panelWhite);
this.groupBoxColors.Controls.Add(this.panelYellow);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Location = new System.Drawing.Point(321, 12);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(264, 155);
this.groupBoxColors.TabIndex = 6;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(197, 87);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(53, 55);
this.panelPurple.TabIndex = 7;
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(138, 87);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(53, 55);
this.panelBlack.TabIndex = 6;
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGray
//
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(79, 87);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(53, 55);
this.panelGray.TabIndex = 5;
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(20, 87);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(53, 55);
this.panelWhite.TabIndex = 4;
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(197, 26);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(53, 55);
this.panelYellow.TabIndex = 3;
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(138, 26);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(53, 55);
this.panelBlue.TabIndex = 2;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(79, 26);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(53, 55);
this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(20, 26);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(53, 55);
this.panelRed.TabIndex = 0;
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// checkBoxDopWing
//
this.checkBoxDopWing.AutoSize = true;
this.checkBoxDopWing.Location = new System.Drawing.Point(12, 196);
this.checkBoxDopWing.Name = "checkBoxDopWing";
this.checkBoxDopWing.Size = new System.Drawing.Size(339, 24);
this.checkBoxDopWing.TabIndex = 5;
this.checkBoxDopWing.Text = "Признак наличия дополнительных крыльев";
this.checkBoxDopWing.UseVisualStyleBackColor = true;
//
// checkBoxRocket
//
this.checkBoxRocket.AutoSize = true;
this.checkBoxRocket.Location = new System.Drawing.Point(12, 166);
this.checkBoxRocket.Name = "checkBoxRocket";
this.checkBoxRocket.Size = new System.Drawing.Size(196, 24);
this.checkBoxRocket.TabIndex = 4;
this.checkBoxRocket.Text = "Признак наличия ракет";
this.checkBoxRocket.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(118, 85);
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(66, 27);
this.numericUpDownWeight.TabIndex = 3;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(118, 52);
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(66, 27);
this.numericUpDownSpeed.TabIndex = 2;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(62, 87);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(33, 20);
this.labelWeight.TabIndex = 1;
this.labelWeight.Text = "Вес";
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(39, 52);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(73, 20);
this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = "Скорость";
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(38, 75);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(267, 124);
this.pictureBoxObject.TabIndex = 1;
this.pictureBoxObject.TabStop = false;
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.labelDopColor);
this.panelObject.Controls.Add(this.labelBaseColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(608, 12);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(319, 234);
this.panelObject.TabIndex = 2;
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(185, 26);
this.labelDopColor.Name = "labelDopColor";
this.labelDopColor.Size = new System.Drawing.Size(120, 41);
this.labelDopColor.TabIndex = 3;
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.LabelColor_DragEnter);
//
// labelBaseColor
//
this.labelBaseColor.AllowDrop = true;
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelBaseColor.Location = new System.Drawing.Point(38, 26);
this.labelBaseColor.Name = "labelBaseColor";
this.labelBaseColor.Size = new System.Drawing.Size(127, 41);
this.labelBaseColor.TabIndex = 2;
this.labelBaseColor.Text = "Цвет";
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(646, 271);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(117, 38);
this.buttonOk.TabIndex = 7;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(778, 271);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(122, 38);
this.buttonCancel.TabIndex = 8;
this.buttonCancel.Text = "Отменить";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// FormAirFighterConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(934, 316);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxConfig);
this.Name = "FormAirFighterConfig";
this.Text = "Создание объекта";
this.groupBoxConfig.ResumeLayout(false);
this.groupBoxConfig.PerformLayout();
this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.panelObject.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private CheckBox checkBoxDopWing;
private CheckBox checkBoxRocket;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelWeight;
private Label labelSpeed;
private Label labelSimpleObject;
private Label labelModifiedObject;
private GroupBox groupBoxColors;
private Panel panelPurple;
private Panel panelBlack;
private Panel panelGray;
private Panel panelWhite;
private Panel panelYellow;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelRed;
private PictureBox pictureBoxObject;
private Panel panelObject;
private Label labelDopColor;
private Label labelBaseColor;
private Button buttonOk;
private Button buttonCancel;
}
}

View File

@@ -0,0 +1,178 @@
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 AirFighter
{
public partial class FormAirFighterConfig : Form
{
/// <summary>
/// Переменная-выбранный самолет
/// </summary>
DrawningAirFighter _airFighter = null;
/// <summary>
/// Событие
/// </summary>
private event Action<DrawningAirFighter> EventAddAirFighter;
/// <summary>
/// Конструктор
/// </summary>
public FormAirFighterConfig()
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
// Закрытие формы
buttonCancel.Click += (object sender, EventArgs e) => this.Close();
}
/// <summary>
/// Отрисовать объект
/// </summary>
private void DrawAirFighter()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_airFighter?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_airFighter?.DrawAirFighter(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev"></param>
public void AddEvent(Action<DrawningAirFighter> ev)
{
if (EventAddAirFighter == null)
{
EventAddAirFighter = new Action<DrawningAirFighter>(ev);
}
else
{
EventAddAirFighter += 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 "labelSimpleObject":
_airFighter = new DrawningAirFighter((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
break;
case "labelModifiedObject":
_airFighter = new DrawningUpgradeAirFighter((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxRocket.Checked, checkBoxDopWing.Checked);
break;
}
DrawAirFighter();
}
/// <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_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 LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)) && _airFighter != null)
{
_airFighter.AirFighter.ChangeColor((Color)e.Data.GetData(typeof(Color)));
DrawAirFighter();
}
}
/// <summary>
/// Принимаем дополнительный цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)) && _airFighter != null)
{
if (_airFighter is DrawningUpgradeAirFighter _upgradeAirFighter)
{
if (_upgradeAirFighter.AirFighter is EntityUpgradeAirFighter _entityUpgradeAirFighter)
{
_entityUpgradeAirFighter.ChangeDopColor((Color)e.Data.GetData(typeof(Color)));
DrawAirFighter();
}
}
}
}
/// <summary>
/// Добавление самолета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddAirFighter?.Invoke(_airFighter);
Close();
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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

@@ -40,12 +40,19 @@
this.buttonAddAirFighter = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxMaps = 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.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.groupBoxMaps.SuspendLayout();
this.SuspendLayout();
//
// groupBox
//
this.groupBox.Controls.Add(this.groupBoxMaps);
this.groupBox.Controls.Add(this.buttonUp);
this.groupBox.Controls.Add(this.buttonDown);
this.groupBox.Controls.Add(this.buttonLeft);
@@ -55,20 +62,20 @@
this.groupBox.Controls.Add(this.buttonRemoveAirFighter);
this.groupBox.Controls.Add(this.maskedTextBoxPosition);
this.groupBox.Controls.Add(this.buttonAddAirFighter);
this.groupBox.Controls.Add(this.comboBoxSelectorMap);
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox.Location = new System.Drawing.Point(550, 0);
this.groupBox.Location = new System.Drawing.Point(732, 0);
this.groupBox.Name = "groupBox";
this.groupBox.Size = new System.Drawing.Size(250, 450);
this.groupBox.Size = new System.Drawing.Size(250, 555);
this.groupBox.TabIndex = 0;
this.groupBox.TabStop = false;
this.groupBox.Text = "Инструменты";
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.Up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(135, 370);
this.buttonUp.Location = new System.Drawing.Point(135, 475);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 2;
@@ -77,9 +84,10 @@
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.Down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(135, 408);
this.buttonDown.Location = new System.Drawing.Point(135, 513);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 3;
@@ -88,9 +96,10 @@
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.Left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(99, 408);
this.buttonLeft.Location = new System.Drawing.Point(99, 513);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4;
@@ -99,9 +108,10 @@
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.Right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(171, 408);
this.buttonRight.Location = new System.Drawing.Point(171, 513);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5;
@@ -110,7 +120,7 @@
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(28, 296);
this.buttonShowOnMap.Location = new System.Drawing.Point(28, 443);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(210, 29);
this.buttonShowOnMap.TabIndex = 5;
@@ -120,7 +130,7 @@
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(28, 252);
this.buttonShowStorage.Location = new System.Drawing.Point(28, 408);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(210, 29);
this.buttonShowStorage.TabIndex = 4;
@@ -130,7 +140,7 @@
//
// buttonRemoveAirFighter
//
this.buttonRemoveAirFighter.Location = new System.Drawing.Point(28, 194);
this.buttonRemoveAirFighter.Location = new System.Drawing.Point(28, 373);
this.buttonRemoveAirFighter.Name = "buttonRemoveAirFighter";
this.buttonRemoveAirFighter.Size = new System.Drawing.Size(210, 29);
this.buttonRemoveAirFighter.TabIndex = 3;
@@ -140,7 +150,7 @@
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(28, 145);
this.maskedTextBoxPosition.Location = new System.Drawing.Point(28, 340);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27);
@@ -148,7 +158,7 @@
//
// buttonAddAirFighter
//
this.buttonAddAirFighter.Location = new System.Drawing.Point(28, 96);
this.buttonAddAirFighter.Location = new System.Drawing.Point(28, 296);
this.buttonAddAirFighter.Name = "buttonAddAirFighter";
this.buttonAddAirFighter.Size = new System.Drawing.Size(210, 29);
this.buttonAddAirFighter.TabIndex = 1;
@@ -163,26 +173,76 @@
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Карта шторма"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(28, 45);
this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 75);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(210, 28);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// 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(550, 450);
this.pictureBox.Size = new System.Drawing.Size(732, 555);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// groupBoxMaps
//
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Location = new System.Drawing.Point(0, 12);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Size = new System.Drawing.Size(250, 278);
this.groupBoxMaps.TabIndex = 6;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты";
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(17, 244);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(210, 29);
this.buttonDeleteMap.TabIndex = 4;
this.buttonDeleteMap.Text = "Удалить карту";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 20;
this.listBoxMaps.Location = new System.Drawing.Point(17, 154);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(210, 84);
this.listBoxMaps.TabIndex = 3;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(17, 119);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(210, 29);
this.buttonAddMap.TabIndex = 2;
this.buttonAddMap.Text = "Добавить карту";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(17, 36);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(210, 27);
this.textBoxNewMapName.TabIndex = 1;
//
// FormMapWithSetAirFighters
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.ClientSize = new System.Drawing.Size(982, 555);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox);
this.Name = "FormMapWithSetAirFighters";
@@ -190,6 +250,8 @@
this.groupBox.ResumeLayout(false);
this.groupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
this.ResumeLayout(false);
}
@@ -208,5 +270,10 @@
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
private GroupBox groupBoxMaps;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
private Button buttonAddMap;
private TextBox textBoxNewMapName;
}
}

View File

@@ -14,42 +14,69 @@ namespace AirFighter
public partial class FormMapWithSetAirFighters : Form
{
/// <summary>
/// Объект от класса карты с набором объектов
/// Словарь для выпадающего списка
/// </summary>
private MapWithSetAirFightersGeneric<DrawningObjectAirFighter, AbstractMap> _mapAirFightersCollectionGeneric;
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{ "Карта шторма", new StormMap() }
};
/// <summary>
/// Объект от коллекции карт
/// </summary>
private readonly MapsCollection _mapsCollection;
/// <summary>
/// Конструктор
public FormMapWithSetAirFighters()
{
InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
/// <summary>
/// Выбор карты
/// Заполнение listBoxMaps
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender,
EventArgs e)
private void ReloadMaps()
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Карта шторма":
map = new StormMap();
break;
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if (map != null)
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >=
listBoxMaps.Items.Count))
{
_mapAirFightersCollectionGeneric = new
MapWithSetAirFightersGeneric<DrawningObjectAirFighter, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
listBoxMaps.SelectedIndex = 0;
}
else
else if (listBoxMaps.Items.Count > 0 && index > -1 && index <
listBoxMaps.Items.Count)
{
_mapAirFightersCollectionGeneric = null;
listBoxMaps.SelectedIndex = index;
}
}
void AddAirFighter(DrawningAirFighter _airFighter)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (_airFighter != null)
{
DrawningObjectAirFighter airFighter = new(_airFighter);
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airFighter) == 0)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
@@ -59,24 +86,11 @@ namespace AirFighter
/// <param name="e"></param>
private void ButtonAddAirFighter_Click(object sender, EventArgs e)
{
if (_mapAirFightersCollectionGeneric == null)
{
return;
}
FormAirFighter form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectAirFighter airFighter = new(form.SelectedAirFighter);
if ((_mapAirFightersCollectionGeneric + airFighter) == 0)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
var formAirFighterConfig = new FormAirFighterConfig();
Action<DrawningAirFighter> airFighterDelegate;
airFighterDelegate = new(AddAirFighter);
formAirFighterConfig.AddEvent(airFighterDelegate);
formAirFighterConfig.Show();
}
/// <summary>
/// Удаление объекта
@@ -85,6 +99,10 @@ namespace AirFighter
/// <param name="e"></param>
private void ButtonRemoveAirFighter_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
@@ -95,10 +113,10 @@ namespace AirFighter
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if ((_mapAirFightersCollectionGeneric - pos) != null)
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos) != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@@ -112,11 +130,11 @@ namespace AirFighter
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapAirFightersCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// <summary>
/// Вывод карты
@@ -125,11 +143,11 @@ namespace AirFighter
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapAirFightersCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowOnMap();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
/// <summary>
/// Перемещение
@@ -138,7 +156,7 @@ namespace AirFighter
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapAirFightersCollectionGeneric == null)
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -160,7 +178,56 @@ namespace AirFighter
dir = Direction.Right;
break;
}
pictureBox.Image = _mapAirFightersCollectionGeneric.MoveObject(dir);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
/// <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>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.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)
{
return;
}
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
}
}

View File

@@ -94,13 +94,9 @@ namespace AirFighter
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setAirFighters.Count; i++)
foreach (var airFighter in _setAirFighters.GetAirFighters())
{
var airFighter = _setAirFighters.Get(i);
if (airFighter != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, airFighter);
}
return _map.CreateMap(_pictureWidth, _pictureHeight, airFighter);
}
return new(_pictureWidth, _pictureHeight);
}
@@ -125,11 +121,11 @@ namespace AirFighter
int j = _setAirFighters.Count - 1;
for (int i = 0; i < _setAirFighters.Count; i++)
{
if (_setAirFighters.Get(i) == null)
if (_setAirFighters[i] == null)
{
for (; j > i; j--)
{
var airFighter = _setAirFighters.Get(j);
var airFighter = _setAirFighters[j];
if (airFighter != null)
{
_setAirFighters.Insert(airFighter, i);
@@ -179,22 +175,23 @@ namespace AirFighter
int currentWidth = _pictureWidth / _placeSizeWidth - 1;
int currentHeight = _pictureHeight / _placeSizeHeight - 1;
for (int i = 0; i < _setAirFighters.Count; i++)
foreach (var airFighter in _setAirFighters.GetAirFighters())
{
_setAirFighters.Get(i)?.SetObject(currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
_setAirFighters.Get(i)?.DrawningObject(g);
airFighter?.SetObject(currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
airFighter?.DrawningObject(g);
if(currentWidth > 0)
if (currentWidth > 0)
{
currentWidth -= 1;
}
else
{
if(currentHeight > 0)
if (currentHeight > 0)
{
currentHeight -= 1;
currentWidth = _pictureWidth / _placeSizeWidth - 1;
}else return;
}
else return;
}
}
}

View File

@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter
{
/// <summary>
/// Класс для хранения коллекции карт
/// </summary>
internal class MapsCollection
{
/// <summary>
/// Словарь (хранилище) с картами
/// </summary>
readonly Dictionary<string, MapWithSetAirFightersGeneric<DrawningObjectAirFighter, 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, MapWithSetAirFightersGeneric<DrawningObjectAirFighter, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="name">Название карты</param>
/// <param name="map">Карта</param>
public void AddMap(string name, AbstractMap map)
{
if (!string.IsNullOrEmpty(name) && map != null && !Keys.Contains(name))
{
_mapStorages.Add(name, new MapWithSetAirFightersGeneric<DrawningObjectAirFighter, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="name">Название карты</param>
public void DelMap(string name)
{
if (!string.IsNullOrEmpty(name))
{
_mapStorages.Remove(name);
}
}
/// <summary>
/// Доступ к парковке
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public MapWithSetAirFightersGeneric<DrawningObjectAirFighter, AbstractMap> this[string ind]
{
get
{
MapWithSetAirFightersGeneric<DrawningObjectAirFighter, AbstractMap> _map;
if (_mapStorages.TryGetValue(ind, out _map))
{
return _map;
}
else
return null;
}
}
}
}

View File

@@ -15,40 +15,25 @@ namespace AirFighter
where T: class
{
/// <summary>
/// Массив объектов, которые храним
/// Список объектов, которые храним
/// </summary>
private readonly T[] _places;
private readonly List<T> _places;
/// <summary>
/// Количество объектов в массиве
/// Количество объектов в списке
/// </summary>
public int Count => _places.Length;
public int Count => _places.Count;
/// <summary>
/// Максимальная длина списка
/// </summary>
private readonly int _maxCount;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetAirFightersGeneric(int count)
{
_places = new T[count];
}
/// <summary>
/// Проверка на наличие пустых мест
/// </summary>
/// <param name="firstIndex"></param>
/// <returns></returns>
private bool CheckNullPosition(int firstIndex)
{
if(firstIndex >= _places.Length && firstIndex < 0)
{
return false;
}
for(int i = firstIndex; i < _places.Length; i++)
{
if(_places[i] == null)
{
return true;
}
}
return false;
_places = new List<T>();
_maxCount = count;
}
/// <summary>
/// Добавление объекта в набор
@@ -67,40 +52,15 @@ namespace AirFighter
/// <returns></returns>
public int Insert(T airFighter, int position)
{
if(airFighter == null)
if (position < 0 && position > _maxCount)
{
return -1;
}
if (_places[position] == null)
{
_places[position] = airFighter;
}
else
{
if(CheckNullPosition(position + 1))
{
T tempMain = airFighter;
for (int i = position; i < _places.Length; i++)
{
if (_places[i] == null)
{
_places[i] = tempMain;
break;
}
else
{
T temp2 = _places[i];
_places[i] = tempMain;
tempMain = temp2;
}
}
}
else
{
return -1;
}
_places.Insert(position, airFighter);
return position;
}
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
@@ -109,28 +69,56 @@ namespace AirFighter
/// <returns></returns>
public T Remove(int position)
{
if (position >= 0 && position < _places.Length && _places[position] != null)
if (position >= 0 && position < _maxCount && _places[position] != null)
{
T temp = _places[position];
_places[position] = null;
_places.RemoveAt(position);
return temp;
}
else
return null;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Get(int position)
{
if (_places[position] != null)
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T this[int position]
{
get
{
return _places[position];
if (position >= 0 && position < _maxCount)
{
return _places[position];
}
else
return null;
}
else
return null;
set
{
if (position >= 0 && position < _maxCount)
{
_places.Insert(position, value);
}
}
}
/// <summary>
/// Проход по набору до первого пустого
/// </summary>
/// <returns></returns>
public IEnumerable<T> GetAirFighters()
{
foreach (var airFighter in _places)
{
if (airFighter != null)
{
yield return airFighter;
}
else
{
yield break;
}
}
}
}
}
}