Merge pull request 'Kargin D.E. Lab Work 3' (#3) from LabWork03 into LabWork02

Reviewed-on: http://student.git.athene.tech/d.kargin/PIbd-21_Kargin_D.E._AirFighter._Base/pulls/3
This commit is contained in:
Евгений Эгов 2022-11-07 09:34:10 +04:00
commit ba37ae1d9b
14 changed files with 775 additions and 331 deletions

View File

@ -78,9 +78,9 @@ namespace AirFighter
{ {
return 2; return 2;
} }
for (int i = (int)(Top / _size_y); i <= (int)(Bottom / _size_y) + 1; i++) for (int i = (int)(Top / _size_y); i <= (int)(Bottom / _size_y); i++)
{ {
for (int j = (int)(Left / _size_x); j <= (int)(Right / _size_x) + 1; j++) for (int j = (int)(Left / _size_x); j <= (int)(Right / _size_x); j++)
{ {
if (_map[i, j] == _barrier) if (_map[i, j] == _barrier)
return 0; return 0;
@ -106,22 +106,23 @@ namespace AirFighter
int flag = 0; int flag = 0;
while (flag == 0) while (flag == 0)
{ {
flag = CheckBarrier((int)Right, (int)Left, (int)Top, (int)Bottom);
y += (int)_size_y; y += (int)_size_y;
Top += _size_y; Top += (int)_size_y;
Bottom += _size_y; Bottom += (int)_size_y;
_drawningObject.SetObject(x, y, _width, _height); _drawningObject.SetObject(x, y, _width, _height);
flag = CheckBarrier((int)Right, (int)Left, (int)Top, (int)Bottom);
} }
if (flag == 1) if (flag == 1)
{ {
return true; return true;
} }
x += (int)_size_x; x += (int)_size_x;
Left += _size_x; Left += (int)_size_x;
Right += _size_x; Right += (int)_size_x;
y = (int)tempTop; y = (int)tempTop;
Top = tempTop; Top = (int)tempTop;
Bottom = tempBottom; Bottom = (int)tempBottom;
} }
return false; return false;
} }

View File

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

View File

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

View File

@ -9,7 +9,7 @@ namespace AirFighter
/// <summary> /// <summary>
/// Класс-сущность "Военный самолет" /// Класс-сущность "Военный самолет"
/// </summary> /// </summary>
internal class EntityAirFighter public class EntityAirFighter
{ {
/// <summary> /// <summary>
/// Скорость /// Скорость

View File

@ -39,6 +39,7 @@
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonUpgrade = new System.Windows.Forms.Button(); this.buttonUpgrade = new System.Windows.Forms.Button();
this.buttonSelectAirFighter = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
this.statusStrip.SuspendLayout(); this.statusStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -154,11 +155,22 @@
this.buttonUpgrade.UseVisualStyleBackColor = true; this.buttonUpgrade.UseVisualStyleBackColor = true;
this.buttonUpgrade.Click += new System.EventHandler(this.ButtonUpgrade_Click); this.buttonUpgrade.Click += new System.EventHandler(this.ButtonUpgrade_Click);
// //
// buttonSelectAirFighter
//
this.buttonSelectAirFighter.Location = new System.Drawing.Point(565, 379);
this.buttonSelectAirFighter.Name = "buttonSelectAirFighter";
this.buttonSelectAirFighter.Size = new System.Drawing.Size(94, 29);
this.buttonSelectAirFighter.TabIndex = 8;
this.buttonSelectAirFighter.Text = "Выбрать";
this.buttonSelectAirFighter.UseVisualStyleBackColor = true;
this.buttonSelectAirFighter.Click += new System.EventHandler(this.ButtonSelectAirFighter_Click);
//
// FormAirFighter // FormAirFighter
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonSelectAirFighter);
this.Controls.Add(this.buttonUpgrade); this.Controls.Add(this.buttonUpgrade);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonLeft);
@ -190,5 +202,6 @@
private Button buttonLeft; private Button buttonLeft;
private Button buttonRight; private Button buttonRight;
private Button buttonUpgrade; private Button buttonUpgrade;
private Button buttonSelectAirFighter;
} }
} }

