5 Commits
laba2 ... laba4

Author SHA1 Message Date
Учебный
b15bf7d2c0 зафиксировать всё 2023-11-12 17:13:14 +04:00
Учебный
2645b2aa47 зафиксировать всё 2023-11-12 17:04:55 +04:00
Учебный
a7591f9928 зафиксировать всё 2023-11-11 19:26:10 +04:00
Учебный
29068866e1 зафиксировать всё 2023-10-30 10:01:38 +04:00
Учебный
bad8d47c56 зафиксировать всё 2023-10-29 22:47:34 +04:00
34 changed files with 659 additions and 372 deletions

View File

@@ -8,10 +8,15 @@ using System.Text;
using ProjectBoat_bae; using ProjectBoat_bae;
using ProjectBoat_bae.Entities; using ProjectBoat_bae.Entities;
using ProjectBoat_bae.MovementStrategy;
namespace ProjectBoat_bae.DrawningObjects namespace ProjectBoat_bae.DrawningObjects
{ {
public class Drawningboat public class Drawningboat
{ {
// Получение объекта IMoveableObject из объекта DrawningCar
public IMoveableObject GetMoveableObject => new
DrawningObjectBoat(this);
// Класс-сущность // Класс-сущность
public EntityBoat? EntityBoat { get; protected set; } public EntityBoat? EntityBoat { get; protected set; }

View File

@@ -29,7 +29,7 @@
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBoat)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBoat));
pictureBox1 = new PictureBox(); pictureBoxBoat = new PictureBox();
button_bottom = new Button(); button_bottom = new Button();
button_top = new Button(); button_top = new Button();
button_right = new Button(); button_right = new Button();
@@ -38,18 +38,19 @@
buttonClickMotorBoat = new Button(); buttonClickMotorBoat = new Button();
buttonStep = new Button(); buttonStep = new Button();
comboBoxStrategy = new ComboBox(); comboBoxStrategy = new ComboBox();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); buttonSelectBoat_Click = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxBoat).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// pictureBox1 // pictureBoxBoat
// //
pictureBox1.Dock = DockStyle.Fill; pictureBoxBoat.Dock = DockStyle.Fill;
pictureBox1.Location = new Point(0, 0); pictureBoxBoat.Location = new Point(0, 0);
pictureBox1.Name = "pictureBox1"; pictureBoxBoat.Name = "pictureBoxBoat";
pictureBox1.Size = new Size(1178, 644); pictureBoxBoat.Size = new Size(1178, 644);
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxBoat.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBox1.TabIndex = 0; pictureBoxBoat.TabIndex = 0;
pictureBox1.TabStop = false; pictureBoxBoat.TabStop = false;
// //
// button_bottom // button_bottom
// //
@@ -144,11 +145,22 @@
comboBoxStrategy.Size = new Size(182, 33); comboBoxStrategy.Size = new Size(182, 33);
comboBoxStrategy.TabIndex = 9; comboBoxStrategy.TabIndex = 9;
// //
// buttonSelectBoat_Click
//
buttonSelectBoat_Click.Location = new Point(517, 598);
buttonSelectBoat_Click.Name = "buttonSelectBoat_Click";
buttonSelectBoat_Click.Size = new Size(233, 34);
buttonSelectBoat_Click.TabIndex = 10;
buttonSelectBoat_Click.Text = "Выбранная лодка";
buttonSelectBoat_Click.UseVisualStyleBackColor = true;
buttonSelectBoat_Click.Click += buttonSelectBoat_Click_Click;
//
// FormBoat // FormBoat
// //
AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1178, 644); ClientSize = new Size(1178, 644);
Controls.Add(buttonSelectBoat_Click);
Controls.Add(comboBoxStrategy); Controls.Add(comboBoxStrategy);
Controls.Add(buttonStep); Controls.Add(buttonStep);
Controls.Add(buttonClickMotorBoat); Controls.Add(buttonClickMotorBoat);
@@ -157,17 +169,17 @@
Controls.Add(button_right); Controls.Add(button_right);
Controls.Add(button_top); Controls.Add(button_top);
Controls.Add(button_bottom); Controls.Add(button_bottom);
Controls.Add(pictureBox1); Controls.Add(pictureBoxBoat);
Name = "FormBoat"; Name = "FormBoat";
Text = "Form1"; Text = "FormBoat";
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxBoat).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
#endregion #endregion
private PictureBox pictureBox1; private PictureBox pictureBoxBoat;
private Button button_bottom; private Button button_bottom;
private Button button_top; private Button button_top;
private Button button_right; private Button button_right;
@@ -176,5 +188,7 @@
private Button buttonClickMotorBoat; private Button buttonClickMotorBoat;
private Button buttonStep; private Button buttonStep;
private ComboBox comboBoxStrategy; private ComboBox comboBoxStrategy;
private Button button1;
private Button buttonSelectBoat_Click;
} }
} }

