LabWork03

This commit is contained in:
Osyagina_Anna 2024-04-03 17:06:31 +04:00
parent b3e0208941
commit 4be235fb0c
21 changed files with 1223 additions and 61 deletions

View File

@ -0,0 +1,31 @@

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}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{D8A4ACE0-0728-47AB-9F80-9EDA475782ED}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp2", "ConsoleApp2\ConsoleApp2.csproj", "{C1FC7C16-B9EC-4007-BD39-E6B47A89CE34}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D8A4ACE0-0728-47AB-9F80-9EDA475782ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8A4ACE0-0728-47AB-9F80-9EDA475782ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8A4ACE0-0728-47AB-9F80-9EDA475782ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8A4ACE0-0728-47AB-9F80-9EDA475782ED}.Release|Any CPU.Build.0 = Release|Any CPU
{C1FC7C16-B9EC-4007-BD39-E6B47A89CE34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1FC7C16-B9EC-4007-BD39-E6B47A89CE34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1FC7C16-B9EC-4007-BD39-E6B47A89CE34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1FC7C16-B9EC-4007-BD39-E6B47A89CE34}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3368BA78-2800-49EC-9A71-865DC3C2F15F}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,68 @@
using System.Collections;
using System;
// Класс компонента компьютера
public class ComputerComponent
{
public string Name { get; set; }
public string Type { get; set; }
public ComputerComponent(string name, string type)
{
Name = name;
Type = type;
}
}
// АТД Очередь на основе массива
public class CustomQueue
{
private ArrayList elements = new ArrayList();
public int Count { get { return elements.Count; } }
public void Enqueue(ComputerComponent component)
{
elements.Add(component);
}
public ComputerComponent Dequeue()
{
if (elements.Count == 0)
{
throw new InvalidOperationException("Queue is empty");
}
ComputerComponent component = (ComputerComponent)elements[0];
elements.RemoveAt(0);
return component;
}
public ComputerComponent Peek()
{
if (elements.Count == 0)
{
throw new InvalidOperationException("Queue is empty");
}
return (ComputerComponent)elements[0];
}
}
class Program
{
public static void Main(string[] args)
{
CustomQueue queue = new CustomQueue();
// Добавление компонентов в очередь
ComputerComponent cpu = new ComputerComponent("Intel Core i7", "CPU");
ComputerComponent gpu = new ComputerComponent("Nvidia RTX 3080", "GPU");
queue.Enqueue(cpu);
queue.Enqueue(gpu);
// Проверка совместимости компонентов в сборке
Console.WriteLine("Первый компонент в очереди: {0} ({1})", queue.Peek().Name, queue.Peek().Type);
Console.WriteLine("Извлечен компонент из очереди: {0} ({1})", queue.Dequeue().Name, queue.Dequeue().Type);
}
}

