Compare commits

...

7 Commits
start ... Lab5

39 changed files with 3137 additions and 0 deletions

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34525.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinF_Lab2_Cruiser", "WinF_Lab2_Cruiser\WinF_Lab2_Cruiser.csproj", "{D13E8CC0-46D6-4CB4-9DE1-E340C99B69FB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D13E8CC0-46D6-4CB4-9DE1-E340C99B69FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D13E8CC0-46D6-4CB4-9DE1-E340C99B69FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D13E8CC0-46D6-4CB4-9DE1-E340C99B69FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D13E8CC0-46D6-4CB4-9DE1-E340C99B69FB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {23A421F3-C54C-4554-B468-133A363BD9CD}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,264 @@
using System.Net.Http.Headers;
using System.Xml.Linq;
namespace WinF_Lab2_Cruiser
{
partial class CollectionForm
{
/// <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()
{
ToolBox = new GroupBox();
StorageBox = new GroupBox();
// labelCollections = new Label();
TextBoxC = new TextBox();
ArrayRB = new RadioButton();
ListRB = new RadioButton();
ButtonAL = new Button();
Elements = new ListBox();
ButtonDelAL = new Button();
CreateCompany = new Button();
Check = new Button();
RandomGenerator = new Button();
RemoveButton = new Button();
maskedTextBox1 = new MaskedTextBox();
// Add2Button = new Button();
AddButton = new Button();
comboBox1 = new ComboBox();
pictureBox1 = new PictureBox();
ToolBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
SuspendLayout();
//
// ToolBox
//
ToolBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
ToolBox.Controls.Add(Check);
ToolBox.Controls.Add(RandomGenerator);
ToolBox.Controls.Add(RemoveButton);
ToolBox.Controls.Add(maskedTextBox1);
// ToolBox.Controls.Add(Add2Button);
ToolBox.Controls.Add(AddButton);
ToolBox.Controls.Add(comboBox1);
ToolBox.Controls.Add(StorageBox);
ToolBox.Controls.Add(CreateCompany);
CreateCompany.Location = new Point(10, 540);
CreateCompany.Size = new Size(190, 80);
CreateCompany.Text = "Create company";
CreateCompany.Click += ButtonCreateCompany_Click;
ToolBox.Location = new Point(1030, 12);
ToolBox.Name = "ToolBox";
ToolBox.Size = new Size(220, 900);
ToolBox.TabIndex = 0;
ToolBox.TabStop = false;
ToolBox.Text = "Tools";
StorageBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
StorageBox.Location = new Point(8, 180);
StorageBox.Size = new Size(204, 350);
StorageBox.TabIndex = 1;
StorageBox.Text = "Collections Name:";
StorageBox.Controls.Add(TextBoxC);
TextBoxC.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
TextBoxC.Location = new Point(7, 70);
TextBoxC.Size = new Size(180, 46);
TextBoxC.TabIndex = 10;
StorageBox.Controls.Add(ArrayRB);
ArrayRB.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
ArrayRB.Location = new Point(4, 118);
ArrayRB.Size = new Size(100, 40);
ArrayRB.TabIndex = 11;
ArrayRB.Text = "Array";
StorageBox.Controls.Add(ListRB);
ListRB.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
ListRB.Location = new Point(96, 118);
ListRB.Size = new Size(80, 40);
ListRB.TabIndex = 12;
ListRB.Text = "List";
StorageBox.Controls.Add(ButtonAL);
ButtonAL.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
ButtonAL.Location = new Point(6, 160);
ButtonAL.Size = new Size(180, 40);
ButtonAL.TabIndex = 13;
ButtonAL.Text = "Add collection";
ButtonAL.Click += ButtonCollectionAdd_Click;
StorageBox.Controls.Add(Elements);
Elements.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
Elements.Location = new Point(6, 200);
Elements.Size = new Size(180, 100);
StorageBox.Controls.Add(ButtonDelAL);
ButtonDelAL.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
ButtonDelAL.Location = new Point(6, 300);
ButtonDelAL.Size = new Size(180, 40);
ButtonDelAL.TabIndex = 14;
ButtonDelAL.Text = "Remove";
ButtonDelAL.Click += ButtonCollectionDel_Click;
//
// Check
//
Check.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
Check.Location = new Point(34, 824);
Check.Name = "Check";
Check.Size = new Size(150, 46);
Check.TabIndex = 2;
Check.Text = "Check";
Check.UseVisualStyleBackColor = true;
Check.Click += Check_Click;
//
// RandomGenerator
//
RandomGenerator.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
RandomGenerator.Location = new Point(34, 734);
RandomGenerator.Name = "RandomGenerator";
RandomGenerator.Size = new Size(150, 90);
RandomGenerator.TabIndex = 3;
RandomGenerator.Text = "Generator Random";
RandomGenerator.UseVisualStyleBackColor = true;
RandomGenerator.Click += RandomGenerator_Click;
//
// RemoveButton
//
RemoveButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
RemoveButton.Location = new Point(34, 694);
RemoveButton.Name = "RemoveButton";
RemoveButton.Size = new Size(150, 40);
RemoveButton.TabIndex = 4;
RemoveButton.Text = "Delete";
RemoveButton.UseVisualStyleBackColor = true;
RemoveButton.Click += RemoveButton_Click;
//
// maskedTextBox1
//
maskedTextBox1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
maskedTextBox1.Location = new Point(6, 648);
maskedTextBox1.Mask = "00";
maskedTextBox1.Name = "maskedTextBox1";
maskedTextBox1.Size = new Size(198, 35);
maskedTextBox1.TabIndex = 5;
maskedTextBox1.ValidatingType = typeof(int);
//
// Add2Button
//
/*
Add2Button.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
Add2Button.Location = new Point(6, 126);
Add2Button.Name = "Add2Button";
Add2Button.Size = new Size(198, 40);
Add2Button.TabIndex = 6;
Add2Button.Text = "Advanced";
Add2Button.UseVisualStyleBackColor = true;
// Add2Button.Click += Add2Button_Click;
// Add2Button.Click += NewFormCreate;
*/
//
// AddButton
//
AddButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
AddButton.Location = new Point(6, 84);
AddButton.Name = "AddButton";
AddButton.Size = new Size(198, 70);
AddButton.TabIndex = 7;
AddButton.Text = "Create a cruiser";
AddButton.UseVisualStyleBackColor = true;
AddButton.Click += NewFormCreate;
// AddButton.Click += AddButton_Click;
//
// comboBox1
//
comboBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.FormattingEnabled = true;
comboBox1.Items.AddRange(new object[] { "Storage" });
comboBox1.Location = new Point(6, 35);
comboBox1.Name = "comboBox1";
comboBox1.Size = new Size(198, 40);
comboBox1.TabIndex = 8;
comboBox1.SelectedIndexChanged += comboBox_SelectedIndexChanged;
//
// pictureBox1
//
pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
pictureBox1.Dock = DockStyle.Left;
pictureBox1.Location = new Point(0, 0);
pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new Size(1020, 860);
pictureBox1.TabIndex = 9;
pictureBox1.TabStop = false;
//
// CollectionForm
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1260, 920);
Controls.Add(pictureBox1);
Controls.Add(ToolBox);
Name = "CollectionForm";
Text = "CollectionForm";
ToolBox.ResumeLayout(false);
ToolBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox ToolBox;
private GroupBox StorageBox;
// private Label labelCollections;
private TextBox TextBoxC;
private RadioButton ArrayRB;
private RadioButton ListRB;
private Button ButtonAL;
private ListBox Elements;
private Button ButtonDelAL;
private Button CreateCompany;
private ComboBox comboBox1;
private Button AddButton;
// private Button Add2Button;
private MaskedTextBox maskedTextBox1;
private PictureBox pictureBox1;
private Button RemoveButton;
private Button RandomGenerator;
private Button Check;
}
}

View File

@ -0,0 +1,263 @@
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 WinF_Lab2_Cruiser.CollectionGenericObjects;
using WinF_Lab2_Cruiser.Drawing_tools;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using WinF_Lab2_Cruiser.Entity_Folder;
namespace WinF_Lab2_Cruiser
{
public partial class CollectionForm : Form
{
private readonly StorageCollection<DrawingBase> _storageCollection;
private AbstractCompany? _Company = null;
public CollectionForm()
{
InitializeComponent();
_storageCollection = new();
}
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
ToolBox.Enabled = true;
/*
switch (comboBox1.Text)
{
case "Storage":
_Company = new NewClassCollection(pictureBox1.Width, pictureBox1.Height, new ArrayAlg<DrawingBase>());
break;
}
*/
}
/*
private static Color GetColor(Random r)
{
Color cl = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{ cl = dialog.Color; }
return cl;
}
private void CreateObject(string type)
{
if (_Company == null)
{
return;
}
Random rn = new();
DrawingBase Transport;
switch (type)
{
case nameof(DrawingBase):
Transport = new DrawingBase(rn.Next(100, 300), rn.Next(1000, 3000), GetColor(rn));
break;
case nameof(DrawingCruiser):
Transport = new DrawingCruiser(rn.Next(100, 300), rn.Next(1000, 3000),
GetColor(rn), GetColor(rn), Convert.ToBoolean(rn.Next(0, 2)),
Convert.ToBoolean(rn.Next(0, 2)), rn.Next(1, 4), rn.Next(5, 10), rn.Next(1, 3));
// (Obj);
break;
default:
return;
}
if (_Company + Transport >= 0)
{
MessageBox.Show("> Object was added");
pictureBox1.Image = _Company.Show();
}
else { MessageBox.Show("[!] Failed to add object"); }
}
private void AddButton_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBase));
private void Add2Button_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingCruiser));
*/
private void NewFormCreate(object sender, EventArgs e)
{
FormTransportConfig form = new();
// TODO передать метод
form.Show();
form.AddEvent(SetObj);
}
private void SetObj(DrawingBase? ship)
{
if (_Company == null || ship == null)
{
return;
}
if (_Company + ship != -1)
{
MessageBox.Show(" > Object was added");
pictureBox1.Image = _Company.Show();
}
else
{
MessageBox.Show(" > Can't create an object");
}
}
private void RemoveButton_Click(object sender, EventArgs e)
{
if (_Company == null)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBox1?.Text) || _Company == null) { return; }
if (MessageBox.Show("[*] Remove object: Are you sure?", "Remove",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
if ((_Company - Convert.ToInt32(maskedTextBox1.Text)) != null)
{
MessageBox.Show("> Object was removed");
pictureBox1.Image = _Company.Show();
}
else { MessageBox.Show("[!] No object to be removed"); }
}
private void RandomGenerator_Click(object sender, EventArgs e)
{
if (_Company == null)
{
return;
}
int counter = 100;
DrawingBase? drBase = null;
while (drBase == null)
{
drBase = _Company.GetRandomObj();
counter--;
if (counter <= 0)
{
break;
}
}
if (drBase == null)
{
return;
}
DrawingCanvas Form = new DrawingCanvas();
/*
DrawingCanvas Form = new() { SetTransport = drBase };
*/
Form.SetTransport = drBase;
Form.ShowDialog();
// --------------------------------------------------
}
private void Check_Click(object sender, EventArgs e)
{
if (_Company == null)
{
return;
}
pictureBox1.Image = _Company.Show();
}
private void ButtonCollectionAdd_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(TextBoxC.Text) || (!ListRB.Checked && !ArrayRB.Checked))
{
MessageBox.Show("Enter correct data or choose an option", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
CollectionType collType = CollectionType.None;
if (ArrayRB.Checked)
{
collType = CollectionType.Array;
}
else if (ListRB.Checked)
{
collType = CollectionType.List;
}
_storageCollection.AddCollection(TextBoxC.Text, collType);
RefreshListBoxItems();
}
private void RefreshListBoxItems()
{
Elements.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
{
string? collName = _storageCollection.Keys?[i];
if (!string.IsNullOrEmpty(collName))
{
Elements.Items.Add(collName);
}
}
}
private void ButtonCollectionDel_Click(object sender, EventArgs e)
{
if (Elements.SelectedItem == null || Elements.SelectedIndex < 0)
{
MessageBox.Show("Collection was not choosed");
return;
}
if (MessageBox.Show("Are you sure?", "Removing", MessageBoxButtons.OK, MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
_storageCollection.DelCollection(Elements.SelectedItem.ToString());
RefreshListBoxItems();
}
private void ButtonCreateCompany_Click(object sender, EventArgs e)
{
if (Elements.SelectedIndex < 0 || Elements.SelectedItem == null)
{
MessageBox.Show("Collection was not choosed");
return;
}
ICGO<DrawingBase>? collection = _storageCollection[Elements.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Collection is not initialized");
return;
}
switch (comboBox1.Text)
{
case "Storage":
_Company = new NewClassCollection(pictureBox1.Width, pictureBox1.Height, collection);
break;
}
ToolBox.Enabled = true;
RefreshListBoxItems();
}
}
}

View 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>

View File

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinF_Lab2_Cruiser.Drawing_tools;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
public abstract class AbstractCompany
{
protected readonly int _placeSizeWidth = 302;
protected readonly int _placeSizeHeight = 46;
protected readonly int _picW, _picH;
protected ICGO<DrawingBase>? _Array = null;
// max num of vehicles
private int GetMaxCount => _picW * _picH / (_placeSizeWidth * _placeSizeHeight);
public AbstractCompany(int SizeWidth, int SizeHeight, ICGO<DrawingBase>? array)
{
_picW = SizeWidth;
_picH = SizeHeight;
_Array = array;
_Array.SetMaxCount = GetMaxCount;
}
// insted of bool:
public static int operator +(AbstractCompany cmp,
DrawingBase trasport) => (cmp._Array.Insert(trasport));
public static DrawingBase operator -(AbstractCompany cmp,
int pos) => (cmp._Array.Remove(pos));
public DrawingBase? GetRandomObj()
{
Random r = new();
return _Array?.GetItem(r.Next(GetMaxCount));
}
public Bitmap? Show()
{
Bitmap bitmap = new(_picW, _picH);
Graphics Gr = Graphics.FromImage(bitmap);
DrawBackgound(Gr);
SetObjectsPosition();
for (int i = 0; i < (_Array?.Count ?? 0); ++i)
{
DrawingBase? obj = _Array?.GetItem(i);
obj?.DrawTransport(Gr);
}
return bitmap;
}
protected abstract void DrawBackgound(Graphics g);
protected abstract void SetObjectsPosition();
}
}

View File

@ -0,0 +1,112 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
public class ArrayAlg<K> : ICGO<K>
where K : class
{
private K?[] _Array;
public ArrayAlg()
{
_Array = Array.Empty<K?>();
}
public int Count => _Array.Length;
public int SetMaxCount { set {
if (value > 0)
{
if (_Array.Length > 0)
{
Array.Resize(ref _Array, value);
}
else
{
_Array = new K?[value];
}
}
}
}
public K? GetItem(int index)
{
if (index > Count || index < 0)
{
return null;
}
return _Array[index];
}
public int Insert(K item)
{
// any empty place
for (int i = 0; i <= Count; i++)
{
if (_Array[i] == null)
{
_Array[i] = item;
return i;
}
}
return -1;
}
public int Insert(int index, K item)
{
if (_Array[index] == null)
{
_Array[index] = item;
return index;
}
else
{
int min_diff = 100, min_index = 100;
for (int i = 0; i < Count; i++)
{
if (_Array[i] == null && min_diff > Math.Abs(index - i))
{
min_diff = Math.Abs(index - i);
min_index = i;
}
}
_Array[min_index] = item;
return min_index;
}
return -1;
}
public K Remove(int index)
{
K item;
if (index < Count && index >= 0)
{
item = _Array[index];
_Array[index] = null;
return item;
}
return null;
}
/*
public bool Remove(int index)
{
K item;
if (index < Count)
{
item = _Array[index];
_Array[index] = null;
return true;
}
return false;
}
*/
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
public enum CollectionType
{
None = 0,
Array = 1,
List = 2
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
public interface ICGO<K>
where K : class // ссылочный тип
{
int Count { get; }
int SetMaxCount { set; }
int Insert(K item);
int Insert(int index, K item);
K? Remove(int index);
//bool Remove(int index);
K? GetItem(int index);
}
}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
public class ListGenericObjects<K> : ICGO<K> where K : class
{
private readonly List<K?> _collection;
private int _maxCount;
public int Count => _collection.Count;
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
public ListGenericObjects()
{
_collection = new();
}
public K? GetItem(int index)
{
if (index >= Count || index < 0)
{
return null;
}
return _collection[index];
}
public int Insert(K item)
{
if (item == null) // unneccesary
{
return -1; // [!] not 0,
// 'cause 0 can be an index of item
}
_collection.Add(item);
return _collection.Count;
}
public int Insert(int index, K item)
{
if (index >= _maxCount || index < 0 || _collection[index] != null)
{
return -1;
}
_collection.Insert(index, item);
return index;
}
public K? Remove(int index)
{
if (index >= Count || index < 0) // on the other positions item doesn't exist
{
return null;
}
K item = _collection[index];
_collection.RemoveAt(index);
return item;
}
}
}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinF_Lab2_Cruiser.Drawing_tools;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
internal class NewClassCollection : AbstractCompany // service
{
private int startCoordX = 10, startCoordY = 10, between = 30;
public int maxWkolvo { get; private set; }
public int maxHkolvo { get; private set; }
public NewClassCollection(int SizeWidth, int SizeHeight, ICGO<DrawingBase>? array) : base(SizeWidth, SizeHeight, array)
{
maxWkolvo = _picW / (_placeSizeWidth + between);
maxHkolvo = _picH / _placeSizeHeight;
}
protected override void DrawBackgound(Graphics g)
{
Pen pen = new(Color.Black, 2);
int currentH = 10, currentW = 10;
for (int i = 0; i < maxWkolvo; i++)
{
currentH = 10;
for (int j = 0; j < maxHkolvo; j++)
{
g.DrawLine(pen, currentW + 302, currentH - 1, currentW - 1, currentH - 1);
g.DrawLine(pen, currentW - 1, currentH - 1, currentW - 1, currentH + 50);
currentH += _placeSizeHeight + 1; // + between;
}
currentW += _placeSizeWidth + between;
}
}
protected override void SetObjectsPosition()
{
int index_collection = 0;
int newX = startCoordX, newY = startCoordY;
if (_Array != null)
{
for(int i = 0; i < maxHkolvo; ++i)
{
newX = startCoordX;
for (int j = 0; j < maxWkolvo; ++j)
{
if (_Array.GetItem(index_collection) != null)
{
_Array.GetItem(index_collection).SetPicSize(_picW, _picH);
_Array.GetItem(index_collection).SetPos(newX, newY);
newX += _placeSizeWidth + between;
index_collection++;
}
}
newY += _placeSizeHeight + 2;
}
}
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinF_Lab2_Cruiser.Drawing_tools;
namespace WinF_Lab2_Cruiser.CollectionGenericObjects
{
public class StorageCollection<T> where T : class
{
private Dictionary<string, ICGO<T>> _storage;
public List<string> Keys => _storage.Keys.ToList();
public StorageCollection()
{
_storage = new Dictionary<string, ICGO<T>>();
}
public void AddCollection(string name, CollectionType CollType)
{
if (name == null || _storage.ContainsKey(name) || CollType == CollectionType.None)
{
return;
}
switch (CollType)
{
case CollectionType.Array : _storage.Add(name, new ArrayAlg<T>()); break; // ------------------------------------------------ [ !!! ]
case CollectionType.List : _storage[name] = new ListGenericObjects<T>(); break;
}
}
public void DelCollection(string name)
{
if (_storage.ContainsKey(name)) _storage.Remove(name);
return;
}
public ICGO<T>? this[string name] // int i
{
get
{
/*
int k = 0;
foreach (string key in Keys)
{
if (k >= i)
{
if (_storage.ContainsKey(Keys[k])) return _storage[name];
return null;
}
k++;
}
*/
if (_storage.ContainsKey(name)) return _storage[name];
return null;
}
}
}
}

View File

@ -0,0 +1,201 @@

namespace WinF_Lab2_Cruiser
{
partial class DrawingCanvas
{
/// <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()
{
pictureBox1 = new PictureBox();
//CreateButton = new Button();
//CreateButton2 = new Button();
buttonUp = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
ButtonActivate = new Button();
comboBox = new ComboBox();
Activate = new Button();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
SuspendLayout();
//
// pictureBox1
//
pictureBox1.Dock = DockStyle.Fill;
pictureBox1.Location = new Point(0, 0);
pictureBox1.Margin = new Padding(6);
pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new Size(1018, 604);
pictureBox1.TabIndex = 0;
pictureBox1.TabStop = false;
//
// CreateButton
//
/*
CreateButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
CreateButton.Location = new Point(22, 465);
CreateButton.Margin = new Padding(6);
CreateButton.Name = "CreateButton";
CreateButton.Size = new Size(139, 113);
CreateButton.TabIndex = 1;
CreateButton.Text = "Create object";
CreateButton.UseVisualStyleBackColor = true;
CreateButton.Click += buttonCr_Click;
//
// CreateButton2
//
CreateButton2.Location = new Point(22, 26);
CreateButton2.Margin = new Padding(6);
CreateButton2.Name = "CreateButton2";
CreateButton2.Size = new Size(139, 113);
CreateButton2.TabIndex = 2;
CreateButton2.Text = "Cr Updated Object";
CreateButton2.UseVisualStyleBackColor = true;
CreateButton2.Click += buttonCr2_Click;
*/
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.up_arrow_res;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(817, 371);
buttonUp.Margin = new Padding(6);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(84, 96);
buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.left_arrow_res;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(722, 480);
buttonLeft.Margin = new Padding(6);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(84, 96);
buttonLeft.TabIndex = 4;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.down_arrow_res;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(817, 480);
buttonDown.Margin = new Padding(6);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(84, 96);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.right_arrow_res;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(912, 480);
buttonRight.Margin = new Padding(6);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(84, 96);
buttonRight.TabIndex = 6;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// ListComboBox
//
//
// ButtonActivate
//
ButtonActivate.Anchor = AnchorStyles.Right;
ButtonActivate.Location = new Point(22, 149);
ButtonActivate.Margin = new Padding(6);
ButtonActivate.Name = "ButtonActivate";
ButtonActivate.Size = new Size(84, 96);
ButtonActivate.TabIndex = 8;
ButtonActivate.UseVisualStyleBackColor = true;
ButtonActivate.Click += comboBox_Activate;
//
// comboBox1
//
comboBox.FormattingEnabled = true;
comboBox.Items.AddRange(new object[] { "Center", "Boarder" });
comboBox.Location = new Point(188, 26);
comboBox.Name = "Directions";
comboBox.Size = new Size(203, 40);
comboBox.TabIndex = 9;
//
// Activate
//
Activate.Location = new Point(188, 93);
Activate.Name = "Activate";
Activate.Size = new Size(203, 46);
Activate.TabIndex = 10;
Activate.Text = "ActivateStep";
Activate.UseVisualStyleBackColor = true;
Activate.Click += comboBox_Activate;
//
// DrawingCanvas
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
AutoValidate = AutoValidate.EnableAllowFocusChange;
BackColor = Color.CornflowerBlue;
ClientSize = new Size(1018, 604);
Controls.Add(Activate);
Controls.Add(comboBox);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
//Controls.Add(CreateButton);
//Controls.Add(CreateButton2);
Controls.Add(pictureBox1);
Controls.Add(ButtonActivate);
Margin = new Padding(4, 2, 4, 2);
Name = "DrawingCanvas";
StartPosition = FormStartPosition.Manual;
Text = "DrawingCanvas";
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
ResumeLayout(false);
}
#endregion
private PictureBox pictureBox1;
//private Button CreateButton;
//private Button CreateButton2;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button ButtonActivate;
private ComboBox comboBox;
private Button Activate;
}
}

View File

@ -0,0 +1,131 @@
using WinF_Lab2_Cruiser.Drawing_tools;
using WinF_Lab2_Cruiser.Entity_Folder;
using WinF_Lab2_Cruiser.Move_Strategy;
using System.Windows.Forms;
namespace WinF_Lab2_Cruiser
{
public partial class DrawingCanvas : Form
{
private DrawingBase? _DrCruiser;
private AbstractStrategy? _strategy;
public DrawingBase SetTransport
{
set
{
_DrCruiser = value;
_DrCruiser.SetPicSize(pictureBox1.Width, pictureBox1.Height);
comboBox.Enabled = true;
_strategy = null;
Draw();
}
}
public DrawingCanvas()
{
InitializeComponent();
_strategy = null;
// DrawBackgound(Gr);
}
//private DrawingCanvas_Load(object sender, EventArgs e);
private void Draw()
{
if (_DrCruiser == null)
{
return;
}
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
Graphics gr = Graphics.FromImage(bmp); _DrCruiser.DrawTransport(gr);
pictureBox1.Image = bmp;
// DrawBackgound(gr);
}
/*
private void CreateObj(string type)
{
Random rn = new Random();
switch (type)
{
case nameof(DrawingBase):
_DrCruiser = new DrawingBase(rn.Next(100, 300), rn.Next(1000, 3000), Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)));
break;
case nameof(DrawingCruiser):
Class_CruiserEntity Obj = new Class_CruiserEntity(rn.Next(100, 300), rn.Next(1000, 3000),
Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)), Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)),
Convert.ToBoolean(rn.Next(0, 2)), Convert.ToBoolean(rn.Next(0, 2)), rn.Next(1, 4), rn.Next(5, 10), rn.Next(1, 3));
_DrCruiser = new DrawingCruiser(Obj);
break;
default:
return;
}
_DrCruiser.SetPicSize(pictureBox1.Width, pictureBox1.Height);
_DrCruiser.SetPos(rn.Next(pictureBox1.Width - 600, pictureBox1.Width - _DrCruiser._CruiserMaxW), rn.Next(0, 100)); _strategy = null;
comboBox.Enabled = true;
Draw();
}
private void buttonCr2_Click(object sender, EventArgs e) => CreateObj(nameof(DrawingCruiser));
private void buttonCr_Click(object sender, EventArgs e) => CreateObj(nameof(DrawingBase));
*/
private void comboBox_Activate(object sender, EventArgs e)
{
if (_DrCruiser == null) return;
if (comboBox.Enabled)
{
_strategy = comboBox.SelectedIndex switch
{
0 => new Center(),
1 => new Boarder()
};
if (_strategy == null) return;
_strategy.SetData(new MovableCruiser(_DrCruiser), pictureBox1.Width, pictureBox1.Height);
}
if (_strategy == null) return;
comboBox.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == Status.Finish)
{
comboBox.Enabled = true;
_strategy = null;
}
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_DrCruiser == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false; switch (name)
{
case "buttonUp":
result = _DrCruiser.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _DrCruiser.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _DrCruiser.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _DrCruiser.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();
}
}
}
}

View 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>

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.Drawing_tools
{
public enum DirectionType
{
Unknown = -1,
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,191 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinF_Lab2_Cruiser.Entity_Folder;
namespace WinF_Lab2_Cruiser.Drawing_tools
{
public class DrawingBase
{
/// Инициализация свойств (все параметры класса (сущности))
public Base_Class_Cruiser? BaseEntity { get; protected set; }
/// Передача размеров поля & объекта
private int? _pictureWidth;
private int? _pictureHeight;
public readonly int _CruiserMaxW = 302;
public readonly int _CruiserMaxH = 72;
/// Установка позиции
protected int? _startPosX;
protected int? _startPosY;
// for relationship with Moves*
public int? GetPosX => _startPosX;
public int? GetPosY => _startPosY;
public int GetWidth => _CruiserMaxW;
public int GetHeight => _CruiserMaxH;
private DrawingBase()
{
_pictureHeight = null;
_pictureWidth = null;
_startPosX = null;
_startPosY = null;
}
public DrawingBase(int speed, double weight, Color mainc) : this()
{
BaseEntity = new Base_Class_Cruiser(speed, weight, mainc);
}
protected DrawingBase(int MaxW, int MaxH) : this()
{
_CruiserMaxW = MaxW;
_CruiserMaxH = MaxH;
}
public bool SetPicSize(int w, int h)
{
if (w > _pictureWidth || h > _pictureHeight)
{
return false;
}
_pictureWidth = w;
_pictureHeight = h;
if (_startPosX != null || _startPosY != null)
{
SetPos(_startPosX.Value, _startPosY.Value);
}
return true;
}
public void SetPos(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
if (x > _pictureWidth - _CruiserMaxW) _startPosX = _pictureWidth - _CruiserMaxW;
else if (x < 0) _startPosX = 0;
else _startPosX = x;
if (y > _pictureHeight - _CruiserMaxH) _startPosY = _pictureHeight.Value - _CruiserMaxH;
else if (y < 0) _startPosY = 0;
else _startPosY = y;
}
public bool MoveTransport(DirectionType direction) // public Direction (?)
{
if (BaseEntity == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - BaseEntity.Step > 0)
{
_startPosX -= (int)BaseEntity.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - BaseEntity.Step > 0)
{
_startPosY -= (int)BaseEntity.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + _CruiserMaxW + BaseEntity.Step < _pictureWidth.Value)
{
_startPosX += (int)BaseEntity.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + _CruiserMaxH + BaseEntity.Step < _pictureHeight.Value)
{
_startPosY += (int)BaseEntity.Step;
}
return true;
default:
return false;
}
}
public virtual void DrawTransport(Graphics g)
{
if (BaseEntity == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black, 2);
Brush PadBrush = new HatchBrush(HatchStyle.DottedDiamond, Color.LightGray, Color.Black);
// Brush additionalBrush = new SolidBrush(BaseEntity.AdditionalC);
Brush mainBrush = new SolidBrush(BaseEntity.MainC);
Random random = new();
// границы cruiser
Point point0 = new Point(_startPosX.Value + 2, _startPosY.Value + 7);
Point point1 = new Point(_startPosX.Value + 2, _startPosY.Value + 30);
Point point2 = new Point(_startPosX.Value + 184, _startPosY.Value + 42);
Point point3 = new Point(_startPosX.Value + 260, _startPosY.Value + 34);
Point point4 = new Point(_startPosX.Value + 300, _startPosY.Value + 22);
Point point5 = new Point(_startPosX.Value + 260, _startPosY.Value + 10);
Point point6 = new Point(_startPosX.Value + 184, _startPosY.Value + 2);
Point[] boarders = {
point0,
point1,
point2,
point3,
point4,
point5,
point6,
};
g.DrawPolygon(pen, boarders);
g.FillPolygon(mainBrush, boarders);
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 7, 38, 24);
g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + 7, 20, 12);
g.FillRectangle(mainBrush, _startPosX.Value + 110, _startPosY.Value + 7, 20, 12);
g.DrawRectangle(pen, _startPosX.Value + 117, _startPosY.Value + 18, 6, 20);
g.FillRectangle(mainBrush, _startPosX.Value + 117, _startPosY.Value + 18, 6, 20);
// салон на верхней палубе
//if (BaseEntity.Deckhouse)
//{
// // random location
// int y_h = BaseEntity.values[1];
// g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + y_h, 38, 24); // 40, 26
//
// g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
// g.FillRectangle(additionalBrush, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
// g.DrawRectangle(pen, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
// g.FillRectangle(additionalBrush, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
//}
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinF_Lab2_Cruiser.Entity_Folder;
namespace WinF_Lab2_Cruiser.Drawing_tools
{
internal class DrawingCruiser : DrawingBase
{
/// Инициализация свойств (все параметры класса (сущности))
// public Class_CruiserEntity? CE { get; private set; }
// CE = new Class_CruiserEntity( <...> );
// public DrawingCruiser(int speed, double weight,
// Color mainc, Color addtc, bool pad,
// bool hangar, int p, int d_coordinates, int h) : base(302, 72) // <...>
//{
// BaseEntity = new Class_CruiserEntity(speed, weight, mainc, addtc, pad, hangar, p, d_coordinates, h);
//}
public DrawingCruiser(int speed, double weight,
Color mainc, Color addtc, bool pad,
bool hangar, int p, int d_coordinates, int h) : base(302, 72) // Class_CruiserEntity Obj) : base(302, 72)
{
BaseEntity = new Class_CruiserEntity(speed, weight, mainc,
addtc, pad, hangar, p, d_coordinates, h);
}
public override void DrawTransport(Graphics g)
{
if (BaseEntity is not Class_CruiserEntity cruiser || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return;
}
base.DrawTransport(g);
Pen pen = new(Color.Black, 2);
Brush PadBrush = new HatchBrush(HatchStyle.DottedDiamond, Color.LightGray, Color.Black);
Brush additionalBrush = new SolidBrush(cruiser.AdditionalC);
Random random = new();
//границы cruiser <...>
if (cruiser.HelicopterPads)
{
g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
}
// салон на верхней палубе - Deckhouse <...>
if (cruiser.Hangar)
{
int n = cruiser.values[2];
if (n == 1) g.FillRectangle(additionalBrush, _startPosX.Value + 250, _startPosY.Value + 20, 14, 7);
else
{
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 10, 10, 20);
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 12, 8, 12);
}
}
}
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.Entity_Folder
{
public class Base_Class_Cruiser
{
/// MAIN свойства
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color MainC { get; private set; }
public void setMColor(Color color)
{
MainC = color;
}
public double Step => Speed * 100 / Weight;
/// Конструктор
public Base_Class_Cruiser(int speed, double weight,
Color mainc)
{
Speed = speed;
Weight = weight;
MainC = mainc;
}
}
}

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.Entity_Folder
{
internal class Class_CruiserEntity : Base_Class_Cruiser
{
/// ADDITIONAL свойства
public Color AdditionalC { get; private set; }
public void setAdditionalColor(Color color)
{
AdditionalC = color;
}
/// признаки (наличия)
public bool HelicopterPads { get; private set; } /// вертолетная площадка
public bool Hangar { get; private set; } /// ангар
public bool Deckhouse { get; private set; } /// салон на верхней палубе
public int[] values = { 0, 0, 0 };
public Class_CruiserEntity(int speed, double weight,
Color mainc, Color addtc, bool pad,
bool hangar, int p, int d_coordinates, int h) : base(speed, weight, mainc)
{
// NOT PUBLIC, so: -> impossible
//base.Speed = speed;
//base.Weight = weight;
//base.MainC = mainc;
AdditionalC = addtc;
HelicopterPads = pad;
Hangar = hangar;
values[0] = p;
values[1] = d_coordinates;
values[2] = h;
}
}
}

View File

@ -0,0 +1,344 @@
namespace WinF_Lab2_Cruiser
{
partial class FormTransportConfig
{
/// <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()
{
ParametersBox = new GroupBox();
AdvLabel = new Label();
BaseLabel = new Label();
groupBox2 = new GroupBox();
PurpleP = new Panel();
GreenP = new Panel();
PinkP = new Panel();
OrangeP = new Panel();
CyanP = new Panel();
YellowP = new Panel();
RedP = new Panel();
BlueP = new Panel();
CheckBox_Pads = new CheckBox();
CheckBox_Hangars = new CheckBox();
WeightN = new NumericUpDown();
SpeedN = new NumericUpDown();
Label = new Label();
Showcase = new PictureBox();
AddButton = new Button();
CancelButton = new Button();
panelObject = new Panel();
labelAcolor = new Label();
labelMcolor = new Label();
ParametersBox.SuspendLayout();
groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)WeightN).BeginInit();
((System.ComponentModel.ISupportInitialize)SpeedN).BeginInit();
((System.ComponentModel.ISupportInitialize)Showcase).BeginInit();
panelObject.SuspendLayout();
SuspendLayout();
//
// ParametersBox
//
ParametersBox.Controls.Add(AdvLabel);
ParametersBox.Controls.Add(BaseLabel);
ParametersBox.Controls.Add(groupBox2);
ParametersBox.Controls.Add(CheckBox_Pads);
ParametersBox.Controls.Add(CheckBox_Hangars);
ParametersBox.Controls.Add(WeightN);
ParametersBox.Controls.Add(SpeedN);
ParametersBox.Controls.Add(Label);
ParametersBox.Location = new Point(12, 0);
ParametersBox.Name = "ParametersBox";
ParametersBox.Size = new Size(388, 495);
ParametersBox.TabIndex = 0;
ParametersBox.TabStop = false;
ParametersBox.Text = "Parameters";
//
// AdvLabel
//
AdvLabel.BorderStyle = BorderStyle.FixedSingle;
AdvLabel.Location = new Point(175, 428);
AdvLabel.Name = "AdvLabel";
AdvLabel.Size = new Size(184, 46);
AdvLabel.TabIndex = 5;
AdvLabel.Text = "Advanced";
AdvLabel.TextAlign = ContentAlignment.MiddleCenter;
AdvLabel.MouseDown += BaseAdvLabel_MouseDown;
//
// BaseLabel
//
BaseLabel.BorderStyle = BorderStyle.FixedSingle;
BaseLabel.Location = new Point(17, 428);
BaseLabel.Name = "BaseLabel";
BaseLabel.Size = new Size(132, 46);
BaseLabel.TabIndex = 4;
BaseLabel.Text = "Base";
BaseLabel.TextAlign = ContentAlignment.MiddleCenter;
BaseLabel.MouseDown += BaseAdvLabel_MouseDown;
//
// groupBox2
//
groupBox2.Controls.Add(PurpleP);
groupBox2.Controls.Add(GreenP);
groupBox2.Controls.Add(PinkP);
groupBox2.Controls.Add(OrangeP);
groupBox2.Controls.Add(CyanP);
groupBox2.Controls.Add(YellowP);
groupBox2.Controls.Add(RedP);
groupBox2.Controls.Add(BlueP);
groupBox2.Location = new Point(17, 197);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(342, 213);
groupBox2.TabIndex = 1;
groupBox2.TabStop = false;
groupBox2.Text = "Color picker";
//
// PurpleP
//
PurpleP.BackColor = Color.DarkViolet;
PurpleP.Location = new Point(260, 126);
PurpleP.Name = "PurpleP";
PurpleP.Size = new Size(63, 59);
PurpleP.TabIndex = 12;
//
// GreenP
//
GreenP.BackColor = Color.SpringGreen;
GreenP.Location = new Point(259, 49);
GreenP.Name = "GreenP";
GreenP.Size = new Size(63, 59);
GreenP.TabIndex = 9;
//
// PinkP
//
PinkP.BackColor = Color.DeepPink;
PinkP.Location = new Point(180, 126);
PinkP.Name = "PinkP";
PinkP.Size = new Size(63, 59);
PinkP.TabIndex = 11;
//
// OrangeP
//
OrangeP.BackColor = Color.DarkOrange;
OrangeP.Location = new Point(180, 49);
OrangeP.Name = "OrangeP";
OrangeP.Size = new Size(63, 59);
OrangeP.TabIndex = 8;
//
// CyanP
//
CyanP.BackColor = Color.Cyan;
CyanP.Location = new Point(100, 126);
CyanP.Name = "CyanP";
CyanP.Size = new Size(63, 59);
CyanP.TabIndex = 10;
//
// YellowP
//
YellowP.BackColor = Color.Gold;
YellowP.Location = new Point(19, 126);
YellowP.Name = "YellowP";
YellowP.Size = new Size(63, 59);
YellowP.TabIndex = 9;
//
// RedP
//
RedP.BackColor = Color.Firebrick;
RedP.Location = new Point(100, 49);
RedP.Name = "RedP";
RedP.Size = new Size(63, 59);
RedP.TabIndex = 7;
//
// BlueP
//
BlueP.BackColor = SystemColors.Highlight;
BlueP.Location = new Point(19, 49);
BlueP.Name = "BlueP";
BlueP.Size = new Size(63, 59);
BlueP.TabIndex = 6;
//
// CheckBox_Pads
//
CheckBox_Pads.AutoSize = true;
CheckBox_Pads.Location = new Point(24, 142);
CheckBox_Pads.Name = "CheckBox_Pads";
CheckBox_Pads.Size = new Size(203, 36);
CheckBox_Pads.TabIndex = 3;
CheckBox_Pads.Text = "Helicopter pad";
CheckBox_Pads.UseVisualStyleBackColor = true;
//
// CheckBox_Hangars
//
CheckBox_Hangars.AutoSize = true;
CheckBox_Hangars.Location = new Point(234, 142);
CheckBox_Hangars.Name = "CheckBox_Hangars";
CheckBox_Hangars.Size = new Size(133, 36);
CheckBox_Hangars.TabIndex = 1;
CheckBox_Hangars.Text = "Hangars";
CheckBox_Hangars.UseVisualStyleBackColor = true;
//
// WeightN
//
WeightN.Location = new Point(198, 88);
WeightN.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
WeightN.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
WeightN.Name = "WeightN";
WeightN.Size = new Size(142, 39);
WeightN.TabIndex = 2;
WeightN.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// SpeedN
//
SpeedN.Location = new Point(36, 88);
SpeedN.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
SpeedN.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
SpeedN.Name = "SpeedN";
SpeedN.Size = new Size(142, 39);
SpeedN.TabIndex = 1;
SpeedN.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// Label
//
Label.AutoSize = true;
Label.Location = new Point(36, 53);
Label.Name = "Label";
Label.Size = new Size(304, 32);
Label.TabIndex = 1;
Label.Text = "Speed Weight";
//
// Showcase
//
Showcase.Location = new Point(58, 98);
Showcase.Name = "Showcase";
Showcase.Size = new Size(458, 272);
Showcase.TabIndex = 1;
Showcase.TabStop = false;
//
// AddButton
//
AddButton.Location = new Point(419, 447);
AddButton.Name = "AddButton";
AddButton.Size = new Size(268, 46);
AddButton.TabIndex = 2;
AddButton.Text = "Add";
AddButton.UseVisualStyleBackColor = true;
AddButton.Click += AddButton_Click;
//
// CancelButton
//
CancelButton.Location = new Point(694, 447);
CancelButton.Name = "CancelButton";
CancelButton.Size = new Size(286, 46);
CancelButton.TabIndex = 3;
CancelButton.Text = "Cancel";
CancelButton.UseVisualStyleBackColor = true;
//
// panelObject
//
panelObject.AllowDrop = true;
panelObject.Controls.Add(labelAcolor);
panelObject.Controls.Add(labelMcolor);
panelObject.Controls.Add(Showcase);
panelObject.Location = new Point(419, 12);
panelObject.Name = "panelObject";
panelObject.Size = new Size(561, 410);
panelObject.TabIndex = 4;
panelObject.DragDrop += PanelObject_DragDrop;
panelObject.DragEnter += PanelObject_DragEnter;
//
// labelAcolor
//
labelAcolor.AllowDrop = true;
labelAcolor.BorderStyle = BorderStyle.FixedSingle;
labelAcolor.Location = new Point(253, 39);
labelAcolor.Name = "labelAcolor";
labelAcolor.Size = new Size(263, 42);
labelAcolor.TabIndex = 7;
labelAcolor.Text = "Additional color";
labelAcolor.TextAlign = ContentAlignment.MiddleCenter;
labelAcolor.DragDrop += AdditionalColor_DragDrop;
labelAcolor.DragEnter += AdditionalColor_DragEnter;
//
// labelMcolor
//
labelMcolor.AllowDrop = true;
labelMcolor.BorderStyle = BorderStyle.FixedSingle;
labelMcolor.Location = new Point(58, 39);
labelMcolor.Name = "labelMcolor";
labelMcolor.Size = new Size(180, 42);
labelMcolor.TabIndex = 6;
labelMcolor.Text = "Main color";
labelMcolor.TextAlign = ContentAlignment.MiddleCenter;
labelMcolor.DragDrop += BodyColor_DragDrop;
labelMcolor.DragEnter += BodyColor_DragEnter;
//
// FormTransportConfig
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(992, 516);
Controls.Add(panelObject);
Controls.Add(CancelButton);
Controls.Add(AddButton);
Controls.Add(ParametersBox);
Name = "FormTransportConfig";
Text = "FormTransportConfig";
ParametersBox.ResumeLayout(false);
ParametersBox.PerformLayout();
groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)WeightN).EndInit();
((System.ComponentModel.ISupportInitialize)SpeedN).EndInit();
((System.ComponentModel.ISupportInitialize)Showcase).EndInit();
panelObject.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private GroupBox ParametersBox;
private Label Label;
private CheckBox CheckBox_Pads;
private CheckBox CheckBox_Hangars;
private NumericUpDown WeightN;
private NumericUpDown SpeedN;
private GroupBox groupBox2;
private Label BaseLabel;
private Label AdvLabel;
private Panel PurpleP;
private Panel GreenP;
private Panel PinkP;
private Panel OrangeP;
private Panel CyanP;
private Panel YellowP;
private Panel RedP;
private Panel BlueP;
private PictureBox Showcase;
private Button AddButton;
private Button CancelButton;
private Panel panelObject;
private Label labelMcolor;
private Label labelAcolor;
}
}

View File

@ -0,0 +1,137 @@
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 WinF_Lab2_Cruiser.Drawing_tools;
using WinF_Lab2_Cruiser.Entity_Folder;
namespace WinF_Lab2_Cruiser
{
public partial class FormTransportConfig : Form
{
private DrawingBase _cruiser;
// private event Action<DrawingBase>? shipDelegate;
private event ShipDelegate? shipDelegate;
public FormTransportConfig()
{
InitializeComponent();
BlueP.MouseDown += Panel_MouseDown;
RedP.MouseDown += Panel_MouseDown;
PinkP.MouseDown += Panel_MouseDown;
YellowP.MouseDown += Panel_MouseDown;
CyanP.MouseDown += Panel_MouseDown;
PurpleP.MouseDown += Panel_MouseDown;
GreenP.MouseDown += Panel_MouseDown;
OrangeP.MouseDown += Panel_MouseDown;
CancelButton.Click += (sender, e) => Close();
}
public void AddEvent(ShipDelegate del)// Action<DrawingBase> delegator)
{
if (shipDelegate == null) shipDelegate = del;
else shipDelegate += del;
//shipDelegate += del;
}
private void DrawObject()
{
Bitmap bmp = new(Showcase.Width, Showcase.Height);
Graphics gr = Graphics.FromImage(bmp);
_cruiser?.SetPicSize(Showcase.Width, Showcase.Height);
_cruiser?.SetPos(Showcase.Width - 400, Showcase.Height - 120);
_cruiser?.DrawTransport(gr);
Showcase.Image = bmp;
}
private void Panel_MouseDown(object? sender, MouseEventArgs e)
{
// TODO отправка цвета в Drag&Drop
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
//private void FormTransportConfig_Load(object sender, EventArgs e)
//{
//
//}
private void BaseAdvLabel_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) e.Effect = DragDropEffects.Copy;
else e.Effect = DragDropEffects.None;
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
{
case "BaseLabel":
_cruiser = new DrawingBase((int)SpeedN.Value, (double)WeightN.Value, Color.White);
break;
case "AdvLabel":
Random rn = new Random();
_cruiser = new DrawingCruiser((int)SpeedN.Value, (double)WeightN.Value,
Color.White, Color.Black, CheckBox_Pads.Checked, CheckBox_Hangars.Checked,
rn.Next(1, 4), rn.Next(5, 10), rn.Next(1, 3));
break;
}
labelMcolor.BackColor = Color.Empty;
labelAcolor.BackColor = Color.Empty;
DrawObject();
}
// TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта)
private void BodyColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color))) e.Effect = DragDropEffects.Copy;
else e.Effect = DragDropEffects.None;
}
private void BodyColor_DragDrop(object sender, DragEventArgs e)
{
if (_cruiser != null)
{
_cruiser.BaseEntity.setMColor((Color)e.Data.GetData(typeof(Color)));
DrawObject();
}
}
private void AdditionalColor_DragEnter(object sender, DragEventArgs e)
{
if (_cruiser is DrawingCruiser)
{
if (e.Data.GetDataPresent(typeof(Color))) e.Effect = DragDropEffects.Copy;
else e.Effect = DragDropEffects.None;
}
}
private void AdditionalColor_DragDrop(object sender, DragEventArgs e)
{
if (_cruiser.BaseEntity is Class_CruiserEntity _ship)
{
_ship.setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
}
DrawObject();
}
private void AddButton_Click(object sender, EventArgs e)
{
if (_cruiser != null)
{
shipDelegate?.Invoke(_cruiser);
Close();
}
}
}
}

