Создание двух дополнительных реализаций абстрактного класса.
This commit is contained in:
parent
fc7c4b87fb
commit
bc0803532e
@ -19,7 +19,7 @@ namespace Airbus
|
||||
|
||||
void IDrawningObject.DrawningObject(Graphics g)
|
||||
{
|
||||
//ДОДУМАТЬ ЛОГИКУ ЭТОГО МЕТОДА
|
||||
_airbus.DrawTransport(g);
|
||||
}
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
|
4
Airbus/Airbus/FormMap.Designer.cs
generated
4
Airbus/Airbus/FormMap.Designer.cs
generated
@ -160,7 +160,9 @@
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта"});
|
||||
"Простая карта",
|
||||
"Буря в пустыне",
|
||||
"Звёздные войны"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28);
|
||||
|
@ -13,11 +13,14 @@ namespace Airbus
|
||||
public partial class FormMap : Form
|
||||
{
|
||||
private AbstractMap _abstractMap;
|
||||
private SecondVersionAbstractMap _secondAbstractMap;
|
||||
private ThirdVersionAbstractMap _thirdVersionAbstractMap;
|
||||
|
||||
public FormMap()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractMap = new SimpleMap();
|
||||
_secondAbstractMap = new SecondSimpleMap();
|
||||
}
|
||||
|
||||
//заполнение информации по объекту
|
||||
@ -26,9 +29,23 @@ namespace Airbus
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {airbus.Airbus?.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {airbus.Airbus?.Weight}";
|
||||
toolStripStatusLabelCorpusColor.Text = $"Цвет: {airbus.Airbus?.CorpusColor.Name}";
|
||||
|
||||
if (comboBoxSelectorMap.Text == "Простая карта")
|
||||
{
|
||||
pictureBoxAirbus.Image = _abstractMap.CreateMap(pictureBoxAirbus.Width, pictureBoxAirbus.Height,
|
||||
new DrawningObjectAirbus(airbus));
|
||||
}
|
||||
if (comboBoxSelectorMap.Text == "Буря в пустыне")
|
||||
{
|
||||
pictureBoxAirbus.Image = _secondAbstractMap.CreateMap(pictureBoxAirbus.Width, pictureBoxAirbus.Height,
|
||||
new DrawningObjectAirbus(airbus));
|
||||
}
|
||||
if (comboBoxSelectorMap.Text == "Звёздные войны")
|
||||
{
|
||||
pictureBoxAirbus.Image = _thirdVersionAbstractMap.CreateMap(pictureBoxAirbus.Width, pictureBoxAirbus.Height,
|
||||
new DrawningObjectAirbus(airbus));
|
||||
}
|
||||
}
|
||||
|
||||
//обработка нажатия кнопки "Создать"
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
@ -59,8 +76,20 @@ namespace Airbus
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
|
||||
if (comboBoxSelectorMap.Text == "Простая карта")
|
||||
{
|
||||
pictureBoxAirbus.Image = _abstractMap?.MoveObject(dir);
|
||||
}
|
||||
if (comboBoxSelectorMap.Text == "Буря в пустыне")
|
||||
{
|
||||
pictureBoxAirbus.Image = _secondAbstractMap?.MoveObject(dir);
|
||||
}
|
||||
if (comboBoxSelectorMap.Text == "Звёздные войны")
|
||||
{
|
||||
pictureBoxAirbus.Image = _thirdVersionAbstractMap?.MoveObject(dir);
|
||||
}
|
||||
}
|
||||
|
||||
//обработка нажития кнопки "Модификация"
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
@ -80,6 +109,12 @@ namespace Airbus
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Буря в пустыне":
|
||||
_secondAbstractMap = new SecondSimpleMap();
|
||||
break;
|
||||
case "Звёздные войны":
|
||||
_thirdVersionAbstractMap = new ThirdSimpleMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
60
Airbus/Airbus/SecondSimpleMap.cs
Normal file
60
Airbus/Airbus/SecondSimpleMap.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal class SecondSimpleMap : SecondVersionAbstractMap
|
||||
{
|
||||
//цвет закрытого участка
|
||||
Brush barriedColor = new SolidBrush(Color.DarkRed);
|
||||
|
||||
//цвет открытого участка
|
||||
Brush roadColor = new SolidBrush(Color.DarkOrange);
|
||||
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
//float _weightLength = i * (_size_x + 1) - i * _size_x;
|
||||
//float _heightLength = j * (_size_y + 1) - j * _size_y;
|
||||
|
||||
g.FillEllipse(barriedColor, i * _size_x, j * _size_y, 10, 10);
|
||||
}
|
||||
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
float _weightLength = i * (_size_x + 1);
|
||||
float _heightLength = j * (_size_y + 1);
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _weightLength, _heightLength);
|
||||
}
|
||||
|
||||
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 < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
95
Airbus/Airbus/SecondVersionAbstractMap.cs
Normal file
95
Airbus/Airbus/SecondVersionAbstractMap.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal abstract class SecondVersionAbstractMap
|
||||
{
|
||||
private IDrawningObject _drawningObject = null;
|
||||
protected int[,] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected readonly Random _random = new();
|
||||
protected readonly int _freeRoad = 0;
|
||||
protected readonly int _barrier = 1;
|
||||
|
||||
public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawningObject = drawningObject;
|
||||
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
//Сделать проверку на то, что объект может поместиться в выбранном направлении
|
||||
if (true)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int x = _random.Next(0, 10);
|
||||
int y = _random.Next(0, 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
//Сделать проверку на то, то объект не "накладывается" на закрытые участки
|
||||
return true;
|
||||
}
|
||||
|
||||
private Bitmap DrawMapWithObject()
|
||||
{
|
||||
Bitmap bmp = new(_width, _height);
|
||||
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i, j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i, j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_drawningObject.DrawningObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ namespace Airbus
|
||||
{
|
||||
internal class SimpleMap : AbstractMap
|
||||
{
|
||||
//цвет закрытого уастка
|
||||
//цвет закрытого участка
|
||||
Brush barriedColor = new SolidBrush(Color.Black);
|
||||
|
||||
//цвет открытого участка
|
||||
|
63
Airbus/Airbus/ThirdSimpleMap.cs
Normal file
63
Airbus/Airbus/ThirdSimpleMap.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal class ThirdSimpleMap : ThirdVersionAbstractMap
|
||||
{
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
//цвет выстрела из лазера
|
||||
Color randomColor = new Color();
|
||||
|
||||
//цвет закрытого участка
|
||||
Brush barriedColor;
|
||||
|
||||
//цвет открытого участка
|
||||
Brush roadColor = new SolidBrush(Color.DarkBlue);
|
||||
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
|
||||
barriedColor = new SolidBrush(randomColor);
|
||||
g.FillRectangle(barriedColor, i * _size_x, j * _size_y, i * (_size_x + 1) + 10, 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 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 < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
95
Airbus/Airbus/ThirdVersionAbstractMap.cs
Normal file
95
Airbus/Airbus/ThirdVersionAbstractMap.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal abstract class ThirdVersionAbstractMap
|
||||
{
|
||||
private IDrawningObject _drawningObject = null;
|
||||
protected int[,] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected readonly Random _random = new();
|
||||
protected readonly int _freeRoad = 0;
|
||||
protected readonly int _barrier = 1;
|
||||
|
||||
public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawningObject = drawningObject;
|
||||
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
//Сделать проверку на то, что объект может поместиться в выбранном направлении
|
||||
if (true)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int x = _random.Next(0, 10);
|
||||
int y = _random.Next(0, 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
//Сделать проверку на то, то объект не "накладывается" на закрытые участки
|
||||
return true;
|
||||
}
|
||||
|
||||
private Bitmap DrawMapWithObject()
|
||||
{
|
||||
Bitmap bmp = new(_width, _height);
|
||||
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i, j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i, j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_drawningObject.DrawningObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user