View File

@ -3,6 +3,10 @@ namespace AirFighter
public partial class FormAirFighter : Form public partial class FormAirFighter : Form
{ {
private DrawningAirFighter _airFighter; private DrawningAirFighter _airFighter;
/// <summary>
/// Âűáđŕííűé îáúĺęň
/// </summary>
public DrawningAirFighter SelectedAirFighter { get ; private set; }
public FormAirFighter() public FormAirFighter()
{ {
InitializeComponent(); InitializeComponent();
@ -36,7 +40,13 @@ namespace AirFighter
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new Random(); Random rnd = new Random();
_airFighter = new DrawningAirFighter(rnd.Next(200, 500), rnd.Next(2000, 5000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_airFighter = new DrawningAirFighter(rnd.Next(200, 500), rnd.Next(2000, 5000), color);
SetData(); SetData();
Draw(); Draw();
} }
@ -83,10 +93,28 @@ namespace AirFighter
private void ButtonUpgrade_Click(object sender, EventArgs e) private void ButtonUpgrade_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_airFighter = new DrawningUpgradeAirFighter(rnd.Next(300, 600), rnd.Next(2000, 5000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_airFighter = new DrawningUpgradeAirFighter(rnd.Next(300, 600), rnd.Next(2000, 5000), color,
dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(); SetData();
Draw(); Draw();
} }
private void ButtonSelectAirFighter_Click(object sender, EventArgs e)
{
SelectedAirFighter = _airFighter;
DialogResult = DialogResult.OK;
}
} }
} }

View File

@ -1,209 +0,0 @@
namespace AirFighter
{
partial class FormMap
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBoxAirFighter = new System.Windows.Forms.PictureBox();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonUpgrade = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxAirFighter
//
this.pictureBoxAirFighter.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxAirFighter.Location = new System.Drawing.Point(0, 0);
this.pictureBoxAirFighter.Name = "pictureBoxAirFighter";
this.pictureBoxAirFighter.Size = new System.Drawing.Size(800, 424);
this.pictureBoxAirFighter.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxAirFighter.TabIndex = 0;
this.pictureBoxAirFighter.TabStop = false;
//
// statusStrip
//
this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip.Location = new System.Drawing.Point(0, 424);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 26);
this.statusStrip.TabIndex = 1;
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(80, 20);
this.toolStripStatusLabelSpeed.Text = "Скорость: ";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(40, 20);
this.toolStripStatusLabelWeight.Text = "Вес: ";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(49, 20);
this.toolStripStatusLabelBodyColor.Text = "Цвет: ";
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(39, 378);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.Up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(722, 341);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.Down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(722, 377);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 4;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.Left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(686, 377);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 5;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.Right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(758, 378);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 6;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUpgrade
//
this.buttonUpgrade.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonUpgrade.Location = new System.Drawing.Point(148, 379);
this.buttonUpgrade.Name = "buttonUpgrade";
this.buttonUpgrade.Size = new System.Drawing.Size(127, 29);
this.buttonUpgrade.TabIndex = 7;
this.buttonUpgrade.Text = "Модификация";
this.buttonUpgrade.UseVisualStyleBackColor = true;
this.buttonUpgrade.Click += new System.EventHandler(this.ButtonUpgrade_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(12, 12);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28);
this.comboBoxSelectorMap.TabIndex = 8;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// FormMap
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.comboBoxSelectorMap);
this.Controls.Add(this.buttonUpgrade);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxAirFighter);
this.Controls.Add(this.statusStrip);
this.Name = "FormMap";
this.Text = "Карта";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxAirFighter;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate;
private Button buttonUp;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
private Button buttonUpgrade;
private ComboBox comboBoxSelectorMap;
}
}

View File

