Compare commits

...

8 Commits
main ... Lab5

Author SHA1 Message Date
344fbdbca8 Лабораторная №5 готова 2023-11-19 18:24:41 +04:00
5510581b53 Лабораторная №4 готова 2023-11-19 17:56:27 +04:00
0922c3809f Всё готово 2023-11-19 17:11:10 +04:00
a768d109b5 Финальные правки 2023-11-19 00:10:06 +04:00
530345052e До редактирования формы 2023-11-18 23:42:06 +04:00
d898e0f034 Лаб1 2023-11-18 22:48:03 +04:00
e49ac3812f readme 2023-11-18 22:22:28 +04:00
af229fc84e readme 2023-11-18 22:21:30 +04:00
36 changed files with 2478 additions and 81 deletions

View File

@ -8,4 +8,23 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Folder Include="MovementStrategy\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
using AirBomber.Rendering;
namespace AirBomber
{
public delegate void BomberDelegate(BomberRendererBase Renderer);
}

193
AirBomber/BomberForm.Designer.cs generated Normal file
View File

@ -0,0 +1,193 @@
namespace AirBomber
{
partial class BomberForm
{
/// <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()
{
BomberPictureBox = new PictureBox();
ButtonCreateBomberBase = new Button();
ButtonRight = new Button();
ButtonDown = new Button();
ButtonLeft = new Button();
ButtonUp = new Button();
MovementStrategyComboBox = new ComboBox();
ButtonCreateBomber = new Button();
ButtonPerformMove = new Button();
SelectBomberButton = new Button();
((System.ComponentModel.ISupportInitialize)BomberPictureBox).BeginInit();
SuspendLayout();
//
// BomberPictureBox
//
BomberPictureBox.Dock = DockStyle.Fill;
BomberPictureBox.Location = new Point(0, 0);
BomberPictureBox.Name = "BomberPictureBox";
BomberPictureBox.Size = new Size(884, 461);
BomberPictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
BomberPictureBox.TabIndex = 0;
BomberPictureBox.TabStop = false;
//
// ButtonCreateBomberBase
//
ButtonCreateBomberBase.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonCreateBomberBase.Location = new Point(177, 407);
ButtonCreateBomberBase.Name = "ButtonCreateBomberBase";
ButtonCreateBomberBase.Size = new Size(159, 42);
ButtonCreateBomberBase.TabIndex = 1;
ButtonCreateBomberBase.Text = "Создать бомбардировщик";
ButtonCreateBomberBase.UseVisualStyleBackColor = true;
ButtonCreateBomberBase.Click += ButtonCreateBomberBase_Click;
//
// ButtonRight
//
ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
ButtonRight.BackgroundImage = Properties.Resources.ArrowRight;
ButtonRight.BackgroundImageLayout = ImageLayout.Zoom;
ButtonRight.Location = new Point(842, 419);
ButtonRight.Name = "ButtonRight";
ButtonRight.Size = new Size(30, 30);
ButtonRight.TabIndex = 2;
ButtonRight.UseVisualStyleBackColor = true;
ButtonRight.Click += ButtonMove_Click;
//
// ButtonDown
//
ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
ButtonDown.BackgroundImage = Properties.Resources.ArrowDown;
ButtonDown.BackgroundImageLayout = ImageLayout.Zoom;
ButtonDown.Location = new Point(806, 419);
ButtonDown.Name = "ButtonDown";
ButtonDown.Size = new Size(30, 30);
ButtonDown.TabIndex = 3;
ButtonDown.UseVisualStyleBackColor = true;
ButtonDown.Click += ButtonMove_Click;
//
// ButtonLeft
//
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
ButtonLeft.BackgroundImage = Properties.Resources.ArrowLeft;
ButtonLeft.BackgroundImageLayout = ImageLayout.Zoom;
ButtonLeft.Location = new Point(770, 419);
ButtonLeft.Name = "ButtonLeft";
ButtonLeft.Size = new Size(30, 30);
ButtonLeft.TabIndex = 4;
ButtonLeft.UseVisualStyleBackColor = true;
ButtonLeft.Click += ButtonMove_Click;
//
// ButtonUp
//
ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
ButtonUp.BackgroundImage = Properties.Resources.ArrowUp;
ButtonUp.BackgroundImageLayout = ImageLayout.Zoom;
ButtonUp.Location = new Point(806, 383);
ButtonUp.Name = "ButtonUp";
ButtonUp.Size = new Size(30, 30);
ButtonUp.TabIndex = 5;
ButtonUp.UseVisualStyleBackColor = true;
ButtonUp.Click += ButtonMove_Click;
//
// MovementStrategyComboBox
//
MovementStrategyComboBox.Anchor = AnchorStyles.Top | AnchorStyles.Right;
MovementStrategyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
MovementStrategyComboBox.FormattingEnabled = true;
MovementStrategyComboBox.Items.AddRange(new object[] { "Перемещать в центр", "Перемещать вправо вниз" });
MovementStrategyComboBox.Location = new Point(706, 12);
MovementStrategyComboBox.Name = "MovementStrategyComboBox";
MovementStrategyComboBox.Size = new Size(166, 23);
MovementStrategyComboBox.TabIndex = 6;
//
// ButtonCreateBomber
//
ButtonCreateBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonCreateBomber.Location = new Point(12, 407);
ButtonCreateBomber.Name = "ButtonCreateBomber";
ButtonCreateBomber.Size = new Size(159, 42);
ButtonCreateBomber.TabIndex = 7;
ButtonCreateBomber.Text = "Создать продвинутый бомбардировщик";
ButtonCreateBomber.UseVisualStyleBackColor = true;
ButtonCreateBomber.Click += ButtonCreateBomber_Click;
//
// ButtonPerformMove
//
ButtonPerformMove.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonPerformMove.Location = new Point(706, 50);
ButtonPerformMove.Name = "ButtonPerformMove";
ButtonPerformMove.Size = new Size(166, 31);
ButtonPerformMove.TabIndex = 8;
ButtonPerformMove.Text = "Сделать шаг";
ButtonPerformMove.UseVisualStyleBackColor = true;
ButtonPerformMove.Click += ButtonPerformStep_Click;
//
// SelectBomberButton
//
SelectBomberButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
SelectBomberButton.Location = new Point(354, 407);
SelectBomberButton.Name = "SelectBomberButton";
SelectBomberButton.Size = new Size(159, 42);
SelectBomberButton.TabIndex = 9;
SelectBomberButton.Text = "Выбрать бомбардировщик";
SelectBomberButton.UseVisualStyleBackColor = true;
SelectBomberButton.Click += ButtonSelectEntity_Click;
//
// BomberForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(884, 461);
Controls.Add(SelectBomberButton);
Controls.Add(ButtonPerformMove);
Controls.Add(ButtonCreateBomber);
Controls.Add(MovementStrategyComboBox);
Controls.Add(ButtonUp);
Controls.Add(ButtonLeft);
Controls.Add(ButtonDown);
Controls.Add(ButtonRight);
Controls.Add(ButtonCreateBomberBase);
Controls.Add(BomberPictureBox);
Name = "BomberForm";
StartPosition = FormStartPosition.CenterScreen;
Text = "Бомбардировщик";
((System.ComponentModel.ISupportInitialize)BomberPictureBox).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private PictureBox BomberPictureBox;
private Button ButtonCreateBomberBase;
private Button ButtonRight;
private Button ButtonDown;
private Button ButtonLeft;
private Button ButtonUp;
private ComboBox MovementStrategyComboBox;
private Button ButtonCreateBomber;
private Button ButtonPerformMove;
private Button SelectBomberButton;
}
}

163
AirBomber/BomberForm.cs Normal file
View File

@ -0,0 +1,163 @@
using AirBomber.MovementStrategy;
using AirBomber.Rendering;
namespace AirBomber
{
public partial class BomberForm : Form
{
private BomberRendererBase? _bomberRenderer;
private AbstractStrategy? _strategy;
public BomberRendererBase? SelectedRenderer { get; private set; }
public BomberForm()
{
InitializeComponent();
_strategy = null;
SelectedRenderer = null;
}
private void Draw()
{
if (_bomberRenderer == null)
return;
Bitmap bmp = new Bitmap(BomberPictureBox.Width, BomberPictureBox.Height);
Graphics g = Graphics.FromImage(bmp);
_bomberRenderer.DrawEntity(g);
BomberPictureBox.Image = bmp;
}
private void ButtonCreateBomber_Click(object sender, EventArgs e)
{
Random random = new Random();
Color BodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color AdditionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog BodyColorPicker = new ColorDialog();
if (BodyColorPicker.ShowDialog() == DialogResult.OK)
BodyColor = BodyColorPicker.Color;
ColorDialog AdditionalColorPicker = new ColorDialog();
if (AdditionalColorPicker.ShowDialog() == DialogResult.OK)
AdditionalColor = AdditionalColorPicker.Color;
_bomberRenderer = new BomberRenderer(
random.Next(100, 300),
random.Next(1000, 3000),
BodyColor,
AdditionalColor,
true,
true,
BomberPictureBox.Width,
BomberPictureBox.Height
);
_bomberRenderer.SetPosition(random.Next(10, 60), random.Next(10, 60));
MovementStrategyComboBox.Enabled = true;
Draw();
}
private void ButtonCreateBomberBase_Click(object sender, EventArgs e)
{
Random random = new Random();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_bomberRenderer = new BomberRendererBase(
random.Next(100, 200),
random.Next(1000, 1800),
color,
BomberPictureBox.Width,
BomberPictureBox.Height
);
_bomberRenderer.SetPosition(random.Next(20, 100), random.Next(20, 100));
MovementStrategyComboBox.Enabled = true;
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_bomberRenderer == null)
return;
string ButtonName = ((Button)sender)?.Name ?? string.Empty;
switch (ButtonName)
{
case "ButtonUp":
_bomberRenderer.MoveEntity(DirectionType.Up);
break;
case "ButtonDown":
_bomberRenderer.MoveEntity(DirectionType.Down);
break;
case "ButtonLeft":
_bomberRenderer.MoveEntity(DirectionType.Left);
break;
case "ButtonRight":
_bomberRenderer.MoveEntity(DirectionType.Right);
break;
}
Draw();
}
private void ButtonPerformStep_Click(object sender, EventArgs e)
{
if (_bomberRenderer is null)
return;
if (MovementStrategyComboBox.Enabled)
{
_strategy = MovementStrategyComboBox.SelectedIndex switch
{
0 => new MoveToCenterStrategy(),
1 => new MoveToDownRightStrategy(),
_ => null,
};
if (_strategy is null)
return;
_strategy.SetData(
_bomberRenderer.MovableObject,
BomberPictureBox.Width,
BomberPictureBox.Height
);
}
if (_strategy is null)
return;
MovementStrategyComboBox.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == Status.Finish)
{
MovementStrategyComboBox.Enabled = true;
_strategy = null;
}
}
private void ButtonSelectEntity_Click(object sender, EventArgs e)
{
SelectedRenderer = _bomberRenderer;
DialogResult = DialogResult.OK;
}
}
}

