Fix
This commit is contained in:
parent
c84fb1538f
commit
fc9a0ce177
@ -22,7 +22,13 @@ namespace DoubleDeckerBus
|
|||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_bus = new DrawingBus(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_bus = new DrawingBus(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||||
SetData();
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
@ -63,9 +69,19 @@ namespace DoubleDeckerBus
|
|||||||
private void ButtonÑreateExtra_Click(object sender, EventArgs e)
|
private void ButtonÑreateExtra_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_bus = new DrawingDDB(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
ColorDialog dialog = new();
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialogDop = new();
|
||||||
|
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogDop.Color;
|
||||||
|
}
|
||||||
|
_bus = new DrawingDDB(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
|
||||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
SetData();
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
|
@ -63,7 +63,7 @@ namespace DoubleDeckerBus
|
|||||||
|
|
||||||
DrawingObjectBus bus = new(form.SelectedBus);
|
DrawingObjectBus bus = new(form.SelectedBus);
|
||||||
|
|
||||||
if (_mapBusesCollectionGeneric + bus)
|
if (_mapBusesCollectionGeneric + bus != -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBox.Image = _mapBusesCollectionGeneric.ShowSet();
|
pictureBox.Image = _mapBusesCollectionGeneric.ShowSet();
|
||||||
@ -86,7 +86,7 @@ namespace DoubleDeckerBus
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
if (_mapBusesCollectionGeneric - pos)
|
if (_mapBusesCollectionGeneric - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBox.Image = _mapBusesCollectionGeneric.ShowSet();
|
pictureBox.Image = _mapBusesCollectionGeneric.ShowSet();
|
||||||
|
@ -28,12 +28,12 @@ namespace DoubleDeckerBus
|
|||||||
_map = map;
|
_map = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator +(MapWithSetBusesGeneric<T, U> map, T bus)
|
public static int operator +(MapWithSetBusesGeneric<T, U> map, T bus)
|
||||||
{
|
{
|
||||||
return map._setBuses.Insert(bus);
|
return map._setBuses.Insert(bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator -(MapWithSetBusesGeneric<T, U> map, int position)
|
public static T operator -(MapWithSetBusesGeneric<T, U> map, int position)
|
||||||
{
|
{
|
||||||
return map._setBuses.Remove(position);
|
return map._setBuses.Remove(position);
|
||||||
}
|
}
|
||||||
@ -98,11 +98,21 @@ namespace DoubleDeckerBus
|
|||||||
private void DrawBackground(Graphics g)
|
private void DrawBackground(Graphics g)
|
||||||
{
|
{
|
||||||
Pen pen = new(Color.Black, 3);
|
Pen pen = new(Color.Black, 3);
|
||||||
|
Brush pointColor = new SolidBrush(Color.Orange);
|
||||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
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, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight,
|
||||||
|
i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (40)));
|
||||||
|
|
||||||
|
g.FillPolygon(pointColor, new Point[] {
|
||||||
|
new Point(i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (40))),
|
||||||
|
new Point(i * _placeSizeWidth + _placeSizeWidth / 2 - 10, (int)((j * _placeSizeHeight) - (50))),
|
||||||
|
new Point(i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (60))),
|
||||||
|
new Point(i * _placeSizeWidth + _placeSizeWidth / 2 + 10, (int)((j * _placeSizeHeight) - (50)))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||||
}
|
}
|
||||||
@ -113,7 +123,7 @@ namespace DoubleDeckerBus
|
|||||||
int width = _pictureWidth / _placeSizeWidth;
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
int height = _pictureHeight / _placeSizeHeight;
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
int currentWidth = 0;
|
int currentWidth = width - 1;
|
||||||
int currentHeight = 0;
|
int currentHeight = 0;
|
||||||
|
|
||||||
for (int i = 0; i < _setBuses.Count; i++) {
|
for (int i = 0; i < _setBuses.Count; i++) {
|
||||||
@ -123,14 +133,14 @@ namespace DoubleDeckerBus
|
|||||||
_pictureWidth, _pictureHeight);
|
_pictureWidth, _pictureHeight);
|
||||||
_setBuses.Get(i)?.DrawingObject(g);
|
_setBuses.Get(i)?.DrawingObject(g);
|
||||||
|
|
||||||
if (currentHeight < height)
|
if (currentWidth > 0)
|
||||||
currentHeight++;
|
currentWidth--;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentHeight = 0;
|
currentWidth = width - 1;
|
||||||
currentWidth++;
|
currentHeight++;
|
||||||
}
|
}
|
||||||
if (currentWidth > width) return;
|
if (currentHeight > height) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,14 @@ namespace DoubleDeckerBus
|
|||||||
_places = new T[count];
|
_places = new T[count];
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Insert(T bus)
|
public int Insert(T bus)
|
||||||
{
|
{
|
||||||
return Insert(bus, 0);
|
return Insert(bus, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Insert(T bus, int position)
|
public int Insert(T bus, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _places.Length || BusyPlaces == _places.Length) return false;
|
if (position < 0 || position >= _places.Length || BusyPlaces == _places.Length) return -1;
|
||||||
|
|
||||||
BusyPlaces++;
|
BusyPlaces++;
|
||||||
while (_places[position] != null) {
|
while (_places[position] != null) {
|
||||||
@ -38,14 +38,15 @@ namespace DoubleDeckerBus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_places[position] = bus;
|
_places[position] = bus;
|
||||||
return true;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _places.Length) return false;
|
if (position < 0 || position >= _places.Length) return null;
|
||||||
|
T savedBus = _places[position];
|
||||||
_places[position] = null;
|
_places[position] = null;
|
||||||
return true;
|
return savedBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get(int position)
|
public T Get(int position)
|
||||||
|
Loading…
Reference in New Issue
Block a user