View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,113 @@
using System;
// Реализация АТД Очередь
public class Queue<T>
{
private T[] elements;
private int front, rear, size, capacity;
public Queue(int capacity)
{
this.capacity = capacity;
elements = new T[capacity];
front = size = 0;
rear = capacity - 1;
}
public void Enqueue(T item)
{
if (size == capacity)
throw new Exception("Queue is full");
rear = (rear + 1) % capacity;
elements[rear] = item;
size++;
}
public T Dequeue()
{
if (size == 0)
throw new Exception("Queue is empty");
T item = elements[front];
front = (front + 1) % capacity;
size--;
return item;
}
// Реализация СД Массив
public static void SelectionSort(int[] array)
{
for (int i = 0; i < array.Length - 1; i++)
{
int minIndex = i;
for (int j = i + 1; j < array.Length; j++)
{
if (array[j] < array[minIndex])
{
minIndex = j;
}
}
if (minIndex != i)
{
int temp = array[i];
array[i] = array[minIndex];
array[minIndex] = temp;
}
}
}
// Быстрая сортировка
public static void QuickSort(int[] array, int left, int right)
{
if (left < right)
{
int pivot = Partition(array, left, right);
QuickSort(array, left, pivot - 1);
QuickSort(array, pivot + 1, right);
}
}
private static int Partition(int[] array, int left, int right)
{
int pivot = array[right];
int i = left - 1;
for (int j = left; j < right; j++)
{
if (array[j] < pivot)
{
i++;
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
int temp1 = array[i + 1];
array[i + 1] = array[right];
array[right] = temp1;
return i + 1;
}
public static void Main()
{
int[] array = { 64, 34, 25, 12, 22, 11, 90 };
// Сортировка выбором
Console.WriteLine("Before selection sort:");
foreach (var item in array) Console.Write(item + " ");
SelectionSort(array);
Console.WriteLine("\n\nAfter selection sort:");
foreach (var item in array) Console.Write(item + " ");
// Быстрая сортировка
Console.WriteLine("\n\nBefore quick sort:");
foreach (var item in array) Console.Write(item + " ");
QuickSort(array, 0, array.Length - 1);
Console.WriteLine("\n\nAfter quick sort:");
foreach (var item in array) Console.Write(item + " ");
// Использование Очереди
Queue<int> queue = new Queue<int>(5);
queue.Enqueue(10);
queue.Enqueue(20);
queue.Dequeue();
}
}

25
LAB01/LAB01.sln Normal file
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}") = "LAB01", "LAB01\LAB01.csproj", "{34001B70-EBBF-45A9-BEB8-AD3C2CB8B984}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{34001B70-EBBF-45A9-BEB8-AD3C2CB8B984}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34001B70-EBBF-45A9-BEB8-AD3C2CB8B984}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34001B70-EBBF-45A9-BEB8-AD3C2CB8B984}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34001B70-EBBF-45A9-BEB8-AD3C2CB8B984}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {70E24174-2A6E-49F3-92B6-8C86A8B8C4EF}
EndGlobalSection
EndGlobal

39
LAB01/LAB01/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,39 @@
namespace LAB01
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

10
LAB01/LAB01/Form1.cs Normal file
View File

@ -0,0 +1,10 @@
namespace LAB01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

120
LAB01/LAB01/Form1.resx Normal file
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>

10
LAB01/LAB01/LAB01.csproj Normal file
View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

55
LAB01/LAB01/Program.cs Normal file
View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
// Структура данных для комплектующих компьютера
public class ComputerComponent
{
public string Name { get; set; }
public string Type { get; set; }
// Другие характеристики компонента
public ComputerComponent(string name, string type)
{
Name = name;
Type = type;
}
}
// Класс для проверки совместимости компонентов в сборке
public class CompatibilityChecker
{
public bool CheckCompatibility(List<ComputerComponent> components)
{
// Логика проверки совместимости компонентов
foreach (var component in components)
{
// Проверка совместимости
if (component.Type == "CPU" && components.Exists(c => c.Type == "Motherboard"))
{
// Логика проверки совместимости процессора и материнской платы
Console.WriteLine($"Процессор {component.Name} совместим с материнской платой.");
}
// Другие логические проверки
}
Console.WriteLine("Проверка совместимости завершена.");
return true; // или false в зависимости от результата проверки
}
}
// Пример использования
class Program
{
static void Main()
{
var components = new List<ComputerComponent>
{
new ComputerComponent("Intel Core i7", "CPU"),
new ComputerComponent("MSI Z390 Gaming Pro", "Motherboard"),
// Другие компоненты
};
var checker = new CompatibilityChecker();
checker.CheckCompatibility(components);
}
}

View File

@ -0,0 +1,61 @@
using ProjectMotorboat.CollectionGenericObjects;
using ProjectMotorboat.Drownings;
namespace ProjectMotorboat.CollectionGenericObjects;
public abstract class AbstractCompany
{
protected readonly int _placeSizeWidth = 190;
protected readonly int _placeSizeHeight = 100;
protected readonly int _pictureWidth;
protected readonly int _pictureHeight;
protected ICollectionGenericObjects<DrawningBoat>? _collection = null;
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
public static int operator +(AbstractCompany company, DrawningBoat boat)
{
return company._collection.Insert(boat);
}
public static DrawningBoat operator -(AbstractCompany company, int position)
{
return company._collection.Remove(position);
}
public DrawningBoat? GetRandomObject()
{
Random rnd = new();
return _collection?.Get(rnd.Next(GetMaxCount));
}
public Bitmap? Show()
{
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap);
DrawBackgound(graphics);
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningBoat? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
return bitmap;
}
protected abstract void DrawBackgound(Graphics g);
protected abstract void SetObjectsPosition();
}