View File

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

View File

@ -0,0 +1,22 @@
namespace AirBomber.Entities
{
public class BomberEntity : BomberEntityBase
{
public Color AdditionalColor { get; private set; }
public bool Bombs { get; private set; }
public bool FuelTanks { get; private set; }
public BomberEntity(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool FuelTanks, bool Bombs)
: base(Speed, Weight, BodyColor)
{
this.AdditionalColor = AdditionalColor;
this.FuelTanks = FuelTanks;
this.Bombs = Bombs;
}
public void SetAdditionalColor(Color AdditionalColor)
{
this.AdditionalColor = AdditionalColor;
}
}
}

View File

@ -0,0 +1,22 @@
namespace AirBomber.Entities
{
public class BomberEntityBase
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public double Step => (double)Speed * 100 / Weight * 5 / 2;
public BomberEntityBase(int Speed, double Weight, Color BodyColor)
{
this.Speed = Speed;
this.Weight = Weight;
this.BodyColor = BodyColor;
}
public void SetBaseColor(Color BaseColor)
{
BodyColor = BaseColor;
}
}
}

View File

@ -1,39 +0,0 @@
namespace AirBomber
{
partial class Form1
{
/// <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.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace AirBomber
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

370
AirBomber/FormBomberConfig.Designer.cs generated Normal file
View File

@ -0,0 +1,370 @@
namespace AirBomber
{
partial class FormBomberConfig
{
/// <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()
{
ParamsGroupBox = new GroupBox();
AdvancedEntityLabel = new Label();
BaseEntityLabel = new Label();
ColorsGroupBox = new GroupBox();
VioletPanel = new Panel();
BlackPanel = new Panel();
GrayPanel = new Panel();
WhitePanel = new Panel();
OrangePanel = new Panel();
BluePanel = new Panel();
GreenPanel = new Panel();
RedPanel = new Panel();
FuelTanksCheckbox = new CheckBox();
BombsCheckBox = new CheckBox();
WeightNumericUpDown = new NumericUpDown();
SpeedNumericUpDown = new NumericUpDown();
WeightLabel = new Label();
SpeedLabel = new Label();
ObjectRepresentationPanel = new Panel();
EntityPictureBox = new PictureBox();
AdditionalColorLabel = new Label();
ColorLabel = new Label();
AddButton = new Button();
ConfigCancelButton = new Button();
ParamsGroupBox.SuspendLayout();
ColorsGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)WeightNumericUpDown).BeginInit();
((System.ComponentModel.ISupportInitialize)SpeedNumericUpDown).BeginInit();
ObjectRepresentationPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)EntityPictureBox).BeginInit();
SuspendLayout();
//
// ParamsGroupBox
//
ParamsGroupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
ParamsGroupBox.Controls.Add(AdvancedEntityLabel);
ParamsGroupBox.Controls.Add(BaseEntityLabel);
ParamsGroupBox.Controls.Add(ColorsGroupBox);
ParamsGroupBox.Controls.Add(FuelTanksCheckbox);
ParamsGroupBox.Controls.Add(BombsCheckBox);
ParamsGroupBox.Controls.Add(WeightNumericUpDown);
ParamsGroupBox.Controls.Add(SpeedNumericUpDown);
ParamsGroupBox.Controls.Add(WeightLabel);
ParamsGroupBox.Controls.Add(SpeedLabel);
ParamsGroupBox.Location = new Point(12, 12);
ParamsGroupBox.Name = "ParamsGroupBox";
ParamsGroupBox.Size = new Size(555, 343);
ParamsGroupBox.TabIndex = 0;
ParamsGroupBox.TabStop = false;
ParamsGroupBox.Text = "Параметры";
//
// AdvancedEntityLabel
//
AdvancedEntityLabel.BorderStyle = BorderStyle.FixedSingle;
AdvancedEntityLabel.Location = new Point(391, 200);
AdvancedEntityLabel.Name = "AdvancedEntityLabel";
AdvancedEntityLabel.Size = new Size(110, 40);
AdvancedEntityLabel.TabIndex = 9;
AdvancedEntityLabel.Text = "Продвинутый";
AdvancedEntityLabel.TextAlign = ContentAlignment.MiddleCenter;
AdvancedEntityLabel.MouseDown += LabelObject_MouseDown;
//
// BaseEntityLabel
//
BaseEntityLabel.BorderStyle = BorderStyle.FixedSingle;
BaseEntityLabel.Location = new Point(250, 200);
BaseEntityLabel.Name = "BaseEntityLabel";
BaseEntityLabel.Size = new Size(110, 40);
BaseEntityLabel.TabIndex = 8;
BaseEntityLabel.Text = "Простой";
BaseEntityLabel.TextAlign = ContentAlignment.MiddleCenter;
BaseEntityLabel.MouseDown += LabelObject_MouseDown;
//
// ColorsGroupBox
//
ColorsGroupBox.Controls.Add(VioletPanel);
ColorsGroupBox.Controls.Add(BlackPanel);
ColorsGroupBox.Controls.Add(GrayPanel);
ColorsGroupBox.Controls.Add(WhitePanel);
ColorsGroupBox.Controls.Add(OrangePanel);
ColorsGroupBox.Controls.Add(BluePanel);
ColorsGroupBox.Controls.Add(GreenPanel);
ColorsGroupBox.Controls.Add(RedPanel);
ColorsGroupBox.Location = new Point(235, 22);
ColorsGroupBox.Name = "ColorsGroupBox";
ColorsGroupBox.Size = new Size(281, 155);
ColorsGroupBox.TabIndex = 7;
ColorsGroupBox.TabStop = false;
ColorsGroupBox.Text = "Цвета";
//
// VioletPanel
//
VioletPanel.BackColor = Color.BlueViolet;
VioletPanel.ForeColor = SystemColors.ControlText;
VioletPanel.Location = new Point(216, 90);
VioletPanel.Name = "VioletPanel";
VioletPanel.Size = new Size(50, 50);
VioletPanel.TabIndex = 4;
//
// BlackPanel
//
BlackPanel.BackColor = Color.Black;
BlackPanel.ForeColor = SystemColors.ControlText;
BlackPanel.Location = new Point(150, 90);
BlackPanel.Name = "BlackPanel";
BlackPanel.Size = new Size(50, 50);
BlackPanel.TabIndex = 3;
//
// GrayPanel
//
GrayPanel.BackColor = Color.LightSlateGray;
GrayPanel.ForeColor = SystemColors.ControlText;
GrayPanel.Location = new Point(82, 90);
GrayPanel.Name = "GrayPanel";
GrayPanel.Size = new Size(50, 50);
GrayPanel.TabIndex = 2;
//
// WhitePanel
//
WhitePanel.BackColor = Color.White;
WhitePanel.ForeColor = SystemColors.ControlText;
WhitePanel.Location = new Point(15, 90);
WhitePanel.Name = "WhitePanel";
WhitePanel.Size = new Size(50, 50);
WhitePanel.TabIndex = 1;
//
// OrangePanel
//
OrangePanel.BackColor = Color.Orange;
OrangePanel.ForeColor = SystemColors.ControlText;
OrangePanel.Location = new Point(216, 22);
OrangePanel.Name = "OrangePanel";
OrangePanel.Size = new Size(50, 50);
OrangePanel.TabIndex = 3;
//
// BluePanel
//
BluePanel.BackColor = Color.RoyalBlue;
BluePanel.ForeColor = SystemColors.ControlText;
BluePanel.Location = new Point(150, 22);
BluePanel.Name = "BluePanel";
BluePanel.Size = new Size(50, 50);
BluePanel.TabIndex = 2;
//
// GreenPanel
//
GreenPanel.BackColor = Color.Green;
GreenPanel.ForeColor = SystemColors.ControlText;
GreenPanel.Location = new Point(82, 22);
GreenPanel.Name = "GreenPanel";
GreenPanel.Size = new Size(50, 50);
GreenPanel.TabIndex = 1;
//
// RedPanel
//
RedPanel.BackColor = Color.Red;
RedPanel.ForeColor = SystemColors.ControlText;
RedPanel.Location = new Point(15, 22);
RedPanel.Name = "RedPanel";
RedPanel.Size = new Size(50, 50);
RedPanel.TabIndex = 0;
//
// FuelTanksCheckbox
//
FuelTanksCheckbox.AutoSize = true;
FuelTanksCheckbox.Location = new Point(20, 158);
FuelTanksCheckbox.Name = "FuelTanksCheckbox";
FuelTanksCheckbox.Size = new Size(174, 19);
FuelTanksCheckbox.TabIndex = 5;
FuelTanksCheckbox.Text = "Наличие топливных баков";
FuelTanksCheckbox.UseVisualStyleBackColor = true;
//
// BombsCheckBox
//
BombsCheckBox.AutoSize = true;
BombsCheckBox.Location = new Point(20, 123);
BombsCheckBox.Name = "BombsCheckBox";
BombsCheckBox.Size = new Size(108, 19);
BombsCheckBox.TabIndex = 4;
BombsCheckBox.Text = "Наличие бомб";
BombsCheckBox.UseVisualStyleBackColor = true;
//
// WeightNumericUpDown
//
WeightNumericUpDown.Location = new Point(88, 71);
WeightNumericUpDown.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
WeightNumericUpDown.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
WeightNumericUpDown.Name = "WeightNumericUpDown";
WeightNumericUpDown.Size = new Size(120, 23);
WeightNumericUpDown.TabIndex = 3;
WeightNumericUpDown.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// SpeedNumericUpDown
//
SpeedNumericUpDown.Location = new Point(88, 32);
SpeedNumericUpDown.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
SpeedNumericUpDown.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
SpeedNumericUpDown.Name = "SpeedNumericUpDown";
SpeedNumericUpDown.Size = new Size(120, 23);
SpeedNumericUpDown.TabIndex = 2;
SpeedNumericUpDown.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// WeightLabel
//
WeightLabel.AutoSize = true;
WeightLabel.Location = new Point(20, 73);
WeightLabel.Name = "WeightLabel";
WeightLabel.Size = new Size(29, 15);
WeightLabel.TabIndex = 1;
WeightLabel.Text = "Вес:";
//
// SpeedLabel
//
SpeedLabel.AutoSize = true;
SpeedLabel.Location = new Point(20, 34);
SpeedLabel.Name = "SpeedLabel";
SpeedLabel.Size = new Size(62, 15);
SpeedLabel.TabIndex = 0;
SpeedLabel.Text = "Скорость:";
//
// ObjectRepresentationPanel
//
ObjectRepresentationPanel.AllowDrop = true;
ObjectRepresentationPanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
ObjectRepresentationPanel.Controls.Add(EntityPictureBox);
ObjectRepresentationPanel.Controls.Add(AdditionalColorLabel);
ObjectRepresentationPanel.Controls.Add(ColorLabel);
ObjectRepresentationPanel.Location = new Point(582, 12);
ObjectRepresentationPanel.Name = "ObjectRepresentationPanel";
ObjectRepresentationPanel.Size = new Size(311, 307);
ObjectRepresentationPanel.TabIndex = 1;
ObjectRepresentationPanel.DragDrop += PanelObject_DragDrop;
ObjectRepresentationPanel.DragEnter += PanelObject_DragEnter;
//
// EntityPictureBox
//
EntityPictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
EntityPictureBox.Location = new Point(13, 52);
EntityPictureBox.Name = "EntityPictureBox";
EntityPictureBox.Size = new Size(283, 252);
EntityPictureBox.TabIndex = 2;
EntityPictureBox.TabStop = false;
//
// AdditionalColorLabel
//
AdditionalColorLabel.AllowDrop = true;
AdditionalColorLabel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
AdditionalColorLabel.BorderStyle = BorderStyle.FixedSingle;
AdditionalColorLabel.Location = new Point(180, 12);
AdditionalColorLabel.Name = "AdditionalColorLabel";
AdditionalColorLabel.Size = new Size(115, 35);
AdditionalColorLabel.TabIndex = 1;
AdditionalColorLabel.Text = "Доп цвет";
AdditionalColorLabel.TextAlign = ContentAlignment.MiddleCenter;
AdditionalColorLabel.DragDrop += LabelAdditionalColor_DragDrop;
AdditionalColorLabel.DragEnter += LabelColor_DragEnter;
//
// ColorLabel
//
ColorLabel.AllowDrop = true;
ColorLabel.BorderStyle = BorderStyle.FixedSingle;
ColorLabel.Location = new Point(13, 12);
ColorLabel.Name = "ColorLabel";
ColorLabel.Size = new Size(115, 35);
ColorLabel.TabIndex = 0;
ColorLabel.Text = "Цвет";
ColorLabel.TextAlign = ContentAlignment.MiddleCenter;
ColorLabel.DragDrop += LabelBaseColor_DragDrop;
ColorLabel.DragEnter += LabelColor_DragEnter;
//
// AddButton
//
AddButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
AddButton.Location = new Point(607, 325);
AddButton.Name = "AddButton";
AddButton.Size = new Size(104, 30);
AddButton.TabIndex = 2;
AddButton.Text = "Добавить";
AddButton.UseVisualStyleBackColor = true;
AddButton.Click += OkButtonClick;
//
// ConfigCancelButton
//
ConfigCancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
ConfigCancelButton.Location = new Point(764, 325);
ConfigCancelButton.Name = "ConfigCancelButton";
ConfigCancelButton.Size = new Size(100, 30);
ConfigCancelButton.TabIndex = 3;
ConfigCancelButton.Text = "Отмена";
ConfigCancelButton.UseVisualStyleBackColor = true;
//
// FormBomberConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(905, 367);
Controls.Add(ConfigCancelButton);
Controls.Add(AddButton);
Controls.Add(ObjectRepresentationPanel);
Controls.Add(ParamsGroupBox);
Name = "FormBomberConfig";
Text = "Создание объекта";
ParamsGroupBox.ResumeLayout(false);
ParamsGroupBox.PerformLayout();
ColorsGroupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)WeightNumericUpDown).EndInit();
((System.ComponentModel.ISupportInitialize)SpeedNumericUpDown).EndInit();
ObjectRepresentationPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)EntityPictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox ParamsGroupBox;
private GroupBox ColorsGroupBox;
private Panel RedPanel;
private CheckBox FuelTanksCheckbox;
private CheckBox BombsCheckBox;
private NumericUpDown WeightNumericUpDown;
private NumericUpDown SpeedNumericUpDown;
private Label WeightLabel;
private Label SpeedLabel;
private Panel ObjectRepresentationPanel;
private PictureBox EntityPictureBox;
private Label AdditionalColorLabel;
private Label ColorLabel;
private Button AddButton;
private Panel OrangePanel;
private Panel BluePanel;
private Panel GreenPanel;
private Label AdvancedEntityLabel;
private Label BaseEntityLabel;
private Panel VioletPanel;
private Panel BlackPanel;
private Panel GrayPanel;
private Panel WhitePanel;
private Button ConfigCancelButton;
}
}

