Done
This commit is contained in:
parent
468abaf5f8
commit
c5f197893f
@ -13,6 +13,7 @@ namespace ProjStormtrooper
|
||||
protected int FieldWidth { get; private set; }
|
||||
protected int FieldHeight { get; private set; }
|
||||
public Status GetStatus() { return _state; }
|
||||
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
@ -53,7 +54,6 @@ namespace ProjStormtrooper
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
|
||||
protected abstract void MoveToTarget();
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
private bool MoveTo(Direction directionType)
|
||||
|
@ -6,7 +6,6 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProjStormtrooper
|
||||
{
|
||||
|
||||
public class DrawingPlane
|
||||
{
|
||||
public EntityPlane? EntityPlane { get; protected set; }
|
||||
@ -54,18 +53,18 @@ namespace ProjStormtrooper
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
|
||||
|
||||
Direction.Up => _startPosY - EntityPlane.Step > 0,
|
||||
|
||||
|
||||
Direction.Down => _startPosY + _planeHeight + EntityPlane.Step < _pictureHeight,
|
||||
|
||||
|
||||
Direction.Left => _startPosX - EntityPlane.Step > 0,
|
||||
|
||||
|
||||
Direction.Right => _startPosX + _planeWidth + EntityPlane.Step < _pictureWidth,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0)
|
||||
@ -97,19 +96,19 @@ namespace ProjStormtrooper
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
|
||||
|
||||
case Direction.Up:
|
||||
_startPosY -= (int)EntityPlane.Step;
|
||||
break;
|
||||
|
||||
|
||||
case Direction.Down:
|
||||
_startPosY += (int)EntityPlane.Step;
|
||||
break;
|
||||
|
||||
|
||||
case Direction.Left:
|
||||
_startPosX -= (int)EntityPlane.Step;
|
||||
break;
|
||||
|
||||
|
||||
case Direction.Right:
|
||||
_startPosX += (int)EntityPlane.Step;
|
||||
break;
|
||||
@ -126,10 +125,11 @@ namespace ProjStormtrooper
|
||||
Brush brushBlack = new SolidBrush(Color.Black);
|
||||
Brush brushBodyColor = new SolidBrush(EntityPlane.BodyColor);
|
||||
|
||||
|
||||
|
||||
int bodyHeight = _planeHeight / 9;
|
||||
|
||||
|
||||
|
||||
Point[] pointsCockPit = {
|
||||
new Point(_startPosX, _startPosY + _planeHeight / 2),
|
||||
new Point(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2),
|
||||
@ -138,7 +138,7 @@ namespace ProjStormtrooper
|
||||
|
||||
g.FillPolygon(brushBlack, pointsCockPit);
|
||||
|
||||
|
||||
|
||||
|
||||
Point[] pointsWings = {
|
||||
new Point(_startPosX + _planeWidth / 2, _startPosY),
|
||||
@ -151,7 +151,6 @@ namespace ProjStormtrooper
|
||||
g.FillPolygon(brushBodyColor, pointsWings);
|
||||
g.DrawPolygon(penBlack, pointsWings);
|
||||
|
||||
|
||||
|
||||
Point[] pointsTail = {
|
||||
new Point(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 - _planeHeight / 3),
|
||||
@ -162,12 +161,12 @@ namespace ProjStormtrooper
|
||||
};
|
||||
|
||||
g.FillPolygon(brushBodyColor, pointsTail);
|
||||
|
||||
g.DrawPolygon(penBlack, pointsTail);
|
||||
|
||||
|
||||
|
||||
g.FillRectangle(brushBodyColor, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight);
|
||||
g.DrawRectangle(penBlack, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight);
|
||||
}
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectPlane(this);
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,10 @@ namespace ProjStormtrooper
|
||||
{
|
||||
public class EntityPlane
|
||||
{
|
||||
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public double Step => (double)Speed * 250 / Weight;
|
||||
|
||||
public EntityPlane(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
|
@ -11,7 +11,6 @@ namespace ProjStormtrooper
|
||||
public Color AdditionalColor { get; private set; }
|
||||
public bool Rockets { get; private set; }
|
||||
public bool Bombs { get; private set; }
|
||||
|
||||
public EntityStormtrooper(int speed, double weight, Color bodyColor,
|
||||
Color additionalColor, bool rockets, bool bombs) : base(speed, weight, bodyColor)
|
||||
{
|
||||
|
@ -18,7 +18,6 @@ namespace ProjStormtrooper
|
||||
public int DownBorder => _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;
|
||||
|
128
ProjStormtrooper/ProjStormtrooper/PlaneCollection.Designer.cs
generated
Normal file
128
ProjStormtrooper/ProjStormtrooper/PlaneCollection.Designer.cs
generated
Normal file
@ -0,0 +1,128 @@
|
||||
namespace ProjStormtrooper
|
||||
{
|
||||
partial class PlaneCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonRefreshCollection = new Button();
|
||||
buttonRemovePlane = new Button();
|
||||
buttonAddPlane = new Button();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(maskedTextBoxNumber);
|
||||
groupBoxTools.Controls.Add(buttonRefreshCollection);
|
||||
groupBoxTools.Controls.Add(buttonRemovePlane);
|
||||
groupBoxTools.Controls.Add(buttonAddPlane);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(787, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(230, 538);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(6, 87);
|
||||
maskedTextBoxNumber.Mask = "00";
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(218, 27);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
maskedTextBoxNumber.TextAlign = HorizontalAlignment.Center;
|
||||
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(6, 180);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(218, 29);
|
||||
buttonRefreshCollection.TabIndex = 3;
|
||||
buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||
//
|
||||
// buttonRemovePlane
|
||||
//
|
||||
buttonRemovePlane.Location = new Point(6, 120);
|
||||
buttonRemovePlane.Name = "buttonRemovePlane";
|
||||
buttonRemovePlane.Size = new Size(218, 29);
|
||||
buttonRemovePlane.TabIndex = 2;
|
||||
buttonRemovePlane.Text = "Удалить самолет";
|
||||
buttonRemovePlane.UseVisualStyleBackColor = true;
|
||||
buttonRemovePlane.Click += buttonRemovePlane_Click;
|
||||
//
|
||||
// buttonAddPlane
|
||||
//
|
||||
buttonAddPlane.Location = new Point(6, 26);
|
||||
buttonAddPlane.Name = "buttonAddPlane";
|
||||
buttonAddPlane.Size = new Size(218, 29);
|
||||
buttonAddPlane.TabIndex = 0;
|
||||
buttonAddPlane.Text = "Добавить самолет";
|
||||
buttonAddPlane.UseVisualStyleBackColor = true;
|
||||
buttonAddPlane.Click += buttonAddPlane_Click;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||
pictureBoxCollection.Location = new Point(0, 0);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(787, 538);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// FormPlaneCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1017, 538);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormPlaneCollection";
|
||||
Text = "Набор самолетов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private Button buttonRefreshCollection;
|
||||
private Button buttonRemovePlane;
|
||||
private Button buttonAddPlane;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private PictureBox pictureBoxCollection;
|
||||
}
|
||||
}
|
59
ProjStormtrooper/ProjStormtrooper/PlaneCollection.cs
Normal file
59
ProjStormtrooper/ProjStormtrooper/PlaneCollection.cs
Normal file
@ -0,0 +1,59 @@
|
||||
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 ProjStormtrooper
|
||||
{
|
||||
public partial class PlaneCollection : Form
|
||||
{
|
||||
private readonly PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> _planes;
|
||||
public PlaneCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_planes = new PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
private void buttonAddPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
Stormtrooper form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_planes + form.SelectedPlane > -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _planes.ShowPlanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void buttonRemovePlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_planes - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _planes.ShowPlanes();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _planes.ShowPlanes();
|
||||
}
|
||||
}
|
||||
}
|
120
ProjStormtrooper/ProjStormtrooper/PlaneCollection.resx
Normal file
120
ProjStormtrooper/ProjStormtrooper/PlaneCollection.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>
|
91
ProjStormtrooper/ProjStormtrooper/PlanesGenericCollection.cs
Normal file
91
ProjStormtrooper/ProjStormtrooper/PlanesGenericCollection.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjStormtrooper
|
||||
{
|
||||
internal class PlanesGenericCollection<T, U>
|
||||
where T : DrawingPlane
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 160;
|
||||
private readonly int _placeSizeHeight = 120;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public PlanesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int horizontalObjectsCount = picWidth / _placeSizeWidth;
|
||||
int verticalObjectsCount = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(horizontalObjectsCount * verticalObjectsCount);
|
||||
}
|
||||
|
||||
public static int operator +(PlanesGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
|
||||
public static bool operator -(PlanesGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
|
||||
public Bitmap ShowPlanes()
|
||||
{
|
||||
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++)
|
||||
{
|
||||
DrawingPlane plane = _collection.Get(i);
|
||||
if (plane != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
plane.SetPosition((_pictureWidth - 30 - (i % inRow + 1) * _placeSizeWidth), (i / inRow) * _placeSizeHeight);
|
||||
plane.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ namespace ProjStormtrooper
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Stormtrooper());
|
||||
Application.Run(new PlaneCollection());
|
||||
}
|
||||
}
|
||||
}
|
76
ProjStormtrooper/ProjStormtrooper/SetGeneric.cs
Normal file
76
ProjStormtrooper/ProjStormtrooper/SetGeneric.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjStormtrooper
|
||||
{
|
||||
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 plane)
|
||||
{
|
||||
return Insert(plane, 0);
|
||||
}
|
||||
public int Insert(T plane, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int nullIndex = -1;
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
nullIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nullIndex < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int j = nullIndex - 1;
|
||||
while (j >= position)
|
||||
{
|
||||
_places[j + 1] = _places[j];
|
||||
j--;
|
||||
}
|
||||
}
|
||||
_places[position] = plane;
|
||||
return position;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
T? plane = _places[position];
|
||||
_places[position] = null;
|
||||
return plane;
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@
|
||||
buttonCreatePlane = new Button();
|
||||
buttonStep = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonSelectPlane = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -122,7 +123,7 @@
|
||||
buttonCreatePlane.TabIndex = 8;
|
||||
buttonCreatePlane.Text = "Создать самолет";
|
||||
buttonCreatePlane.UseVisualStyleBackColor = true;
|
||||
buttonCreatePlane.Click += buttonCreatePlane_Click_1;
|
||||
buttonCreatePlane.Click += buttonCreatePlane_Click;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
@ -146,11 +147,22 @@
|
||||
comboBoxStrategy.Size = new Size(133, 23);
|
||||
comboBoxStrategy.TabIndex = 10;
|
||||
//
|
||||
// buttonSelectPlane
|
||||
//
|
||||
buttonSelectPlane.Location = new Point(376, 428);
|
||||
buttonSelectPlane.Name = "buttonSelectPlane";
|
||||
buttonSelectPlane.Size = new Size(198, 23);
|
||||
buttonSelectPlane.TabIndex = 11;
|
||||
buttonSelectPlane.Text = "выбрать";
|
||||
buttonSelectPlane.UseVisualStyleBackColor = true;
|
||||
buttonSelectPlane.Click += buttonSelectPlane_Click;
|
||||
//
|
||||
// Stormtrooper
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(884, 461);
|
||||
Controls.Add(buttonSelectPlane);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(buttonCreatePlane);
|
||||
@ -179,5 +191,6 @@
|
||||
private Button buttonCreatePlane;
|
||||
private Button buttonStep;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonSelectPlane;
|
||||
}
|
||||
}
|
@ -7,12 +7,16 @@ namespace ProjStormtrooper
|
||||
public partial class Stormtrooper : Form
|
||||
{
|
||||
private DrawingPlane? _drawingPlane;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
private AbstractStrategy? _strategy;
|
||||
public DrawingPlane? SelectedPlane { get; private set; }
|
||||
|
||||
public Stormtrooper()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
SelectedPlane = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingPlane == null)
|
||||
@ -28,11 +32,23 @@ namespace ProjStormtrooper
|
||||
private void buttonCreateStormtrooper_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;
|
||||
}
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialog.Color;
|
||||
}
|
||||
_drawingPlane = new DrawingStormtrooper(
|
||||
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)),
|
||||
color,
|
||||
dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxStormtrooper.Width,
|
||||
@ -42,6 +58,26 @@ namespace ProjStormtrooper
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonCreatePlane_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;
|
||||
}
|
||||
_drawingPlane = new DrawingPlane(
|
||||
random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
color,
|
||||
pictureBoxStormtrooper.Width,
|
||||
pictureBoxStormtrooper.Height
|
||||
);
|
||||
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingPlane == null)
|
||||
@ -75,44 +111,36 @@ namespace ProjStormtrooper
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToRightBottom(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
if (_strategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCreatePlane_Click_1(object sender, EventArgs e)
|
||||
private void buttonSelectPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingPlane = new DrawingPlane(
|
||||
random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
pictureBoxStormtrooper.Width,
|
||||
pictureBoxStormtrooper.Height
|
||||
);
|
||||
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
SelectedPlane = _drawingPlane;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
@ -123,7 +123,7 @@
|
||||
iVBORw0KGgoAAAANSUhEUgAAANQAAADuCAMAAAB24dnhAAAABGdBTUEAALGPC/xhBQAAAHtQTFRFAAAA
|
||||
////7u7u7e3t9fX1+Pj48/Pz+/v79PT0fn5+UFBQ5+fnMzMzs7Oz19fXb29vjY2NtLS00tLSpaWlHh4e
|
||||
vLy8U1NTOzs7CgoKTExMysrK4eHhLy8vFBQUNzc3a2trk5OTXV1denp6JycnnJycIyMjWlpaREREw8PD
|
||||
TPw7owAAAAlwSFlzAAAOvgAADr4B6kKxwAAACpZJREF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owAAAAlwSFlzAAAOvAAADrwBlbxySQAACPxJREFUeF7lnXtjmjAUxcMbq9W2a31Uu9a22/r9P+Fu
|
||||
wklycay+ECH3+MfWQ+TwQ4RLDKAipyS2ghFFhfNyOFGUWS/J4ERR6rwCThTlsOIEBgmO8T4xyy5j4+vh
|
||||
blaV12XsFXFv1MdUe13GXhVXTR7I6zL2urhKPcnCfXkShavUD2+iUdC4jBeNeoCbXA5XzbK8ejsaXTCW
|
||||
48Lhq7SAE8clHMqFE8csF04cN+R6jGZcNSrNPDuIjVXihGkkGAlbuQWcJEnh6BVu5Zcgh5OwFR7DqUUw
|
||||
|
Loading…
x
Reference in New Issue
Block a user