View File

@ -0,0 +1,58 @@
using ProjectMotorboat.CollectionGenericObjects;
using ProjectMotorboat.Drownings;
namespace ProjectMotorboat.CollectionGenericObjects;
public class HarborService : AbstractCompany
{
public HarborService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackgound(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
Pen pen = new(Color.Black, 2);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height + 1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5 + _placeSizeWidth - 45, j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5, j * _placeSizeHeight - _placeSizeHeight);
}
}
}
protected override void SetObjectsPosition()
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int boatWidth = 0;
int boatHeight = 0;
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
if (_collection.Get(i) != null)
{
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(i).SetPosition(_placeSizeWidth * boatWidth + 20, boatHeight * _placeSizeHeight + 20);
}
if (boatWidth < width - 1)
boatWidth++;
else
{
boatWidth = 0;
boatHeight++;
}
if (boatHeight > height)
{
return;
}
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMotorboat.CollectionGenericObjects;
public interface ICollectionGenericObjects<T>
where T : class
{
int Count { get; }
int SetMaxCount { set; }
int Insert(T obj);
int Insert(T obj, int position);
T Remove(int position);
T? Get(int position);
}

View File

@ -0,0 +1,97 @@
namespace ProjectMotorboat.CollectionGenericObjects;
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
private T?[] _collection;
public int Count => _collection.Length;
public int SetMaxCount
{
set
{
if (value > 0)
{
if (_collection.Length > 0)
{
Array.Resize(ref _collection, value);
}
else
{
_collection = new T?[value];
}
}
}
}
public MassiveGenericObjects()
{
_collection = Array.Empty<T?>();
}
public T? Get(int position)
{
if (position < 0 || position >= _collection.Length)
{
return null;
}
return _collection[position];
}
public int Insert(T obj)
{
for (int i = 0; i < _collection.Length; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
}
return -1;
}
public int Insert(T obj, int position)
{
if (position < 0 || position >= _collection.Length) { return position; }
if (_collection[position] == null)
{
_collection[position] = obj;
return position;
}
else
{
for (int i = position + 1; i < _collection.Length; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
}
for (int i = position - 1; i >= 0; i--)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
}
}
return -1;
}
public T Remove(int position)
{
if (position < 0 || position >= _collection.Length)
{
return null;
}
T? obj = _collection[position];
_collection[position] = null;
return obj;
}
}

View File

@ -0,0 +1,172 @@
namespace ProjectMotorboat
{
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()
{
groupBoxTools = new GroupBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonDelBoat = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddMotorboat = new Button();
buttonAddBoat = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonDelBoat);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddMotorboat);
groupBoxTools.Controls.Add(buttonAddBoat);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(821, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(231, 569);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(20, 488);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(199, 54);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(20, 365);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(199, 54);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonDelBoat
//
buttonDelBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelBoat.Location = new Point(20, 272);
buttonDelBoat.Name = "buttonDelBoat";
buttonDelBoat.Size = new Size(199, 54);
buttonDelBoat.TabIndex = 4;
buttonDelBoat.Text = "удалить лодку";
buttonDelBoat.UseVisualStyleBackColor = true;
buttonDelBoat.Click += ButtonRemoveBoat_Click;
//
// maskedTextBox
//
maskedTextBox.Location = new Point(20, 239);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(199, 27);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonAddMotorboat
//
buttonAddMotorboat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddMotorboat.Location = new Point(20, 130);
buttonAddMotorboat.Name = "buttonAddMotorboat";
buttonAddMotorboat.Size = new Size(199, 54);
buttonAddMotorboat.TabIndex = 2;
buttonAddMotorboat.Text = "Добавление моторной лодки";
buttonAddMotorboat.UseVisualStyleBackColor = true;
buttonAddMotorboat.Click += ButtonMotorboat_Click;
//
// buttonAddBoat
//
buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBoat.Location = new Point(20, 70);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(199, 54);
buttonAddBoat.TabIndex = 1;
buttonAddBoat.Text = "Добавление лодки";
buttonAddBoat.UseVisualStyleBackColor = true;
buttonAddBoat.Click += ButtonAddBoat_Click;
//
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(20, 36);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(199, 28);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(821, 569);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormBoatCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1052, 569);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormBoatCollection";
Text = "Коллекция лодок";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private Button buttonAddBoat;
private ComboBox comboBoxSelectorCompany;
private MaskedTextBox maskedTextBox;
private Button buttonAddMotorboat;
private PictureBox pictureBox;
private Button buttonDelBoat;
private Button buttonGoToCheck;
private Button buttonRefresh;
}
}