@ -1,103 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AirFighter
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
comboBoxSelectorMap.SelectedIndex = 0;
}
/// <summary>
/// Заполнение информации по объекту
/// </summary>
private void SetData(DrawningAirFighter airFighter)
{
toolStripStatusLabelSpeed.Text = $"Скорость: {airFighter.AirFighter?.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {airFighter.AirFighter?.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {airFighter.AirFighter?.BodyColor}";
pictureBoxAirFighter.Image = _abstractMap.CreateMap(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height,
new DrawningObjectAirFighter(airFighter));
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
var _airFighter = new DrawningAirFighter(rnd.Next(200, 500), rnd.Next(2000, 5000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetData(_airFighter);
}
/// <summary>
/// Обработка нажатий кнопок перемещения
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBoxAirFighter.Image = _abstractMap?.MoveObject(dir);
}
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonUpgrade_Click(object sender, EventArgs e)
{
Random rnd = new();
var _airFighter = new DrawningUpgradeAirFighter(rnd.Next(300, 600), rnd.Next(2000, 5000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(_airFighter);
}
/// <summary>
/// Изменение карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Карта шторма":
_abstractMap = new StormMap();
break;
}
}
}
}

View File

@ -0,0 +1,212 @@
namespace AirFighter
{
partial class FormMapWithSetAirFighters
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox = new System.Windows.Forms.GroupBox();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveAirFighter = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddAirFighter = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBox
//
this.groupBox.Controls.Add(this.buttonUp);
this.groupBox.Controls.Add(this.buttonDown);
this.groupBox.Controls.Add(this.buttonLeft);
this.groupBox.Controls.Add(this.buttonRight);
this.groupBox.Controls.Add(this.buttonShowOnMap);
this.groupBox.Controls.Add(this.buttonShowStorage);
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.Name = "groupBox";
this.groupBox.Size = new System.Drawing.Size(250, 450);
this.groupBox.TabIndex = 0;
this.groupBox.TabStop = false;
this.groupBox.Text = "Инструменты";
//
// buttonUp
//
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.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 2;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
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.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 3;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
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.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
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.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(28, 296);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(210, 29);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(28, 252);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(210, 29);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonRemoveAirFighter
//
this.buttonRemoveAirFighter.Location = new System.Drawing.Point(28, 194);
this.buttonRemoveAirFighter.Name = "buttonRemoveAirFighter";
this.buttonRemoveAirFighter.Size = new System.Drawing.Size(210, 29);
this.buttonRemoveAirFighter.TabIndex = 3;
this.buttonRemoveAirFighter.Text = "Удалить самолет";
this.buttonRemoveAirFighter.UseVisualStyleBackColor = true;
this.buttonRemoveAirFighter.Click += new System.EventHandler(this.ButtonRemoveAirFighter_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(28, 145);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27);
this.maskedTextBoxPosition.TabIndex = 2;
//
// buttonAddAirFighter
//
this.buttonAddAirFighter.Location = new System.Drawing.Point(28, 96);
this.buttonAddAirFighter.Name = "buttonAddAirFighter";
this.buttonAddAirFighter.Size = new System.Drawing.Size(210, 29);
this.buttonAddAirFighter.TabIndex = 1;
this.buttonAddAirFighter.Text = "Добавить самолет";
this.buttonAddAirFighter.UseVisualStyleBackColor = true;
this.buttonAddAirFighter.Click += new System.EventHandler(this.ButtonAddAirFighter_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(28, 45);
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.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// 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.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox);
this.Name = "FormMapWithSetAirFighters";
this.Text = "FormMapWithSetAirFighters";
this.groupBox.ResumeLayout(false);
this.groupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBox;
private Button buttonShowOnMap;
private Button buttonShowStorage;
private Button buttonRemoveAirFighter;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddAirFighter;
private ComboBox comboBoxSelectorMap;
private PictureBox pictureBox;
private Button buttonUp;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
}
}

View File

@ -0,0 +1,166 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.DataFormats;
namespace AirFighter
{
public partial class FormMapWithSetAirFighters : Form
{
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetAirFightersGeneric<DrawningObjectAirFighter, AbstractMap> _mapAirFightersCollectionGeneric;
/// <summary>
/// Конструктор
public FormMapWithSetAirFighters()
{
InitializeComponent();
}
/// <summary>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender,
EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Карта шторма":
map = new StormMap();
break;
}
if (map != null)
{
_mapAirFightersCollectionGeneric = new
MapWithSetAirFightersGeneric<DrawningObjectAirFighter, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapAirFightersCollectionGeneric = null;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <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("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveAirFighter_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if ((_mapAirFightersCollectionGeneric - pos) != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapAirFightersCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapAirFightersCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapAirFightersCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapAirFightersCollectionGeneric == null)
{
return;
}
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBox.Image = _mapAirFightersCollectionGeneric.MoveObject(dir);
}
}
}

