Dolgov D.A. Lab Work 3 #3

Merged
eegov merged 6 commits from LabWork03 into LabWork02 2022-10-14 09:45:51 +04:00
6 changed files with 188 additions and 61 deletions
Showing only changes of commit 6306f4c3b3 - Show all commits

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()
{
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.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRemovePlane = new System.Windows.Forms.Button();
@ -38,9 +41,6 @@
this.buttonAddPlane = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
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();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
@ -65,6 +65,36 @@
this.groupBoxTools.TabStop = false;
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
//
this.buttonUp.BackgroundImage = global::ProjectPlane.Properties.Resources.up;
@ -129,7 +159,9 @@
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
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.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
@ -145,36 +177,6 @@
this.pictureBox.TabIndex = 1;
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);

View File

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

View File

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

View File

@ -55,7 +55,7 @@ namespace ProjectPlane
/// <param name="map"></param>
/// <param name="plane"></param>
/// <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);
}
@ -65,7 +65,7 @@ namespace ProjectPlane
/// <param name="map"></param>
/// <param name="position"></param>
/// <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);
}
@ -145,11 +145,16 @@ namespace ProjectPlane
private void DrawBackground(Graphics g)
{
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 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);
}
@ -160,11 +165,21 @@ namespace ProjectPlane
/// <param name="g"></param>
private void DrawPlanes(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int curWidth = 0;
int curHeight = 0;
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);
}
if (curWidth < width) curWidth++;
else
{
curWidth = 0;
curHeight++;
}
}
}
}

View File

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