View File

@ -0,0 +1,190 @@
using ProjectMotorboat.CollectionGenericObjects;
using ProjectMotorboat.Drownings;
using ProjectMotorboat.CollectionGenericObjects;
using ProjectMotorboat.Drownings;
using System.Windows.Forms;
namespace ProjectMotorboat;
/// <summary>
/// Форма работы с компанией и ее коллекцией
/// </summary>
public partial class FormBoatCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormBoatCollection()
{
InitializeComponent();
}
/// <summary>
/// Выбор компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new HarborService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningBoat>());
break;
}
}
/// <summary>
/// Добавление обычного автомобиля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat));
/// <summary>
/// Добавление спортивного автомобиля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMotorboat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMotorboat));
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningBoat drawningBoat;
switch (type)
{
case nameof(DrawningBoat):
drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningMotorboat):
drawningBoat = new DrawningMotorboat(random.Next(100, 300), random.Next(1000, 3000), GetColor(random),
GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + drawningBoat != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Генератор случайных чисел</param>
/// <returns></returns>
private static Color GetColor(Random random)
{
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
return color;
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningBoat? boat = null;
int counter = 100;
while (boat == null)
{
boat = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (boat == null)
{
return;
}
FormMotorboat form = new()
{
SetBoat = boat
};
form.ShowDialog();
}
/// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
pictureBox.Image = _company.Show();
}
}

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

@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxMotorboat = new PictureBox();
buttonCreate = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonCreateBoat = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxMotorboat).BeginInit();
@ -49,17 +47,6 @@
pictureBoxMotorboat.TabIndex = 0;
pictureBoxMotorboat.TabStop = false;
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 409);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(240, 29);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать моторную лодку";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -109,17 +96,6 @@
buttonUp.Click += ButtonMove_Click;
buttonUp.MouseClick += ButtonMove_Click;
//
// buttonCreateBoat
//
buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateBoat.Location = new Point(275, 409);
buttonCreateBoat.Name = "buttonCreateBoat";
buttonCreateBoat.Size = new Size(240, 29);
buttonCreateBoat.TabIndex = 6;
buttonCreateBoat.Text = "Создать лодку";
buttonCreateBoat.UseVisualStyleBackColor = true;
buttonCreateBoat.Click += ButtonBoat_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -147,12 +123,10 @@
ClientSize = new Size(800, 450);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateBoat);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxMotorboat);
Name = "FormMotorboat";
Text = "Моторная лодка";
@ -163,12 +137,10 @@
#endregion
private PictureBox pictureBoxMotorboat;
private Button buttonCreate;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
private Button buttonCreateBoat;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -7,6 +7,19 @@ public partial class FormMotorboat : Form
{
private DrawningBoat? _drawningBoat;
private AbstractStrategy? _strategy;
public DrawningBoat SetBoat
{
set
{
_drawningBoat = value;
_drawningBoat.SetPictureSize(pictureBoxMotorboat.Width, pictureBoxMotorboat.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
public FormMotorboat()
{
InitializeComponent();
@ -23,38 +36,6 @@ public partial class FormMotorboat : Form
_drawningBoat.DrawTransport(gr);
pictureBoxMotorboat.Image = bmp;
}
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningBoat):
_drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
break;
case nameof(DrawningMotorboat):
_drawningBoat = new DrawningMotorboat(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
_drawningBoat.SetPictureSize(pictureBoxMotorboat.Width, pictureBoxMotorboat.Height);
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
comboBoxStrategy.Enabled = true;
Draw();
}
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMotorboat));
private void ButtonBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat));
private void ButtonMove_Click(object sender, EventArgs e)
{

View File

@ -11,7 +11,7 @@ namespace ProjectMotorboat
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormMotorboat());
Application.Run(new FormBoatCollection());
}
}
}