lab-3 done
This commit is contained in:
parent
70f40c1f99
commit
f50833a276
@ -0,0 +1,67 @@
|
|||||||
|
using Catamaran.Drawings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Catamaran.CollectionGenericObjects
|
||||||
|
{
|
||||||
|
public abstract class AbstractCompany
|
||||||
|
{
|
||||||
|
protected readonly int _placeSizeWidth = 180;
|
||||||
|
|
||||||
|
protected readonly int _placeSizeHeight = 80;
|
||||||
|
|
||||||
|
protected readonly int _pictureWidth;
|
||||||
|
|
||||||
|
protected readonly int _pictureHeight;
|
||||||
|
|
||||||
|
protected ICollectionGenericObjects<DrawingBoat>? _collection = null;
|
||||||
|
|
||||||
|
private int GetMaxCount => (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight / 2) ;
|
||||||
|
|
||||||
|
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawingBoat> collection)
|
||||||
|
{
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_collection = collection;
|
||||||
|
_collection.SetMaxCount = GetMaxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int operator +(AbstractCompany company, DrawingBoat boat)
|
||||||
|
{
|
||||||
|
return company._collection.Insert(boat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DrawingBoat operator -(AbstractCompany company, int position)
|
||||||
|
{
|
||||||
|
return company._collection.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingBoat? GetRandomObject()
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap? Show()
|
||||||
|
{
|
||||||
|
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics graphics = Graphics.FromImage(bitmap);
|
||||||
|
DrawBackground(graphics);
|
||||||
|
SetObjectsPosition();
|
||||||
|
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||||
|
{
|
||||||
|
DrawingBoat? obj = _collection?.Get(i);
|
||||||
|
obj?.DrawTransport(graphics);
|
||||||
|
}
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void DrawBackground(Graphics g);
|
||||||
|
|
||||||
|
protected abstract void SetObjectsPosition();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Catamaran.CollectionGenericObjects
|
||||||
|
{
|
||||||
|
public class ArrayGenericObjects<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 ArrayGenericObjects()
|
||||||
|
{
|
||||||
|
_collection = Array.Empty<T?>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
if (position < Count)
|
||||||
|
{
|
||||||
|
if (_collection[position] == null)
|
||||||
|
{
|
||||||
|
_collection[position] = obj;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Remove(int position)
|
||||||
|
{
|
||||||
|
if (position > Count || position < 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
T? obj = _collection[position];
|
||||||
|
_collection[position] = null;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
60
Catamaran/Catamaran/CollectionGenericObjects/Harbor.cs
Normal file
60
Catamaran/Catamaran/CollectionGenericObjects/Harbor.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using Catamaran.Drawings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Catamaran.CollectionGenericObjects
|
||||||
|
{
|
||||||
|
public class Harbor : AbstractCompany
|
||||||
|
{
|
||||||
|
public Harbor(int picWidth, int picHeight, ICollectionGenericObjects<DrawingBoat> collection) : base(picWidth, picHeight, collection)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new Pen(Color.Black, 4f);
|
||||||
|
for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, 0, _pictureHeight - i * _placeSizeHeight * 2, _placeSizeWidth * (_pictureWidth / _placeSizeWidth), _pictureHeight - i * _placeSizeHeight * 2);
|
||||||
|
for (int j = 0; j < _pictureWidth / _placeSizeWidth + 1; j++)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, _placeSizeWidth * j, _pictureHeight - i * _placeSizeHeight * 2, _placeSizeWidth * j, _pictureHeight - i * _placeSizeHeight * 2 - _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override void SetObjectsPosition()
|
||||||
|
{
|
||||||
|
int curPosX = 0;
|
||||||
|
int curPosY = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||||
|
{
|
||||||
|
if (curPosX > _pictureWidth / _placeSizeWidth)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_collection?.Get(i) != null)
|
||||||
|
{
|
||||||
|
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||||
|
_collection?.Get(i)?.SetPosition(curPosX * _placeSizeWidth + 20, curPosY * _placeSizeHeight * -2 + (_pictureHeight - 60) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curPosX < _pictureWidth / _placeSizeWidth - 1)
|
||||||
|
{
|
||||||
|
curPosX++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curPosX = 0;
|
||||||
|
curPosY++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Catamaran.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);
|
||||||
|
}
|
||||||
|
}
|
169
Catamaran/Catamaran/FormBoatColletion.Designer.cs
generated
Normal file
169
Catamaran/Catamaran/FormBoatColletion.Designer.cs
generated
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
namespace Catamaran
|
||||||
|
{
|
||||||
|
partial class FormBoatColletion
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
groupBox1 = new GroupBox();
|
||||||
|
UpdateButton = new Button();
|
||||||
|
GoToTestButton = new Button();
|
||||||
|
DeleteButton = new Button();
|
||||||
|
maskedTextBox = new MaskedTextBox();
|
||||||
|
AddCatamaranButton = new Button();
|
||||||
|
AddBoatButton = new Button();
|
||||||
|
InstrumentBox = new ComboBox();
|
||||||
|
pictureBox = new PictureBox();
|
||||||
|
groupBox1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
groupBox1.Controls.Add(UpdateButton);
|
||||||
|
groupBox1.Controls.Add(GoToTestButton);
|
||||||
|
groupBox1.Controls.Add(DeleteButton);
|
||||||
|
groupBox1.Controls.Add(maskedTextBox);
|
||||||
|
groupBox1.Controls.Add(AddCatamaranButton);
|
||||||
|
groupBox1.Controls.Add(AddBoatButton);
|
||||||
|
groupBox1.Controls.Add(InstrumentBox);
|
||||||
|
groupBox1.Dock = DockStyle.Right;
|
||||||
|
groupBox1.Location = new Point(809, 0);
|
||||||
|
groupBox1.Name = "groupBox1";
|
||||||
|
groupBox1.Size = new Size(237, 642);
|
||||||
|
groupBox1.TabIndex = 0;
|
||||||
|
groupBox1.TabStop = false;
|
||||||
|
groupBox1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// UpdateButton
|
||||||
|
//
|
||||||
|
UpdateButton.Location = new Point(6, 565);
|
||||||
|
UpdateButton.Name = "UpdateButton";
|
||||||
|
UpdateButton.Size = new Size(225, 38);
|
||||||
|
UpdateButton.TabIndex = 6;
|
||||||
|
UpdateButton.Text = "Обновить";
|
||||||
|
UpdateButton.UseVisualStyleBackColor = true;
|
||||||
|
UpdateButton.Click += UpdateButton_Click;
|
||||||
|
//
|
||||||
|
// GoToTestButton
|
||||||
|
//
|
||||||
|
GoToTestButton.Location = new Point(12, 355);
|
||||||
|
GoToTestButton.Name = "GoToTestButton";
|
||||||
|
GoToTestButton.Size = new Size(225, 38);
|
||||||
|
GoToTestButton.TabIndex = 5;
|
||||||
|
GoToTestButton.Text = "Передать на тесты";
|
||||||
|
GoToTestButton.UseVisualStyleBackColor = true;
|
||||||
|
GoToTestButton.Click += GoToTestButton_Click;
|
||||||
|
//
|
||||||
|
// DeleteButton
|
||||||
|
//
|
||||||
|
DeleteButton.Location = new Point(6, 238);
|
||||||
|
DeleteButton.Name = "DeleteButton";
|
||||||
|
DeleteButton.Size = new Size(225, 38);
|
||||||
|
DeleteButton.TabIndex = 4;
|
||||||
|
DeleteButton.Text = "Удалить лодку";
|
||||||
|
DeleteButton.UseVisualStyleBackColor = true;
|
||||||
|
DeleteButton.Click += DeleteButton_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBox
|
||||||
|
//
|
||||||
|
maskedTextBox.Location = new Point(6, 205);
|
||||||
|
maskedTextBox.Mask = "00";
|
||||||
|
maskedTextBox.Name = "maskedTextBox";
|
||||||
|
maskedTextBox.Size = new Size(225, 27);
|
||||||
|
maskedTextBox.TabIndex = 3;
|
||||||
|
maskedTextBox.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// AddCatamaranButton
|
||||||
|
//
|
||||||
|
AddCatamaranButton.Location = new Point(6, 104);
|
||||||
|
AddCatamaranButton.Name = "AddCatamaranButton";
|
||||||
|
AddCatamaranButton.Size = new Size(225, 38);
|
||||||
|
AddCatamaranButton.TabIndex = 2;
|
||||||
|
AddCatamaranButton.Text = "Добавить катамаран";
|
||||||
|
AddCatamaranButton.UseVisualStyleBackColor = true;
|
||||||
|
AddCatamaranButton.Click += AddCatamaranButton_Click;
|
||||||
|
//
|
||||||
|
// AddBoatButton
|
||||||
|
//
|
||||||
|
AddBoatButton.Location = new Point(6, 60);
|
||||||
|
AddBoatButton.Name = "AddBoatButton";
|
||||||
|
AddBoatButton.Size = new Size(225, 38);
|
||||||
|
AddBoatButton.TabIndex = 1;
|
||||||
|
AddBoatButton.Text = "Добавить лодку";
|
||||||
|
AddBoatButton.UseVisualStyleBackColor = true;
|
||||||
|
AddBoatButton.Click += AddBoatButton_Click;
|
||||||
|
//
|
||||||
|
// InstrumentBox
|
||||||
|
//
|
||||||
|
InstrumentBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
InstrumentBox.AutoCompleteCustomSource.AddRange(new string[] { "Хранилище" });
|
||||||
|
InstrumentBox.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
InstrumentBox.FormattingEnabled = true;
|
||||||
|
InstrumentBox.Items.AddRange(new object[] { "Хранилище" });
|
||||||
|
InstrumentBox.Location = new Point(6, 26);
|
||||||
|
InstrumentBox.Name = "InstrumentBox";
|
||||||
|
InstrumentBox.Size = new Size(225, 28);
|
||||||
|
InstrumentBox.TabIndex = 0;
|
||||||
|
InstrumentBox.SelectedIndexChanged += InstrumentBox_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
|
pictureBox.Location = new Point(0, 0);
|
||||||
|
pictureBox.Name = "pictureBox";
|
||||||
|
pictureBox.Size = new Size(809, 642);
|
||||||
|
pictureBox.TabIndex = 1;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormBoatColletion
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1046, 642);
|
||||||
|
Controls.Add(pictureBox);
|
||||||
|
Controls.Add(groupBox1);
|
||||||
|
Name = "FormBoatColletion";
|
||||||
|
Text = "Коллекция лодок";
|
||||||
|
groupBox1.ResumeLayout(false);
|
||||||
|
groupBox1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private ComboBox InstrumentBox;
|
||||||
|
private Button AddBoatButton;
|
||||||
|
private Button AddCatamaranButton;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private MaskedTextBox maskedTextBox;
|
||||||
|
private Button DeleteButton;
|
||||||
|
private Button GoToTestButton;
|
||||||
|
private Button UpdateButton;
|
||||||
|
}
|
||||||
|
}
|
156
Catamaran/Catamaran/FormBoatColletion.cs
Normal file
156
Catamaran/Catamaran/FormBoatColletion.cs
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
using Catamaran.CollectionGenericObjects;
|
||||||
|
using Catamaran.Drawings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Catamaran
|
||||||
|
{
|
||||||
|
public partial class FormBoatColletion : Form
|
||||||
|
{
|
||||||
|
|
||||||
|
private AbstractCompany? _company = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public FormBoatColletion()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InstrumentBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
switch (InstrumentBox.Text)
|
||||||
|
{
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new Harbor(pictureBox.Width, pictureBox.Height, new ArrayGenericObjects<DrawingBoat>());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawingBoat drawingBoat;
|
||||||
|
Random random = new();
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawingBoat):
|
||||||
|
drawingBoat = new DrawingBoat(random.Next(100, 500), random.Next(1000, 3000), GetColor(random));
|
||||||
|
break;
|
||||||
|
case nameof(DrawingCatamaran):
|
||||||
|
drawingBoat = new DrawingCatamaran(random.Next(100, 500), random.Next(1000, 3000), GetColor(random), GetColor(random),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_company + drawingBoat >= 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddBoatButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawingBoat));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddCatamaranButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawingCatamaran));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null || string.IsNullOrEmpty(maskedTextBox.Text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||||
|
if (_company - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GoToTestButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawingBoat? boat = null;
|
||||||
|
int counter = 100;
|
||||||
|
while (boat == null)
|
||||||
|
{
|
||||||
|
boat = _company.GetRandomObject();
|
||||||
|
|
||||||
|
counter--;
|
||||||
|
if (counter <= 0) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (boat == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FormCatamaran form = new()
|
||||||
|
{
|
||||||
|
SetBoat = boat
|
||||||
|
};
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
Catamaran/Catamaran/FormBoatColletion.resx
Normal file
120
Catamaran/Catamaran/FormBoatColletion.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
28
Catamaran/Catamaran/FormCatamaran.Designer.cs
generated
28
Catamaran/Catamaran/FormCatamaran.Designer.cs
generated
@ -29,12 +29,10 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBox1 = new PictureBox();
|
pictureBox1 = new PictureBox();
|
||||||
CreateButton = new Button();
|
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
CreateBoat_button = new Button();
|
|
||||||
StrategyBox = new ComboBox();
|
StrategyBox = new ComboBox();
|
||||||
StepButton = new Button();
|
StepButton = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||||
@ -49,17 +47,6 @@
|
|||||||
pictureBox1.TabIndex = 0;
|
pictureBox1.TabIndex = 0;
|
||||||
pictureBox1.TabStop = false;
|
pictureBox1.TabStop = false;
|
||||||
//
|
//
|
||||||
// CreateButton
|
|
||||||
//
|
|
||||||
CreateButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
CreateButton.Location = new Point(12, 456);
|
|
||||||
CreateButton.Name = "CreateButton";
|
|
||||||
CreateButton.Size = new Size(168, 29);
|
|
||||||
CreateButton.TabIndex = 1;
|
|
||||||
CreateButton.Text = "Создать катамаран";
|
|
||||||
CreateButton.UseVisualStyleBackColor = true;
|
|
||||||
CreateButton.Click += CreateButton_Click;
|
|
||||||
//
|
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
@ -108,17 +95,6 @@
|
|||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
buttonUp.Click += ButtonMove_Click;
|
buttonUp.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// CreateBoat_button
|
|
||||||
//
|
|
||||||
CreateBoat_button.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
CreateBoat_button.Location = new Point(186, 456);
|
|
||||||
CreateBoat_button.Name = "CreateBoat_button";
|
|
||||||
CreateBoat_button.Size = new Size(168, 29);
|
|
||||||
CreateBoat_button.TabIndex = 6;
|
|
||||||
CreateBoat_button.Text = "Создать лодку";
|
|
||||||
CreateBoat_button.UseVisualStyleBackColor = true;
|
|
||||||
CreateBoat_button.Click += CreateBoat_button_Click;
|
|
||||||
//
|
|
||||||
// StrategyBox
|
// StrategyBox
|
||||||
//
|
//
|
||||||
StrategyBox.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
StrategyBox.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
@ -148,12 +124,10 @@
|
|||||||
ClientSize = new Size(668, 497);
|
ClientSize = new Size(668, 497);
|
||||||
Controls.Add(StepButton);
|
Controls.Add(StepButton);
|
||||||
Controls.Add(StrategyBox);
|
Controls.Add(StrategyBox);
|
||||||
Controls.Add(CreateBoat_button);
|
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(CreateButton);
|
|
||||||
Controls.Add(pictureBox1);
|
Controls.Add(pictureBox1);
|
||||||
Name = "FormCatamaran";
|
Name = "FormCatamaran";
|
||||||
Text = "Катамаран";
|
Text = "Катамаран";
|
||||||
@ -165,12 +139,10 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBox1;
|
private PictureBox pictureBox1;
|
||||||
private Button CreateButton;
|
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button CreateBoat_button;
|
|
||||||
private ComboBox StrategyBox;
|
private ComboBox StrategyBox;
|
||||||
private Button StepButton;
|
private Button StepButton;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,18 @@ namespace Catamaran
|
|||||||
_strategy = null;
|
_strategy = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrawingBoat SetBoat
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_drawingBoat = value;
|
||||||
|
_drawingBoat.SetPictureSize(pictureBox1.Width, pictureBox1.Height);
|
||||||
|
StrategyBox.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawingBoat == null) return;
|
if (_drawingBoat == null) return;
|
||||||
@ -35,40 +47,6 @@ namespace Catamaran
|
|||||||
pictureBox1.Image = bmp;
|
pictureBox1.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateObject(string type)
|
|
||||||
{
|
|
||||||
Random random = new Random();
|
|
||||||
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case nameof(DrawingBoat):
|
|
||||||
_drawingBoat = new DrawingBoat(random.Next(100, 500), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
|
||||||
break;
|
|
||||||
case nameof(DrawingCatamaran):
|
|
||||||
_drawingBoat = new DrawingCatamaran(random.Next(100, 500), 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)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_drawingBoat.SetPictureSize(pictureBox1.Width, pictureBox1.Height);
|
|
||||||
_drawingBoat.SetPosition(random.Next(10, 600), random.Next(10, 600));
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateButton_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
CreateObject(nameof(DrawingCatamaran));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateBoat_button_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
CreateObject(nameof(DrawingBoat));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawingBoat == null) return;
|
if (_drawingBoat == null) return;
|
||||||
|
@ -11,7 +11,7 @@ namespace Catamaran
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormCatamaran());
|
Application.Run(new FormBoatColletion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user