Доработка

This commit is contained in:
Володя 2022-10-10 18:49:01 +03:00
parent ba81bb1249
commit e086076f00
6 changed files with 207 additions and 13 deletions

View File

@ -15,7 +15,7 @@ namespace AirPlaneWithRadar
private int? pictureWidth = null;
private int? pictureHeight = null;
protected readonly int plainWidth = 120;
protected readonly int plainHeight = 70;
protected readonly int plainHeight = 60;
public DrawingPlain(int speed, float weight, Color bodycolor)
{
Plain = new EntetyPlain(speed, weight, bodycolor);

View File

@ -26,7 +26,12 @@ namespace AirPlaneWithRadar
case "Простая карта":
map = new SimpleMap();
break;
case "Пользовательская карта №1":
map = new UserMap_BigBox();
break;
case "Пользовательская карта №2":
map = new UserMap_Colums();
break;
}
if (map != null)
{
@ -51,7 +56,7 @@ namespace AirPlaneWithRadar
{
DrawingObjectPlane plain = new(form.SelectedPlain);
if (_mapPlainsCollectionGeneric + plain)
if ((_mapPlainsCollectionGeneric + plain) >= 0)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapPlainsCollectionGeneric.ShowSet();

View File

@ -33,12 +33,12 @@ namespace AirPlaneWithRadar
_map = map;
}
public static bool operator +(MapWithSetPlainGeneric<T, U> map, T plain)
public static int operator +(MapWithSetPlainGeneric<T, U> map, T plain)
{
return map._setPlains.Insert(plain);
}
public static bool operator -(MapWithSetPlainGeneric<T, U> map, int position)
public static T operator -(MapWithSetPlainGeneric<T, U> map, int position)
{
return map._setPlains.Remove(position);
}
@ -103,7 +103,7 @@ namespace AirPlaneWithRadar
private void DrawBackground(Graphics g)
{
Brush BrushRazmetka = new SolidBrush(Color.DarkGray);
g.FillRectangle(BrushRazmetka, 0, 0, _pictureWidth, _pictureHeight);
Pen pen = new(Color.White, 5);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
@ -117,7 +117,42 @@ namespace AirPlaneWithRadar
}
private void DrawPlains(Graphics g)
{
int CountWidth = _pictureWidth / _placeSizeWidth;
int x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4;
int y = _placeSizeHeight / 4;
for (int k = 0; k < _setPlains.Count; k++)
{
if (_setPlains.Get(k) != null)
{
if ((k + 1) % CountWidth != 0 || k == 0)
{
_setPlains.Get(k)?.SetObject(x, y, _pictureWidth, _pictureHeight);
_setPlains.Get(k)?.DrawningObject(g);
x -= _placeSizeWidth;
}
else
{
_setPlains.Get(k)?.SetObject(x, y, _pictureWidth, _pictureHeight);
_setPlains.Get(k)?.DrawningObject(g);
x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4;
y += _placeSizeHeight;
}
}
if (_setPlains.Get(k) == null)
{
if ((k + 1) % CountWidth != 0 || k == 0)
x -= _placeSizeWidth;
else
{
x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4;
y += _placeSizeHeight;
}
}
}
}
}

View File

@ -16,18 +16,63 @@ namespace AirPlaneWithRadar
{
_places = new T[count];
}
public bool Insert(T plain)
public int Insert(T plain)
{
return true;
int i;
for (i = 0; i < Count; i++)
{
if (_places[i] == null)
{
for (int j = i; j >= 1; j--)
{
_places[j] = _places[j - 1];
}
public bool Insert(T plain, int position)
_places[0] = plain;
return i;
}
}
return -1;
}
public int Insert(T plain, int position)
{
return true;
if (position > Count || position < 0)
return -1;
if (_places[position] == null)
{
_places[position] = plain;
return position;
}
else
{
for (int i = position; i < Count; i++)
{
if (_places[i] == null)
{
for (int j = i; j >= position + 1; j--)
{
_places[j] = _places[j - 1];
}
_places[position] = plain;
return position;
}
}
}
return -1;
}
public bool Remove(int position)
public T Remove(int position)
{
return false;
T mid;
if (_places[position] != null && position < _places.Length)
{
mid = _places[position];
_places[position] = null;
return mid;
}
else
return null;
}
public T Get(int position)
{

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirPlaneWithRadar
{
internal class UserMap_BigBox : AbstractMap
{
Brush barrierColor = new SolidBrush(Color.DarkGray);
Brush roadColor = new SolidBrush(Color.Aqua);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void GenerateMap()
{
_map = new int[100, 100];
_size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1);
int sizeKub = 5;
int counter = 0;
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
_map[i, j] = _freeRoad;
}
} while (counter < 10)
{
Random rand = new Random();
int i = rand.Next(0, 100);
int j = rand.Next(0, 100);
if (i > _map.GetLength(0) - sizeKub || j > _map.GetLength(0) - sizeKub)
continue;
for (int iKub = i; iKub < i + sizeKub; iKub++)
{
for (int jKub = j; jKub < j + sizeKub; jKub++)
{
_map[iKub, jKub] = _barrier;
}
}
counter++;
}
}
}
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirPlaneWithRadar
{
internal class UserMap_Colums : AbstractMap
{
Brush barrierColor = new SolidBrush(Color.DarkGray);
Brush roadColor = new SolidBrush(Color.Aqua);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void GenerateMap()
{
_map = new int[100, 100];
_size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1);
int sizeHole = 30;
int counter = 0;
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
_map[i, j] = _freeRoad;
}
} while (counter < 3)
{
Random rand = new Random();
int iWall = rand.Next(0, 100);
int jWall = rand.Next(0, 100);
if (iWall > _map.GetLength(0) - sizeHole)
continue;
for (int i = 0; i < _map.GetLength(0); i++)
{
if (i < iWall || i > iWall + sizeHole)
_map[jWall, i] = _barrier;
}
counter++;
}
}
}
}