View File

@ -0,0 +1,124 @@
using AirBomber.Rendering;
namespace AirBomber
{
public partial class FormBomberConfig : Form
{
BomberRendererBase? _renderer = null;
private event Action<BomberRendererBase>? OnBomberAdded;
public FormBomberConfig()
{
InitializeComponent();
RedPanel.MouseDown += PanelColor_MouseDown;
GreenPanel.MouseDown += PanelColor_MouseDown;
BluePanel.MouseDown += PanelColor_MouseDown;
OrangePanel.MouseDown += PanelColor_MouseDown;
WhitePanel.MouseDown += PanelColor_MouseDown;
GrayPanel.MouseDown += PanelColor_MouseDown;
BlackPanel.MouseDown += PanelColor_MouseDown;
VioletPanel.MouseDown += PanelColor_MouseDown;
ConfigCancelButton.Click += (sender, e) => { Close(); };
}
private void DrawBomber()
{
Bitmap bmp = new Bitmap(EntityPictureBox.Width, EntityPictureBox.Height);
Graphics g = Graphics.FromImage(bmp);
_renderer?.SetPosition(5, 5);
_renderer?.DrawEntity(g);
EntityPictureBox.Image = bmp;
}
public void AddEvent(Action<BomberRendererBase> ev)
{
if (OnBomberAdded is null)
OnBomberAdded = ev;
else
OnBomberAdded += ev;
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelColor_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent("System.Drawing.Color") ?? false)
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "BaseEntityLabel":
_renderer = new BomberRendererBase(
(int)SpeedNumericUpDown.Value,
(int)WeightNumericUpDown.Value,
Color.White,
EntityPictureBox.Width, EntityPictureBox.Height
);
break;
case "AdvancedEntityLabel":
_renderer = new BomberRenderer(
(int)SpeedNumericUpDown.Value,
(int)WeightNumericUpDown.Value,
Color.White, Color.Black,
FuelTanksCheckbox.Checked,
BombsCheckBox.Checked,
EntityPictureBox.Width, EntityPictureBox.Height
);
break;
}
DrawBomber();
}
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
Color SelectedColor = (Color)e.Data?.GetData("System.Drawing.Color")!;
_renderer?.SetBaseColor(SelectedColor);
DrawBomber();
}
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
Color SelectedColor = (Color)e.Data?.GetData("System.Drawing.Color")!;
(_renderer as BomberRenderer)?.SetAdditionalColor(SelectedColor);
DrawBomber();
}
private void OkButtonClick(object sender, EventArgs e)
{
if (_renderer is not null)
OnBomberAdded?.Invoke(_renderer);
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

192
AirBomber/FormEntityCollection.Designer.cs generated Normal file
View File

@ -0,0 +1,192 @@
namespace AirBomber
{
partial class FormEntityCollection
{
/// <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()
{
CollectionPictureBox = new PictureBox();
ToolGroupBox = new GroupBox();
SetsGroupBox = new GroupBox();
SetNameTextBox = new TextBox();
StorageListBox = new ListBox();
AddSetButton = new Button();
RemoveSetButton = new Button();
RefreshCollectionButton = new Button();
RemoveBomberButton = new Button();
NumberMaskedTextBox = new MaskedTextBox();
AddBomberButton = new Button();
((System.ComponentModel.ISupportInitialize)CollectionPictureBox).BeginInit();
ToolGroupBox.SuspendLayout();
SetsGroupBox.SuspendLayout();
SuspendLayout();
//
// CollectionPictureBox
//
CollectionPictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
CollectionPictureBox.Location = new Point(0, 0);
CollectionPictureBox.Name = "CollectionPictureBox";
CollectionPictureBox.Size = new Size(812, 603);
CollectionPictureBox.TabIndex = 0;
CollectionPictureBox.TabStop = false;
//
// ToolGroupBox
//
ToolGroupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
ToolGroupBox.Controls.Add(SetsGroupBox);
ToolGroupBox.Controls.Add(RefreshCollectionButton);
ToolGroupBox.Controls.Add(RemoveBomberButton);
ToolGroupBox.Controls.Add(NumberMaskedTextBox);
ToolGroupBox.Controls.Add(AddBomberButton);
ToolGroupBox.Location = new Point(818, 12);
ToolGroupBox.Name = "ToolGroupBox";
ToolGroupBox.Size = new Size(176, 579);
ToolGroupBox.TabIndex = 1;
ToolGroupBox.TabStop = false;
ToolGroupBox.Text = "Инструменты";
//
// SetsGroupBox
//
SetsGroupBox.Controls.Add(SetNameTextBox);
SetsGroupBox.Controls.Add(StorageListBox);
SetsGroupBox.Controls.Add(AddSetButton);
SetsGroupBox.Controls.Add(RemoveSetButton);
SetsGroupBox.Location = new Point(6, 22);
SetsGroupBox.Name = "SetsGroupBox";
SetsGroupBox.Size = new Size(164, 232);
SetsGroupBox.TabIndex = 8;
SetsGroupBox.TabStop = false;
SetsGroupBox.Text = "Наборы";
//
// SetNameTextBox
//
SetNameTextBox.Location = new Point(6, 22);
SetNameTextBox.Name = "SetNameTextBox";
SetNameTextBox.Size = new Size(152, 23);
SetNameTextBox.TabIndex = 4;
//
// StorageListBox
//
StorageListBox.FormattingEnabled = true;
StorageListBox.ItemHeight = 15;
StorageListBox.Items.AddRange(new object[] { "Наборы здесь..." });
StorageListBox.Location = new Point(6, 96);
StorageListBox.Name = "StorageListBox";
StorageListBox.Size = new Size(152, 79);
StorageListBox.TabIndex = 7;
StorageListBox.SelectedIndexChanged += StorageListBoxIndexChanged;
//
// AddSetButton
//
AddSetButton.Location = new Point(6, 51);
AddSetButton.Name = "AddSetButton";
AddSetButton.Size = new Size(152, 30);
AddSetButton.TabIndex = 5;
AddSetButton.Text = "Добавить набор";
AddSetButton.UseVisualStyleBackColor = true;
AddSetButton.Click += ButtonAddSet_Click;
//
// RemoveSetButton
//
RemoveSetButton.Location = new Point(6, 190);
RemoveSetButton.Name = "RemoveSetButton";
RemoveSetButton.Size = new Size(152, 30);
RemoveSetButton.TabIndex = 6;
RemoveSetButton.Text = "Удалить набор";
RemoveSetButton.UseVisualStyleBackColor = true;
RemoveSetButton.Click += ButtonRemoveSet_Click;
//
// RefreshCollectionButton
//
RefreshCollectionButton.Location = new Point(6, 543);
RefreshCollectionButton.Name = "RefreshCollectionButton";
RefreshCollectionButton.Size = new Size(164, 30);
RefreshCollectionButton.TabIndex = 3;
RefreshCollectionButton.Text = "Обновить коллекцию";
RefreshCollectionButton.UseVisualStyleBackColor = true;
RefreshCollectionButton.Click += ButtonRefreshCollection_Click;
//
// RemoveBomberButton
//
RemoveBomberButton.Location = new Point(6, 467);
RemoveBomberButton.Name = "RemoveBomberButton";
RemoveBomberButton.Size = new Size(164, 30);
RemoveBomberButton.TabIndex = 2;
RemoveBomberButton.Text = "Удалить бомбардировщик";
RemoveBomberButton.UseVisualStyleBackColor = true;
RemoveBomberButton.Click += ButtonRemoveEntity_Click;
//
// NumberMaskedTextBox
//
NumberMaskedTextBox.Location = new Point(6, 428);
NumberMaskedTextBox.Mask = "00000";
NumberMaskedTextBox.Name = "NumberMaskedTextBox";
NumberMaskedTextBox.Size = new Size(164, 23);
NumberMaskedTextBox.TabIndex = 1;
NumberMaskedTextBox.ValidatingType = typeof(int);
//
// AddBomberButton
//
AddBomberButton.Location = new Point(6, 358);
AddBomberButton.Name = "AddBomberButton";
AddBomberButton.Size = new Size(164, 43);
AddBomberButton.TabIndex = 0;
AddBomberButton.Text = "Добавить бомбардировщик";
AddBomberButton.UseVisualStyleBackColor = true;
AddBomberButton.Click += ButtonAddEntity_Click;
//
// FormEntityCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1006, 603);
Controls.Add(ToolGroupBox);
Controls.Add(CollectionPictureBox);
Name = "FormEntityCollection";
Text = "Набор бомбардировщиков";
((System.ComponentModel.ISupportInitialize)CollectionPictureBox).EndInit();
ToolGroupBox.ResumeLayout(false);
ToolGroupBox.PerformLayout();
SetsGroupBox.ResumeLayout(false);
SetsGroupBox.PerformLayout();
ResumeLayout(false);
}
#endregion
private PictureBox CollectionPictureBox;
private GroupBox ToolGroupBox;
private Button RefreshCollectionButton;
private Button RemoveBomberButton;
private MaskedTextBox NumberMaskedTextBox;
private Button AddBomberButton;
private GroupBox SetsGroupBox;
private TextBox SetNameTextBox;
private ListBox StorageListBox;
private Button AddSetButton;
private Button RemoveSetButton;
}
}

View File

@ -0,0 +1,131 @@
using AirBomber.Generics;
using AirBomber.Rendering;
namespace AirBomber
{
public partial class FormEntityCollection : Form
{
private readonly EntitiesGenericStorage _storage;
public FormEntityCollection()
{
InitializeComponent();
_storage = new EntitiesGenericStorage(CollectionPictureBox.Width, CollectionPictureBox.Height);
}
private void ReloadObjects()
{
int index = StorageListBox.SelectedIndex;
StorageListBox.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
StorageListBox.Items.Add(_storage.Keys[i]);
if (StorageListBox.Items.Count > 0 && (index == -1 || index >= StorageListBox.Items.Count))
StorageListBox.SelectedIndex = 0;
else if (StorageListBox.Items.Count > 0 && index > -1 && index < StorageListBox.Items.Count)
StorageListBox.SelectedIndex = index;
}
public void ButtonAddEntity_Click(object sender, EventArgs e)
{
if (StorageListBox.SelectedIndex == -1)
return;
FormBomberConfig ConfigForm = new FormBomberConfig();
ConfigForm.AddEvent(OnEntityAdded);
ConfigForm.Show();
}
public void OnEntityAdded(BomberRendererBase Renderer)
{
var obj = _storage[StorageListBox.SelectedItem.ToString() ?? string.Empty];
if (obj is null)
return;
if (obj + (Renderer) != -1)
{
MessageBox.Show("Объект добавлен");
CollectionPictureBox.Image = obj.ShowEntities();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
public void ButtonRemoveEntity_Click(object sender, EventArgs e)
{
if (StorageListBox.SelectedIndex == -1)
return;
var obj = _storage[StorageListBox.SelectedItem.ToString() ?? string.Empty];
if (obj is null)
return;
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
int Pos = Convert.ToInt32(NumberMaskedTextBox.Text);
if (obj - Pos == true)
{
MessageBox.Show("Объект удален");
CollectionPictureBox.Image = obj.ShowEntities();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
public void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
if (StorageListBox.SelectedIndex == -1)
return;
var obj = _storage[StorageListBox.SelectedItem.ToString() ?? string.Empty];
if (obj is null)
return;
CollectionPictureBox.Image = obj.ShowEntities();
}
private void ButtonAddSet_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(SetNameTextBox.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(SetNameTextBox.Text);
ReloadObjects();
}
private void ButtonRemoveSet_Click(object sender, EventArgs e)
{
if (StorageListBox.SelectedIndex == -1)
return;
if (MessageBox.Show(
$"Удалить объект{StorageListBox.SelectedItem}?",
"Удаление",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
) == DialogResult.Yes)
{
_storage.RemoveSet(StorageListBox.SelectedItem.ToString() ?? string.Empty);
ReloadObjects();
}
}
private void StorageListBoxIndexChanged(object sender, EventArgs e)
{
CollectionPictureBox.Image = _storage[StorageListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowEntities();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,102 @@
using AirBomber.MovementStrategy;
using AirBomber.Rendering;
namespace AirBomber.Generics
{
internal class EntitiesGenericCollection<T, U>
where T : BomberRendererBase
where U : IMovableObject
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 200;
private readonly int _placeSizeHeight = 200;
private readonly SetGeneric<T> _collection;
public EntitiesGenericCollection(int PictureWidth, int PictureHeight)
{
int width = PictureWidth / _placeSizeWidth;
int height = PictureHeight / _placeSizeHeight;
_pictureWidth = PictureWidth;
_pictureHeight = PictureHeight;
_collection = new SetGeneric<T>(width * height);
}
public static int operator +(EntitiesGenericCollection<T, U> collect, T? obj)
{
if (obj is null || collect is null)
return -1;
return collect._collection.Insert(obj);
}
public static bool operator -(EntitiesGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
return collect._collection.Remove(pos);
return false;
}
public U? GetU(int pos)
{
return (U?)_collection[pos]?.MovableObject;
}
public Bitmap ShowEntities()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
g.DrawLine(
pen,
i * _placeSizeWidth, j * _placeSizeHeight,
i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight
);
g.DrawLine(
pen,
i * _placeSizeWidth, 0,
i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight
);
}
}
private void DrawObjects(Graphics g)
{
int i = -1;
foreach (T? Entity in _collection.GetEntities())
{
i++;
if (Entity is null)
continue;
/** Установка позиции */
int NumX = _pictureWidth / _placeSizeWidth;
int PosX = (NumX - 1 - i % NumX) * _placeSizeWidth;
int PosY = (i / NumX) * _placeSizeHeight;
Entity.SetPosition(PosX, PosY);
Entity.DrawEntity(g);
}
}
}
}

View File

@ -0,0 +1,53 @@
using AirBomber.MovementStrategy;
using AirBomber.Rendering;
namespace AirBomber.Generics
{
internal class EntitiesGenericStorage
{
readonly Dictionary<string, EntitiesGenericCollection<BomberRendererBase, ObjectEntityRenderer>> _entityStorages;
public List<string> Keys => _entityStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public EntitiesGenericStorage(int PictureWidth, int PictureHeight)
{
_entityStorages = new Dictionary<string, EntitiesGenericCollection<BomberRendererBase, ObjectEntityRenderer>>();
_pictureWidth = PictureWidth;
_pictureHeight = PictureHeight;
}
public void AddSet(string Name)
{
var NewCollection =
new EntitiesGenericCollection<BomberRendererBase, ObjectEntityRenderer>(_pictureWidth, _pictureHeight);
if (Keys.Contains(Name))
{
MessageBox.Show("Набор с таким именем уже существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_entityStorages.Add(Name, NewCollection);
}
public void RemoveSet(string Name)
{
_entityStorages.Remove(Name);
}
public EntitiesGenericCollection<BomberRendererBase, ObjectEntityRenderer>? this[string Index]
{
get
{
if (!_entityStorages.ContainsKey(Index))
return null;
return _entityStorages[Index];
}
}
}
}

View File

@ -0,0 +1,88 @@
namespace AirBomber.Generics
{
internal class SetGeneric<T>
where T : class
{
private readonly List<T?> _objects;
private readonly int _maxCount;
public int Count => _objects.Count;
public SetGeneric(int Count)
{
_maxCount = Count;
_objects = new List<T?>(_maxCount);
for (int i = 0; i < _maxCount; i++)
_objects.Add(null);
}
public int Insert(T Entity)
{
/** Вставка в начало набора */
for (int i = 0; i < _maxCount; i++)
if (_objects[i] is null)
{
_objects[i] = Entity;
return i;
}
return -1;
}
public int Insert(T Entity, int Position)
{
if (Position >= _maxCount)
return -1;
if (_objects[Position] is null)
{
_objects[Position] = Entity;
return Position;
}
return -1;
}
public bool Remove(int Position)
{
if (Position >= _maxCount)
return false;
_objects[Position] = default(T);
return true;
}
public T? this[int Position]
{
get
{
if (Position >= _maxCount)
return null;
return _objects[Position];
}
set
{
if (Position >= _maxCount)
return;
if (_objects[Position] is not null)
return;
_objects[Position] = value;
}
}
public IEnumerable<T?> GetEntities(int? MaxEntities = null)
{
for (int i = 0; i < _objects.Count; ++i)
{
yield return _objects[i];
if (MaxEntities.HasValue && i == MaxEntities.Value)
yield break;
}
}
}
}

View File

@ -0,0 +1,76 @@
namespace AirBomber.MovementStrategy
{
public abstract class AbstractStrategy
{
private IMovableObject? _movableObject;
private Status _state = Status.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; }
public void SetData(IMovableObject MovableObject, int Width, int Height)
{
if (MovableObject is null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_movableObject = MovableObject;
FieldWidth = Width;
FieldHeight = Height;
}
public void MakeStep()
{
if (_state != Status.InProgress)
return;
if (IsTargetDestination())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(DirectionType.Left);
protected bool MoveRight() => MoveTo(DirectionType.Right);
protected bool MoveUp() => MoveTo(DirectionType.Up);
protected bool MoveDown() => MoveTo(DirectionType.Down);
protected ObjectParameters? ObjectParameters => _movableObject?.ObjectPosition;
protected int? GetStep()
{
if (_state != Status.InProgress)
return null;
return _movableObject?.Step;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestination();
private bool MoveTo(DirectionType DirectionType)
{
if (_state != Status.InProgress)
return false;
if (_movableObject?.CanMove(DirectionType) ?? false)
{
_movableObject.MoveObject(DirectionType);
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,10 @@
namespace AirBomber.MovementStrategy
{
public enum DirectionType
{
Up = 1,
Down,
Left,
Right
}
}

View File

@ -0,0 +1,12 @@
namespace AirBomber.MovementStrategy
{
public interface IMovableObject
{
ObjectParameters? ObjectPosition { get; }
int Step { get; }
bool CanMove(DirectionType Direction);
void MoveObject(DirectionType Direction);
}
}

View File

@ -0,0 +1,44 @@
namespace AirBomber.MovementStrategy
{
public class MoveToCenterStrategy : AbstractStrategy
{
protected override bool IsTargetDestination()
{
ObjectParameters? ObjParams = ObjectParameters;
if (ObjParams is null)
return false;
float FieldMiddleHorizontal = FieldWidth / 2;
float FieldMiddleVertical = FieldHeight / 2;
return
Math.Abs(ObjParams.ObjectMiddleHorizontal - FieldMiddleHorizontal) < GetStep() &&
Math.Abs(ObjParams.ObjectMiddleVertical - FieldMiddleVertical) < GetStep();
}
protected override void MoveToTarget()
{
ObjectParameters? ObjParams = ObjectParameters;
if (ObjParams is null)
return;
float diffX = ObjParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
MoveLeft();
else
MoveRight();
}
float diffY = ObjParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
MoveUp();
else
MoveDown();
}
}
}
}

View File

@ -0,0 +1,43 @@
namespace AirBomber.MovementStrategy
{
public class MoveToDownRightStrategy : AbstractStrategy
{
protected override bool IsTargetDestination()
{
ObjectParameters? ObjParams = ObjectParameters;
if (ObjParams is null)
return false;
return
ObjParams.RightBorder <= FieldWidth &&
ObjParams.RightBorder + GetStep() >= FieldWidth &&
ObjParams.BottomBorder <= FieldHeight &&
ObjParams.BottomBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
ObjectParameters? ObjParams = ObjectParameters;
if (ObjParams is null)
return;
float diffX = ObjParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
MoveLeft();
else
MoveRight();
}
float diffY = ObjParams.BottomBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
MoveUp();
else
MoveDown();
}
}
}
}

View File

@ -0,0 +1,36 @@
using AirBomber.Rendering;
namespace AirBomber.MovementStrategy
{
public class ObjectEntityRenderer : IMovableObject
{
private readonly BomberRendererBase? _entityRenderer = null;
public ObjectEntityRenderer(BomberRendererBase? EntityRenderer)
{
_entityRenderer = EntityRenderer;
}
public ObjectParameters? ObjectPosition
{
get
{
if (_entityRenderer is null || _entityRenderer.EntityBomber is null)
return null;
return new ObjectParameters(
_entityRenderer.PosX,
_entityRenderer.PosY,
_entityRenderer.EntityWidth,
_entityRenderer.EntityHeight
);
}
}
public int Step => (int)(_entityRenderer?.EntityBomber?.Step ?? 0);
public bool CanMove(DirectionType Direction) => _entityRenderer?.CanMove(Direction) ?? false;
public void MoveObject(DirectionType Direction) => _entityRenderer?.MoveEntity(Direction);
}
}

View File

@ -0,0 +1,27 @@
namespace AirBomber.MovementStrategy
{
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int TopBorder => _y;
public int RightBorder => _x + _width;
public int BottomBorder => _y + _height;
public int ObjectMiddleHorizontal => _x + _width / 2;
public int ObjectMiddleVertical => _y + _height / 2;
public ObjectParameters(int X, int Y, int Width, int Height)
{
_x = X;
_y = Y;
_width = Width;
_height = Height;
}
}
}

View File

@ -0,0 +1,9 @@
namespace AirBomber.MovementStrategy
{
public enum Status
{
NotInit = 1,
InProgress,
Finish,
}
}

View File

@ -2,16 +2,11 @@ namespace AirBomber
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(new FormEntityCollection());
}
}
}

103
AirBomber/Properties/Resources.Designer.cs generated Normal file
View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AirBomber.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AirBomber.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap ArrowDown {
get {
object obj = ResourceManager.GetObject("ArrowDown", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap ArrowLeft {
get {
object obj = ResourceManager.GetObject("ArrowLeft", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap ArrowRight {
get {
object obj = ResourceManager.GetObject("ArrowRight", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap ArrowUp {
get {
object obj = ResourceManager.GetObject("ArrowUp", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ArrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ArrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ArrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ArrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ArrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ArrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ArrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -0,0 +1,61 @@
using AirBomber.Entities;
namespace AirBomber.Rendering
{
public class BomberRenderer : BomberRendererBase
{
public BomberRenderer(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool FuelTanks, bool Bombs, int Width, int Height)
: base(Speed, Weight, BodyColor, Width, Height, 200, 200)
{
if (EntityBomber is not null)
EntityBomber = new BomberEntity(Speed, Weight, BodyColor, AdditionalColor, FuelTanks, Bombs);
}
public override void DrawEntity(Graphics g)
{
if (EntityBomber is not BomberEntity DerivedEntityBomber)
return;
base.DrawEntity(g);
Brush AdditionalBrush = new SolidBrush(DerivedEntityBomber.AdditionalColor);
/** Отрисовка дополнительных элементов */
if (DerivedEntityBomber.FuelTanks)
{
Point[] LeftGasTank = {
new Point(_startPosX + 50, _startPosY + 85),
new Point(_startPosX + 75, _startPosY + 85),
new Point(_startPosX + 75, _startPosY + 70),
new Point(_startPosX + 50, _startPosY + 70),
};
g.FillPolygon(AdditionalBrush, LeftGasTank);
Point[] RightGasTank = {
new Point(_startPosX + 50, _startPosY + 115),
new Point(_startPosX + 75, _startPosY + 115),
new Point(_startPosX + 75, _startPosY + 130),
new Point(_startPosX + 50, _startPosY + 130),
};
g.FillPolygon(AdditionalBrush, RightGasTank);
}
if (DerivedEntityBomber.Bombs)
{
Point LeftBombStartXY = new Point(_startPosX + 110, _startPosY + 115);
Size LeftBombSize = new Size(50, 25);
g.FillEllipse(AdditionalBrush, new Rectangle(LeftBombStartXY, LeftBombSize));
Point RightBombStartXY = new Point(_startPosX + 110, _startPosY + 60);
Size RightBombSize = new Size(50, 25);
g.FillEllipse(AdditionalBrush, new Rectangle(RightBombStartXY, RightBombSize));
}
}
public void SetAdditionalColor(Color AdditionalColor)
{
if (EntityBomber is BomberEntity AdvancedBomber)
AdvancedBomber.SetAdditionalColor(AdditionalColor);
}
}
}

View File

@ -0,0 +1,172 @@
using AirBomber.Entities;
using AirBomber.MovementStrategy;
namespace AirBomber.Rendering
{
public class BomberRendererBase
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public BomberEntityBase? EntityBomber { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _bomberWidth = 200;
protected readonly int _bomberHeight = 200;
public int PosX => _startPosX;
public int PosY => _startPosY;
public int EntityWidth => _bomberWidth;
public int EntityHeight => _bomberHeight;
public IMovableObject MovableObject => new ObjectEntityRenderer(this);
public BomberRendererBase(int Speed, double Weight, Color BodyColor, int Width, int Height)
{
if (Width < _bomberWidth || Height < _bomberHeight)
return;
_pictureWidth = Width;
_pictureHeight = Height;
EntityBomber = new BomberEntityBase(Speed, Weight, BodyColor);
}
public BomberRendererBase(int Speed, double Weight, Color BodyColor, int Width, int Height, int EntityWidth, int EntityHeight)
{
if (Width < _bomberWidth || Height < _bomberHeight)
return;
_pictureWidth = Width;
_pictureHeight = Height;
_bomberWidth = EntityWidth;
_bomberHeight = EntityHeight;
EntityBomber = new BomberEntityBase(Speed, Weight, BodyColor);
}
public void SetPosition(int x, int y)
{
if (EntityBomber is null)
return;
if (x < 0)
x = 0;
_startPosX = x;
if (y < 0)
y = 0;
_startPosY = y;
}
public bool CanMove(DirectionType direction)
{
if (EntityBomber is null)
return false;
return direction switch
{
DirectionType.Left => _startPosX - EntityBomber.Step > 0,
DirectionType.Up => _startPosY - EntityBomber.Step > 0,
DirectionType.Right => _startPosX + _bomberWidth + EntityBomber.Step <= _pictureWidth,
DirectionType.Down => _startPosY + _bomberHeight + EntityBomber.Step <= _pictureHeight,
_ => false,
};
}
public void MoveEntity(DirectionType Direction)
{
if (EntityBomber == null || !CanMove(Direction))
return;
switch (Direction)
{
case DirectionType.Left:
_startPosX -= (int)EntityBomber.Step;
break;
case DirectionType.Up:
_startPosY -= (int)EntityBomber.Step;
break;
case DirectionType.Right:
_startPosX += (int)EntityBomber.Step;
break;
case DirectionType.Down:
_startPosY += (int)EntityBomber.Step;
break;
}
}
public virtual void DrawEntity(Graphics g)
{
if (EntityBomber == null)
return;
Pen Pen = new Pen(EntityBomber.BodyColor);
Brush Brush = new SolidBrush(EntityBomber.BodyColor);
/** Отрисовка основной части */
Point[] LeftWing = {
new Point(_startPosX + 90, _startPosY),
new Point(_startPosX + 100, _startPosY),
new Point(_startPosX + 108, _startPosY + 85),
new Point(_startPosX + 90, _startPosY + 85),
};
g.DrawPolygon(Pen, LeftWing);
Point[] RightWing = {
new Point(_startPosX + 90, _startPosY + 200),
new Point(_startPosX + 100, _startPosY + 200),
new Point(_startPosX + 108, _startPosY + 115),
new Point(_startPosX + 90, _startPosY + 115),
};
g.DrawPolygon(Pen, RightWing);
Point[] Body = {
new Point(_startPosX + 35, _startPosY + 85),
new Point(_startPosX + 200, _startPosY + 85),
new Point(_startPosX + 200, _startPosY + 115),
new Point(_startPosX + 35, _startPosY + 115),
};
g.DrawPolygon(Pen, Body);
Point[] Nose = {
new Point(_startPosX, _startPosY + 100),
new Point(_startPosX + 35, _startPosY + 85),
new Point(_startPosX + 35, _startPosY + 115),
};
g.FillPolygon(Brush, Nose);
Point[] BackLeftWing = {
new Point(_startPosX + 170, _startPosY + 70),
new Point(_startPosX + 200, _startPosY + 40),
new Point(_startPosX + 200, _startPosY + 85),
new Point(_startPosX + 170, _startPosY + 85),
};
g.DrawPolygon(Pen, BackLeftWing);
Point[] BackRightWing = {
new Point(_startPosX + 170, _startPosY + 130),
new Point(_startPosX + 200, _startPosY + 160),
new Point(_startPosX + 200, _startPosY + 115),
new Point(_startPosX + 170, _startPosY + 115),
};
g.DrawPolygon(Pen, BackRightWing);
}
public void SetBaseColor(Color BaseColor)
{
EntityBomber?.SetBaseColor(BaseColor);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 B

View File

@ -1,2 +1,2 @@
# PIbd-22_Shabunov_O.A._AirBomber_Base
# AirBomber base project (PIbd-22 Shabunov O.A.)