View 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>

View File

@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public abstract class AbstractStrategy
{
private IMO? _movableObj;
private Status _state = Status.NotInit;
protected int FieldHeight { get; private set; }
protected int FieldWidth { get; private set; }
public Status GetStatus() { return _state; } // => _state;
public void SetData(IMO movableObj, int width, int height)
{
if (movableObj == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_movableObj = movableObj;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDes())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(Moves.Left);
protected bool MoveRight() => MoveTo(Moves.Right);
protected bool MoveUp() => MoveTo(Moves.Up);
protected bool MoveDown() => MoveTo(Moves.Down);
protected ObjectParam? GetObjParam => _movableObj?.GetPos;
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _movableObj?.GetStep;
}
// protected virtual void AdditionalMethod() { }
protected virtual void MoveToTarget()
{
ObjectParam? objParams = GetObjParam;
if (objParams == null) { return; }
int diffx = objParams.MiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffx) > GetStep())
{
if (diffx > 0) MoveLeft();
else MoveRight();
}
int diffy = objParams.MiddleVertical - FieldHeight / 2;
if (Math.Abs(diffy) > GetStep())
{
if (diffy > 0) MoveUp();
else MoveDown();
}
}
protected virtual bool IsTargetDes()
{
ObjectParam? objParams = GetObjParam;
if (objParams == null) { return false; }
return objParams.MiddleHorizontal - GetStep() <= FieldWidth / 2 &&
objParams.MiddleHorizontal + GetStep() + 1 >= FieldWidth / 2 &&
objParams.MiddleVertical - GetStep() <= FieldHeight / 2 &&
objParams.MiddleVertical + GetStep() >= FieldHeight / 2;
}
private bool MoveTo(Moves moves)
{
if (_state != Status.InProgress)
{
return false;
}
return _movableObj?.TryMoveObj(moves) ?? false;
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.Move_Strategy;
public class Boarder : AbstractStrategy
{
protected override bool IsTargetDes()
{
ObjectParam? objP = GetObjParam;
if (objP == null)
{
return false;
}
return FieldWidth < objP.SecondCoordX
&& FieldHeight < objP.SecondCoordY;
}
protected override void MoveToTarget()
{
ObjectParam? objP = GetObjParam;
if (objP == null)
{
return;
}
int s = (int)GetStep();
int diffx = objP.SecondCoordX - (FieldWidth - s);
if (Math.Abs(diffx) >= GetStep())
{
if (diffx > 0)
{
MoveLeft();
// MoveRight();
}
else { MoveRight(); }
}
int diffy = objP.SecondCoordY - (FieldHeight - s);
if (Math.Abs(diffy) >= GetStep())
{
if (diffy > 0)
{
MoveUp();
// MoveDown();
}
else { MoveDown(); }
}
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.Move_Strategy;
public class Center : AbstractStrategy
{
protected override bool IsTargetDes()
{
ObjectParam? objP = GetObjParam;
if (objP == null)
{
return false;
}
return objP.MiddleHorizontal - GetStep() <= FieldWidth / 2 && objP.MiddleHorizontal + GetStep() >= FieldWidth / 2
&& objP.MiddleVertical - GetStep() <= FieldHeight / 2 && objP.MiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
ObjectParam? objP = GetObjParam;
if (objP == null)
{
return;
}
int diffx = objP.MiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffx) > GetStep())
{
if (diffx > 0)
{
MoveLeft();
}
else { MoveRight(); }
}
int diffy = objP.MiddleVertical - FieldHeight / 2;
if (Math.Abs(diffy) > GetStep())
{
if (diffy > 0)
{
MoveUp();
}
else { MoveDown(); }
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public interface IMO
{
// methods ! only
ObjectParam? GetPos { get; }
int GetStep { get; }
int AdditionalMethod { set; }
bool TryMoveObj(Moves direction);
}
}

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinF_Lab2_Cruiser.Drawing_tools;
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public class MovableCruiser : IMO
{
private readonly DrawingBase? _DrBase = null;
public MovableCruiser(DrawingBase drBase)
{
_DrBase = drBase;
}
public ObjectParam? GetPos
{
get
{
if (_DrBase == null || _DrBase.BaseEntity == null || !_DrBase.GetPosX.HasValue || !_DrBase.GetPosY.HasValue)
{
return null;
}
return new ObjectParam(_DrBase.GetPosX.Value, _DrBase.GetPosY.Value, _DrBase.GetWidth, _DrBase.GetHeight);
}
}
public int GetStep => (int)(_DrBase?.BaseEntity?.Step ?? 0);
public int AdditionalMethod { set => throw new NotImplementedException(); }
public bool TryMoveObj(Moves direction)
{
if (_DrBase == null || _DrBase.BaseEntity == null)
{
return false;
}
return _DrBase.MoveTransport(GetDirectionType(direction));
}
private static DirectionType GetDirectionType(Moves direction)
{
return direction switch
{
Moves.Left => DirectionType.Left,
Moves.Right => DirectionType.Right,
Moves.Up => DirectionType.Up,
Moves.Down => DirectionType.Down,
_ => DirectionType.Unknown
};
}
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public enum Moves
{
Unknown = -1,
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public class ObjectParam
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int RightBorder => _x + _width;
public int TopBorder => _y;
public int BottomBorder => _y + _height;
public int MiddleHorizontal => _x + _width / 2;
public int MiddleVertical => _y + _height / 2;
public int SecondCoordY => _y + _height;
public int SecondCoordX => _x + _width;
public ObjectParam(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinF_Lab2_Cruiser.Move_Strategy
{
public enum Status
{
NotInit,
InProgress,
Finish
}
}

View File

@ -0,0 +1,18 @@
namespace WinF_Lab2_Cruiser
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
// Application.Run(new DrawingCanvas());
Application.Run(new CollectionForm());
}
}
}

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WinF_Lab2_Cruiser.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinF_Lab2_Cruiser.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap down_arrow_res {
get {
object obj = ResourceManager.GetObject("down_arrow_res", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap left_arrow_res {
get {
object obj = ResourceManager.GetObject("left_arrow_res", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap right_arrow_res {
get {
object obj = ResourceManager.GetObject("right_arrow_res", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap up_arrow_res {
get {
object obj = ResourceManager.GetObject("up_arrow_res", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,133 @@
<?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>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="right_arrow_res" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\right_arrow_res.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="up_arrow_res" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\up_arrow_res.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="left_arrow_res" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\left_arrow_res.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="down_arrow_res" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\down_arrow_res.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 905 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 877 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 B

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinF_Lab2_Cruiser.Drawing_tools;
namespace WinF_Lab2_Cruiser
{
public delegate void ShipDelegate(DrawingBase transport);
}