View File

@@ -8,8 +8,6 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using ProjectBoat_bae;
using ProjectBoat_bae.Properties;
using ProjectBoat_bae.Entities; using ProjectBoat_bae.Entities;
using ProjectBoat_bae.MovementStrategy; using ProjectBoat_bae.MovementStrategy;
using ProjectBoat_bae.DrawningObjects; using ProjectBoat_bae.DrawningObjects;
@@ -22,10 +20,14 @@ namespace ProjectBoat_bae
private Drawningboat? _drawingBoat; private Drawningboat? _drawingBoat;
private AbstractStrategy? _abstractStrategy; private AbstractStrategy? _abstractStrategy;
/// Âûáðàííûé àâòîìîáèëü
public Drawningboat? SelectedBoat { get; private set; }
public FormBoat() public FormBoat()
{ {
InitializeComponent(); InitializeComponent();
_abstractStrategy = null;
SelectedBoat = null;
} }
// Ìåòîä ïðîðèñîâêè // Ìåòîä ïðîðèñîâêè
@@ -35,11 +37,11 @@ namespace ProjectBoat_bae
{ {
return; return;
} }
Bitmap bmp = new(pictureBox1.Width, Bitmap bmp = new(pictureBoxBoat.Width,
pictureBox1.Height); pictureBoxBoat.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_drawingBoat.DrawTransport(gr); _drawingBoat.DrawTransport(gr);
pictureBox1.Image = bmp; pictureBoxBoat.Image = bmp;
} }
// Èçìåíåíèå ðàçìåðîâ ôîðìû // Èçìåíåíèå ðàçìåðîâ ôîðìû
@@ -69,19 +71,39 @@ namespace ProjectBoat_bae
} }
private void buttonClickMotorBoat_Click(object sender, EventArgs e) private void buttonClickMotorBoat_Click(object sender, EventArgs e)
{ {
Random random = new Random(); Random random = new();
_drawingBoat = 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)), 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;
}
Color dopColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogAddColor = new();
if (dialogAddColor.ShowDialog() == DialogResult.OK)
{
dopColor = dialogAddColor.Color;
}
_drawingBoat = new DrawningMotorBoat(random.Next(100, 300),
random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)), pictureBox1.Width, pictureBox1.Height); pictureBoxBoat.Width, pictureBoxBoat.Height);
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }
private void buttonClick_Click(object sender, EventArgs e) private void buttonClick_Click(object sender, EventArgs e)
{ {
Random random = new(); Random random = new();
_drawingBoat = new Drawningboat(random.Next(100, 300), random.Next(1000, 3000), Color color = 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)), ColorDialog dialog = new();
pictureBox1.Width, pictureBox1.Height); if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_drawingBoat = new Drawningboat(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxBoat.Width, pictureBoxBoat.Height);
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }
@@ -105,7 +127,7 @@ namespace ProjectBoat_bae
{ {
return; return;
} }
_abstractStrategy.SetData(new DrawningObjectBoat(_drawingBoat), pictureBox1.Width, pictureBox1.Height); _abstractStrategy.SetData(new DrawningObjectBoat(_drawingBoat), pictureBoxBoat.Width, pictureBoxBoat.Height);
comboBoxStrategy.Enabled = false; comboBoxStrategy.Enabled = false;
} }
if (_abstractStrategy == null) if (_abstractStrategy == null)
@@ -120,5 +142,11 @@ namespace ProjectBoat_bae
_abstractStrategy = null; _abstractStrategy = null;
} }
} }
private void buttonSelectBoat_Click_Click(object sender, EventArgs e)
{
SelectedBoat = _drawingBoat;
DialogResult = DialogResult.OK;
}
} }
} }

