SemesterFirstLabThirdBomberBase
This commit is contained in:
parent
35feab6891
commit
4b4f3eed79
@ -1,4 +1,5 @@
|
|||||||
using ProjectBomber.Entities;
|
using ProjectBomber.Entities;
|
||||||
|
using ProjectBomber.MovementStrategy;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
@ -207,6 +208,11 @@ namespace ProjectBomber.DrawningObjects
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||||
|
/// </summary>
|
||||||
|
public IMoveableObject GetMoveableObject => new
|
||||||
|
DrawningObjectBomber(this);
|
||||||
public virtual void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityBomber == null)
|
if (EntityBomber == null)
|
||||||
|
13
ProjectBomber/ProjectBomber/Form1.Designer.cs
generated
13
ProjectBomber/ProjectBomber/Form1.Designer.cs
generated
@ -38,6 +38,7 @@
|
|||||||
this.comboBox1Strategy = new System.Windows.Forms.ComboBox();
|
this.comboBox1Strategy = new System.Windows.Forms.ComboBox();
|
||||||
this.ButtonCreatePlane = new System.Windows.Forms.Button();
|
this.ButtonCreatePlane = new System.Windows.Forms.Button();
|
||||||
this.ButtonStep = new System.Windows.Forms.Button();
|
this.ButtonStep = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonSelectPlane = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBomber)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBomber)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -142,10 +143,21 @@
|
|||||||
this.ButtonStep.UseVisualStyleBackColor = true;
|
this.ButtonStep.UseVisualStyleBackColor = true;
|
||||||
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
||||||
//
|
//
|
||||||
|
// ButtonSelectPlane
|
||||||
|
//
|
||||||
|
this.ButtonSelectPlane.Location = new System.Drawing.Point(295, 421);
|
||||||
|
this.ButtonSelectPlane.Name = "ButtonSelectPlane";
|
||||||
|
this.ButtonSelectPlane.Size = new System.Drawing.Size(101, 28);
|
||||||
|
this.ButtonSelectPlane.TabIndex = 11;
|
||||||
|
this.ButtonSelectPlane.Text = "Выбрать";
|
||||||
|
this.ButtonSelectPlane.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonSelectPlane.Click += new System.EventHandler(this.ButtonSelectPlane_Click);
|
||||||
|
//
|
||||||
// FormBomber
|
// FormBomber
|
||||||
//
|
//
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
||||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||||
|
this.Controls.Add(this.ButtonSelectPlane);
|
||||||
this.Controls.Add(this.ButtonStep);
|
this.Controls.Add(this.ButtonStep);
|
||||||
this.Controls.Add(this.ButtonCreatePlane);
|
this.Controls.Add(this.ButtonCreatePlane);
|
||||||
this.Controls.Add(this.comboBox1Strategy);
|
this.Controls.Add(this.comboBox1Strategy);
|
||||||
@ -175,6 +187,7 @@
|
|||||||
private System.Windows.Forms.ComboBox comboBox1Strategy;
|
private System.Windows.Forms.ComboBox comboBox1Strategy;
|
||||||
private System.Windows.Forms.Button ButtonCreatePlane;
|
private System.Windows.Forms.Button ButtonCreatePlane;
|
||||||
private System.Windows.Forms.Button ButtonStep;
|
private System.Windows.Forms.Button ButtonStep;
|
||||||
|
private System.Windows.Forms.Button ButtonSelectPlane;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +22,15 @@ namespace ProjectBomber
|
|||||||
/// Стратегии перемещения
|
/// Стратегии перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractStrategy _abstractStrategy;
|
private AbstractStrategy _abstractStrategy;
|
||||||
|
/// <summary>
|
||||||
|
/// Выбранный автомобиль
|
||||||
|
/// </summary>
|
||||||
|
public DrawningBomber SelectedBomber { get; private set; }
|
||||||
public FormBomber()
|
public FormBomber()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
SelectedBomber = null;
|
||||||
}
|
}
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
@ -45,11 +51,22 @@ namespace ProjectBomber
|
|||||||
private void ButtonCreateBomber_Click(object sender, EventArgs e)
|
private void ButtonCreateBomber_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
//выбор основного цвета и дополнительного
|
||||||
|
ColorDialog colorDialog = new ColorDialog();
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = colorDialog.Color;
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = colorDialog.Color;
|
||||||
|
}
|
||||||
|
}
|
||||||
_drawningBomber = new DrawningBomberAdvanced(random.Next(100, 300), random.Next(1000, 3000),
|
_drawningBomber = new DrawningBomberAdvanced(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
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)),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
Convert.ToBoolean(random.Next(0, 2)), pictureBoxBomber.Width, pictureBoxBomber.Height);
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
|
||||||
pictureBoxBomber.Width, pictureBoxBomber.Height);
|
|
||||||
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
@ -61,8 +78,13 @@ namespace ProjectBomber
|
|||||||
private void ButtonCreatePlane_Click(object sender, EventArgs e)
|
private void ButtonCreatePlane_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
_drawningBomber = new DrawningBomber(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
random.Next(0, 256)), pictureBoxBomber.Width, pictureBoxBomber.Height);
|
ColorDialog colorDialog = new ColorDialog();
|
||||||
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = colorDialog.Color;
|
||||||
|
}
|
||||||
|
_drawningBomber = new DrawningBomber(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxBomber.Width, pictureBoxBomber.Height);
|
||||||
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
@ -132,5 +154,15 @@ namespace ProjectBomber
|
|||||||
_abstractStrategy = null;
|
_abstractStrategy = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор самолета
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonSelectPlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedBomber = _drawningBomber;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
124
ProjectBomber/ProjectBomber/FormPlaneCollection.Designer.cs
generated
Normal file
124
ProjectBomber/ProjectBomber/FormPlaneCollection.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
namespace ProjectBomber
|
||||||
|
{
|
||||||
|
partial class FormPlaneCollection
|
||||||
|
{
|
||||||
|
/// <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.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonRemovePlane = new System.Windows.Forms.Button();
|
||||||
|
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||||
|
this.ButtonAddPlane = new System.Windows.Forms.Button();
|
||||||
|
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.ButtonRefreshCollection);
|
||||||
|
this.groupBox1.Controls.Add(this.ButtonRemovePlane);
|
||||||
|
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
|
||||||
|
this.groupBox1.Controls.Add(this.ButtonAddPlane);
|
||||||
|
this.groupBox1.Location = new System.Drawing.Point(586, 2);
|
||||||
|
this.groupBox1.Name = "groupBox1";
|
||||||
|
this.groupBox1.Size = new System.Drawing.Size(216, 453);
|
||||||
|
this.groupBox1.TabIndex = 0;
|
||||||
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
this.ButtonRefreshCollection.Location = new System.Drawing.Point(17, 237);
|
||||||
|
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
this.ButtonRefreshCollection.Size = new System.Drawing.Size(178, 41);
|
||||||
|
this.ButtonRefreshCollection.TabIndex = 3;
|
||||||
|
this.ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
|
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||||
|
//
|
||||||
|
// ButtonRemovePlane
|
||||||
|
//
|
||||||
|
this.ButtonRemovePlane.Location = new System.Drawing.Point(17, 136);
|
||||||
|
this.ButtonRemovePlane.Name = "ButtonRemovePlane";
|
||||||
|
this.ButtonRemovePlane.Size = new System.Drawing.Size(179, 41);
|
||||||
|
this.ButtonRemovePlane.TabIndex = 2;
|
||||||
|
this.ButtonRemovePlane.Text = "Удалить автомобиль";
|
||||||
|
this.ButtonRemovePlane.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonRemovePlane.Click += new System.EventHandler(this.ButtonRemovePlane_Click);
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
this.maskedTextBoxNumber.Location = new System.Drawing.Point(17, 99);
|
||||||
|
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
this.maskedTextBoxNumber.Size = new System.Drawing.Size(180, 20);
|
||||||
|
this.maskedTextBoxNumber.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// ButtonAddPlane
|
||||||
|
//
|
||||||
|
this.ButtonAddPlane.Location = new System.Drawing.Point(17, 36);
|
||||||
|
this.ButtonAddPlane.Name = "ButtonAddPlane";
|
||||||
|
this.ButtonAddPlane.Size = new System.Drawing.Size(185, 40);
|
||||||
|
this.ButtonAddPlane.TabIndex = 0;
|
||||||
|
this.ButtonAddPlane.Text = "Добавить самолет";
|
||||||
|
this.ButtonAddPlane.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonAddPlane.Click += new System.EventHandler(this.ButtonAddPlane_Click);
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
this.pictureBoxCollection.Location = new System.Drawing.Point(-2, 2);
|
||||||
|
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
this.pictureBoxCollection.Size = new System.Drawing.Size(600, 452);
|
||||||
|
this.pictureBoxCollection.TabIndex = 1;
|
||||||
|
this.pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormPlaneCollection
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.pictureBoxCollection);
|
||||||
|
this.Controls.Add(this.groupBox1);
|
||||||
|
this.Name = "FormPlaneCollection";
|
||||||
|
this.Text = "Набор самолетов";
|
||||||
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
this.groupBox1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.GroupBox groupBox1;
|
||||||
|
private System.Windows.Forms.Button ButtonRefreshCollection;
|
||||||
|
private System.Windows.Forms.Button ButtonRemovePlane;
|
||||||
|
private System.Windows.Forms.TextBox maskedTextBoxNumber;
|
||||||
|
private System.Windows.Forms.Button ButtonAddPlane;
|
||||||
|
private System.Windows.Forms.PictureBox pictureBoxCollection;
|
||||||
|
}
|
||||||
|
}
|
89
ProjectBomber/ProjectBomber/FormPlaneCollection.cs
Normal file
89
ProjectBomber/ProjectBomber/FormPlaneCollection.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
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 ProjectBomber.MovementStrategy;
|
||||||
|
using ProjectBomber.Generics;
|
||||||
|
using ProjectBomber.DrawningObjects;
|
||||||
|
|
||||||
|
namespace ProjectBomber
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Форма для работы с набором объектов класса DrawningCar
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormPlaneCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly PlanesGenericCollection<DrawningBomber,
|
||||||
|
DrawningObjectBomber> _planes;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormPlaneCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_planes = new PlanesGenericCollection<DrawningBomber,
|
||||||
|
DrawningObjectBomber>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddPlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormBomber form = new FormBomber();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_planes + form.SelectedBomber != 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = _planes.ShowPlanes();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
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("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обновление рисунка по набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _planes.ShowPlanes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectBomber/ProjectBomber/FormPlaneCollection.resx
Normal file
120
ProjectBomber/ProjectBomber/FormPlaneCollection.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>
|
156
ProjectBomber/ProjectBomber/PlanesGenericCollection.cs
Normal file
156
ProjectBomber/ProjectBomber/PlanesGenericCollection.cs
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
using ProjectBomber.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectBomber.DrawningObjects;
|
||||||
|
|
||||||
|
namespace ProjectBomber.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный класс для набора объектов DrawningBomber
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
internal class PlanesGenericCollection<T, U>
|
||||||
|
where T : DrawningBomber
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 200;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
public PlanesGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int? operator +(PlanesGenericCollection<T, U> collect, T
|
||||||
|
obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect?._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool operator -(PlanesGenericCollection<T, U> collect, int
|
||||||
|
pos)
|
||||||
|
{
|
||||||
|
T obj = collect._collection.Get(pos);
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public U GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U)_collection.Get(pos)?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowPlanes()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new Bitmap(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new Pen(Color.Black, 3);
|
||||||
|
int numColumns = _pictureWidth / _placeSizeWidth;
|
||||||
|
int numRows = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
|
for (int i = 0; i <= numColumns; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j <= numRows; ++j)
|
||||||
|
{
|
||||||
|
// Линии разметки места
|
||||||
|
int x = i * _placeSizeWidth;
|
||||||
|
int y = j * _placeSizeHeight;
|
||||||
|
g.DrawLine(pen, x, y, x + _placeSizeWidth / 2, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, numRows * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int numColumns = _pictureWidth / _placeSizeWidth;
|
||||||
|
int numRows = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
DrawningBomber plane = _collection.Get(i);
|
||||||
|
if (plane != null)
|
||||||
|
{
|
||||||
|
// Вычисляем позицию объекта
|
||||||
|
int row = i / numColumns; // Номер строки
|
||||||
|
int column = numColumns - 1 - (i % numColumns); // Номер столбца, инвертируем для движения справа налево
|
||||||
|
int x = column * _placeSizeWidth;
|
||||||
|
int y = row * _placeSizeHeight;
|
||||||
|
|
||||||
|
plane.SetPosition(x, y);
|
||||||
|
plane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@ namespace ProjectBomber
|
|||||||
{
|
{
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new FormBomber());
|
Application.Run(new FormPlaneCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,21 @@
|
|||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
|
<PublishUrl>publish\</PublishUrl>
|
||||||
|
<Install>true</Install>
|
||||||
|
<InstallFrom>Disk</InstallFrom>
|
||||||
|
<UpdateEnabled>false</UpdateEnabled>
|
||||||
|
<UpdateMode>Foreground</UpdateMode>
|
||||||
|
<UpdateInterval>7</UpdateInterval>
|
||||||
|
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||||
|
<UpdatePeriodically>false</UpdatePeriodically>
|
||||||
|
<UpdateRequired>false</UpdateRequired>
|
||||||
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
|
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||||
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
@ -59,16 +74,27 @@
|
|||||||
<Compile Include="Form1.Designer.cs">
|
<Compile Include="Form1.Designer.cs">
|
||||||
<DependentUpon>Form1.cs</DependentUpon>
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="FormPlaneCollection.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="FormPlaneCollection.Designer.cs">
|
||||||
|
<DependentUpon>FormPlaneCollection.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="IMoveableObject.cs" />
|
<Compile Include="IMoveableObject.cs" />
|
||||||
<Compile Include="MoveToBottomRight.cs" />
|
<Compile Include="MoveToBottomRight.cs" />
|
||||||
<Compile Include="MoveToCenter.cs" />
|
<Compile Include="MoveToCenter.cs" />
|
||||||
<Compile Include="ObjectParameters.cs" />
|
<Compile Include="ObjectParameters.cs" />
|
||||||
|
<Compile Include="PlanesGenericCollection.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="SetGeneric.cs" />
|
||||||
<Compile Include="Status.cs" />
|
<Compile Include="Status.cs" />
|
||||||
<EmbeddedResource Include="Form1.resx">
|
<EmbeddedResource Include="Form1.resx">
|
||||||
<DependentUpon>Form1.cs</DependentUpon>
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="FormPlaneCollection.resx">
|
||||||
|
<DependentUpon>FormPlaneCollection.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
<EmbeddedResource Include="Properties\Resources.resx">
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
@ -91,5 +117,17 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 и x64%29</ProductName>
|
||||||
|
<Install>true</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||||
|
<Install>false</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
123
ProjectBomber/ProjectBomber/SetGeneric.cs
Normal file
123
ProjectBomber/ProjectBomber/SetGeneric.cs
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectBomber.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly T[] _places;
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Length;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T[count];
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plane">Добавляемый самолет</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T plane)
|
||||||
|
{
|
||||||
|
int index = -1;
|
||||||
|
for (int i = 0; i < _places.Length; i++)
|
||||||
|
{
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
index = i; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (int i = index; i > 0; i--)
|
||||||
|
{
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
_places[0] = plane;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plane">Добавляемый автомобиль</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T plane, int position)
|
||||||
|
{
|
||||||
|
///Проверка позиции
|
||||||
|
if (position < 0 || position >= _places.Length)
|
||||||
|
return -1;
|
||||||
|
/// Проверка, что элемент массива по этой позиции пустой, если нет, то проверка,
|
||||||
|
/// что после вставляемого элемента в массиве есть пустой элемент
|
||||||
|
if (_places[position] != null)
|
||||||
|
{
|
||||||
|
/// Проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||||
|
int firstEmptyPosition = -1;
|
||||||
|
for (int i = position + 1; i < _places.Length; i++)
|
||||||
|
{
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
firstEmptyPosition = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Нет пустой позиции после вставляемой
|
||||||
|
if (firstEmptyPosition == -1)
|
||||||
|
return -1;
|
||||||
|
/// Сдвиг всех объектов, находящихся справа от позиции, до первого пустого элемента
|
||||||
|
for (int i = firstEmptyPosition; i > position; i--)
|
||||||
|
{
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Вставка по позиции
|
||||||
|
_places[position] = plane;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
/// Проверка позиции
|
||||||
|
if (position < 0 || position >= _places.Length)
|
||||||
|
return false;
|
||||||
|
/// Удаление объекта из массива, присвоив элементу массива значение null
|
||||||
|
_places[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T Get(int position)
|
||||||
|
{
|
||||||
|
// Проверка позиции
|
||||||
|
if (position < 0 || position >= _places.Length)
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user