Ievlewa_lab03_Base #3
140
speed_Boat/speed_Boat/BoatsGenericCollection.cs
Normal file
140
speed_Boat/speed_Boat/BoatsGenericCollection.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SpeedBoatLab.Drawings;
|
||||
using speed_Boat.MovementStrategy;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace speed_Boat.Generics
|
||||
{
|
||||
internal class BoatsGenericCollection<T, U>
|
||||
where T : DrawingBoat
|
||||
where U : IMovementObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 180;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
public readonly GenericClass<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public BoatsGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new GenericClass<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool operator + (BoatsGenericCollection<T, U> collect, T? obj)
|
||||
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
public static bool? operator - (BoatsGenericCollection<T, U> collect, int pos)//bool??
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Remove(pos) ?? false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowBoats()
|
||||
{
|
||||
Bitmap bmp = new(_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(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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
int col = 0;
|
||||
int width_Col = _pictureWidth / _placeSizeWidth;//количество колонок в окне прорисовки
|
||||
for (int j = 0; j < _collection.Count; j++)
|
||||
{
|
||||
DrawingBoat? boat = _collection.Get(j);
|
||||
if (boat == null)
|
||||
{
|
||||
col++;
|
||||
if (col > 2)
|
||||
col = 0;
|
||||
continue;
|
||||
}
|
||||
boat.SetPosition(col * _placeSizeWidth, j / width_Col * _placeSizeHeight);
|
||||
col++;
|
||||
if (col > 2)
|
||||
col = 0;
|
||||
boat.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -34,5 +34,6 @@ namespace speed_Boat.MovementStrategy
|
||||
public bool CheckCanMove(DirectionType direction) => _drawingBoat?.CanMove(direction) ?? false;
|
||||
|
||||
public void MoveObject(DirectionType direction) => _drawingBoat?.MoveBoat(direction);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,10 @@ namespace SpeedBoatLab.Drawings
|
||||
_entityBoat = new EntitySpeedboat(speed, weight, mainColor, secondColor, _isMotor, _isProtectedGlass);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// перегружаемый метод DrawTransport
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_entityBoat is not EntitySpeedboat speedBoat)
|
||||
|
136
speed_Boat/speed_Boat/FormBoatCollection.Designer.cs
generated
Normal file
136
speed_Boat/speed_Boat/FormBoatCollection.Designer.cs
generated
Normal file
@ -0,0 +1,136 @@
|
||||
|
||||
namespace SpeedBoatLab
|
||||
{
|
||||
partial class FormBoatCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||
UpdateCollectionButton = new System.Windows.Forms.Button();
|
||||
DeleteBoatButton = new System.Windows.Forms.Button();
|
||||
AddBoatButton = new System.Windows.Forms.Button();
|
||||
pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
label1 = new System.Windows.Forms.Label();
|
||||
groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(label1);
|
||||
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||
groupBox1.Controls.Add(UpdateCollectionButton);
|
||||
groupBox1.Controls.Add(DeleteBoatButton);
|
||||
groupBox1.Controls.Add(AddBoatButton);
|
||||
groupBox1.Location = new System.Drawing.Point(581, 12);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new System.Drawing.Size(205, 426);
|
||||
groupBox1.TabIndex = 0;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Настройки";
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new System.Drawing.Point(6, 108);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new System.Drawing.Size(193, 27);
|
||||
maskedTextBoxNumber.TabIndex = 3;
|
||||
//
|
||||
// UpdateCollectionButton
|
||||
//
|
||||
UpdateCollectionButton.Location = new System.Drawing.Point(6, 194);
|
||||
UpdateCollectionButton.Name = "UpdateCollectionButton";
|
||||
UpdateCollectionButton.Size = new System.Drawing.Size(193, 47);
|
||||
UpdateCollectionButton.TabIndex = 2;
|
||||
UpdateCollectionButton.Text = "Обновить коллекцию";
|
||||
UpdateCollectionButton.UseVisualStyleBackColor = true;
|
||||
UpdateCollectionButton.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// DeleteBoatButton
|
||||
//
|
||||
DeleteBoatButton.Location = new System.Drawing.Point(6, 141);
|
||||
DeleteBoatButton.Name = "DeleteBoatButton";
|
||||
DeleteBoatButton.Size = new System.Drawing.Size(193, 47);
|
||||
DeleteBoatButton.TabIndex = 1;
|
||||
DeleteBoatButton.Text = "Удалить Катер";
|
||||
DeleteBoatButton.UseVisualStyleBackColor = true;
|
||||
DeleteBoatButton.Click += ButtonRemoveBoat_Click;
|
||||
//
|
||||
// AddBoatButton
|
||||
//
|
||||
AddBoatButton.Location = new System.Drawing.Point(6, 26);
|
||||
AddBoatButton.Name = "AddBoatButton";
|
||||
AddBoatButton.Size = new System.Drawing.Size(193, 47);
|
||||
AddBoatButton.TabIndex = 0;
|
||||
AddBoatButton.Text = "Добавить Катер";
|
||||
AddBoatButton.UseVisualStyleBackColor = true;
|
||||
AddBoatButton.Click += ButtonAddBoat_Click;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location = new System.Drawing.Point(12, 12);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new System.Drawing.Size(554, 425);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new System.Drawing.Point(6, 85);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new System.Drawing.Size(135, 20);
|
||||
label1.TabIndex = 4;
|
||||
label1.Text = "введите позицию:";
|
||||
//
|
||||
// FormBoatCollection
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(800, 450);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "FormBoatCollection";
|
||||
Text = "FormBoatCollection";
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.Button UpdateCollectionButton;
|
||||
private System.Windows.Forms.Button DeleteBoatButton;
|
||||
private System.Windows.Forms.Button AddBoatButton;
|
||||
private System.Windows.Forms.PictureBox pictureBoxCollection;
|
||||
private System.Windows.Forms.MaskedTextBox maskedTextBoxNumber;
|
||||
private System.Windows.Forms.Label label1;
|
||||
}
|
||||
}
|
98
speed_Boat/speed_Boat/FormBoatCollection.cs
Normal file
98
speed_Boat/speed_Boat/FormBoatCollection.cs
Normal file
@ -0,0 +1,98 @@
|
||||
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 SpeedBoatLab.Drawings;
|
||||
using speed_Boat.Generics;
|
||||
using speed_Boat.MovementStrategy;
|
||||
|
||||
|
||||
namespace SpeedBoatLab
|
||||
{
|
||||
public partial class FormBoatCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> _boats;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormBoatCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_boats = new BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>
|
||||
(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormSpeedBoat form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_boats + form.SelectedBoat != false)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _boats.ShowBoats();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string insertPosition = maskedTextBoxNumber.Text;
|
||||
int pos = -1;
|
||||
if (insertPosition != string.Empty)
|
||||
{
|
||||
int.TryParse(insertPosition, out pos);
|
||||
if (pos < 0 || pos > _boats._collection.Count - 1)
|
||||
MessageBox.Show("Неверный формат позиции");
|
||||
|
||||
if (_boats - pos != false)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _boats.ShowBoats();
|
||||
}
|
||||
}
|
||||
else if(insertPosition == string.Empty)
|
||||
{
|
||||
MessageBox.Show("Неверный формат позиции");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _boats.ShowBoats();
|
||||
}
|
||||
}
|
||||
}
|
120
speed_Boat/speed_Boat/FormBoatCollection.resx
Normal file
120
speed_Boat/speed_Boat/FormBoatCollection.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>
|
244
speed_Boat/speed_Boat/FormSpeedBoat.Designer.cs
generated
244
speed_Boat/speed_Boat/FormSpeedBoat.Designer.cs
generated
@ -29,149 +29,164 @@ namespace SpeedBoatLab
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxSpeedBoat = new System.Windows.Forms.PictureBox();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.buttonUp = 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.comboBox1 = new System.Windows.Forms.ComboBox();
|
||||
this.StepButton = new System.Windows.Forms.Button();
|
||||
this.buttonCreateSpeedBoat = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSpeedBoat)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
pictureBoxSpeedBoat = new System.Windows.Forms.PictureBox();
|
||||
buttonCreate = new System.Windows.Forms.Button();
|
||||
buttonUp = new System.Windows.Forms.Button();
|
||||
buttonLeft = new System.Windows.Forms.Button();
|
||||
buttonDown = new System.Windows.Forms.Button();
|
||||
buttonRight = new System.Windows.Forms.Button();
|
||||
comboBox1 = new System.Windows.Forms.ComboBox();
|
||||
StepButton = new System.Windows.Forms.Button();
|
||||
buttonCreateSpeedBoat = new System.Windows.Forms.Button();
|
||||
mainColorDialog = new System.Windows.Forms.ColorDialog();
|
||||
additionalColorDialog = new System.Windows.Forms.ColorDialog();
|
||||
BoatSelectButton = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxSpeedBoat).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxSpeedBoat
|
||||
//
|
||||
this.pictureBoxSpeedBoat.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxSpeedBoat.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxSpeedBoat.Name = "pictureBoxSpeedBoat";
|
||||
this.pictureBoxSpeedBoat.Size = new System.Drawing.Size(800, 450);
|
||||
this.pictureBoxSpeedBoat.TabIndex = 0;
|
||||
this.pictureBoxSpeedBoat.TabStop = false;
|
||||
pictureBoxSpeedBoat.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
pictureBoxSpeedBoat.Location = new System.Drawing.Point(0, 0);
|
||||
pictureBoxSpeedBoat.Name = "pictureBoxSpeedBoat";
|
||||
pictureBoxSpeedBoat.Size = new System.Drawing.Size(800, 450);
|
||||
pictureBoxSpeedBoat.TabIndex = 0;
|
||||
pictureBoxSpeedBoat.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.BackColor = System.Drawing.Color.White;
|
||||
this.buttonCreate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.buttonCreate.Location = new System.Drawing.Point(12, 387);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(103, 51);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать катер";
|
||||
this.buttonCreate.UseVisualStyleBackColor = false;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
buttonCreate.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
||||
buttonCreate.BackColor = System.Drawing.Color.White;
|
||||
buttonCreate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
buttonCreate.Location = new System.Drawing.Point(12, 387);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new System.Drawing.Size(103, 51);
|
||||
buttonCreate.TabIndex = 2;
|
||||
buttonCreate.Text = "Создать катер";
|
||||
buttonCreate.UseVisualStyleBackColor = false;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::speed_Boat.Properties.Resources.UP;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.buttonUp.Location = new System.Drawing.Point(716, 372);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 10;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
buttonUp.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = speed_Boat.Properties.Resources.UP;
|
||||
buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
buttonUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
buttonUp.Location = new System.Drawing.Point(716, 372);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
buttonUp.TabIndex = 10;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::speed_Boat.Properties.Resources.LEFT;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(680, 408);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 9;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
buttonLeft.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = speed_Boat.Properties.Resources.LEFT;
|
||||
buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
buttonLeft.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
buttonLeft.Location = new System.Drawing.Point(680, 408);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
buttonLeft.TabIndex = 9;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::speed_Boat.Properties.Resources.DOWN;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.buttonDown.Location = new System.Drawing.Point(716, 408);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 8;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
buttonDown.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = speed_Boat.Properties.Resources.DOWN;
|
||||
buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
buttonDown.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
buttonDown.Location = new System.Drawing.Point(716, 408);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
buttonDown.TabIndex = 8;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::speed_Boat.Properties.Resources.RIGHT;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.buttonRight.Location = new System.Drawing.Point(752, 408);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 7;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
buttonRight.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = speed_Boat.Properties.Resources.RIGHT;
|
||||
buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
buttonRight.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
buttonRight.Location = new System.Drawing.Point(752, 408);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
buttonRight.TabIndex = 7;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
//
|
||||
// comboBox1
|
||||
//
|
||||
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBox1.FormattingEnabled = true;
|
||||
this.comboBox1.Items.AddRange(new object[] {
|
||||
"MoveToCenter",
|
||||
"MoveToBorder"});
|
||||
this.comboBox1.Location = new System.Drawing.Point(637, 12);
|
||||
this.comboBox1.Name = "comboBox1";
|
||||
this.comboBox1.Size = new System.Drawing.Size(151, 28);
|
||||
this.comboBox1.TabIndex = 11;
|
||||
comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
comboBox1.FormattingEnabled = true;
|
||||
comboBox1.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
|
||||
comboBox1.Location = new System.Drawing.Point(637, 12);
|
||||
comboBox1.Name = "comboBox1";
|
||||
comboBox1.Size = new System.Drawing.Size(151, 28);
|
||||
comboBox1.TabIndex = 11;
|
||||
//
|
||||
// StepButton
|
||||
//
|
||||
this.StepButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.StepButton.BackColor = System.Drawing.Color.White;
|
||||
this.StepButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.StepButton.Location = new System.Drawing.Point(731, 46);
|
||||
this.StepButton.Name = "StepButton";
|
||||
this.StepButton.Size = new System.Drawing.Size(57, 33);
|
||||
this.StepButton.TabIndex = 12;
|
||||
this.StepButton.Text = "Шаг";
|
||||
this.StepButton.UseVisualStyleBackColor = false;
|
||||
this.StepButton.Click += new System.EventHandler(this.StepButton_Click);
|
||||
StepButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
||||
StepButton.BackColor = System.Drawing.Color.White;
|
||||
StepButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
StepButton.Location = new System.Drawing.Point(731, 46);
|
||||
StepButton.Name = "StepButton";
|
||||
StepButton.Size = new System.Drawing.Size(57, 33);
|
||||
StepButton.TabIndex = 12;
|
||||
StepButton.Text = "Шаг";
|
||||
StepButton.UseVisualStyleBackColor = false;
|
||||
StepButton.Click += StepButton_Click;
|
||||
//
|
||||
// buttonCreateSpeedBoat
|
||||
//
|
||||
this.buttonCreateSpeedBoat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateSpeedBoat.BackColor = System.Drawing.Color.White;
|
||||
this.buttonCreateSpeedBoat.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.buttonCreateSpeedBoat.Location = new System.Drawing.Point(121, 387);
|
||||
this.buttonCreateSpeedBoat.Name = "buttonCreateSpeedBoat";
|
||||
this.buttonCreateSpeedBoat.Size = new System.Drawing.Size(143, 51);
|
||||
this.buttonCreateSpeedBoat.TabIndex = 13;
|
||||
this.buttonCreateSpeedBoat.Text = "Создать скоростной катер";
|
||||
this.buttonCreateSpeedBoat.UseVisualStyleBackColor = false;
|
||||
this.buttonCreateSpeedBoat.Click += new System.EventHandler(this.buttonCreateSpeedBoat_Click);
|
||||
buttonCreateSpeedBoat.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
||||
buttonCreateSpeedBoat.BackColor = System.Drawing.Color.White;
|
||||
buttonCreateSpeedBoat.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
buttonCreateSpeedBoat.Location = new System.Drawing.Point(121, 387);
|
||||
buttonCreateSpeedBoat.Name = "buttonCreateSpeedBoat";
|
||||
buttonCreateSpeedBoat.Size = new System.Drawing.Size(143, 51);
|
||||
buttonCreateSpeedBoat.TabIndex = 13;
|
||||
buttonCreateSpeedBoat.Text = "Создать скоростной катер";
|
||||
buttonCreateSpeedBoat.UseVisualStyleBackColor = false;
|
||||
buttonCreateSpeedBoat.Click += buttonCreateSpeedBoat_Click;
|
||||
//
|
||||
// BoatSelectButton
|
||||
//
|
||||
BoatSelectButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
||||
BoatSelectButton.BackColor = System.Drawing.Color.White;
|
||||
BoatSelectButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
BoatSelectButton.Location = new System.Drawing.Point(637, 294);
|
||||
BoatSelectButton.Name = "BoatSelectButton";
|
||||
BoatSelectButton.Size = new System.Drawing.Size(151, 41);
|
||||
BoatSelectButton.TabIndex = 18;
|
||||
BoatSelectButton.Text = "Выбор катера";
|
||||
BoatSelectButton.UseVisualStyleBackColor = false;
|
||||
BoatSelectButton.Click += BoatSelectButton_Click;
|
||||
//
|
||||
// FormSpeedBoat
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonCreateSpeedBoat);
|
||||
this.Controls.Add(this.StepButton);
|
||||
this.Controls.Add(this.comboBox1);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.pictureBoxSpeedBoat);
|
||||
this.Name = "FormSpeedBoat";
|
||||
this.Text = "Движение катера";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSpeedBoat)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(800, 450);
|
||||
Controls.Add(BoatSelectButton);
|
||||
Controls.Add(buttonCreateSpeedBoat);
|
||||
Controls.Add(StepButton);
|
||||
Controls.Add(comboBox1);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxSpeedBoat);
|
||||
Name = "FormSpeedBoat";
|
||||
Text = "Движение катера";
|
||||
Load += FormSpeedBoat_Load;
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxSpeedBoat).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -185,6 +200,9 @@ namespace SpeedBoatLab
|
||||
private System.Windows.Forms.ComboBox comboBox1;
|
||||
private System.Windows.Forms.Button StepButton;
|
||||
private System.Windows.Forms.Button buttonCreateSpeedBoat;
|
||||
private System.Windows.Forms.ColorDialog mainColorDialog;
|
||||
private System.Windows.Forms.ColorDialog additionalColorDialog;
|
||||
private System.Windows.Forms.Button BoatSelectButton;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@ namespace SpeedBoatLab
|
||||
{
|
||||
public partial class FormSpeedBoat : Form
|
||||
{
|
||||
Color mainColor = Color.White;
|
||||
Color addColor = Color.White;
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
@ -23,10 +25,16 @@ namespace SpeedBoatLab
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
/// <summary>
|
||||
/// Выбранный автомобиль
|
||||
/// </summary>
|
||||
public DrawingBoat? SelectedBoat { get; private set; }
|
||||
|
||||
public FormSpeedBoat()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedBoat = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -50,13 +58,20 @@ namespace SpeedBoatLab
|
||||
/// </summary>
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
mainColorDialog.ShowDialog();
|
||||
mainColor = mainColorDialog.Color;
|
||||
|
||||
Random random = new();
|
||||
if (mainColor == Color.White)
|
||||
{
|
||||
mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
}
|
||||
_boatMovement = new DrawingBoat(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
mainColor,
|
||||
pictureBoxSpeedBoat.Width, pictureBoxSpeedBoat.Height);
|
||||
|
||||
//startXCoord and startYCoord
|
||||
///startXCoord and startYCoord
|
||||
_boatMovement.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
|
||||
Draw();
|
||||
@ -67,16 +82,28 @@ namespace SpeedBoatLab
|
||||
/// </summary>
|
||||
private void buttonCreateSpeedBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
mainColorDialog.ShowDialog();
|
||||
mainColor = mainColorDialog.Color;
|
||||
|
||||
additionalColorDialog.ShowDialog();
|
||||
addColor = additionalColorDialog.Color;
|
||||
|
||||
Random random = new();
|
||||
if (mainColor == Color.White || addColor == Color.White)
|
||||
{
|
||||
mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
}
|
||||
|
||||
_boatMovement = new DrawingSpeedBoat(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)),
|
||||
mainColor,
|
||||
addColor,
|
||||
true,
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxSpeedBoat.Width, pictureBoxSpeedBoat.Height);
|
||||
|
||||
//startXCoord and startYCoord
|
||||
///startXCoord and startYCoord
|
||||
_boatMovement.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
|
||||
Draw();
|
||||
@ -115,19 +142,19 @@ namespace SpeedBoatLab
|
||||
/// </summary>
|
||||
private void StepButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if(_boatMovement == null)
|
||||
if (_boatMovement == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(comboBox1.Enabled)
|
||||
{
|
||||
if (comboBox1.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBox1.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null
|
||||
};
|
||||
if(_abstractStrategy == null)
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -140,11 +167,18 @@ namespace SpeedBoatLab
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if(_abstractStrategy.GetStatus() == Status.Finish)
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBox1.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void BoatSelectButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedBoat = _boatMovement;
|
||||
DialogResult = DialogResult.OK;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,64 @@
|
||||
<root>
|
||||
<?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">
|
||||
@ -57,4 +117,10 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="mainColorDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="additionalColorDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>161, 17</value>
|
||||
</metadata>
|
||||
</root>
|
124
speed_Boat/speed_Boat/GenericClass.cs
Normal file
124
speed_Boat/speed_Boat/GenericClass.cs
Normal file
@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace speed_Boat.Generics
|
||||
{
|
||||
internal class GenericClass<T> where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T?[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public GenericClass(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
public bool Insert(T boat)
|
||||
{
|
||||
int currentI = -1;
|
||||
eegov
commented
Правильнее было вызвать Insert(T obj, 0); Правильнее было вызвать Insert(T obj, 0);
|
||||
// TODO вставка в начало набора
|
||||
for(int i = 0; i < _places.Length; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
currentI = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentI < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int i = currentI; i > 0; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
|
||||
_places[0] = boat;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию.
|
||||
/// Если позиция пуста, то производится вставка.
|
||||
/// Если позиция занята, то происходит сдвиг элементов
|
||||
/// вправо(при возможности) на одну позицию.
|
||||
/// </summary>
|
||||
public bool Insert(T boat, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
return false;
|
||||
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = boat;
|
||||
return true;
|
||||
}
|
||||
|
||||
int currentI = -1;
|
||||
for (int i = position; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
currentI = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentI < 0)
|
||||
return false;
|
||||
|
||||
for (int i = currentI + 1; i > 0; i--)
|
||||
_places[i] = _places[i - 1];
|
||||
|
||||
|
||||
_places[currentI] = boat;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _places[position];//возвращает элемент тип genericClass
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,6 @@ namespace speed_Boat.MovementStrategy
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//return objParams.RightBorder == FieldWidth && objParams.DownBorder == FieldHeight;
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth&&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
|
@ -17,7 +17,7 @@ namespace SpeedBoatLab
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormSpeedBoat());
|
||||
Application.Run(new FormBoatCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using SpeedBoatLab;
|
||||
using System.Drawing;
|
||||
using SpeedBoatLab.Entity;
|
||||
using speed_Boat.MovementStrategy;
|
||||
|
||||
|
||||
namespace SpeedBoatLab.Drawings
|
||||
@ -62,6 +63,11 @@ namespace SpeedBoatLab.Drawings
|
||||
/// </summary>
|
||||
public int GetHeight => heightBoat;
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningBoat
|
||||
/// </summary>
|
||||
public IMovementObject GetMoveableObject => new DrawingObjectBoat(this);
|
||||
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (_entityBoat == null)
|
||||
@ -104,9 +110,6 @@ namespace SpeedBoatLab.Drawings
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// конструктор
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user
Требовалось поменять тип возвращаемого значения