еще немножк

This commit is contained in:
devil_1nc 2022-10-11 11:45:41 +04:00
parent 8b95a84ef0
commit 6306f4c3b3
6 changed files with 188 additions and 61 deletions

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPlane
{
internal class AirfieldMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Black);
private readonly Brush lineColor = new SolidBrush(Color.Yellow);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.Gray);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
Point[] Triangle = new Point[3];
Triangle[0].X = i * (int)_size_x; Triangle[0].Y = j * (int)_size_y;
Triangle[1].X = i * (int)_size_x + 8; Triangle[1].Y = j * (int)_size_y - 5;
Triangle[2].X = i * (int)_size_x + 8; Triangle[2].Y = j * (int)_size_y + 5;
g.FillPolygon(barrierColor, Triangle);
}
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 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 < 30)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
}
}
}
}

View File

@ -30,6 +30,9 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxTools = new System.Windows.Forms.GroupBox(); this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRemovePlane = new System.Windows.Forms.Button(); this.buttonRemovePlane = new System.Windows.Forms.Button();
@ -38,9 +41,6 @@
this.buttonAddPlane = new System.Windows.Forms.Button(); this.buttonAddPlane = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox(); this.pictureBox = new System.Windows.Forms.PictureBox();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.groupBoxTools.SuspendLayout(); this.groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -65,6 +65,36 @@
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools"; this.groupBoxTools.Text = "Tools";
// //
// buttonRight
//
this.buttonRight.BackgroundImage = global::ProjectPlane.Properties.Resources.right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(135, 495);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(48, 47);
this.buttonRight.TabIndex = 9;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.BackgroundImage = global::ProjectPlane.Properties.Resources.down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(81, 495);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(48, 47);
this.buttonDown.TabIndex = 8;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.BackgroundImage = global::ProjectPlane.Properties.Resources.left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(27, 495);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(48, 47);
this.buttonLeft.TabIndex = 7;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUp // buttonUp
// //
this.buttonUp.BackgroundImage = global::ProjectPlane.Properties.Resources.up; this.buttonUp.BackgroundImage = global::ProjectPlane.Properties.Resources.up;
@ -129,7 +159,9 @@
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] { this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Simple map"}); "Simple map",
"Sky map",
"Airfield map"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32); this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23); this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
@ -145,36 +177,6 @@
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
// buttonLeft
//
this.buttonLeft.BackgroundImage = global::ProjectPlane.Properties.Resources.left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(27, 495);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(48, 47);
this.buttonLeft.TabIndex = 7;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.BackgroundImage = global::ProjectPlane.Properties.Resources.down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(81, 495);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(48, 47);
this.buttonDown.TabIndex = 8;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.BackgroundImage = global::ProjectPlane.Properties.Resources.right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(135, 495);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(48, 47);
this.buttonRight.TabIndex = 9;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// FormMapWithSetPlanes // FormMapWithSetPlanes
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);

View File

