Process
This commit is contained in:
parent
a2997fa460
commit
52117152e0
93
AirFighter/AirplaneGenericCollection.cs
Normal file
93
AirFighter/AirplaneGenericCollection.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using ProjectAirFighter.MovementStrategy;
|
||||
using ProjectAirFighter.DrawningObjects;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ProjectAirFighter.Generics
|
||||
{
|
||||
internal class AirplaneslGenericCollection<T,U>
|
||||
where T :DrawningAirplane
|
||||
where U: IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
private readonly int _placeSizeWidth = 133;
|
||||
|
||||
private readonly int _placeSizeHeight = 50;
|
||||
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
public AirplaneslGenericCollection(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 +(AirplaneslGenericCollection<T,U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return -1;
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
|
||||
public static bool operator -(AirplaneslGenericCollection<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 ShowAirplanes()
|
||||
{
|
||||
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)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawningAirplane airplane = _collection.Get(i);
|
||||
if (airplane != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
airplane.SetPosition(i % inRow * _placeSizeWidth, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight );
|
||||
airplane.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectAirFighter.Entities;
|
||||
using ProjectAirFighter.MovementStrategy;
|
||||
|
||||
namespace ProjectAirFighter.DrawningObjects
|
||||
{
|
||||
@ -24,6 +25,7 @@ namespace ProjectAirFighter.DrawningObjects
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _airplaneWidth;
|
||||
public int GetHeight => _airplaneHeight;
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectAirplane(this);
|
||||
|
||||
public DrawningAirplane(int speed, double weight, Color bodyColor,int width, int height)
|
||||
{
|
||||
|
190
AirFighter/FormAirFighter.Designer.cs
generated
190
AirFighter/FormAirFighter.Designer.cs
generated
@ -1,9 +1,17 @@
|
||||
namespace ProjectAirFighter
|
||||
|
||||
namespace ProjectAirFighter
|
||||
{
|
||||
partial class FormAirFighter
|
||||
{
|
||||
/// <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))
|
||||
@ -12,23 +20,25 @@
|
||||
}
|
||||
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.
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxAirFighter = new System.Windows.Forms.PictureBox();
|
||||
this.ButtonCreateAirFighter = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonAirplane = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.ButtonCreateAirplane = new System.Windows.Forms.Button();
|
||||
this.ButtonStep = new System.Windows.Forms.Button();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
this.buttonCreateAirFighter = new System.Windows.Forms.Button();
|
||||
this.buttonSelectAirplane = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -42,115 +52,124 @@
|
||||
this.pictureBoxAirFighter.TabIndex = 0;
|
||||
this.pictureBoxAirFighter.TabStop = false;
|
||||
//
|
||||
// ButtonCreateAirFighter
|
||||
// buttonAirplane
|
||||
//
|
||||
this.ButtonCreateAirFighter.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreateAirFighter.Location = new System.Drawing.Point(0, 405);
|
||||
this.ButtonCreateAirFighter.Name = "ButtonCreateAirFighter";
|
||||
this.ButtonCreateAirFighter.Size = new System.Drawing.Size(144, 48);
|
||||
this.ButtonCreateAirFighter.TabIndex = 1;
|
||||
this.ButtonCreateAirFighter.Text = "Создать военный самолёт";
|
||||
this.ButtonCreateAirFighter.UseVisualStyleBackColor = true;
|
||||
this.ButtonCreateAirFighter.Click += new System.EventHandler(this.ButtonCreateAirFighter_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.kisspng_up_arrow_computer_icons_arrow_down_clip_art_5af6157c473cb4_0747815015260767962918;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(816, 387);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 2;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
this.buttonAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonAirplane.Location = new System.Drawing.Point(186, 411);
|
||||
this.buttonAirplane.Name = "buttonAirplane";
|
||||
this.buttonAirplane.Size = new System.Drawing.Size(180, 40);
|
||||
this.buttonAirplane.TabIndex = 1;
|
||||
this.buttonAirplane.Text = "Создать";
|
||||
this.buttonAirplane.UseVisualStyleBackColor = true;
|
||||
this.buttonAirplane.Click += new System.EventHandler(this.ButtonCreateAirplane_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.png_clipart_computer_icons_graphics_arrow_symbol_arrow_angle_desktop_wallpaper;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(780, 424);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(768, 411);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 3;
|
||||
this.buttonLeft.TabIndex = 2;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.png_clipart_computer_icons_uma_musume_pretty_derby_fate_grand_order_saber_kemono_friends_three_arrow_game_angle;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(816, 424);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 4;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMoveClick);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.png_transparent_grammatical_person_paper_narration_direzione_didattica_statale_gestione_scuola_elementare_copy_print_right_arrow_miscellaneous_game_angle;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(852, 423);
|
||||
this.buttonRight.Location = new System.Drawing.Point(840, 411);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 5;
|
||||
this.buttonRight.TabIndex = 3;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMoveClick);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.kisspng_up_arrow_computer_icons_arrow_down_clip_art_5af6157c473cb4_0747815015260767962918;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(804, 375);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 4;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMoveClick);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.png_clipart_computer_icons_uma_musume_pretty_derby_fate_grand_order_saber_kemono_friends_three_arrow_game_angle;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(804, 411);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 5;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMoveClick);
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxStrategy.FormattingEnabled = true;
|
||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||
"0",
|
||||
"1"});
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(731, 0);
|
||||
"Довести до центра",
|
||||
"Довести до края"});
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(719, 12);
|
||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28);
|
||||
this.comboBoxStrategy.TabIndex = 6;
|
||||
//
|
||||
// ButtonCreateAirplane
|
||||
// buttonStep
|
||||
//
|
||||
this.ButtonCreateAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreateAirplane.Location = new System.Drawing.Point(150, 405);
|
||||
this.ButtonCreateAirplane.Name = "ButtonCreateAirplane";
|
||||
this.ButtonCreateAirplane.Size = new System.Drawing.Size(143, 47);
|
||||
this.ButtonCreateAirplane.TabIndex = 7;
|
||||
this.ButtonCreateAirplane.Text = "Создать самолёт";
|
||||
this.ButtonCreateAirplane.UseVisualStyleBackColor = true;
|
||||
this.ButtonCreateAirplane.Click += new System.EventHandler(this.ButtonCreateAirplane_Click);
|
||||
this.buttonStep.Location = new System.Drawing.Point(768, 46);
|
||||
this.buttonStep.Name = "buttonStep";
|
||||
this.buttonStep.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonStep.TabIndex = 7;
|
||||
this.buttonStep.Text = "Шаг";
|
||||
this.buttonStep.UseVisualStyleBackColor = true;
|
||||
this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
|
||||
//
|
||||
// ButtonStep
|
||||
// buttonCreateAirFighter
|
||||
//
|
||||
this.ButtonStep.Location = new System.Drawing.Point(788, 34);
|
||||
this.ButtonStep.Name = "ButtonStep";
|
||||
this.ButtonStep.Size = new System.Drawing.Size(94, 29);
|
||||
this.ButtonStep.TabIndex = 8;
|
||||
this.ButtonStep.Text = "Шаг";
|
||||
this.ButtonStep.UseVisualStyleBackColor = true;
|
||||
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
||||
this.buttonCreateAirFighter.Location = new System.Drawing.Point(0, 411);
|
||||
this.buttonCreateAirFighter.Name = "buttonCreateAirFighter";
|
||||
this.buttonCreateAirFighter.Size = new System.Drawing.Size(180, 40);
|
||||
this.buttonCreateAirFighter.TabIndex = 8;
|
||||
this.buttonCreateAirFighter.Text = "Создать продвинутый";
|
||||
this.buttonCreateAirFighter.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateAirFighter.Click += new System.EventHandler(this.ButtonCreateAirFighter_Click);
|
||||
//
|
||||
// buttonSelectAirplane
|
||||
//
|
||||
this.buttonSelectAirplane.Location = new System.Drawing.Point(372, 411);
|
||||
this.buttonSelectAirplane.Name = "buttonSelectAirplane";
|
||||
this.buttonSelectAirplane.Size = new System.Drawing.Size(180, 40);
|
||||
this.buttonSelectAirplane.TabIndex = 9;
|
||||
this.buttonSelectAirplane.Text = "Выбрать";
|
||||
this.buttonSelectAirplane.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectAirplane.Click += new System.EventHandler(this.buttonSelectAirplane_Click);
|
||||
//
|
||||
// FormAirFighter
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(882, 453);
|
||||
this.Controls.Add(this.ButtonStep);
|
||||
this.Controls.Add(this.ButtonCreateAirplane);
|
||||
this.Controls.Add(this.buttonSelectAirplane);
|
||||
this.Controls.Add(this.buttonCreateAirFighter);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.ButtonCreateAirFighter);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonAirplane);
|
||||
this.Controls.Add(this.pictureBoxAirFighter);
|
||||
this.Name = "FormAirFighter";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "FormAirFighter";
|
||||
this.Text = "Form1";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirFighter)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
@ -158,14 +177,17 @@
|
||||
}
|
||||
|
||||
#endregion
|
||||
private PictureBox pictureBoxAirFighter;
|
||||
private Button ButtonCreateAirFighter;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button ButtonCreateAirplane;
|
||||
private Button ButtonStep;
|
||||
|
||||
private System.Windows.Forms.PictureBox pictureBoxAirFighter;
|
||||
private System.Windows.Forms.Button buttonAirplane;
|
||||
private System.Windows.Forms.Button buttonLeft;
|
||||
private System.Windows.Forms.Button buttonRight;
|
||||
private System.Windows.Forms.Button buttonUp;
|
||||
private System.Windows.Forms.Button buttonDown;
|
||||
public System.Windows.Forms.ComboBox comboBoxStrategy;
|
||||
private System.Windows.Forms.Button buttonStep;
|
||||
private System.Windows.Forms.Button buttonCreateAirFighter;
|
||||
private System.Windows.Forms.Button buttonSelectAirplane;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,26 +1,38 @@
|
||||
using ProjectAirFighter.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectAirFighter.DrawningObjects;
|
||||
using ProjectAirFighter.MovementStrategy;
|
||||
|
||||
namespace ProjectAirFighter
|
||||
{
|
||||
public partial class FormAirFighter : Form
|
||||
{
|
||||
|
||||
private DrawningAirplane? _drawningAirplane;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
public DrawningAirplane? SelectedAirplane { get; private set; }
|
||||
public FormAirFighter()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedAirplane = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAirFighter.Width,
|
||||
pictureBoxAirFighter.Height);
|
||||
|
||||
Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAirplane.DrawTransport(gr);
|
||||
pictureBoxAirFighter.Image = bmp;
|
||||
@ -29,34 +41,24 @@ namespace ProjectAirFighter
|
||||
private void ButtonCreateAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningAirplane = new DrawningAirplane(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodyColor = dialog.Color;
|
||||
}
|
||||
_drawningAirplane = new DrawningAirplane(random.Next(100, 300), random.Next(1000, 3000),
|
||||
bodyColor,pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(70, 100));
|
||||
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateAirFighter_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningAirplane = new DrawningAirFighter (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)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(70, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
private void ButtonMoveClick(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
@ -66,22 +68,38 @@ namespace ProjectAirFighter
|
||||
case "buttonDown":
|
||||
_drawningAirplane.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningAirplane.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningAirplane.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningAirplane.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
private void ButtonCreateAirFighter_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
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 dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
bodyColor = dialog.Color;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
additionalColor = dialog.Color;
|
||||
|
||||
_drawningAirplane = new DrawningAirFighter(random.Next(100, 300), random.Next(1000, 3000),
|
||||
bodyColor,additionalColor, Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
||||
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(70, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
@ -112,7 +130,11 @@ namespace ProjectAirFighter
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedAirplane = _drawningAirplane;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
124
AirFighter/FormAirplaneCollection.Designer.cs
generated
Normal file
124
AirFighter/FormAirplaneCollection.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
||||
namespace ProjectAirFighter
|
||||
{
|
||||
partial class FormAirplaneCollection
|
||||
{
|
||||
/// <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.toolGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.maskedTextBox = new System.Windows.Forms.MaskedTextBox();
|
||||
this.updateCollectionButton = new System.Windows.Forms.Button();
|
||||
this.deleteAirplaneButton = new System.Windows.Forms.Button();
|
||||
this.addAirplaneButton = new System.Windows.Forms.Button();
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.toolGroupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// toolGroupBox
|
||||
//
|
||||
this.toolGroupBox.Controls.Add(this.maskedTextBox);
|
||||
this.toolGroupBox.Controls.Add(this.updateCollectionButton);
|
||||
this.toolGroupBox.Controls.Add(this.deleteAirplaneButton);
|
||||
this.toolGroupBox.Controls.Add(this.addAirplaneButton);
|
||||
this.toolGroupBox.Location = new System.Drawing.Point(623, 12);
|
||||
this.toolGroupBox.Name = "toolGroupBox";
|
||||
this.toolGroupBox.Size = new System.Drawing.Size(227, 426);
|
||||
this.toolGroupBox.TabIndex = 0;
|
||||
this.toolGroupBox.TabStop = false;
|
||||
this.toolGroupBox.Text = "Инструменты";
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
this.maskedTextBox.Location = new System.Drawing.Point(6, 72);
|
||||
this.maskedTextBox.Name = "maskedTextBox";
|
||||
this.maskedTextBox.Size = new System.Drawing.Size(125, 27);
|
||||
this.maskedTextBox.TabIndex = 4;
|
||||
//
|
||||
// updateCollectionButton
|
||||
//
|
||||
this.updateCollectionButton.Location = new System.Drawing.Point(6, 151);
|
||||
this.updateCollectionButton.Name = "updateCollectionButton";
|
||||
this.updateCollectionButton.Size = new System.Drawing.Size(215, 40);
|
||||
this.updateCollectionButton.TabIndex = 3;
|
||||
this.updateCollectionButton.Text = "Обновить коллекцию";
|
||||
this.updateCollectionButton.UseVisualStyleBackColor = true;
|
||||
this.updateCollectionButton.Click += new System.EventHandler(this.updateCollectionButton_Click);
|
||||
//
|
||||
// deleteAirplaneButton
|
||||
//
|
||||
this.deleteAirplaneButton.Location = new System.Drawing.Point(6, 105);
|
||||
this.deleteAirplaneButton.Name = "deleteAirplaneButton";
|
||||
this.deleteAirplaneButton.Size = new System.Drawing.Size(215, 40);
|
||||
this.deleteAirplaneButton.TabIndex = 2;
|
||||
this.deleteAirplaneButton.Text = "Удалить";
|
||||
this.deleteAirplaneButton.UseVisualStyleBackColor = true;
|
||||
this.deleteAirplaneButton.Click += new System.EventHandler(this.deleteAirplaneButton_Click);
|
||||
//
|
||||
// addAirplaneButton
|
||||
//
|
||||
this.addAirplaneButton.Location = new System.Drawing.Point(6, 26);
|
||||
this.addAirplaneButton.Name = "addAirplaneButton";
|
||||
this.addAirplaneButton.Size = new System.Drawing.Size(215, 40);
|
||||
this.addAirplaneButton.TabIndex = 0;
|
||||
this.addAirplaneButton.Text = "Добавить";
|
||||
this.addAirplaneButton.UseVisualStyleBackColor = true;
|
||||
this.addAirplaneButton.Click += new System.EventHandler(this.addAirplaneButton_Click);
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(12, 12);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(605, 426);
|
||||
this.pictureBoxCollection.TabIndex = 1;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// FormAirplaneCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(862, 450);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Controls.Add(this.toolGroupBox);
|
||||
this.Name = "FormAirplaneCollection";
|
||||
this.Text = "FormMonorailCollection";
|
||||
this.toolGroupBox.ResumeLayout(false);
|
||||
this.toolGroupBox.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox toolGroupBox;
|
||||
private System.Windows.Forms.Button updateCollectionButton;
|
||||
private System.Windows.Forms.Button deleteAirplaneButton;
|
||||
private System.Windows.Forms.Button addAirplaneButton;
|
||||
private System.Windows.Forms.PictureBox pictureBoxCollection;
|
||||
private System.Windows.Forms.MaskedTextBox maskedTextBox;
|
||||
}
|
||||
}
|
69
AirFighter/FormAirplaneCollection.cs
Normal file
69
AirFighter/FormAirplaneCollection.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using ProjectAirFighter.DrawningObjects;
|
||||
using ProjectAirFighter.Generics;
|
||||
using ProjectAirFighter.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectAirFighter
|
||||
{
|
||||
public partial class FormAirplaneCollection : Form
|
||||
{
|
||||
private readonly AirplaneslGenericCollection<DrawningAirplane, DrawningObjectAirplane> _airplanes;
|
||||
|
||||
public FormAirplaneCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_airplanes = new AirplaneslGenericCollection<DrawningAirplane,
|
||||
DrawningObjectAirplane>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
private void deleteAirplaneButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_airplanes - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _airplanes.ShowAirplanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCollectionButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _airplanes.ShowAirplanes();
|
||||
|
||||
}
|
||||
|
||||
private void addAirplaneButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormAirFighter form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_airplanes + form.SelectedAirplane != null)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _airplanes.ShowAirplanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
AirFighter/FormAirplaneCollection.resx
Normal file
60
AirFighter/FormAirplaneCollection.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -9,7 +9,7 @@ namespace ProjectAirFighter
|
||||
{
|
||||
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormAirFighter());
|
||||
Application.Run(new FormAirplaneCollection());
|
||||
}
|
||||
}
|
||||
}
|
60
AirFighter/SetGeneric.cs
Normal file
60
AirFighter/SetGeneric.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirFighter.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 airplane)
|
||||
{
|
||||
if (_places[Count-1] != null)
|
||||
return -1;
|
||||
return Insert(airplane, 0);
|
||||
}
|
||||
|
||||
public int Insert(T airplane, int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return -1;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int ind = position;
|
||||
while (ind < Count && _places[ind] != null)
|
||||
ind++;
|
||||
if (ind == Count)
|
||||
return -1;
|
||||
for (int i = ind - 1; i >= position; i--)
|
||||
_places[i + 1] = _places[i];
|
||||
}
|
||||
_places[position] = airplane;
|
||||
return position;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count) || _places[position] == null)
|
||||
return false;
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user