laba3 BlokhinDA PIbd-21 Airbus #3
61
RPP/RPP/Airbus.Designer.cs
generated
61
RPP/RPP/Airbus.Designer.cs
generated
@ -37,6 +37,7 @@
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonCreateFlyAirbus = new Button();
|
||||
ButtonStep = new Button();
|
||||
ButtonSelectAirbus = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirbus).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -45,9 +46,8 @@
|
||||
pictureBoxAirbus.BackColor = SystemColors.Window;
|
||||
pictureBoxAirbus.Dock = DockStyle.Fill;
|
||||
pictureBoxAirbus.Location = new Point(0, 0);
|
||||
pictureBoxAirbus.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxAirbus.Name = "pictureBoxAirbus";
|
||||
pictureBoxAirbus.Size = new Size(982, 553);
|
||||
pictureBoxAirbus.Size = new Size(859, 415);
|
||||
pictureBoxAirbus.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxAirbus.TabIndex = 0;
|
||||
pictureBoxAirbus.TabStop = false;
|
||||
@ -56,10 +56,9 @@
|
||||
// buttonCreateAirbus
|
||||
//
|
||||
buttonCreateAirbus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateAirbus.Location = new Point(224, 456);
|
||||
buttonCreateAirbus.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreateAirbus.Location = new Point(196, 342);
|
||||
buttonCreateAirbus.Name = "buttonCreateAirbus";
|
||||
buttonCreateAirbus.Size = new Size(166, 80);
|
||||
buttonCreateAirbus.Size = new Size(145, 60);
|
||||
buttonCreateAirbus.TabIndex = 1;
|
||||
buttonCreateAirbus.Text = "Создать аэробус";
|
||||
buttonCreateAirbus.UseVisualStyleBackColor = true;
|
||||
@ -70,10 +69,9 @@
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.buttonDown;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(883, 493);
|
||||
buttonDown.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDown.Location = new Point(773, 370);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 29);
|
||||
buttonDown.Size = new Size(26, 22);
|
||||
buttonDown.TabIndex = 2;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
@ -83,10 +81,9 @@
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.buttonLeft;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(847, 493);
|
||||
buttonLeft.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonLeft.Location = new Point(741, 370);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 29);
|
||||
buttonLeft.Size = new Size(26, 22);
|
||||
buttonLeft.TabIndex = 3;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
@ -96,10 +93,9 @@
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.buttonUp;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(883, 456);
|
||||
buttonUp.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonUp.Location = new Point(773, 342);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 29);
|
||||
buttonUp.Size = new Size(26, 22);
|
||||
buttonUp.TabIndex = 4;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
@ -109,10 +105,9 @@
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.buttonRight;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(919, 493);
|
||||
buttonRight.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRight.Location = new Point(804, 370);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 29);
|
||||
buttonRight.Size = new Size(26, 22);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
@ -121,19 +116,17 @@
|
||||
//
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "0", "1" });
|
||||
comboBoxStrategy.Location = new Point(830, 28);
|
||||
comboBoxStrategy.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxStrategy.Location = new Point(726, 21);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(138, 28);
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 6;
|
||||
comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
|
||||
//
|
||||
// buttonCreateFlyAirbus
|
||||
//
|
||||
buttonCreateFlyAirbus.Location = new Point(38, 456);
|
||||
buttonCreateFlyAirbus.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreateFlyAirbus.Location = new Point(33, 342);
|
||||
buttonCreateFlyAirbus.Name = "buttonCreateFlyAirbus";
|
||||
buttonCreateFlyAirbus.Size = new Size(166, 80);
|
||||
buttonCreateFlyAirbus.Size = new Size(145, 60);
|
||||
buttonCreateFlyAirbus.TabIndex = 7;
|
||||
buttonCreateFlyAirbus.Text = "Создать пассажирский аэробус";
|
||||
buttonCreateFlyAirbus.UseVisualStyleBackColor = true;
|
||||
@ -141,20 +134,30 @@
|
||||
//
|
||||
// ButtonStep
|
||||
//
|
||||
ButtonStep.Location = new Point(882, 79);
|
||||
ButtonStep.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonStep.Location = new Point(772, 59);
|
||||
ButtonStep.Name = "ButtonStep";
|
||||
ButtonStep.Size = new Size(86, 31);
|
||||
ButtonStep.Size = new Size(75, 23);
|
||||
ButtonStep.TabIndex = 8;
|
||||
ButtonStep.Text = "Шаг";
|
||||
ButtonStep.UseVisualStyleBackColor = true;
|
||||
ButtonStep.Click += ButtonStep_Click;
|
||||
//
|
||||
// ButtonSelectAirbus
|
||||
//
|
||||
ButtonSelectAirbus.Location = new Point(357, 342);
|
||||
ButtonSelectAirbus.Name = "ButtonSelectAirbus";
|
||||
ButtonSelectAirbus.Size = new Size(145, 61);
|
||||
ButtonSelectAirbus.TabIndex = 9;
|
||||
ButtonSelectAirbus.Text = "Смена самолета";
|
||||
ButtonSelectAirbus.UseVisualStyleBackColor = true;
|
||||
ButtonSelectAirbus.Click += ButtonSelectAirbus_Click;
|
||||
//
|
||||
// FormAirbus
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(982, 553);
|
||||
ClientSize = new Size(859, 415);
|
||||
Controls.Add(ButtonSelectAirbus);
|
||||
Controls.Add(ButtonStep);
|
||||
Controls.Add(buttonCreateFlyAirbus);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
@ -164,7 +167,6 @@
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonCreateAirbus);
|
||||
Controls.Add(pictureBoxAirbus);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormAirbus";
|
||||
Text = "Airbus";
|
||||
Load += FormAirbus_Load;
|
||||
@ -184,5 +186,6 @@
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonCreateFlyAirbus;
|
||||
private Button ButtonStep;
|
||||
private Button ButtonSelectAirbus;
|
||||
}
|
||||
}
|
@ -8,9 +8,12 @@ namespace RPP
|
||||
{
|
||||
private DrawningAirbus? _drawningAirbus;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawningAirbus? SelectedAirbus { get; private set; }
|
||||
public FormAirbus()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedAirbus = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
@ -29,28 +32,38 @@ namespace RPP
|
||||
private void buttonCreateFlyAirbus_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color MainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color AdditionColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
MainColor = dialog.Color;
|
||||
}
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
AdditionColor = dialog.Color;
|
||||
}
|
||||
_drawningAirbus = new DrawningFlyAirbus(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
MainColor, AdditionColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
_drawningAirbus.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void ButtonCreateAirbus_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
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;
|
||||
}
|
||||
_drawningAirbus = new DrawningAirbus(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
random.Next(1000, 3000), color,
|
||||
pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
_drawningAirbus.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
@ -105,8 +118,7 @@ namespace RPP
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawningObjectAirbus(_drawningAirbus), pictureBoxAirbus.Width,
|
||||
_abstractStrategy.SetData(_drawningAirbus.GetMoveableObject, pictureBoxAirbus.Width,
|
||||
pictureBoxAirbus.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
@ -123,6 +135,12 @@ namespace RPP
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSelectAirbus_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedAirbus = _drawningAirbus;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
private void pictureBoxAirbus_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
<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="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>
|
||||
|
102
RPP/RPP/AirbusGenericCollection.cs
Normal file
102
RPP/RPP/AirbusGenericCollection.cs
Normal file
@ -0,0 +1,102 @@
|
||||
|
||||
using RPP.DrawningObjects;
|
||||
using RPP.MovementStrategy;
|
||||
|
||||
namespace RPP.Generics
|
||||
{
|
||||
public class AirbusGenericCollection<T,U>
|
||||
where T : DrawningAirbus
|
||||
where U : IMoveableObject
|
||||
{
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
private readonly int _placeSizeWidth = 220;
|
||||
|
||||
private readonly int _placeSizeHeight = 120;
|
||||
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
public AirbusGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
public static int? operator +(AirbusGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj);
|
||||
}
|
||||
|
||||
public static bool operator -(AirbusGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
|
||||
public Bitmap ShowCars()
|
||||
{
|
||||
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 width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
|
||||
DrawningAirbus accept = _collection.Get(i);
|
||||
if (accept == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
accept.SetPosition((width - 1 - (i % width)) * _placeSizeWidth + 12, (height - 1 - (i / width)) * _placeSizeHeight + 10);
|
||||
|
||||
accept.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RPP.Entities;
|
||||
using RPP.Entities;
|
||||
using RPP.MovementStrategy;
|
||||
|
||||
|
||||
namespace RPP.DrawningObjects
|
||||
|
||||
{
|
||||
public class DrawningAirbus
|
||||
{
|
||||
@ -23,6 +21,7 @@ namespace RPP.DrawningObjects
|
||||
private readonly int _AirbusWidth = 200;
|
||||
|
||||
private readonly int _AirbusHeight = 100;
|
||||
|
||||
public int GetPosX => _startPosX;
|
||||
|
||||
public int GetPosY => _startPosY;
|
||||
@ -31,7 +30,7 @@ namespace RPP.DrawningObjects
|
||||
|
||||
public int GetHeight => _AirbusHeight;
|
||||
|
||||
public virtual bool CanMove(Direction direction)
|
||||
public bool CanMove(Direction direction)
|
||||
{
|
||||
if (EntityAirbus == null)
|
||||
{
|
||||
@ -39,20 +38,19 @@ namespace RPP.DrawningObjects
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
Direction.Left => _startPosX - EntityAirbus.Step > 5,
|
||||
//вверх
|
||||
Direction.Up => _startPosY - EntityAirbus.Step > 0,
|
||||
// вправо
|
||||
Direction.Right => _startPosX + EntityAirbus.Step + _AirbusWidth < _pictureWidth,
|
||||
Direction.Down => _startPosY + EntityAirbus.Step + _AirbusHeight < _pictureHeight,
|
||||
_ => false
|
||||
Direction.Down => _startPosY + EntityAirbus.Step + _AirbusHeight < _pictureHeight
|
||||
};
|
||||
}
|
||||
|
||||
public DrawningAirbus(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
if (width < _AirbusWidth || height < _AirbusHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityAirbus = new EntityAirbus(speed, weight, bodyColor);
|
||||
@ -71,16 +69,13 @@ namespace RPP.DrawningObjects
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x > _pictureWidth || y > _pictureHeight || x < 0 || y < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
_startPosY = 0;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectAirbus(this);
|
||||
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
@ -120,6 +115,8 @@ namespace RPP.DrawningObjects
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
@ -127,8 +124,8 @@ namespace RPP.DrawningObjects
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black, 3);
|
||||
Brush brush = new SolidBrush(Color.Black);
|
||||
Pen pen = new(EntityAirbus.BodyColor, 3);
|
||||
Brush brush = new SolidBrush(EntityAirbus.BodyColor);
|
||||
//Тело
|
||||
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 50, 170, 30);
|
||||
g.DrawPie(pen, _startPosX - 5, _startPosY + 50, 20, 30, 90, 180);
|
||||
@ -139,7 +136,7 @@ namespace RPP.DrawningObjects
|
||||
g.DrawLine(pen, _startPosX, _startPosY, _startPosX, _startPosY + 52);
|
||||
//Заднее боковые крылья
|
||||
|
||||
Pen bigPen = new Pen(Color.Black, 8);
|
||||
Pen bigPen = new Pen(EntityAirbus.BodyColor, 8);
|
||||
g.DrawPie(pen, _startPosX - 7, _startPosY + 45, 5, 10, 90, 180);
|
||||
g.DrawLine(bigPen, _startPosX - 6, _startPosY + 48, _startPosX + 30, _startPosY + 48);
|
||||
g.DrawLine(bigPen, _startPosX - 6, _startPosY + 52, _startPosX + 30, _startPosY + 52);
|
||||
@ -155,7 +152,7 @@ namespace RPP.DrawningObjects
|
||||
g.DrawPie(pen, _startPosX + 139, _startPosY + 62, 5, 5, 180, 270);
|
||||
//Задние шасси
|
||||
g.DrawLine(pen, _startPosX + 55, _startPosY + 80, _startPosX + 55, _startPosY + 90);
|
||||
Pen tallpen = new(Color.Black, 2);
|
||||
Pen tallpen = new(EntityAirbus.BodyColor, 2);
|
||||
g.DrawEllipse(pen, _startPosX + 47, _startPosY + 90, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX + 57, _startPosY + 90, 5, 5);
|
||||
//Передние шасси
|
||||
@ -163,6 +160,7 @@ namespace RPP.DrawningObjects
|
||||
g.DrawEllipse(pen, _startPosX + 163, _startPosY + 91, 5, 5);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
136
RPP/RPP/FormAirbusCollection.Designer.cs
generated
Normal file
136
RPP/RPP/FormAirbusCollection.Designer.cs
generated
Normal file
@ -0,0 +1,136 @@
|
||||
namespace RPP
|
||||
{
|
||||
partial class FormAirbusCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
panel1 = new Panel();
|
||||
ButtonRefreshCollection = new Button();
|
||||
ButtonRemoveAirbus = new Button();
|
||||
maskedTextBoxNumber = new TextBox();
|
||||
AddAirbusButton = new Button();
|
||||
label = new Label();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.Controls.Add(ButtonRefreshCollection);
|
||||
panel1.Controls.Add(ButtonRemoveAirbus);
|
||||
panel1.Controls.Add(maskedTextBoxNumber);
|
||||
panel1.Controls.Add(AddAirbusButton);
|
||||
panel1.Controls.Add(label);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(600, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(200, 450);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Location = new Point(5, 236);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new Size(190, 40);
|
||||
ButtonRefreshCollection.TabIndex = 4;
|
||||
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// ButtonRemoveAirbus
|
||||
//
|
||||
ButtonRemoveAirbus.Location = new Point(5, 154);
|
||||
ButtonRemoveAirbus.Name = "ButtonRemoveAirbus";
|
||||
ButtonRemoveAirbus.Size = new Size(190, 40);
|
||||
ButtonRemoveAirbus.TabIndex = 3;
|
||||
ButtonRemoveAirbus.Text = "Удалить аэробус";
|
||||
ButtonRemoveAirbus.UseVisualStyleBackColor = true;
|
||||
ButtonRemoveAirbus.Click += ButtonRemoveAirbus_Click;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(45, 125);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(98, 23);
|
||||
maskedTextBoxNumber.TabIndex = 2;
|
||||
//
|
||||
// AddAirbusButton
|
||||
//
|
||||
AddAirbusButton.Location = new Point(5, 36);
|
||||
AddAirbusButton.Name = "AddAirbusButton";
|
||||
AddAirbusButton.Size = new Size(190, 40);
|
||||
AddAirbusButton.TabIndex = 1;
|
||||
AddAirbusButton.Text = "Добавить аэробус";
|
||||
AddAirbusButton.UseVisualStyleBackColor = true;
|
||||
AddAirbusButton.Click += AddAirbusButton_Click;
|
||||
//
|
||||
// label
|
||||
//
|
||||
label.AutoSize = true;
|
||||
label.Location = new Point(5, 0);
|
||||
label.Name = "label";
|
||||
label.Size = new Size(83, 15);
|
||||
label.TabIndex = 0;
|
||||
label.Text = "Инструменты";
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||
pictureBoxCollection.Location = new Point(0, 0);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(600, 450);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// FormAirbusCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormAirbusCollection";
|
||||
Text = "FormFlyAirbus";
|
||||
Load += FormFlyAirbus_Load;
|
||||
panel1.ResumeLayout(false);
|
||||
panel1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel panel1;
|
||||
private Button AddAirbusButton;
|
||||
private Label label;
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Button ButtonRefreshCollection;
|
||||
private Button ButtonRemoveAirbus;
|
||||
private TextBox maskedTextBoxNumber;
|
||||
}
|
||||
}
|
65
RPP/RPP/FormAirbusCollection.cs
Normal file
65
RPP/RPP/FormAirbusCollection.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using RPP.DrawningObjects;
|
||||
using RPP.MovementStrategy;
|
||||
using RPP.Generics;
|
||||
|
||||
|
||||
namespace RPP
|
||||
{
|
||||
public partial class FormAirbusCollection : Form
|
||||
{
|
||||
private readonly AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus> _Airbus;
|
||||
|
||||
public FormAirbusCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_Airbus = new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
|
||||
}
|
||||
|
||||
private void FormFlyAirbus_Load(object sender, EventArgs e)
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void AddAirbusButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormAirbus form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_Airbus + form.SelectedAirbus > -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _Airbus.ShowCars();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemoveAirbus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_Airbus - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _Airbus.ShowCars();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _Airbus.ShowCars();
|
||||
}
|
||||
}
|
||||
}
|
120
RPP/RPP/FormAirbusCollection.resx
Normal file
120
RPP/RPP/FormAirbusCollection.resx
Normal 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>
|
@ -6,15 +6,15 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RPP.MovementStrategy
|
||||
{
|
||||
interface IMoveableObject
|
||||
public interface IMoveableObject
|
||||
{
|
||||
|
||||
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
|
||||
|
||||
int GetStep { get; }
|
||||
|
||||
|
||||
bool CheckCanMove(Direction direction);
|
||||
|
||||
|
||||
void MoveObject(Direction direction);
|
||||
|
||||
}
|
||||
|
@ -3,8 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RPP.MovementStrategy;
|
||||
|
||||
namespace RPP.MovementStrategy
|
||||
namespace RPP
|
||||
{
|
||||
internal class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RPP.MovementStrategy
|
||||
{
|
||||
internal class ObjectParameters
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
namespace RPP
|
||||
{
|
||||
internal static class Program
|
||||
@ -11,7 +12,7 @@ namespace RPP
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormAirbus());
|
||||
Application.Run(new FormAirbusCollection());
|
||||
}
|
||||
}
|
||||
}
|
75
RPP/RPP/SetGeneric.cs
Normal file
75
RPP/RPP/SetGeneric.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP.Generics
|
||||
{
|
||||
internal class SetGeneric<T> where T : class
|
||||
{
|
||||
|
||||
|
||||
private readonly T?[] _places;
|
||||
|
||||
public int Count => _places.Length;
|
||||
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
|
||||
public int Insert(T airbus)
|
||||
{
|
||||
return Insert(airbus, 0);
|
||||
}
|
||||
|
||||
public int Insert(T airbus, int position)
|
||||
{
|
||||
|
||||
if(position < 0 && position > Count) {
|
||||
return -1;
|
||||
}
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int d = 0;
|
||||
for (int j = 1; j < Count - position; j++)
|
||||
{
|
||||
if (_places[position + j] == null)
|
||||
{
|
||||
d = position + j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (d == 0) {
|
||||
return -1;
|
||||
}
|
||||
for(int j = d; j > position; j--) {
|
||||
_places[j] = _places[j - 1];
|
||||
}
|
||||
}
|
||||
|
||||
_places[position] = airbus;
|
||||
return position;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
|
||||
if (position < 0 && position > Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
return _places[position];
|
||||
eegov
commented
Требовались проверки Требовались проверки
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
Пустых методов быть не должно