@ -37,7 +37,14 @@ namespace ProjectPlane
case "Simple map": case "Simple map":
map = new SimpleMap(); map = new SimpleMap();
break; break;
case "Sky map":
map = new SkyMap();
break;
case "Airfield map":
map = new AirfieldMap();
break;
} }
if (map != null) if (map != null)
{ {
_mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric<DrawingObject, AbstractMap>( _mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric<DrawingObject, AbstractMap>(
@ -63,7 +70,7 @@ namespace ProjectPlane
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
DrawingObject Plane = new(form.SelectedPlane); DrawingObject Plane = new(form.SelectedPlane);
if (_mapPlanesCollectionGeneric + Plane) if (_mapPlanesCollectionGeneric + Plane != -1)
{ {
MessageBox.Show("Object added"); MessageBox.Show("Object added");
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
@ -90,7 +97,7 @@ namespace ProjectPlane
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapPlanesCollectionGeneric - pos) if (_mapPlanesCollectionGeneric - pos is not null)
{ {
MessageBox.Show("Object removed"); MessageBox.Show("Object removed");
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();

View File

@ -58,8 +58,13 @@
private void buttonCreate_Click(object sender, EventArgs e) private void buttonCreate_Click(object sender, EventArgs e)
{ {
Random rand = new Random(); Random rand = new Random();
_plane = new DrawingPlane(rand.Next(200, 500), rand.Next(2000, 3000), Color color = Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256));
Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256))); ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_plane = new DrawingPlane(rand.Next(200, 500), rand.Next(2000, 3000), color);
SetData(); SetData();
Draw(); Draw();
} }
@ -76,9 +81,19 @@
private void buttonCreateModif_Click(object sender, EventArgs e) private void buttonCreateModif_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_plane = new DrawingWarPlane(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;
}
_plane = new DrawingWarPlane(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)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(); SetData();
Draw(); Draw();

View File

@ -55,7 +55,7 @@ namespace ProjectPlane
/// <param name="map"></param> /// <param name="map"></param>
/// <param name="plane"></param> /// <param name="plane"></param>
/// <returns></returns> /// <returns></returns>
public static bool operator +(MapWithSetPlanesGeneric<T, U> map, T plane) public static int operator +(MapWithSetPlanesGeneric<T, U> map, T plane)
{ {
return map._setPlanes.Insert(plane); return map._setPlanes.Insert(plane);
} }
@ -65,7 +65,7 @@ namespace ProjectPlane
/// <param name="map"></param> /// <param name="map"></param>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public static bool operator -(MapWithSetPlanesGeneric<T, U> map, int position) public static T operator -(MapWithSetPlanesGeneric<T, U> map, int position)
{ {
return map._setPlanes.Remove(position); return map._setPlanes.Remove(position);
} }
@ -145,11 +145,16 @@ namespace ProjectPlane
private void DrawBackground(Graphics g) private void DrawBackground(Graphics g)
{ {
Pen pen = new(Color.Black, 3); Pen pen = new(Color.Black, 3);
Pen pen2 = new(Color.Yellow, 8);
Brush grBrush = new SolidBrush(Color.Gray);
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, j * _placeSizeHeight);
g.FillRectangle(grBrush, i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth, _placeSizeHeight);
g.DrawLine(pen2, i * _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2);
} }
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
} }
@ -160,11 +165,21 @@ namespace ProjectPlane
/// <param name="g"></param> /// <param name="g"></param>
private void DrawPlanes(Graphics g) private void DrawPlanes(Graphics g)
{ {
int width = _pictureWidth / _placeSizeWidth;
int curWidth = 0;
int curHeight = 0;
for (int i = 0; i < _setPlanes.Count; i++) for (int i = 0; i < _setPlanes.Count; i++)
{ {
// TODO установка позиции _setPlanes.Get(i)?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
_setPlanes.Get(i)?.DrawingObject(g); _setPlanes.Get(i)?.DrawingObject(g);
} }
if (curWidth < width) curWidth++;
else
{
curWidth = 0;
curHeight++;
}
} }
} }
} }

View File

@ -29,10 +29,9 @@ namespace ProjectPlane
/// </summary> /// </summary>
/// <param name="plane">Добавляемый самолет</param> /// <param name="plane">Добавляемый самолет</param>
/// <returns></returns> /// <returns></returns>
public bool Insert(T plane) public int Insert(T plane)
{ {
// TODO вставка в начало набора return Insert(plane, 0);
return true;
} }
/// <summary> /// <summary>
/// Добавление объекта в набор на конкретную позицию /// Добавление объекта в набор на конкретную позицию
@ -40,26 +39,52 @@ namespace ProjectPlane
/// <param name="plane">Добавляемый самолет</param> /// <param name="plane">Добавляемый самолет</param>
/// <param name="position">Позиция</param> /// <param name="position">Позиция</param>
/// <returns></returns> /// <returns></returns>
public bool Insert(T plane, int position) public int Insert(T plane, int position)
{ {
// TODO проверка позиции bool isNull = false;
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то int nullElem = 0;
// проверка, что после вставляемого элемента в массиве есть пустой элемент if (position < 0 || position >= Count)
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента {
// TODO вставка по позиции return -1;
}
if (_places[position] == null)
{
_places[position] = plane;
return position;
}
for (int i = position + 1; i < Count; i ++)
{
if (_places[i] == null)
{
isNull = true;
nullElem = i;
break;
}
}
if (!isNull)
{
return -1;
}
for (int i = nullElem; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = plane; _places[position] = plane;
return true; return position;
} }
/// <summary> /// <summary>
/// Удаление объекта из набора с конкретной позиции /// Удаление объекта из набора с конкретной позиции
/// </summary> /// </summary>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public bool Remove(int position) public T Remove(int position)
{ {
// TODO проверка позиции if (position < 0 || position >= Count)
// TODO удаление объекта из массива, присовив элементу массива значение null {
return true; return null;
}
_places[position] = null;
return _places[position];
} }
/// <summary> /// <summary>
/// Получение объекта из набора по позиции /// Получение объекта из набора по позиции
@ -68,7 +93,10 @@ namespace ProjectPlane
/// <returns></returns> /// <returns></returns>
public T Get(int position) public T Get(int position)
{ {
// TODO проверка позиции if (position < 0 || position >= Count)
{
return null;
}
return _places[position]; return _places[position];
} }
} }