2/3 done
This commit is contained in:
parent
c8d9b3ece7
commit
9003758c6b
@ -8,13 +8,13 @@ using ProjectCatamaran.Drawnings;
|
||||
namespace ProjectCatamaran.CollectionGenericObjects;
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
protected readonly int _placeSizeWidth = 210;
|
||||
protected readonly int _placeSizeWidth = 90;
|
||||
|
||||
protected readonly int _placeSizeHeight = 80;
|
||||
protected readonly int _placeSizeHeight = 50;
|
||||
protected readonly int _pictureWidth;
|
||||
protected readonly int _pictureHeight;
|
||||
protected ICollectionGenericObjects<DrawningBoat?> _collection = null;
|
||||
private int GetMaxCount => _pictureWidth + _pictureHeight / (_placeSizeWidth + _placeSizeHeight);
|
||||
private int GetMaxCount => (_pictureWidth / _placeSizeWidth + 1) * (_pictureHeight / _placeSizeHeight / 2) - (_pictureHeight / _placeSizeHeight / 2);
|
||||
|
||||
public AbstractCompany(int picWidth,int picHeight,ICollectionGenericObjects<DrawningBoat?> collection)
|
||||
{
|
||||
|
@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectCatamaran.Drawnings;
|
||||
|
||||
namespace ProjectCatamaran.CollectionGenericObjects;
|
||||
public class BoatSharingService : AbstractCompany
|
||||
{
|
||||
public BoatSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat?> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackground(Graphics g)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void SetObjectPosition()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectCatamaran.Drawnings;
|
||||
|
||||
namespace ProjectCatamaran.CollectionGenericObjects;
|
||||
public class Harbour : AbstractCompany
|
||||
{
|
||||
public Harbour(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat?> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black,2);
|
||||
for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++)
|
||||
{
|
||||
g.DrawLine(pen, 0, _pictureHeight - 10 - (2*i* _placeSizeHeight)
|
||||
, _pictureWidth , _pictureHeight - 10 - (2*i * _placeSizeHeight));
|
||||
for (int j = 0; j - 1 < _pictureWidth / _placeSizeWidth; j++)
|
||||
{
|
||||
g.DrawLine(pen, (j * _placeSizeWidth), _pictureHeight - 10 - (2 * i * _placeSizeHeight),
|
||||
(j * _placeSizeWidth), _pictureHeight - 10 - (2 *i * _placeSizeHeight)- _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectPosition()
|
||||
{
|
||||
int curPosX = 0;
|
||||
int curPosY = 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((curPosX * _placeSizeWidth) + 15,_pictureHeight - 2 * curPosY * _placeSizeHeight - _placeSizeHeight - 5);
|
||||
}
|
||||
curPosX += 1;
|
||||
|
||||
|
||||
if (curPosX > 6)
|
||||
{
|
||||
curPosX = 0;
|
||||
curPosY++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -29,24 +29,69 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> where T : c
|
||||
public T? Get(int position)
|
||||
{
|
||||
//todo
|
||||
if (position >= 0 && position < Count)
|
||||
{
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
//todo
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
//todo
|
||||
if (!(position > 0 && position < _collection.Length))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_collection[position] == null)
|
||||
_collection[position] = obj;
|
||||
else
|
||||
{
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = position - 1; i >= 0; i--)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
//todo
|
||||
if (!(position >= 0 && position < _collection.Length) || _collection[position] == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_collection[position] = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public partial class FormBoatCollection : Form
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new BoatSharingService(pictureBox.Width, pictureBox.Height,
|
||||
_company = new Harbour(pictureBox.Width, pictureBox.Height,
|
||||
new MassiveGenericObjects<DrawningBoat?>());
|
||||
break;
|
||||
}
|
||||
@ -45,8 +45,7 @@ public partial class FormBoatCollection : Form
|
||||
break;
|
||||
case nameof(DrawningCatamaran):
|
||||
drawningBoat = new DrawningCatamaran(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)),
|
||||
GetColor(random), GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
@ -95,7 +94,7 @@ public partial class FormBoatCollection : Form
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.No)
|
||||
MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace ProjectCatamaran
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormCatamaran());
|
||||
Application.Run(new FormBoatCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user