View File

@@ -0,0 +1,163 @@
namespace ProjectBoat_bae
{
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()
{
pictureBoxCollection = new PictureBox();
listBoxStorages = new ListBox();
ButtonAddObject = new Button();
textBoxStorageName = new TextBox();
ButtonDelObject = new Button();
ButtonAddBoat = new Button();
ButtonRemoveBoat = new Button();
ButtonRefreshCollection = new Button();
textBoxBoat = new TextBox();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(929, 647);
pictureBoxCollection.TabIndex = 0;
pictureBoxCollection.TabStop = false;
//
// listBoxStorages
//
listBoxStorages.FormattingEnabled = true;
listBoxStorages.ItemHeight = 25;
listBoxStorages.Location = new Point(935, 146);
listBoxStorages.Name = "listBoxStorages";
listBoxStorages.Size = new Size(231, 129);
listBoxStorages.TabIndex = 1;
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
//
// ButtonAddObject
//
ButtonAddObject.BackColor = SystemColors.ButtonHighlight;
ButtonAddObject.Location = new Point(935, 102);
ButtonAddObject.Name = "ButtonAddObject";
ButtonAddObject.Size = new Size(231, 38);
ButtonAddObject.TabIndex = 2;
ButtonAddObject.Text = "Добавить в набор";
ButtonAddObject.UseVisualStyleBackColor = false;
ButtonAddObject.Click += ButtonAddObject_Click_1;
//
// textBoxStorageName
//
textBoxStorageName.Location = new Point(935, 65);
textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new Size(231, 31);
textBoxStorageName.TabIndex = 3;
//
// ButtonDelObject
//
ButtonDelObject.BackColor = SystemColors.ButtonHighlight;
ButtonDelObject.Location = new Point(935, 281);
ButtonDelObject.Name = "ButtonDelObject";
ButtonDelObject.Size = new Size(231, 34);
ButtonDelObject.TabIndex = 4;
ButtonDelObject.Text = "Удалить набор";
ButtonDelObject.UseVisualStyleBackColor = false;
ButtonDelObject.Click += ButtonDelObject_Click;
//
// ButtonAddBoat
//
ButtonAddBoat.BackColor = SystemColors.ButtonHighlight;
ButtonAddBoat.Location = new Point(935, 401);
ButtonAddBoat.Name = "ButtonAddBoat";
ButtonAddBoat.Size = new Size(231, 34);
ButtonAddBoat.TabIndex = 5;
ButtonAddBoat.Text = "Добавить лодку";
ButtonAddBoat.UseVisualStyleBackColor = false;
ButtonAddBoat.Click += ButtonAddBoat_Click;
//
// ButtonRemoveBoat
//
ButtonRemoveBoat.BackColor = SystemColors.ButtonHighlight;
ButtonRemoveBoat.Location = new Point(935, 479);
ButtonRemoveBoat.Name = "ButtonRemoveBoat";
ButtonRemoveBoat.Size = new Size(231, 34);
ButtonRemoveBoat.TabIndex = 6;
ButtonRemoveBoat.Text = "Удалить лодку";
ButtonRemoveBoat.UseVisualStyleBackColor = false;
ButtonRemoveBoat.Click += ButtonRemoveBoat_Click;
//
// ButtonRefreshCollection
//
ButtonRefreshCollection.BackColor = SystemColors.ButtonHighlight;
ButtonRefreshCollection.Location = new Point(935, 575);
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new Size(231, 34);
ButtonRefreshCollection.TabIndex = 7;
ButtonRefreshCollection.Text = "Обновить коллекцию";
ButtonRefreshCollection.UseVisualStyleBackColor = false;
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
//
// textBoxBoat
//
textBoxBoat.Location = new Point(958, 441);
textBoxBoat.Name = "textBoxBoat";
textBoxBoat.Size = new Size(173, 31);
textBoxBoat.TabIndex = 8;
//
// FormBoatCollection
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1178, 644);
Controls.Add(textBoxBoat);
Controls.Add(ButtonRefreshCollection);
Controls.Add(ButtonRemoveBoat);
Controls.Add(ButtonAddBoat);
Controls.Add(ButtonDelObject);
Controls.Add(textBoxStorageName);
Controls.Add(ButtonAddObject);
Controls.Add(listBoxStorages);
Controls.Add(pictureBoxCollection);
Name = "FormBoatCollection";
Text = "FormBoatCollection";
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private PictureBox pictureBoxCollection;
private ListBox listBoxStorages;
private Button ButtonAddObject;
private TextBox textBoxStorageName;
private Button ButtonDelObject;
private Button ButtonAddBoat;
private Button ButtonRemoveBoat;
private Button ButtonRefreshCollection;
private TextBox textBoxBoat;
}
}

