lab_2
This commit is contained in:
parent
33a595e4b2
commit
f051754b49
135
Stormtrooper/Stormtrooper/AbstractMap.cs
Normal file
135
Stormtrooper/Stormtrooper/AbstractMap.cs
Normal file
@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
{
|
||||
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;
|
||||
|
||||
private bool CheckEnoughPlace(float x, float y)
|
||||
{
|
||||
int right = Convert.ToInt32((_drawningObject.GetCurrentPosition().Right + x) / _size_x) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Right + x) / _size_x) : 0;
|
||||
int left = Convert.ToInt32((_drawningObject.GetCurrentPosition().Left + x) / _size_x) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Left + x) / _size_x) : 0;
|
||||
int up = Convert.ToInt32((_drawningObject.GetCurrentPosition().Top + y) / _size_y) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Top + y) / _size_y) : 0;
|
||||
int down = Convert.ToInt32((_drawningObject.GetCurrentPosition().Bottom + y) / _size_y) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Bottom + y) / _size_y) : 0;
|
||||
for (int i = left; i <= right; i++)
|
||||
{
|
||||
for (int j = up; j <= down; j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// TODO проверка, что объект может переместится в требуемом направлении
|
||||
bool place = false;
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Up:
|
||||
place = CheckEnoughPlace(0, _drawningObject.Step * -1);
|
||||
break;
|
||||
case Direction.Down:
|
||||
place = CheckEnoughPlace(0, _drawningObject.Step);
|
||||
break;
|
||||
case Direction.Left:
|
||||
place = CheckEnoughPlace(_drawningObject.Step * -1, 0);
|
||||
break;
|
||||
case Direction.Right:
|
||||
place = CheckEnoughPlace(_drawningObject.Step, 0);
|
||||
break;
|
||||
}
|
||||
if (place)
|
||||
{
|
||||
_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);
|
||||
// TODO првоерка, что объект не "накладывается" на закрытые участки
|
||||
while (!CheckEnoughPlace(0, 0))
|
||||
{
|
||||
x += 10;
|
||||
if (x >= _width)
|
||||
{
|
||||
if (y <= _height)
|
||||
{
|
||||
y += 10;
|
||||
x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_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,6 +8,7 @@ namespace Stormtrooper
|
||||
{
|
||||
internal enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
|
35
Stormtrooper/Stormtrooper/DrawningObject.cs
Normal file
35
Stormtrooper/Stormtrooper/DrawningObject.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class DrawningObjectStormtrooper : IDrawningObject
|
||||
{
|
||||
private DrowningStormtrooper _stormtrooper = null;
|
||||
public DrawningObjectStormtrooper(DrowningStormtrooper stormtrooper)
|
||||
{
|
||||
_stormtrooper = stormtrooper;
|
||||
}
|
||||
public float Step => _stormtrooper?.Stormtrooper?.Step ?? 0;
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _stormtrooper?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_stormtrooper?.MoveTransport(direction);
|
||||
}
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_stormtrooper.SetPosition(x, y, width, height);
|
||||
}
|
||||
public void DrawningObject(Graphics g)
|
||||
{
|
||||
_stormtrooper?.DrawTransport(g);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -8,15 +8,18 @@ namespace Stormtrooper
|
||||
{
|
||||
internal class DrowningStormtrooper
|
||||
{
|
||||
public EntityStormtrooper Stormtrooper { private set; get; }
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityStormtrooper Stormtrooper { protected set; get; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки автомобиля
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки автомобиля
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -39,11 +42,17 @@ namespace Stormtrooper
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrowningStormtrooper(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Stormtrooper = new EntityStormtrooper();
|
||||
Stormtrooper.Init(speed, weight, bodyColor);
|
||||
Stormtrooper = new EntityStormtrooper(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrowningStormtrooper(int speed, float weight, Color bodyColor, int StormtrooperWidth, int StormtrooperHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_stormtrooperWidth = StormtrooperWidth;
|
||||
_stormtrooperHeight = StormtrooperHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции автомобиля
|
||||
/// </summary>
|
||||
@ -53,7 +62,7 @@ namespace Stormtrooper
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if(x > 0 && y > 0 && width >= _stormtrooperWidth && height >= _stormtrooperHeight && x + _stormtrooperWidth < width && y + _stormtrooperHeight < height)
|
||||
if(x >= 0 && y >= 0 && width >= x + _stormtrooperWidth && height >= y + _stormtrooperHeight)
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
@ -109,7 +118,7 @@ namespace Stormtrooper
|
||||
/// Отрисовка автомобиля
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
@ -198,22 +207,7 @@ namespace Stormtrooper
|
||||
|
||||
g.FillPolygon(Brushes.Black, all_stoormtrooper);
|
||||
|
||||
/*g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY + 30, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 70, _startPosY, 20, 20);
|
||||
g.DrawEllipse(pen, _startPosX + 70, _startPosY + 30, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX - 1, _startPosY + 10, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX + 80, _startPosY + 10, 10, 30);
|
||||
g.DrawRectangle(pen, _startPosX + 10, _startPosY - 1, 70, 52);
|
||||
//задние фары
|
||||
Brush brRed = new SolidBrush(Color.Red);
|
||||
g.FillEllipse(brRed, _startPosX, _startPosY, 20, 20);
|
||||
g.FillEllipse(brRed, _startPosX, _startPosY + 30, 20, 20);
|
||||
//передние фары
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
g.FillEllipse(brYellow, _startPosX + 70, _startPosY, 20, 20);
|
||||
g.FillEllipse(brYellow, _startPosX + 70, _startPosY + 30, 20, 20);*/
|
||||
//кузов
|
||||
|
||||
Brush br = new SolidBrush(Stormtrooper?.BodyColor ?? Color.Black);
|
||||
point1 = new PointF(_startPosX + 30, _startPosY + 50);
|
||||
point2 = new PointF(_startPosX + 40, _startPosY + 10);
|
||||
@ -249,19 +243,7 @@ namespace Stormtrooper
|
||||
g.FillPolygon(Brushes.Brown, cabin);
|
||||
|
||||
|
||||
/*g.FillRectangle(br, _startPosX, _startPosY + 10, 10, 30);
|
||||
g.FillRectangle(br, _startPosX + 80, _startPosY + 10, 10, 30);
|
||||
g.FillRectangle(br, _startPosX + 10, _startPosY, 70, 50);
|
||||
//стекла
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(brBlue, _startPosX + 60, _startPosY + 5, 5, 40);
|
||||
g.FillRectangle(brBlue, _startPosX + 20, _startPosY + 5, 5, 40);
|
||||
g.FillRectangle(brBlue, _startPosX + 25, _startPosY + 3, 35, 2);
|
||||
g.FillRectangle(brBlue, _startPosX + 25, _startPosY + 46, 35, 2);
|
||||
//выделяем рамкой крышу
|
||||
g.DrawRectangle(pen, _startPosX + 25, _startPosY + 5, 35, 40);
|
||||
g.DrawRectangle(pen, _startPosX + 65, _startPosY + 10, 25, 30);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY + 10, 15, 30);*/
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Смена границ формы отрисовки
|
||||
@ -287,6 +269,9 @@ namespace Stormtrooper
|
||||
_startPosY = _pictureHeight.Value - _stormtrooperHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _stormtrooperWidth, _startPosY + _stormtrooperHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
146
Stormtrooper/Stormtrooper/DrowningSuperStormtrooper.cs
Normal file
146
Stormtrooper/Stormtrooper/DrowningSuperStormtrooper.cs
Normal file
@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class DrowningSuperStormtrooper : DrowningStormtrooper
|
||||
{
|
||||
public DrowningSuperStormtrooper(int speed, float weight, Color bodyColor, Color dopColor, bool bombs, bool rockets, bool sportLine) : base(speed, weight, bodyColor, 90, 120)
|
||||
{
|
||||
Stormtrooper = new EntitySuperStormtrooper(speed, weight, bodyColor, dopColor, bombs, rockets, sportLine);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Stormtrooper is not EntitySuperStormtrooper superStormtrooper)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Brush redBrush = new SolidBrush(Color.Red);
|
||||
Brush dopBrush = new SolidBrush(superStormtrooper.DopColor);
|
||||
|
||||
if (superStormtrooper.Bombs)
|
||||
{
|
||||
g.FillEllipse(dopBrush, _startPosX + 55, _startPosY + 50, 10, 10);
|
||||
g.FillEllipse(dopBrush, _startPosX + 55, _startPosY + 70, 10, 10);
|
||||
|
||||
PointF point1 = new PointF(_startPosX + 45, _startPosY + 50);
|
||||
PointF point2 = new PointF(_startPosX + 40, _startPosY + 50);
|
||||
PointF point3 = new PointF(_startPosX + 35, _startPosY + 45);
|
||||
PointF point4 = new PointF(_startPosX + 30, _startPosY + 45);
|
||||
PointF point5 = new PointF(_startPosX + 35, _startPosY + 50);
|
||||
PointF point6 = new PointF(_startPosX + 35, _startPosY + 55);
|
||||
PointF point7 = new PointF(_startPosX + 40, _startPosY + 55);
|
||||
PointF point8 = new PointF(_startPosX + 45, _startPosY + 50);
|
||||
|
||||
PointF[] first_bomb =
|
||||
{
|
||||
point1,
|
||||
point2,
|
||||
point3,
|
||||
point4,
|
||||
point5,
|
||||
point6,
|
||||
point7,
|
||||
point8,
|
||||
};
|
||||
g.FillPolygon(dopBrush, first_bomb);
|
||||
|
||||
PointF point9 = new PointF(_startPosX + 45, _startPosY + 80);
|
||||
PointF point10 = new PointF(_startPosX + 40, _startPosY + 75);
|
||||
PointF point11 = new PointF(_startPosX + 35, _startPosY + 75);
|
||||
PointF point12 = new PointF(_startPosX + 35, _startPosY + 80);
|
||||
PointF point13 = new PointF(_startPosX + 30, _startPosY + 85);
|
||||
PointF point14 = new PointF(_startPosX + 35, _startPosY + 85);
|
||||
PointF point15 = new PointF(_startPosX + 40, _startPosY + 80);
|
||||
PointF point16 = new PointF(_startPosX + 45, _startPosY + 80);
|
||||
PointF[] second_bomb =
|
||||
{
|
||||
point9,
|
||||
point10,
|
||||
point11,
|
||||
point12,
|
||||
point13,
|
||||
point14,
|
||||
point15,
|
||||
point16,
|
||||
};
|
||||
g.FillPolygon(dopBrush, second_bomb);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
|
||||
if (superStormtrooper.Rockets)
|
||||
{
|
||||
PointF point1 = new PointF(_startPosX + 20, _startPosY + 20);
|
||||
PointF point2 = new PointF(_startPosX + 30, _startPosY + 20);
|
||||
PointF point3 = new PointF(_startPosX + 33, _startPosY + 22);
|
||||
PointF point4 = new PointF(_startPosX + 55, _startPosY + 22);
|
||||
PointF point5 = new PointF(_startPosX + 60, _startPosY + 25);
|
||||
PointF point6 = new PointF(_startPosX + 55, _startPosY + 28);
|
||||
PointF point7 = new PointF(_startPosX + 33, _startPosY + 28);
|
||||
PointF point8 = new PointF(_startPosX + 30, _startPosY + 30);
|
||||
PointF point9 = new PointF(_startPosX + 20, _startPosY + 30);
|
||||
PointF point10 = new PointF(_startPosX + 25, _startPosY + 25);
|
||||
PointF point11 = new PointF(_startPosX + 20, _startPosY + 20);
|
||||
|
||||
PointF[] first_rocket =
|
||||
{
|
||||
point1,
|
||||
point2,
|
||||
point3,
|
||||
point4,
|
||||
point5,
|
||||
point6,
|
||||
point7,
|
||||
point8,
|
||||
point9,
|
||||
point10,
|
||||
point11
|
||||
};
|
||||
g.FillPolygon(redBrush, first_rocket);
|
||||
|
||||
PointF point12 = new PointF(_startPosX + 20, _startPosY + 90);
|
||||
PointF point13 = new PointF(_startPosX + 30, _startPosY + 90);
|
||||
PointF point14 = new PointF(_startPosX + 33, _startPosY + 92);
|
||||
PointF point15 = new PointF(_startPosX + 55, _startPosY + 92);
|
||||
PointF point16 = new PointF(_startPosX + 60, _startPosY + 95);
|
||||
PointF point17 = new PointF(_startPosX + 55, _startPosY + 98);
|
||||
PointF point18 = new PointF(_startPosX + 33, _startPosY + 98);
|
||||
PointF point19 = new PointF(_startPosX + 30, _startPosY + 100);
|
||||
PointF point20 = new PointF(_startPosX + 20, _startPosY + 100);
|
||||
PointF point21 = new PointF(_startPosX + 25, _startPosY + 95);
|
||||
PointF point22 = new PointF(_startPosX + 20, _startPosY + 90);
|
||||
|
||||
PointF[] second_rocket =
|
||||
{
|
||||
point12,
|
||||
point13,
|
||||
point14,
|
||||
point15,
|
||||
point16,
|
||||
point17,
|
||||
point18,
|
||||
point19,
|
||||
point20,
|
||||
point21,
|
||||
point22
|
||||
};
|
||||
g.FillPolygon(redBrush, second_rocket);
|
||||
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -28,11 +28,11 @@ namespace Stormtrooper
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityStormtrooper(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(500, 1500) : speed;
|
||||
Weight = weight <= 0 ? rnd.Next(4, 7) : weight;
|
||||
Speed = speed <= 0 ? rnd.Next(5, 30) : speed;
|
||||
Weight = weight <= 0 ? rnd.Next(30, 100) : weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
|
44
Stormtrooper/Stormtrooper/EntitySuperStormtrooper.cs
Normal file
44
Stormtrooper/Stormtrooper/EntitySuperStormtrooper.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class EntitySuperStormtrooper : EntityStormtrooper
|
||||
{
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия обвеса
|
||||
/// </summary>
|
||||
public bool Bombs { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия антикрыла
|
||||
/// </summary>
|
||||
public bool Rockets { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool SportLine { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bombs">Признак наличия бомб</param>
|
||||
/// <param name="rockets">Признак наличия рокет</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
|
||||
public EntitySuperStormtrooper(int speed, float weight, Color bodyColor, Color dopColor, bool bombs, bool rockets, bool sportLine) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Bombs = bombs;
|
||||
Rockets = rockets;
|
||||
SportLine = sportLine;
|
||||
}
|
||||
}
|
||||
}
|
208
Stormtrooper/Stormtrooper/FormMap.Designer.cs
generated
Normal file
208
Stormtrooper/Stormtrooper/FormMap.Designer.cs
generated
Normal file
@ -0,0 +1,208 @@
|
||||
namespace Stormtrooper
|
||||
{
|
||||
partial class FormMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxStormtrooper = new System.Windows.Forms.PictureBox();
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxStormtrooper)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxStormtrooper
|
||||
//
|
||||
this.pictureBoxStormtrooper.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxStormtrooper.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxStormtrooper.Name = "pictureBoxStormtrooper";
|
||||
this.pictureBoxStormtrooper.Size = new System.Drawing.Size(800, 424);
|
||||
this.pictureBoxStormtrooper.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxStormtrooper.TabIndex = 0;
|
||||
this.pictureBoxStormtrooper.TabStop = false;
|
||||
//
|
||||
// statusStrip1
|
||||
//
|
||||
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelBodyColor});
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 424);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Size = new System.Drawing.Size(800, 26);
|
||||
this.statusStrip1.TabIndex = 1;
|
||||
this.statusStrip1.Text = "statusStrip1";
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20);
|
||||
this.toolStripStatusLabelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20);
|
||||
this.toolStripStatusLabelWeight.Text = "Вес:";
|
||||
//
|
||||
// toolStripStatusLabelBodyColor
|
||||
//
|
||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(31, 364);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Create";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(713, 328);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 3;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(713, 364);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 4;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(677, 365);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 5;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(749, 364);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 6;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(150, 364);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(129, 29);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
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(31, 12);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 8;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
|
||||
//
|
||||
// FormMap
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.pictureBoxStormtrooper);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Name = "FormMap";
|
||||
this.Text = "FormMap";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxStormtrooper)).EndInit();
|
||||
this.statusStrip1.ResumeLayout(false);
|
||||
this.statusStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxStormtrooper;
|
||||
private StatusStrip statusStrip1;
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private Button buttonCreate;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateModif;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
}
|
||||
}
|
106
Stormtrooper/Stormtrooper/FormMap.cs
Normal file
106
Stormtrooper/Stormtrooper/FormMap.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
public partial class FormMap : Form
|
||||
{
|
||||
private AbstractMap _abstractMap;
|
||||
public FormMap()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение информации по объекту
|
||||
/// </summary>
|
||||
/// <param name="car"></param>
|
||||
private void SetData(DrowningStormtrooper car)
|
||||
{
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {car.Stormtrooper.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {car.Stormtrooper.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет:{ car.Stormtrooper.BodyColor.Name}";
|
||||
pictureBoxStormtrooper.Image = _abstractMap.CreateMap(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height, new DrawningObjectStormtrooper(car));
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var car = new DrowningStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
SetData(car);
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение размеров формы
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBoxStormtrooper.Image = _abstractMap?.MoveObject(dir);
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Модификация"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var car = new DrowningSuperStormtrooper(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)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData(car);
|
||||
}
|
||||
/// <summary>
|
||||
/// Смена карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender,
|
||||
EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
{
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Своя карта":
|
||||
_abstractMap = new MyMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
63
Stormtrooper/Stormtrooper/FormMap.resx
Normal file
63
Stormtrooper/Stormtrooper/FormMap.resx
Normal file
@ -0,0 +1,63 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -39,6 +39,7 @@
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxStormtrooper)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -72,7 +73,6 @@
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20);
|
||||
this.toolStripStatusLabelSpeed.Text = "Скорость:";
|
||||
this.toolStripStatusLabelSpeed.Click += new System.EventHandler(this.ToolStripStatusLabelSpeed_Click);
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
@ -145,11 +145,22 @@
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(150, 364);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(129, 29);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||
//
|
||||
// FormStormtrooper
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
@ -180,5 +191,6 @@
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -32,11 +32,18 @@ namespace Stormtrooper
|
||||
pictureBoxStormtrooper.Image = bmp;
|
||||
}
|
||||
|
||||
private void SetData(DrowningStormtrooper stormtrooper)
|
||||
{
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {stormtrooper.Stormtrooper.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {stormtrooper.Stormtrooper.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет:{ stormtrooper.Stormtrooper.BodyColor.Name}";
|
||||
//pictureBoxCar.Image = _abstractMap.CreateMap(pictureBoxCar.Width, pictureBoxCar.Height, new DrawningObjectCar(car));
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_stormtrooper = new DrowningStormtrooper();
|
||||
_stormtrooper.Init(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
_stormtrooper = new DrowningStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_stormtrooper.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
|
||||
pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
@ -74,5 +81,15 @@ namespace Stormtrooper
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var stormtrooper = new DrowningSuperStormtrooper(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)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData(stormtrooper);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
Stormtrooper/Stormtrooper/IDrawningObject.cs
Normal file
37
Stormtrooper/Stormtrooper/IDrawningObject.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal interface IDrawningObject
|
||||
{
|
||||
public float Step { get; }
|
||||
/// <summary>
|
||||
/// Установка позиции объекта
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина полотна</param>
|
||||
/// <param name="height">Высота полотна</param>
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(Direction direction);
|
||||
/// <summary>
|
||||
/// Отрисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
void DrawningObject(Graphics g);
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
(float Left, float Right, float Top, float Bottom)
|
||||
GetCurrentPosition();
|
||||
}
|
||||
}
|
54
Stormtrooper/Stormtrooper/MyMap.cs
Normal file
54
Stormtrooper/Stormtrooper/MyMap.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class MyMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Red);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.FromArgb(242, 242, 242));
|
||||
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[150, 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 < 10)
|
||||
{
|
||||
int x = _random.Next(0, _map.GetLength(0));
|
||||
int y = _random.Next(0, _map.GetLength(1));
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace Stormtrooper
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormStormtrooper());
|
||||
Application.Run(new FormMap());
|
||||
}
|
||||
}
|
||||
}
|
51
Stormtrooper/Stormtrooper/SimpleMap.cs
Normal file
51
Stormtrooper/Stormtrooper/SimpleMap.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class SimpleMap : AbstractMap
|
||||
{
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||
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 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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user