Compare commits

...

3 Commits

Author SHA1 Message Date
MaxKarme
a112213e0a main commit 2022-11-01 17:51:11 +03:00
MaxKarme
dfdc51e414 end commit 2022-10-26 16:37:29 +03:00
MaxKarme
1260b0dc88 fix bug 2022-10-19 08:11:37 +03:00
11 changed files with 1006 additions and 126 deletions

View File

@ -32,17 +32,29 @@ namespace AirFighter
private (int mapI, int mapJ) checkBarrier((float Left, float Right, float Top, float Bottom) rect) private (int mapI, int mapJ) checkBarrier((float Left, float Right, float Top, float Bottom) rect)
{ {
return checkBarrier(rect, false, false, true, false);
}
private (int mapI, int mapJ) checkBarrier((float Left, float Right, float Top, float Bottom) rect, bool minLeft, bool maxLeft, bool isTop, bool isBottom)
{
(int mapI, int mapJ) res = (-1, -1);
for (int i = (int)(rect.Top / _size_y); i <= (int)(rect.Bottom / _size_y) && i < _map.GetLength(0); ++i) for (int i = (int)(rect.Top / _size_y); i <= (int)(rect.Bottom / _size_y) && i < _map.GetLength(0); ++i)
{ {
for (int j = (int)(rect.Left / _size_x); j <= (int)(rect.Right / _size_x) && j < _map.GetLength(1); ++j) for (int j = (int)(rect.Left / _size_x); j <= (int)(rect.Right / _size_x) && j < _map.GetLength(1); ++j)
{ {
if (j < 0) j = 0; if (j < 0) j = 0;
if (i < 0) i = 0; if (i < 0) i = 0;
if (_map[i, j] == _barrier) return (i, j); if (_map[i, j] != _barrier) continue;
if (res.mapI == -1) res = (i, j);
if (minLeft && res.mapJ > j) res = (i, j);
if (maxLeft && res.mapJ < j) res = (i, j);
if(isBottom) res = (i, j);
if (isTop) return (i, j);
} }
} }
return (-1, -1); return res;
} }
public Bitmap MoveObject(Direction direction) public Bitmap MoveObject(Direction direction)
{ {
@ -53,17 +65,37 @@ namespace AirFighter
float drawningWidth = position.Right - position.Left; float drawningWidth = position.Right - position.Left;
float drawningHeight = position.Bottom - position.Top; float drawningHeight = position.Bottom - position.Top;
if (direction == Direction.Left) position.Left -= _drawningObject.Step; bool minLeft = false;
if (direction == Direction.Right) position.Left += _drawningObject.Step; bool maxLeft = false;
if (direction == Direction.Up) position.Top -= _drawningObject.Step; bool isTop = false;
if (direction == Direction.Down) position.Top += _drawningObject.Step; bool isBottom = false;
if (direction == Direction.Left)
{
position.Left -= _drawningObject.Step;
maxLeft = true;
}
if (direction == Direction.Right)
{
position.Left += _drawningObject.Step;
minLeft = true;
}
if (direction == Direction.Up) {
position.Top -= _drawningObject.Step;
isTop = true;
}
if (direction == Direction.Down)
{
position.Top += _drawningObject.Step;
isBottom = true;
}
position.Right = position.Left + drawningWidth; position.Right = position.Left + drawningWidth;
position.Bottom = position.Top + drawningHeight; position.Bottom = position.Top + drawningHeight;
var currentBarrier = checkBarrier(position); var currentBarrier = checkBarrier(position, minLeft, maxLeft, isTop, isBottom);
if (currentBarrier.mapI == -1) if (currentBarrier.mapI == -1)
{ {
@ -114,7 +146,7 @@ namespace AirFighter
if(position.Right > _width) if(position.Right > _width)
{ {
position.Top = (minRowIndex + 1) * _size_y; position.Top = (minRowIndex + 1) * _size_y + 1;
position.Bottom = position.Top + drawningHeight; position.Bottom = position.Top + drawningHeight;
position.Left = 0; position.Left = 0;

View File

@ -30,6 +30,11 @@ namespace AirFighter
_airFighterHeight = airFighterHeight; _airFighterHeight = airFighterHeight;
} }
public DrawingAirFighter Update(int? speed = null, float? weight = null, Color? bodyColor = null)
{
return new DrawingAirFighter(speed ?? AirFighter.Speed, weight ?? AirFighter.Weight, bodyColor ?? AirFighter.BodyColor);
}
public void SetPosition(int x, int y, int width, int height) public void SetPosition(int x, int y, int width, int height)
{ {
if (width < _airFighterWidth || height < _airFighterHeight) return; if (width < _airFighterWidth || height < _airFighterHeight) return;

View File

@ -13,6 +13,14 @@ namespace AirFighter
{ {
AirFighter = new EntityModernAirFighter(speed, weight, bodyColor, dopColor, dopWings, rockets); AirFighter = new EntityModernAirFighter(speed, weight, bodyColor, dopColor, dopWings, rockets);
} }
public DrawingModernAirFighter Update(int? speed = null, float? weight = null, Color? bodyColor = null,
Color? dopColor = null, bool? dopWings = null, bool? rockets = null)
{
EntityModernAirFighter entity = (EntityModernAirFighter)AirFighter;
return new DrawingModernAirFighter(speed ?? entity.Speed, weight ?? entity.Weight, bodyColor ?? entity.BodyColor,
dopColor ?? entity.DopColor, dopWings ?? entity.DopWings, rockets ?? entity.Rockets);
}
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
if (AirFighter is not EntityModernAirFighter modernAirFighter) if (AirFighter is not EntityModernAirFighter modernAirFighter)

View File

@ -0,0 +1,362 @@
namespace AirFighter
{
partial class FormAircraftConfig
{
/// <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.labelModifiedObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.panelGray = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.checkBoxRockets = new System.Windows.Forms.CheckBox();
this.checkBoxDopWings = new System.Windows.Forms.CheckBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.panel8 = new System.Windows.Forms.Panel();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxConfig.SuspendLayout();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.panel8.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.SuspendLayout();
//
// groupBoxConfig
//
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
this.groupBoxConfig.Controls.Add(this.groupBox1);
this.groupBoxConfig.Controls.Add(this.checkBoxRockets);
this.groupBoxConfig.Controls.Add(this.checkBoxDopWings);
this.groupBoxConfig.Controls.Add(this.label2);
this.groupBoxConfig.Controls.Add(this.label1);
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
this.groupBoxConfig.Location = new System.Drawing.Point(12, 23);
this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Size = new System.Drawing.Size(581, 307);
this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Параметры";
//
// labelModifiedObject
//
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifiedObject.Location = new System.Drawing.Point(410, 240);
this.labelModifiedObject.Name = "labelModifiedObject";
this.labelModifiedObject.Size = new System.Drawing.Size(117, 43);
this.labelModifiedObject.TabIndex = 9;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(276, 240);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(117, 43);
this.labelSimpleObject.TabIndex = 8;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.panelGray);
this.groupBox1.Controls.Add(this.panelBlack);
this.groupBox1.Controls.Add(this.panelPurple);
this.groupBox1.Controls.Add(this.panelWhite);
this.groupBox1.Controls.Add(this.panelBlue);
this.groupBox1.Controls.Add(this.panelGreen);
this.groupBox1.Controls.Add(this.panelYellow);
this.groupBox1.Controls.Add(this.panelRed);
this.groupBox1.Location = new System.Drawing.Point(262, 54);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(280, 165);
this.groupBox1.TabIndex = 7;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Цвета";
//
// panelGray
//
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(81, 100);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(50, 50);
this.panelGray.TabIndex = 2;
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(148, 100);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(50, 50);
this.panelBlack.TabIndex = 2;
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(215, 100);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(50, 50);
this.panelPurple.TabIndex = 2;
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(14, 100);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(50, 50);
this.panelWhite.TabIndex = 1;
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(215, 31);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(50, 50);
this.panelBlue.TabIndex = 1;
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
this.panelGreen.Location = new System.Drawing.Point(148, 31);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(50, 50);
this.panelGreen.TabIndex = 1;
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(81, 31);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(50, 50);
this.panelYellow.TabIndex = 1;
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(14, 31);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(50, 50);
this.panelRed.TabIndex = 0;
//
// checkBoxRockets
//
this.checkBoxRockets.AutoSize = true;
this.checkBoxRockets.Location = new System.Drawing.Point(22, 222);
this.checkBoxRockets.Name = "checkBoxRockets";
this.checkBoxRockets.Size = new System.Drawing.Size(79, 24);
this.checkBoxRockets.TabIndex = 5;
this.checkBoxRockets.Text = "Ракеты";
this.checkBoxRockets.UseVisualStyleBackColor = true;
//
// checkBoxDopWings
//
this.checkBoxDopWings.AutoSize = true;
this.checkBoxDopWings.Location = new System.Drawing.Point(22, 182);
this.checkBoxDopWings.Name = "checkBoxDopWings";
this.checkBoxDopWings.Size = new System.Drawing.Size(207, 24);
this.checkBoxDopWings.TabIndex = 4;
this.checkBoxDopWings.Text = "Дополнительные крылья";
this.checkBoxDopWings.UseVisualStyleBackColor = true;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(22, 105);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(36, 20);
this.label2.TabIndex = 3;
this.label2.Text = "Вес:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(22, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(76, 20);
this.label1.TabIndex = 2;
this.label1.Text = "Скорость:";
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(119, 105);
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(90, 27);
this.numericUpDownWeight.TabIndex = 1;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(119, 54);
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(90, 27);
this.numericUpDownSpeed.TabIndex = 0;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// panel8
//
this.panel8.AllowDrop = true;
this.panel8.Controls.Add(this.label6);
this.panel8.Controls.Add(this.label5);
this.panel8.Controls.Add(this.pictureBoxObject);
this.panel8.Location = new System.Drawing.Point(682, 23);
this.panel8.Name = "panel8";
this.panel8.Size = new System.Drawing.Size(329, 263);
this.panel8.TabIndex = 1;
this.panel8.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panel8.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// label6
//
this.label6.AllowDrop = true;
this.label6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label6.Location = new System.Drawing.Point(171, 24);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(143, 43);
this.label6.TabIndex = 11;
this.label6.Text = "Доп. цвет";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label6.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
this.label6.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// label5
//
this.label5.AllowDrop = true;
this.label5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label5.Location = new System.Drawing.Point(13, 24);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(143, 43);
this.label5.TabIndex = 10;
this.label5.Text = "Цвет";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label5.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
this.label5.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(13, 70);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(301, 176);
this.pictureBoxObject.TabIndex = 0;
this.pictureBoxObject.TabStop = false;
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(695, 308);
this.buttonOk.Name = "buttonOk";
this.buttonOk.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonOk.Size = new System.Drawing.Size(110, 31);
this.buttonOk.TabIndex = 2;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(886, 308);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(110, 31);
this.buttonCancel.TabIndex = 3;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// FormAircraftConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1040, 351);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.panel8);
this.Controls.Add(this.groupBoxConfig);
this.Name = "FormAircraftConfig";
this.Text = "FormAircraftConfig";
this.groupBoxConfig.ResumeLayout(false);
this.groupBoxConfig.PerformLayout();
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.panel8.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private GroupBox groupBox1;
private CheckBox checkBoxRockets;
private CheckBox checkBoxDopWings;
private Label label2;
private Label label1;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelModifiedObject;
private Label labelSimpleObject;
private Panel panelGray;
private Panel panelBlack;
private Panel panelPurple;
private Panel panelWhite;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelYellow;
private Panel panelRed;
private Panel panel8;
private Label label6;
private Label label5;
private PictureBox pictureBoxObject;
private Button buttonOk;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,191 @@
namespace AirFighter
{
/// <summary>
/// Форма создания объекта
/// </summary>
public partial class FormAircraftConfig : Form
{
/// <summary>
/// Переменная-выбранная машина
/// </summary>
DrawingAirFighter _car = null;
private Action<DrawingAirFighter> EventAddCar = null;
/// <summary>
/// Событие
/// </summary>
// private event CarDelegate EventAddCar;
/// <summary>
/// Конструктор
/// </summary>
public FormAircraftConfig()
{
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;
// TODO buttonCancel.Click with lambda
buttonCancel.Click += (s, e) => Close();
}
/// <summary>
/// Отрисовать машину
/// </summary>
public void AddEvent(Action<DrawingAirFighter> ev)
{
if(EventAddCar == null)
{
EventAddCar = ev;
return;
}
EventAddCar += ev;
}
private void DrawCar()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_car?.SetPosition(5, 5, pictureBoxObject.Width,
pictureBoxObject.Height);
_car?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev"></param>
/* public void AddEvent(CarDelegate ev)
{
if (EventAddCar == null)
{
EventAddCar = new CarDelegate(ev);
}
else
{
EventAddCar += 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":
_car = new DrawingAirFighter((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White);
break;
case "labelModifiedObject":
_car = new DrawingModernAirFighter((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxDopWings.Checked, checkBoxRockets.Checked);
break;
}
DrawCar();
}
/// <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>
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// Принимаем основной цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
if (_car == null) return;
Color color = (Color)e.Data.GetData(typeof(Color));
if(_car is DrawingModernAirFighter)
{
_car = ((DrawingModernAirFighter)_car).Update(bodyColor: color);
}
else
{
_car = _car.Update(bodyColor: color);
}
DrawCar();
}
/// <summary>
/// Принимаем дополнительный цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
var car = _car as DrawingModernAirFighter;
if (car == null) return;
Color color = (Color)e.Data.GetData(typeof(Color));
_car = car.Update(dopColor: color);
DrawCar();
}
/// <summary>
/// Добавление машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddCar?.Invoke(_car);
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<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

@ -29,6 +29,12 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.tools = new System.Windows.Forms.GroupBox(); this.tools = new System.Windows.Forms.GroupBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.RightButton = new System.Windows.Forms.Button(); this.RightButton = new System.Windows.Forms.Button();
this.LeftButton = new System.Windows.Forms.Button(); this.LeftButton = new System.Windows.Forms.Button();
this.UpButton = new System.Windows.Forms.Button(); this.UpButton = new System.Windows.Forms.Button();
@ -38,14 +44,15 @@
this.ButtonShowOnMap = new System.Windows.Forms.Button(); this.ButtonShowOnMap = new System.Windows.Forms.Button();
this.ButtonShowStorage = new System.Windows.Forms.Button(); this.ButtonShowStorage = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox(); this.pictureBox = new System.Windows.Forms.PictureBox();
this.tools.SuspendLayout(); this.tools.SuspendLayout();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// tools // tools
// //
this.tools.Controls.Add(this.groupBox1);
this.tools.Controls.Add(this.RightButton); this.tools.Controls.Add(this.RightButton);
this.tools.Controls.Add(this.LeftButton); this.tools.Controls.Add(this.LeftButton);
this.tools.Controls.Add(this.UpButton); this.tools.Controls.Add(this.UpButton);
@ -55,21 +62,83 @@
this.tools.Controls.Add(this.ButtonShowOnMap); this.tools.Controls.Add(this.ButtonShowOnMap);
this.tools.Controls.Add(this.ButtonShowStorage); this.tools.Controls.Add(this.ButtonShowStorage);
this.tools.Controls.Add(this.buttonAdd); this.tools.Controls.Add(this.buttonAdd);
this.tools.Controls.Add(this.comboBoxSelectorMap);
this.tools.Dock = System.Windows.Forms.DockStyle.Right; this.tools.Dock = System.Windows.Forms.DockStyle.Right;
this.tools.Location = new System.Drawing.Point(839, 0); this.tools.Location = new System.Drawing.Point(940, 0);
this.tools.Name = "tools"; this.tools.Name = "tools";
this.tools.Size = new System.Drawing.Size(250, 597); this.tools.Size = new System.Drawing.Size(250, 725);
this.tools.TabIndex = 0; this.tools.TabIndex = 0;
this.tools.TabStop = false; this.tools.TabStop = false;
this.tools.Text = "Инструменты"; this.tools.Text = "Инструменты";
// //
// groupBox1
//
this.groupBox1.Controls.Add(this.buttonDeleteMap);
this.groupBox1.Controls.Add(this.listBoxMaps);
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.groupBox1.Controls.Add(this.buttonAddMap);
this.groupBox1.Controls.Add(this.textBoxNewMapName);
this.groupBox1.Location = new System.Drawing.Point(12, 33);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(226, 286);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "карты";
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(12, 243);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(196, 29);
this.buttonDeleteMap.TabIndex = 13;
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(12, 133);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(196, 104);
this.listBoxMaps.TabIndex = 12;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
// 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(12, 59);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(196, 28);
this.comboBoxSelectorMap.TabIndex = 0;
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(12, 93);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(196, 29);
this.buttonAddMap.TabIndex = 11;
this.buttonAddMap.Text = "Добавить карту";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(12, 26);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(196, 27);
this.textBoxNewMapName.TabIndex = 0;
//
// RightButton // RightButton
// //
this.RightButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.RightButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.RightButton.BackgroundImage = global::AirFighter.Properties.Resources.right; this.RightButton.BackgroundImage = global::AirFighter.Properties.Resources.right;
this.RightButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.RightButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.RightButton.Location = new System.Drawing.Point(148, 555); this.RightButton.Location = new System.Drawing.Point(148, 683);
this.RightButton.Name = "RightButton"; this.RightButton.Name = "RightButton";
this.RightButton.RightToLeft = System.Windows.Forms.RightToLeft.No; this.RightButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.RightButton.Size = new System.Drawing.Size(30, 30); this.RightButton.Size = new System.Drawing.Size(30, 30);
@ -82,7 +151,7 @@
this.LeftButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.LeftButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.LeftButton.BackgroundImage = global::AirFighter.Properties.Resources.left; this.LeftButton.BackgroundImage = global::AirFighter.Properties.Resources.left;
this.LeftButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.LeftButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.LeftButton.Location = new System.Drawing.Point(76, 555); this.LeftButton.Location = new System.Drawing.Point(76, 683);
this.LeftButton.Name = "LeftButton"; this.LeftButton.Name = "LeftButton";
this.LeftButton.RightToLeft = System.Windows.Forms.RightToLeft.No; this.LeftButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.LeftButton.Size = new System.Drawing.Size(30, 30); this.LeftButton.Size = new System.Drawing.Size(30, 30);
@ -95,7 +164,7 @@
this.UpButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.UpButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.UpButton.BackgroundImage = global::AirFighter.Properties.Resources.up; this.UpButton.BackgroundImage = global::AirFighter.Properties.Resources.up;
this.UpButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.UpButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.UpButton.Location = new System.Drawing.Point(112, 520); this.UpButton.Location = new System.Drawing.Point(112, 648);
this.UpButton.Name = "UpButton"; this.UpButton.Name = "UpButton";
this.UpButton.RightToLeft = System.Windows.Forms.RightToLeft.No; this.UpButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.UpButton.Size = new System.Drawing.Size(30, 30); this.UpButton.Size = new System.Drawing.Size(30, 30);
@ -108,7 +177,7 @@
this.DownButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.DownButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.DownButton.BackgroundImage = global::AirFighter.Properties.Resources.down; this.DownButton.BackgroundImage = global::AirFighter.Properties.Resources.down;
this.DownButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.DownButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.DownButton.Location = new System.Drawing.Point(112, 555); this.DownButton.Location = new System.Drawing.Point(112, 683);
this.DownButton.Name = "DownButton"; this.DownButton.Name = "DownButton";
this.DownButton.RightToLeft = System.Windows.Forms.RightToLeft.No; this.DownButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.DownButton.Size = new System.Drawing.Size(30, 30); this.DownButton.Size = new System.Drawing.Size(30, 30);
@ -118,17 +187,17 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(3, 145); this.maskedTextBoxPosition.Location = new System.Drawing.Point(24, 392);
this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(235, 27); this.maskedTextBoxPosition.Size = new System.Drawing.Size(196, 27);
this.maskedTextBoxPosition.TabIndex = 5; this.maskedTextBoxPosition.TabIndex = 5;
// //
// buttonRemove // buttonRemove
// //
this.buttonRemove.Location = new System.Drawing.Point(3, 178); this.buttonRemove.Location = new System.Drawing.Point(24, 425);
this.buttonRemove.Name = "buttonRemove"; this.buttonRemove.Name = "buttonRemove";
this.buttonRemove.Size = new System.Drawing.Size(235, 29); this.buttonRemove.Size = new System.Drawing.Size(196, 29);
this.buttonRemove.TabIndex = 4; this.buttonRemove.TabIndex = 4;
this.buttonRemove.Text = "Удалить"; this.buttonRemove.Text = "Удалить";
this.buttonRemove.UseVisualStyleBackColor = true; this.buttonRemove.UseVisualStyleBackColor = true;
@ -136,9 +205,9 @@
// //
// ButtonShowOnMap // ButtonShowOnMap
// //
this.ButtonShowOnMap.Location = new System.Drawing.Point(3, 313); this.ButtonShowOnMap.Location = new System.Drawing.Point(24, 520);
this.ButtonShowOnMap.Name = "ButtonShowOnMap"; this.ButtonShowOnMap.Name = "ButtonShowOnMap";
this.ButtonShowOnMap.Size = new System.Drawing.Size(235, 29); this.ButtonShowOnMap.Size = new System.Drawing.Size(196, 29);
this.ButtonShowOnMap.TabIndex = 3; this.ButtonShowOnMap.TabIndex = 3;
this.ButtonShowOnMap.Text = "Посмотреть карту"; this.ButtonShowOnMap.Text = "Посмотреть карту";
this.ButtonShowOnMap.UseVisualStyleBackColor = true; this.ButtonShowOnMap.UseVisualStyleBackColor = true;
@ -146,9 +215,9 @@
// //
// ButtonShowStorage // ButtonShowStorage
// //
this.ButtonShowStorage.Location = new System.Drawing.Point(3, 244); this.ButtonShowStorage.Location = new System.Drawing.Point(24, 472);
this.ButtonShowStorage.Name = "ButtonShowStorage"; this.ButtonShowStorage.Name = "ButtonShowStorage";
this.ButtonShowStorage.Size = new System.Drawing.Size(235, 29); this.ButtonShowStorage.Size = new System.Drawing.Size(196, 29);
this.ButtonShowStorage.TabIndex = 2; this.ButtonShowStorage.TabIndex = 2;
this.ButtonShowStorage.Text = "Посмотреть хранилище"; this.ButtonShowStorage.Text = "Посмотреть хранилище";
this.ButtonShowStorage.UseVisualStyleBackColor = true; this.ButtonShowStorage.UseVisualStyleBackColor = true;
@ -156,33 +225,20 @@
// //
// buttonAdd // buttonAdd
// //
this.buttonAdd.Location = new System.Drawing.Point(3, 91); this.buttonAdd.Location = new System.Drawing.Point(24, 357);
this.buttonAdd.Name = "buttonAdd"; this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(235, 29); this.buttonAdd.Size = new System.Drawing.Size(196, 29);
this.buttonAdd.TabIndex = 1; this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить"; this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAddCar_Click); this.buttonAdd.Click += new System.EventHandler(this.ButtonAddCar_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(3, 23);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(235, 28);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// pictureBox // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0); this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(839, 597); this.pictureBox.Size = new System.Drawing.Size(940, 725);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -190,13 +246,15 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1089, 597); this.ClientSize = new System.Drawing.Size(1190, 725);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.tools); this.Controls.Add(this.tools);
this.Name = "FormMapWithSetCars"; this.Name = "FormMapWithSetCars";
this.Text = "FormMapWithSetCars"; this.Text = "FormMapWithSetCars";
this.tools.ResumeLayout(false); this.tools.ResumeLayout(false);
this.tools.PerformLayout(); this.tools.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -216,5 +274,10 @@
private Button LeftButton; private Button LeftButton;
private Button UpButton; private Button UpButton;
private Button DownButton; private Button DownButton;
private GroupBox groupBox1;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
private Button buttonAddMap;
private TextBox textBoxNewMapName;
} }
} }

View File

@ -12,67 +12,124 @@ namespace AirFighter
{ {
public partial class FormMapWithSetCars : Form public partial class FormMapWithSetCars : Form
{ {
private MapWithSetCarsGeneric<DrawingObjectAirFighter, AbstractMap> _mapCarsCollectionGeneric; private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{ "Моя карта", new MyMap() }
};
/// <summary>
/// Объект от коллекции карт
/// </summary>
private readonly MapsCollection _mapsCollection;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
public FormMapWithSetCars() public FormMapWithSetCars()
{ {
InitializeComponent(); InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width,
pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
} }
}
/// <summary> /// <summary>
/// Выбор карты /// Выбор карты
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Моя карта":
map = new MyMap();
break;
}
if (map != null)
{
_mapCarsCollectionGeneric = new
MapWithSetCarsGeneric<DrawingObjectAirFighter, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapCarsCollectionGeneric = null;
}
}
/// <summary> /// <summary>
/// Добавление объекта /// Добавление объекта
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonAddCar_Click(object sender, EventArgs e) ///
private void ReloadMaps()
{ {
if (_mapCarsCollectionGeneric == null) 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;
}
}
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();
}
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
FormAirFighter form = new();
if (form.ShowDialog() == DialogResult.OK) if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
DrawingObjectAirFighter car = new(form.SelectedAirFighter); _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ??
if (_mapCarsCollectionGeneric + car != -1) string.Empty);
ReloadMaps();
}
}
private void AircraftAddCallback(DrawingAirFighter aircraft)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectAirFighter(aircraft) != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); pictureBox.Image =
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
} }
private void ButtonAddCar_Click(object sender, EventArgs e)
{
FormAircraftConfig form = new();
form.AddEvent(AircraftAddCallback);
form.Show();
} }
/// <summary> /// <summary>
/// Удаление объекта /// Удаление объекта
@ -81,6 +138,10 @@ namespace AirFighter
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonRemoveCar_Click(object sender, EventArgs e) private void ButtonRemoveCar_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{ {
return; return;
@ -91,15 +152,17 @@ namespace AirFighter
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapCarsCollectionGeneric - pos != null) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); pictureBox.Image =
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось удалить объект"); MessageBox.Show("Не удалось удалить объект");
} }
} }
/// <summary> /// <summary>
/// Вывод набора /// Вывод набора
@ -108,11 +171,12 @@ namespace AirFighter
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e) private void ButtonShowStorage_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
/// <summary> /// <summary>
/// Вывод карты /// Вывод карты
@ -121,11 +185,11 @@ namespace AirFighter
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapCarsCollectionGeneric.ShowOnMap(); pictureBox.Image =_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
} }
/// <summary> /// <summary>
/// Перемещение /// Перемещение
@ -134,7 +198,7 @@ namespace AirFighter
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -156,7 +220,8 @@ namespace AirFighter
dir = Direction.Right; dir = Direction.Right;
break; break;
} }
pictureBox.Image = _mapCarsCollectionGeneric.MoveObject(dir); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
} }
} }
} }

View File

@ -89,14 +89,11 @@ namespace AirFighter
public Bitmap ShowOnMap() public Bitmap ShowOnMap()
{ {
Shaking(); Shaking();
for (int i = 0; i < _setCars.Count; i++)
{ foreach(var car in _setCars.GetCars())
var car = _setCars.Get(i);
if (car != null)
{ {
return _map.CreateMap(_pictureWidth, _pictureHeight, car); return _map.CreateMap(_pictureWidth, _pictureHeight, car);
} }
}
return new(_pictureWidth, _pictureHeight); return new(_pictureWidth, _pictureHeight);
} }
/// <summary> /// <summary>
@ -120,11 +117,11 @@ namespace AirFighter
int j = _setCars.Count - 1; int j = _setCars.Count - 1;
for (int i = 0; i < _setCars.Count; i++) for (int i = 0; i < _setCars.Count; i++)
{ {
if (_setCars.Get(i) == null) if (_setCars[i] == null)
{ {
for (; j > i; j--) for (; j > i; j--)
{ {
var car = _setCars.Get(j); var car = _setCars[j];
if (car != null) if (car != null)
{ {
_setCars.Insert(car, i); _setCars.Insert(car, i);
@ -181,13 +178,17 @@ namespace AirFighter
int width = _pictureWidth / _placeSizeWidth; int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight; int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _setCars.Count; i++) int i = 0;
foreach(var car in _setCars.GetCars())
{ {
int x = i % width; int x = i % width;
int y = i / width; int y = i / width;
_setCars.Get(i)?.SetObject(x * _placeSizeWidth, y * _placeSizeHeight, _pictureWidth, _pictureHeight); car.SetObject((width - x - 1) * _placeSizeWidth, (height - y - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight);
_setCars.Get(i)?.DrawningObject(g); car.DrawningObject(g);
i++;
} }
} }
} }

View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter
{
internal class MapsCollection
{
/// <summary>
/// Словарь (хранилище) с картами
/// </summary>
readonly Dictionary<string, MapWithSetCarsGeneric<DrawingObjectAirFighter, 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,
MapWithSetCarsGeneric<DrawingObjectAirFighter, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="name">Название карты</param>
/// <param name="map">Карта</param>
public void AddMap(string name, AbstractMap map)
{
// TODO Прописать логику для добавления
bool check = _mapStorages.TryGetValue(name, out var value);
if (check) return;
_mapStorages[name] = new(_pictureWidth, _pictureHeight, map);
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="name">Название карты</param>
public void DelMap(string name)
{
// TODO Прописать логику для удаления
_mapStorages.Remove(name);
}
/// <summary>
/// Доступ к парковке
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public MapWithSetCarsGeneric<DrawingObjectAirFighter, AbstractMap> this[string ind]
{
get
{
// TODO Продумать логику получения объекта
bool check = _mapStorages.TryGetValue(ind, out var mapWithSet);
return mapWithSet;
}
}
}
}

View File

@ -10,33 +10,29 @@ namespace AirFighter
where T : class where T : class
{ {
/// <summary> /// <summary>
/// Массив объектов, которые храним /// Список объектов, которые храним
/// </summary> /// </summary>
private readonly T[] _places; private readonly List<T> _places;
/// <summary> /// <summary>
/// Количество объектов в массиве /// Количество объектов в списке
/// </summary> /// </summary>
public int Count => _places.Length; public int Count => _places.Count;
private readonly int _maxCount;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
/// <param name="count"></param> /// <param name="count"></param>
public SetCarsGeneric(int count) public SetCarsGeneric(int count)
{ {
_places = new T[count]; _maxCount = count;
_places = new List<T>();
} }
public int Insert(T car) public int Insert(T car)
{ {
// TODO вставка в начало набора // TODO вставка в начало набора
for(int i = 0; i < _places.Length; i++) if (_places.Count == _maxCount) return -1;
{ _places.Insert(0, car);
if (_places[i] == null) return 0;
{
_places[i] = car;
return i;
}
}
return -1;
} }
public int Insert(T car, int position) public int Insert(T car, int position)
{ {
@ -45,15 +41,8 @@ namespace AirFighter
// проверка, что после вставляемого элемента в массиве есть пустой элемент // проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции // TODO вставка по позиции
if (_places.Count == _maxCount) return -1;
int index = position; _places.Insert(position, car);
while (_places[index] != null && index < _places.Length) index++;
if (index == _places.Length) return -1;
for (int i = index; i > position; --i) _places[i] = _places[i - 1];
_places[position] = car;
return position; return position;
} }
/// <summary> /// <summary>
@ -66,7 +55,7 @@ namespace AirFighter
// TODO проверка позиции // TODO проверка позиции
// TODO удаление объекта из массива, присовив элементу массива значение null // TODO удаление объекта из массива, присовив элементу массива значение null
T res = _places[position]; T res = _places[position];
_places[position] = null; _places.Remove(res);
return res; return res;
} }
/// <summary> /// <summary>
@ -74,11 +63,38 @@ namespace AirFighter
/// </summary> /// </summary>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public T Get(int position) public T this[int position]
{
get
{ {
// TODO проверка позиции // TODO проверка позиции
if(position < 0) return null;
if(position >= _places.Count) return null;
return _places[position]; return _places[position];
} }
set
{
// TODO проверка позиции
if (position < 0) return;
if (position >= _places.Count) return;
// TODO вставка в список по позиции
Insert(value, position);
}
} }
public IEnumerable<T> GetCars()
{
foreach (var car in _places)
{
if (car != null)
{
yield return car;
}
else
{
yield break;
}
}
}
}
} }