View File

@@ -0,0 +1,161 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectBoat_bae.DrawningObjects;
using ProjectBoat_bae.Generics;
using ProjectBoat_bae.MovementStrategy;
namespace ProjectBoat_bae
{
public partial class FormBoatCollection : Form
{
// Набор объектов
private readonly BoatsGenericStorage _storage;
public FormBoatCollection()
{
InitializeComponent();
_storage = new BoatsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
// Заполнение listBoxObjects
private void ReloadObjects()
{
int index = listBoxStorages.SelectedIndex;
listBoxStorages.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
listBoxStorages.Items.Add(_storage.Keys[i]);
}
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
>= listBoxStorages.Items.Count))
{
listBoxStorages.SelectedIndex = 0;
}
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
index < listBoxStorages.Items.Count)
{
listBoxStorages.SelectedIndex = index;
}
}
// Добавление набора в коллекцию
private void ButtonAddObject_Click_1(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
}
// Удаление набора
private void ButtonDelObject_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
// Добавление объекта в набор
private void ButtonAddBoat_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
FormBoat form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (obj + form.SelectedBoat)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowBoats();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
//удаление объекта
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = 0;
if (textBoxBoat != null)
pos = Convert.ToInt32(textBoxBoat.Text);
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = obj.ShowBoats();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
// Обновление
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowBoats();
}
//Выбор набора
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxCollection.Image =
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBoats();
}
}
}

View File

@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectBoat_bae.MovementStrategy;
using ProjectBoat_bae.DrawningObjects;
namespace ProjectBoat_bae.Generics
{
internal class BoatsGenericCollection <T, U>
where T : Drawningboat
where U : IMoveableObject
{
// Ширина окна прорисовки
private readonly int _pictureWidth;
// Высота окна прорисовки
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 100;
// Размер занимаемого объектом места (высота)
private readonly int _placeSizeHeight = 70;
// Набор объектов
private readonly SetGeneric<T> _collection;
// Конструктор
public BoatsGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
// Перегрузка оператора сложения
public static bool operator +(BoatsGenericCollection<T, U> collect, T obj)
{
if (obj == null)
{
return false;
}
return (bool)collect._collection.Insert(obj);
}
// Перегрузка оператора вычитания
public static T? operator -(BoatsGenericCollection<T, U> collect, int
pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
}
// Получение объекта IMoveableObject
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
// Вывод всего набора объектов
public Bitmap ShowBoats()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
// Метод отрисовки фона
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
// Метод прорисовки объектов
private void DrawObjects(Graphics g)
{
for (int i = 0; i < _collection.Count; i++)
{
T? t = _collection[i];
if (t != null)
{
t.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
if (t is Drawningboat) (t as Drawningboat).DrawTransport(g);
else t.DrawTransport(g);
}
}
}
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectBoat_bae.DrawningObjects;
using ProjectBoat_bae.MovementStrategy;
namespace ProjectBoat_bae.Generics
{
internal class BoatsGenericStorage
{
readonly Dictionary<string, BoatsGenericCollection<Drawningboat, DrawningObjectBoat>> _boatStorages;
public List<string> Keys => _boatStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public BoatsGenericStorage(int pictureWidth, int pictureHeight)
{
_boatStorages = new Dictionary<string, BoatsGenericCollection<Drawningboat, DrawningObjectBoat>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
if (_boatStorages.ContainsKey(name)) return;
_boatStorages[name] = new BoatsGenericCollection<Drawningboat, DrawningObjectBoat>(_pictureWidth, _pictureHeight);
}
public void DelSet(string name)
{
if (!_boatStorages.ContainsKey(name)) return;
_boatStorages.Remove(name);
}
public BoatsGenericCollection<Drawningboat, DrawningObjectBoat>?
this[string ind]
{
get
{
if (_boatStorages.ContainsKey(ind)) return _boatStorages[ind];
return null;
}
}
}
}

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBoat_bae.Generics
{
internal class SetGeneric<T> where T : class
{
private readonly List<T?> _places;
public int Count => _places.Count;
// Максимальное количество объектов в списке
private readonly int _maxCount;
// Конструктор
public SetGeneric(int count)
{
_maxCount = count;
_places = new List<T?>(_maxCount);
}
public bool Insert(T boat)
{
return Insert(boat, 0);
}
public bool Insert(T boat, int position)
{
if (position < 0 || position >= _maxCount)
return false;
if (Count >= _maxCount)
return false;
_places.Insert(0, boat);
return true;
}
public bool Remove(int position)
{
if (position < 0 || position > _maxCount)
return false;
if (position >= Count)
return false;
_places.RemoveAt(position);
return true;
}
public T? this[int position]
{
get
{
if (position < 0 || position > _maxCount)
return null;
return _places[position];
}
set
{
if (position < 0 || position > _maxCount)
return;
_places[position] = value;
}
}
public IEnumerable<T?> GetBoats(int? maxBoats = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxBoats.HasValue && i == maxBoats.Value)
{
yield break;
}
}
}
}
}

