generic classes
This commit is contained in:
parent
ee7a0def18
commit
94bd87f67f
@ -32,12 +32,66 @@ namespace AirPlaneWithRadar
|
|||||||
}
|
}
|
||||||
public Bitmap MoveObject(Direction direction)
|
public Bitmap MoveObject(Direction direction)
|
||||||
{
|
{
|
||||||
// TODO проверка, что объект может переместится в требуемом направлении
|
|
||||||
if (true)
|
switch (direction)
|
||||||
{
|
{
|
||||||
_drawningObject.MoveObject(direction);
|
case Direction.Up:
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Left < i * _size_x && _drawningObject.GetCurrentPosition().Top > i * _size_x)||
|
||||||
|
(_drawningObject.GetCurrentPosition().Left < i * (_size_x+1) && _drawningObject.GetCurrentPosition().Top > i * (_size_x+1)))&&
|
||||||
|
j*(_size_y+1)< _drawningObject.GetCurrentPosition().Right && _drawningObject.GetCurrentPosition().Right - j * (_size_y + 1) <= _drawningObject.Step)
|
||||||
|
return DrawMapWithObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Direction.Down:
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Left < i * _size_x && _drawningObject.GetCurrentPosition().Top > i * _size_x) ||
|
||||||
|
(_drawningObject.GetCurrentPosition().Left < i * (_size_x + 1) && _drawningObject.GetCurrentPosition().Top > i * (_size_x + 1))) &&
|
||||||
|
j * _size_y > _drawningObject.GetCurrentPosition().Bottom && j * _size_y - _drawningObject.GetCurrentPosition().Bottom <= _drawningObject.Step)
|
||||||
|
return DrawMapWithObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Direction.Left:
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Right < j * _size_y && _drawningObject.GetCurrentPosition().Bottom > j * _size_y) ||
|
||||||
|
(_drawningObject.GetCurrentPosition().Right < j * (_size_y + 1) && _drawningObject.GetCurrentPosition().Bottom > j * (_size_y + 1))) &&
|
||||||
|
i * (_size_x+1)< _drawningObject.GetCurrentPosition().Left && _drawningObject.GetCurrentPosition().Left - i * (_size_x + 1) <= _drawningObject.Step)
|
||||||
|
return DrawMapWithObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Direction.Right:
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Right < j * _size_y && _drawningObject.GetCurrentPosition().Bottom > j * _size_y) ||
|
||||||
|
(_drawningObject.GetCurrentPosition().Right < j * (_size_y + 1) && _drawningObject.GetCurrentPosition().Bottom > j * (_size_y + 1))) &&
|
||||||
|
i * (_size_x ) > _drawningObject.GetCurrentPosition().Top && i * (_size_x ) - _drawningObject.GetCurrentPosition().Top <= _drawningObject.Step)
|
||||||
|
return DrawMapWithObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
_drawningObject.MoveObject(direction);
|
||||||
return DrawMapWithObject();
|
return DrawMapWithObject();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private bool SetObjectOnMap()
|
private bool SetObjectOnMap()
|
||||||
{
|
{
|
||||||
@ -48,7 +102,18 @@ namespace AirPlaneWithRadar
|
|||||||
int x = _random.Next(0, 10);
|
int x = _random.Next(0, 10);
|
||||||
int y = _random.Next(0, 10);
|
int y = _random.Next(0, 10);
|
||||||
_drawningObject.SetObject(x, y, _width, _height);
|
_drawningObject.SetObject(x, y, _width, _height);
|
||||||
// TODO првоерка, что объект не "накладывается" на закрытые участки
|
if(_drawningObject is DrawingObjectPlane )
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] == _barrier && _drawningObject.GetCurrentPosition().Left < i*_size_x && _drawningObject.GetCurrentPosition().Right < j*_size_y && _drawningObject.GetCurrentPosition().Top > i*_size_x && _drawningObject.GetCurrentPosition().Bottom > j*_size_y)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private Bitmap DrawMapWithObject()
|
private Bitmap DrawMapWithObject()
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AirPlaneWithRadar
|
namespace AirPlaneWithRadar
|
||||||
{
|
{
|
||||||
internal class DrawingObject : IDrawingObject
|
internal class DrawingObjectPlane : IDrawingObject
|
||||||
{
|
{
|
||||||
private DrawingPlain _plain;
|
private DrawingPlain _plain = null;
|
||||||
|
|
||||||
public DrawingObject(DrawingPlain plain)
|
public DrawingObjectPlane(DrawingPlain plain)
|
||||||
{
|
{
|
||||||
_plain = plain;
|
_plain = plain;
|
||||||
}
|
}
|
||||||
@ -19,14 +20,14 @@ namespace AirPlaneWithRadar
|
|||||||
|
|
||||||
public void DrawningObject(Graphics g)
|
public void DrawningObject(Graphics g)
|
||||||
{
|
{
|
||||||
//TODO
|
_plain?.DrawTransoprt(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||||
{
|
{
|
||||||
return _plain?.GetCurrentPosition() ?? default;
|
return _plain?.GetCurrentPosition() ?? default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveObject(Direction direction)
|
public void MoveObject(Direction direction)
|
||||||
{
|
{
|
||||||
_plain?.MoveTransport(direction);
|
_plain?.MoveTransport(direction);
|
@ -15,7 +15,7 @@ namespace AirPlaneWithRadar
|
|||||||
private int? pictureWidth = null;
|
private int? pictureWidth = null;
|
||||||
private int? pictureHeight = null;
|
private int? pictureHeight = null;
|
||||||
protected readonly int plainWidth = 120;
|
protected readonly int plainWidth = 120;
|
||||||
protected readonly int plainHeight = 70;
|
protected readonly int plainHeight = 80;
|
||||||
public DrawingPlain(int speed, float weight, Color bodycolor)
|
public DrawingPlain(int speed, float weight, Color bodycolor)
|
||||||
{
|
{
|
||||||
Plain = new EntetyPlain(speed, weight, bodycolor);
|
Plain = new EntetyPlain(speed, weight, bodycolor);
|
||||||
|
@ -9,7 +9,7 @@ namespace AirPlaneWithRadar
|
|||||||
{
|
{
|
||||||
internal class DrawingRadarPlane : DrawingPlain
|
internal class DrawingRadarPlane : DrawingPlain
|
||||||
{
|
{
|
||||||
public DrawingRadarPlane(int speed, float weight, Color bodyColor,Color dopColor, bool radar, bool oilBox) : base(speed, weight, bodyColor, 110, 60)
|
public DrawingRadarPlane(int speed, float weight, Color bodyColor,Color dopColor, bool radar, bool oilBox) : base(speed, weight, bodyColor, 120, 80)
|
||||||
{
|
{
|
||||||
Plain = new RadioPlane(speed, weight, bodyColor, dopColor, radar, oilBox);
|
Plain = new RadioPlane(speed, weight, bodyColor, dopColor, radar, oilBox);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
this.pictureBoxPlain.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.pictureBoxPlain.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.pictureBoxPlain.Location = new System.Drawing.Point(0, 0);
|
this.pictureBoxPlain.Location = new System.Drawing.Point(0, 0);
|
||||||
this.pictureBoxPlain.Name = "pictureBoxPlain";
|
this.pictureBoxPlain.Name = "pictureBoxPlain";
|
||||||
this.pictureBoxPlain.Size = new System.Drawing.Size(535, 292);
|
this.pictureBoxPlain.Size = new System.Drawing.Size(908, 470);
|
||||||
this.pictureBoxPlain.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
this.pictureBoxPlain.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
this.pictureBoxPlain.TabIndex = 0;
|
this.pictureBoxPlain.TabIndex = 0;
|
||||||
this.pictureBoxPlain.TabStop = false;
|
this.pictureBoxPlain.TabStop = false;
|
||||||
@ -61,9 +61,9 @@
|
|||||||
this.toolStripStatusLabelSpeed,
|
this.toolStripStatusLabelSpeed,
|
||||||
this.toolStripStatusLabelWeight,
|
this.toolStripStatusLabelWeight,
|
||||||
this.toolStripStatusLabelColor});
|
this.toolStripStatusLabelColor});
|
||||||
this.statusStrip.Location = new System.Drawing.Point(0, 292);
|
this.statusStrip.Location = new System.Drawing.Point(0, 470);
|
||||||
this.statusStrip.Name = "statusStrip";
|
this.statusStrip.Name = "statusStrip";
|
||||||
this.statusStrip.Size = new System.Drawing.Size(535, 26);
|
this.statusStrip.Size = new System.Drawing.Size(908, 26);
|
||||||
this.statusStrip.TabIndex = 1;
|
this.statusStrip.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// toolStripStatusLabelSpeed
|
// toolStripStatusLabelSpeed
|
||||||
@ -89,7 +89,7 @@
|
|||||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonUp.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.up;
|
this.buttonUp.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.up;
|
||||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonUp.Location = new System.Drawing.Point(383, 223);
|
this.buttonUp.Location = new System.Drawing.Point(756, 401);
|
||||||
this.buttonUp.Name = "buttonUp";
|
this.buttonUp.Name = "buttonUp";
|
||||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonUp.TabIndex = 3;
|
this.buttonUp.TabIndex = 3;
|
||||||
@ -102,7 +102,7 @@
|
|||||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonLeft.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.left;
|
this.buttonLeft.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.left;
|
||||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonLeft.Location = new System.Drawing.Point(347, 259);
|
this.buttonLeft.Location = new System.Drawing.Point(720, 437);
|
||||||
this.buttonLeft.Name = "buttonLeft";
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonLeft.TabIndex = 4;
|
this.buttonLeft.TabIndex = 4;
|
||||||
@ -115,7 +115,7 @@
|
|||||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonDown.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.down;
|
this.buttonDown.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.down;
|
||||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonDown.Location = new System.Drawing.Point(383, 259);
|
this.buttonDown.Location = new System.Drawing.Point(756, 437);
|
||||||
this.buttonDown.Name = "buttonDown";
|
this.buttonDown.Name = "buttonDown";
|
||||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonDown.TabIndex = 5;
|
this.buttonDown.TabIndex = 5;
|
||||||
@ -128,7 +128,7 @@
|
|||||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.buttonRight.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.right;
|
this.buttonRight.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.right;
|
||||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonRight.Location = new System.Drawing.Point(419, 259);
|
this.buttonRight.Location = new System.Drawing.Point(792, 437);
|
||||||
this.buttonRight.Name = "buttonRight";
|
this.buttonRight.Name = "buttonRight";
|
||||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonRight.TabIndex = 6;
|
this.buttonRight.TabIndex = 6;
|
||||||
@ -139,7 +139,7 @@
|
|||||||
// ButtonCreate
|
// ButtonCreate
|
||||||
//
|
//
|
||||||
this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
this.ButtonCreate.Location = new System.Drawing.Point(12, 259);
|
this.ButtonCreate.Location = new System.Drawing.Point(12, 437);
|
||||||
this.ButtonCreate.Name = "ButtonCreate";
|
this.ButtonCreate.Name = "ButtonCreate";
|
||||||
this.ButtonCreate.Size = new System.Drawing.Size(94, 29);
|
this.ButtonCreate.Size = new System.Drawing.Size(94, 29);
|
||||||
this.ButtonCreate.TabIndex = 7;
|
this.ButtonCreate.TabIndex = 7;
|
||||||
@ -149,7 +149,8 @@
|
|||||||
//
|
//
|
||||||
// buttonCreateModif
|
// buttonCreateModif
|
||||||
//
|
//
|
||||||
this.buttonCreateModif.Location = new System.Drawing.Point(125, 259);
|
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.buttonCreateModif.Location = new System.Drawing.Point(112, 437);
|
||||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||||
this.buttonCreateModif.Size = new System.Drawing.Size(134, 29);
|
this.buttonCreateModif.Size = new System.Drawing.Size(134, 29);
|
||||||
this.buttonCreateModif.TabIndex = 8;
|
this.buttonCreateModif.TabIndex = 8;
|
||||||
@ -159,12 +160,15 @@
|
|||||||
//
|
//
|
||||||
// comboBoxMap
|
// comboBoxMap
|
||||||
//
|
//
|
||||||
|
this.comboBoxMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
this.comboBoxMap.FormattingEnabled = true;
|
this.comboBoxMap.FormattingEnabled = true;
|
||||||
this.comboBoxMap.Items.AddRange(new object[] {
|
this.comboBoxMap.Items.AddRange(new object[] {
|
||||||
"Простая карта"});
|
"Простая карта",
|
||||||
|
"Пользовательская карта №1",
|
||||||
|
"Пользовательская карта №2"});
|
||||||
this.comboBoxMap.Location = new System.Drawing.Point(24, 12);
|
this.comboBoxMap.Location = new System.Drawing.Point(24, 12);
|
||||||
this.comboBoxMap.Name = "comboBoxMap";
|
this.comboBoxMap.Name = "comboBoxMap";
|
||||||
this.comboBoxMap.Size = new System.Drawing.Size(151, 28);
|
this.comboBoxMap.Size = new System.Drawing.Size(188, 28);
|
||||||
this.comboBoxMap.TabIndex = 9;
|
this.comboBoxMap.TabIndex = 9;
|
||||||
this.comboBoxMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxMap_SelectedIndexChanged);
|
this.comboBoxMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxMap_SelectedIndexChanged);
|
||||||
//
|
//
|
||||||
@ -172,7 +176,7 @@
|
|||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(535, 318);
|
this.ClientSize = new System.Drawing.Size(908, 496);
|
||||||
this.Controls.Add(this.comboBoxMap);
|
this.Controls.Add(this.comboBoxMap);
|
||||||
this.Controls.Add(this.buttonCreateModif);
|
this.Controls.Add(this.buttonCreateModif);
|
||||||
this.Controls.Add(this.ButtonCreate);
|
this.Controls.Add(this.ButtonCreate);
|
||||||
|
@ -23,7 +23,7 @@ namespace AirPlaneWithRadar
|
|||||||
toolStripStatusLabelSpeed.Text = $"Скорость: {plain.Plain.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Скорость: {plain.Plain.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Вес: {plain.Plain.Weight}";
|
toolStripStatusLabelWeight.Text = $"Вес: {plain.Plain.Weight}";
|
||||||
toolStripStatusLabelColor.Text = $"Цвет: {plain.Plain.BodyColor.Name}";
|
toolStripStatusLabelColor.Text = $"Цвет: {plain.Plain.BodyColor.Name}";
|
||||||
pictureBoxPlain.Image = _abstractMap.CreateMap(pictureBoxPlain.Width, pictureBoxPlain.Height,new DrawingObject(plain)) ;
|
pictureBoxPlain.Image = _abstractMap.CreateMap(pictureBoxPlain.Width, pictureBoxPlain.Height,new DrawingObjectPlane(plain)) ;
|
||||||
}
|
}
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -73,6 +73,13 @@ namespace AirPlaneWithRadar
|
|||||||
case "Простая карта":
|
case "Простая карта":
|
||||||
_abstractMap = new SimpleMap();
|
_abstractMap = new SimpleMap();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "Пользовательская карта №1":
|
||||||
|
_abstractMap = new UserMap_BigBox();
|
||||||
|
break;
|
||||||
|
case "Пользовательская карта №2":
|
||||||
|
_abstractMap = new UserMap_Colums();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,8 @@ namespace AirPlaneWithRadar
|
|||||||
void MoveObject(Direction direction);
|
void MoveObject(Direction direction);
|
||||||
|
|
||||||
void DrawningObject(Graphics g);
|
void DrawningObject(Graphics g);
|
||||||
|
|
||||||
|
|
||||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
126
AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs
Normal file
126
AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirPlaneWithRadar
|
||||||
|
{
|
||||||
|
internal class MapWithSetPlainGeneric<T, U>
|
||||||
|
where T : class, IDrawingObject
|
||||||
|
where U : AbstractMap
|
||||||
|
{
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
private readonly int _placeSizeWidth = 180;
|
||||||
|
|
||||||
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
|
||||||
|
private readonly SetPlaneGeneric<T> _setPlains;
|
||||||
|
|
||||||
|
private readonly U _map;
|
||||||
|
|
||||||
|
public MapWithSetPlainGeneric(int picWidth, int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setPlains = new SetPlaneGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator +(MapWithSetPlainGeneric<T, U> map, T car)
|
||||||
|
{
|
||||||
|
return map._setPlains.Insert(car);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator -(MapWithSetPlainGeneric<T, U> map, int position)
|
||||||
|
{
|
||||||
|
return map._setPlains.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap ShowSet()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawPlains(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
for (int i = 0; i < _setPlains.Count; i++)
|
||||||
|
{
|
||||||
|
var car = _setPlains.Get(i);
|
||||||
|
if (car != null)
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
return _map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return new(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setPlains.Count - 1;
|
||||||
|
for (int i = 0; i < _setPlains.Count; i++)
|
||||||
|
{
|
||||||
|
if (_setPlains.Get(i) == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var car = _setPlains.Get(j);
|
||||||
|
if (car != null)
|
||||||
|
{
|
||||||
|
_setPlains.Insert(car, i);
|
||||||
|
_setPlains.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
|
||||||
|
Pen pen = new(Color.White, 5);
|
||||||
|
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, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DrawPlains(Graphics g)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int i = 0; i < _setPlains.Count; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
_setPlains.Get(i)?.DrawningObject(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs
Normal file
41
AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirPlaneWithRadar
|
||||||
|
{
|
||||||
|
internal class SetPlaneGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
private readonly T[] _places;
|
||||||
|
public int Count => _places.Length;
|
||||||
|
public SetPlaneGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T[count];
|
||||||
|
}
|
||||||
|
public bool Insert(T plain)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Insert(T plain, int position)
|
||||||
|
{
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public T Get(int position)
|
||||||
|
{
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,7 @@ namespace AirPlaneWithRadar
|
|||||||
internal class SimpleMap : AbstractMap
|
internal class SimpleMap : AbstractMap
|
||||||
{
|
{
|
||||||
Brush barrierColor = new SolidBrush(Color.DarkGray);
|
Brush barrierColor = new SolidBrush(Color.DarkGray);
|
||||||
Brush roadColor = new SolidBrush(Color.Blue);
|
Brush roadColor = new SolidBrush(Color.Aqua);
|
||||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
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));
|
g.FillRectangle(barrierColor,i*_size_x,j*_size_y,i*(_size_x+1),j*(_size_y+1));
|
||||||
|
55
AirPlaneWithRadar/AirPlaneWithRadar/UserMap_BigBox.cs
Normal file
55
AirPlaneWithRadar/AirPlaneWithRadar/UserMap_BigBox.cs
Normal 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++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
AirPlaneWithRadar/AirPlaneWithRadar/UserMap_Colums.cs
Normal file
54
AirPlaneWithRadar/AirPlaneWithRadar/UserMap_Colums.cs
Normal 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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user