View File

@ -57,7 +57,4 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root> </root>

View File

@ -0,0 +1,203 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirFighter
{
/// <summary>
/// Карта с набром объектов под нее
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class MapWithSetAirFightersGeneric<T, U>
where T : class, IDrawningObject
where U : AbstractMap
{
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetAirFightersGeneric<T> _setAirFighters;
/// <summary>
/// Карта
/// </summary>
private readonly U _map;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="map"></param>
public MapWithSetAirFightersGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setAirFighters = new SetAirFightersGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="map"></param>
/// <param name="car"></param>
/// <returns></returns>
public static int operator +(MapWithSetAirFightersGeneric<T, U> map, T airFighter)
{
return map._setAirFighters.Insert(airFighter);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="map"></param>
/// <param name="position"></param>
/// <returns></returns>
public static T operator -(MapWithSetAirFightersGeneric<T, U> map, int
position)
{
return map._setAirFighters.Remove(position);
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawAirFighters(gr);
return bmp;
}
/// <summary>
/// Просмотр объекта на карте
/// </summary>
/// <returns></returns>
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setAirFighters.Count; i++)
{
var airFighter = _setAirFighters.Get(i);
if (airFighter != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, airFighter);
}
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// Перемещение объекта по крате
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary>
private void Shaking()
{
int j = _setAirFighters.Count - 1;
for (int i = 0; i < _setAirFighters.Count; i++)
{
if (_setAirFighters.Get(i) == null)
{
for (; j > i; j--)
{
var airFighter = _setAirFighters.Get(j);
if (airFighter != null)
{
_setAirFighters.Insert(airFighter, i);
_setAirFighters.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i *
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
g.FillPolygon(new SolidBrush(Color.Gray), new PointF[]
{
new Point(i * _placeSizeWidth + _placeSizeWidth / 5, j * _placeSizeHeight + _placeSizeHeight / 10),
new Point((i + 1) * _placeSizeWidth - _placeSizeWidth / 5, j * _placeSizeHeight + _placeSizeHeight / 10),
new Point((i + 1) * _placeSizeWidth - _placeSizeWidth / 5, (j + 1) * _placeSizeHeight - _placeSizeHeight / 10),
new Point(i * _placeSizeWidth + _placeSizeWidth / 5, (j + 1) * _placeSizeHeight - _placeSizeHeight / 10),
});
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawAirFighters(Graphics g)
{
int currentWidth = _pictureWidth / _placeSizeWidth - 1;
int currentHeight = _pictureHeight / _placeSizeHeight - 1;
for (int i = 0; i < _setAirFighters.Count; i++)
{
_setAirFighters.Get(i)?.SetObject(currentWidth * _placeSizeWidth + 50, currentHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
_setAirFighters.Get(i)?.DrawningObject(g);
if(currentWidth > 0)
{
currentWidth -= 1;
}
else
{
if(currentHeight > 0)
{
currentHeight -= 1;
currentWidth = _pictureWidth / _placeSizeWidth - 1;
}else return;
}
}
}
}
}

View File

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

View File

@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.VisualStyles;
namespace AirFighter
{
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T"></typeparam>
internal class SetAirFightersGeneric<T>
where T: class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private readonly T[] _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Length;
/// <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;
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="airFighter">Добавляемый автомобиль</param>
/// <returns></returns>
public int Insert(T airFighter)
{
return Insert(airFighter, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="airFighter">Добавляемый автомобиль</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public int Insert(T airFighter, int position)
{
if(airFighter == null)
{
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;
}
}
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Remove(int position)
{
if (position >= 0 && position < _places.Length && _places[position] != null)
{
T temp = _places[position];
_places[position] = null;
return temp;
}
else
return null;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Get(int position)
{
if (_places[position] != null)
{
return _places[position];
}
else
return null;
}
}
}