View File

@@ -11,7 +11,7 @@ namespace ProjectBoat_bae
// 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 FormBoat()); Application.Run(new FormBoatCollection());
} }
} }
} }

View File

@@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "laba3(base)", "laba3(base)\laba3(base).csproj", "{0C4A3D74-03A3-4FF3-82C4-D0570E36B3CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0C4A3D74-03A3-4FF3-82C4-D0570E36B3CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C4A3D74-03A3-4FF3-82C4-D0570E36B3CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C4A3D74-03A3-4FF3-82C4-D0570E36B3CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C4A3D74-03A3-4FF3-82C4-D0570E36B3CE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DBC78A3D-9D37-411B-8DAD-A904CC5BF8E0}
EndGlobalSection
EndGlobal

View File

@@ -1,39 +0,0 @@
namespace laba3_base_
{
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
}
}

View File

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

View File

@@ -1,132 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace laba3_base_.Generics
{
internal class CarsGenericCollection<T, U>
where T : DrawningPlane
where U : IMoveableObject
{
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 175;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 80;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public PlanesGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(PlanesGenericCollection<T, U> collect, T?
obj)
{
if (obj == null)
{
return false;
}
return collect?._collection.Insert(obj) ?? false;
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(PlanesGenericCollection<T, U> collect, int
pos)
{
T? obj = collect._collection.Get(pos);
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowCars()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
for (int i = 0; i < _collection.Count; i++)
{
// TODO получение объекта
// TODO установка позиции
// TODO прорисовка объекта
}
}
}
}

View File

@@ -1,85 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace laba3_base_.Generics
{
internal class SetGeneric<T>
where T : class
{
// Массив объектов, которые храним
private readonly T?[] _places;
// Количество объектов в массиве
public int Count => _places.Length;
// Конструктор
public SetGeneric(int count)
{
_places = new T?[count];
}
// Добавление объекта в набор
public bool Insert(T car)
{
try
{
for (int i = _places.Length - 1; i > 0; i--)
{
_places[i] = _places[i - 1];
}
_places[0] = car;
return true;
}
catch
{
return false;
}
}
// Добавление объекта в набор на конкретную позицию
public bool Insert(T car, int position)
{
if (position < 0 || position >= _places.Count() || car == null)
{
return false;
}
if (_places[position] == null)
{
return false;
}
int positionNull = Array.FindIndex(_places, position, x => x == null);
if (positionNull == -1)
return false;
for (int i = positionNull; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = car;
return true;
}
// Удаление объекта из набора с конкретной позиции
public bool Remove(int position)
{
if (position < 0 || position >= _places.Count())
return false;
_places[position] = null;
return true;
}
// Получение объекта из набора по позиции
public T? Get(int position)
{
if (position < 0 || position >= _places.Count())
return null;
return _places[position];
}
}
}

View File

@@ -1,17 +0,0 @@
namespace laba3_base_
{
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 Form1());
}
}
}

View File

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