Compare commits

..

8 Commits
master ... lab4

Author SHA1 Message Date
Александр Разживин
999f216dc3 names 2022-12-05 01:22:45 +04:00
Александр Разживин
bd60416bcb comlete 2022-12-05 01:16:33 +04:00
Александр Разживин
ca8768f67f lab4(nocomplete) 2022-11-07 09:07:49 +04:00
Александр Разживин
1d9c71e330 lab3(complete) 2022-10-14 20:33:13 +04:00
Александр Разживин
efa7099a7a bool broblem 2022-10-10 03:13:45 +04:00
Александр Разживин
5ae5e17d51 test 2022-10-10 00:02:53 +04:00
f051754b49 lab_2 2022-10-03 00:47:26 +04:00
33a595e4b2 Lab1 2022-09-12 10:09:08 +04:00
25 changed files with 9967 additions and 0 deletions

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stormtrooper", "Stormtrooper\Stormtrooper.csproj", "{921570CB-0EBB-4B7A-94D7-6B2E7AC5B34C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{921570CB-0EBB-4B7A-94D7-6B2E7AC5B34C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{921570CB-0EBB-4B7A-94D7-6B2E7AC5B34C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{921570CB-0EBB-4B7A-94D7-6B2E7AC5B34C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{921570CB-0EBB-4B7A-94D7-6B2E7AC5B34C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9A70ADC6-A14D-4219-8E7D-3EBA79D2F7AF}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,137 @@
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;
if (_drawningObject.GetCurrentPosition().Bottom + y > _height || _drawningObject.GetCurrentPosition().Right + x > _width ||
_drawningObject.GetCurrentPosition().Top + y < 0 || _drawningObject.GetCurrentPosition().Left + x < 0) {
return false;
}
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)
{
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);
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);
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
public enum Direction
{
None = 0,
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View 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 DrawningStormtrooper _stormtrooper = null;
public DrawningObjectStormtrooper(DrawningStormtrooper 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);
}
}
}

View File

@ -0,0 +1,277 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
public class DrawningStormtrooper
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityStormtrooper Stormtrooper { protected set; get; }
/// <summary>
/// Левая координата отрисовки автомобиля
/// </summary>
protected float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки автомобиля
/// </summary>
protected float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private int? _pictureWidth = null;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private int? _pictureHeight = null;
/// <summary>
/// Ширина отрисовки автомобиля
/// </summary>
private readonly int _stormtrooperWidth = 80;
/// <summary>
/// Высота отрисовки автомобиля
/// </summary>
private readonly int _stormtrooperHeight = 120;
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
public DrawningStormtrooper(int speed, float weight, Color bodyColor)
{
Stormtrooper = new EntityStormtrooper(speed, weight, bodyColor);
}
protected DrawningStormtrooper(int speed, float weight, Color bodyColor, int StormtrooperWidth, int StormtrooperHeight) :
this(speed, weight, bodyColor)
{
_stormtrooperWidth = StormtrooperWidth;
_stormtrooperHeight = StormtrooperHeight;
}
/// <summary>
/// Установка позиции автомобиля
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public void SetPosition(int x, int y, int width, int height)
{
if(x >= 0 && y >= 0 && width >= x + _stormtrooperWidth && height >= y + _stormtrooperHeight)
{
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
return;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(Direction direction)
{
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
{
return;
}
switch (direction)
{
// вправо
case Direction.Right:
if (_startPosX + _stormtrooperWidth + Stormtrooper.Step < _pictureWidth)
{
_startPosX += Stormtrooper.Step;
}
break;
//влево
case Direction.Left:
if (_startPosX - Stormtrooper.Step > 0)
{
_startPosX -= Stormtrooper.Step;
}
break;
//вверх
case Direction.Up:
if (_startPosY - Stormtrooper.Step > 0)
{
_startPosY -= Stormtrooper.Step;
}
break;
//вниз
case Direction.Down:
if (_startPosY + _stormtrooperHeight + Stormtrooper.Step < _pictureHeight)
{
_startPosY += Stormtrooper.Step;
}
break;
}
}
/// <summary>
/// Отрисовка автомобиля
/// </summary>
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
Pen pen = new(Color.Black);
PointF point1 = new PointF(_startPosX, _startPosY + 30);
PointF point2 = new PointF(_startPosX + 10, _startPosY + 40);
PointF point3 = new PointF(_startPosX + 10, _startPosY + 50);
PointF point4 = new PointF(_startPosX + 30, _startPosY + 50);
PointF point5 = new PointF(_startPosX + 40, _startPosY + 10);
PointF point6 = new PointF(_startPosX + 50, _startPosY);
PointF point7 = new PointF(_startPosX + 50, _startPosY + 10);
PointF point8 = new PointF(_startPosX + 55, _startPosY + 10);
PointF point9 = new PointF(_startPosX + 60, _startPosY + 15);
PointF point10 = new PointF(_startPosX + 55, _startPosY + 20);
PointF point11 = new PointF(_startPosX + 50, _startPosY + 20);
PointF point12 = new PointF(_startPosX + 50, _startPosY + 30);
PointF point13 = new PointF(_startPosX + 55, _startPosY + 30);
PointF point14 = new PointF(_startPosX + 60, _startPosY + 35);
PointF point15 = new PointF(_startPosX + 55, _startPosY + 40);
PointF point16 = new PointF(_startPosX + 50, _startPosY + 40);
PointF point17 = new PointF(_startPosX + 50, _startPosY + 50);
PointF point18 = new PointF(_startPosX + 70, _startPosY + 50);
PointF point19 = new PointF(_startPosX + 80, _startPosY + 60);
PointF point20 = new PointF(_startPosX + 70, _startPosY + 70);
PointF point21 = new PointF(_startPosX + 50, _startPosY + 70);
PointF point22 = new PointF(_startPosX + 50, _startPosY + 80);
PointF point23 = new PointF(_startPosX + 55, _startPosY + 80);
PointF point24 = new PointF(_startPosX + 60, _startPosY + 85);
PointF point25 = new PointF(_startPosX + 55, _startPosY + 90);
PointF point26 = new PointF(_startPosX + 50, _startPosY + 90);
PointF point27 = new PointF(_startPosX + 50, _startPosY + 100);
PointF point28 = new PointF(_startPosX + 55, _startPosY + 100);
PointF point29 = new PointF(_startPosX + 60, _startPosY + 105);
PointF point30 = new PointF(_startPosX + 55, _startPosY + 110);
PointF point31 = new PointF(_startPosX + 50, _startPosY + 110);
PointF point32 = new PointF(_startPosX + 50, _startPosY + 120);
PointF point33 = new PointF(_startPosX + 40, _startPosY + 110);
PointF point34 = new PointF(_startPosX + 30, _startPosY + 70);
PointF point35 = new PointF(_startPosX + 10, _startPosY + 70);
PointF point36 = new PointF(_startPosX + 10, _startPosY + 80);
PointF point37 = new PointF(_startPosX, _startPosY + 90);
PointF[] all_stoormtrooper =
{
point1,
point2,
point3,
point4,
point5,
point6,
point7,
point8,
point9,
point10,
point11,
point12,
point13,
point14,
point15,
point16,
point17,
point18,
point19,
point20,
point21,
point22,
point23,
point24,
point25,
point26,
point27,
point28,
point29,
point30,
point31,
point32,
point33,
point34,
point35,
point36,
point37,
};
g.FillPolygon(Brushes.Black, all_stoormtrooper);
Brush br = new SolidBrush(Stormtrooper?.BodyColor ?? Color.Black);
point1 = new PointF(_startPosX + 30, _startPosY + 50);
point2 = new PointF(_startPosX + 40, _startPosY + 10);
point3 = new PointF(_startPosX + 40, _startPosY + 50);
PointF[] up_wing =
{
point1,
point2,
point3,
};
g.FillPolygon(br, up_wing);
point1 = new PointF(_startPosX + 30, _startPosY + 70);
point2 = new PointF(_startPosX + 40, _startPosY + 70);
point3 = new PointF(_startPosX + 40, _startPosY + 110);
PointF[] down_wing =
{
point1,
point2,
point3,
};
g.FillPolygon(br, down_wing);
point1 = new PointF(_startPosX + 72, _startPosY + 52);
point2 = new PointF(_startPosX + 78, _startPosY + 60);
point3 = new PointF(_startPosX + 72, _startPosY + 68);
PointF[] cabin =
{
point1,
point2,
point3,
};
g.FillPolygon(Brushes.Brown, cabin);
}
/// <summary>
/// Смена границ формы отрисовки
/// </summary>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _stormtrooperWidth || _pictureHeight <= _stormtrooperHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _stormtrooperWidth > _pictureWidth)
{
_startPosX = _pictureWidth.Value - _stormtrooperWidth;
}
if (_startPosY + _stormtrooperHeight > _pictureHeight)
{
_startPosY = _pictureHeight.Value - _stormtrooperHeight;
}
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosX + _stormtrooperWidth, _startPosY, _startPosY + _stormtrooperHeight);
}
}
}

View 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 DrawningSuperStormtrooper : DrawningStormtrooper
{
public DrawningSuperStormtrooper(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(superStormtrooper.BodyColor);
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;
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
public class EntityStormtrooper
{
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public float Weight { get; private set; }
/// <summary>
/// Цвет кузова
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public float Step => Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса автомобиля
/// </summary>
/// <param name="speed"></param>
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <returns></returns>
public EntityStormtrooper(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(5, 30) : speed;
Weight = weight <= 0 ? rnd.Next(30, 100) : weight;
BodyColor = bodyColor;
}
}
}

View 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;
}
}
}

View File

@ -0,0 +1,279 @@
namespace Stormtrooper
{
partial class FormMapWithSetStormtroopers
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMapWithSetStormtroopers));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMap = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveStormtrooper = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddStormtrooper = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.groupBoxMaps);
this.groupBox1.Controls.Add(this.buttonShowOnMap);
this.groupBox1.Controls.Add(this.buttonShowStorage);
this.groupBox1.Controls.Add(this.buttonRemoveStormtrooper);
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonAddStormtrooper);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(637, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(250, 583);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// groupBoxMaps
//
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMap);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Location = new System.Drawing.Point(23, 26);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Size = new System.Drawing.Size(203, 290);
this.groupBoxMaps.TabIndex = 0;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты";
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 20;
this.listBoxMaps.Location = new System.Drawing.Point(19, 128);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(178, 104);
this.listBoxMaps.TabIndex = 4;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(18, 238);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(179, 29);
this.buttonDeleteMap.TabIndex = 3;
this.buttonDeleteMap.Text = "Удалить карту";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(18, 93);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(179, 29);
this.buttonAddMap.TabIndex = 2;
this.buttonAddMap.Text = "Добавить карту";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
//
// textBoxNewMap
//
this.textBoxNewMap.Location = new System.Drawing.Point(18, 26);
this.textBoxNewMap.Name = "textBoxNewMap";
this.textBoxNewMap.Size = new System.Drawing.Size(179, 27);
this.textBoxNewMap.TabIndex = 1;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Location = new System.Drawing.Point(18, 59);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(179, 28);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelector_SelectedIndexChanged);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(41, 517);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(185, 29);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(41, 482);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(185, 29);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonRemoveStormtrooper
//
this.buttonRemoveStormtrooper.Location = new System.Drawing.Point(41, 447);
this.buttonRemoveStormtrooper.Name = "buttonRemoveStormtrooper";
this.buttonRemoveStormtrooper.Size = new System.Drawing.Size(185, 29);
this.buttonRemoveStormtrooper.TabIndex = 3;
this.buttonRemoveStormtrooper.Text = "Удалить";
this.buttonRemoveStormtrooper.UseVisualStyleBackColor = true;
this.buttonRemoveStormtrooper.Click += new System.EventHandler(this.ButtonRemoveStormtrooper_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(41, 414);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(185, 27);
this.maskedTextBoxPosition.TabIndex = 2;
this.maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddStormtrooper
//
this.buttonAddStormtrooper.Location = new System.Drawing.Point(41, 379);
this.buttonAddStormtrooper.Name = "buttonAddStormtrooper";
this.buttonAddStormtrooper.Size = new System.Drawing.Size(185, 29);
this.buttonAddStormtrooper.TabIndex = 1;
this.buttonAddStormtrooper.Text = "Добавить";
this.buttonAddStormtrooper.UseVisualStyleBackColor = true;
this.buttonAddStormtrooper.Click += new System.EventHandler(this.ButtonAddStormtrooper_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage")));
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(552, 541);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 8;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.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.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage")));
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(588, 541);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 10;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage")));
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(516, 542);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 9;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(552, 505);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 7;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(637, 583);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetStormtroopers
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(887, 583);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
this.Name = "FormMapWithSetStormtroopers";
this.Text = "FormMapWithSetStormtroopers";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private Button buttonShowOnMap;
private Button buttonShowStorage;
private Button buttonRemoveStormtrooper;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddStormtrooper;
private PictureBox pictureBox;
private Button buttonRight;
private Button buttonLeft;
private Button buttonDown;
private Button buttonUp;
private GroupBox groupBoxMaps;
private ListBox listBoxMaps;
private Button buttonDeleteMap;
private Button buttonAddMap;
private TextBox textBoxNewMap;
private ComboBox comboBoxSelectorMap;
}
}

View File

@ -0,0 +1,221 @@
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;
using static System.Windows.Forms.DataFormats;
namespace Stormtrooper
{
public partial class FormMapWithSetStormtroopers : Form
{
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{ "Карта со стенами", new MySecondMap() },
};
/// <summary>
/// Объект от коллекции карт
/// </summary>
private readonly MapCollection _mapsCollection;
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetStormtroopersGeneric<DrawningObjectStormtrooper, AbstractMap> _mapStormtroopersCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetStormtroopers()
{
InitializeComponent();
_mapsCollection = new MapCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
private void ReloadMaps()
{
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
}
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{
listBoxMaps.SelectedIndex = index;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddStormtrooper_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
FormStormtrooper form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectStormtrooper stormtrooper = new(form.SelectedStormtrooper);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + stormtrooper != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveStormtrooper_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
//получаем имя кнопки
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;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ??
string.Empty].MoveObject(dir);
}
private void buttonAddMap_Click(object sender, EventArgs e)
{
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMap.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(textBoxNewMap.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
}
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void buttonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
private void comboBoxSelector_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,209 @@
namespace Stormtrooper
{
partial class FormStormtrooper
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormStormtrooper));
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.buttonSelectStormtrooper = new System.Windows.Forms.Button();
((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;
this.pictureBoxStormtrooper.Resize += new System.EventHandler(this.PictureBoxStormtrooper_Resize);
//
// 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.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
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.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage")));
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.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage")));
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.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage")));
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);
//
// buttonSelectStormtrooper
//
this.buttonSelectStormtrooper.Location = new System.Drawing.Point(489, 364);
this.buttonSelectStormtrooper.Name = "buttonSelectStormtrooper";
this.buttonSelectStormtrooper.Size = new System.Drawing.Size(129, 29);
this.buttonSelectStormtrooper.TabIndex = 8;
this.buttonSelectStormtrooper.Text = "Выбрать";
this.buttonSelectStormtrooper.UseVisualStyleBackColor = true;
this.buttonSelectStormtrooper.Click += new System.EventHandler(this.ButtonSelectStormtrooper_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.buttonSelectStormtrooper);
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 = "FormStormtrooper";
this.Text = "Военный самолёт";
this.Click += new System.EventHandler(this.ButtonMove_Click);
((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 Button buttonSelectStormtrooper;
}
}

View File

@ -0,0 +1,125 @@
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 FormStormtrooper : Form
{
private DrawningStormtrooper _stormtrooper;
public DrawningStormtrooper SelectedStormtrooper { get; private set; }
public FormStormtrooper()
{
InitializeComponent();
}
private void ToolStripStatusLabelSpeed_Click(object sender, EventArgs e)
{
}
private void Draw()
{
Bitmap bmp = new(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
Graphics gr = Graphics.FromImage(bmp);
_stormtrooper?.DrawTransport(gr);
pictureBoxStormtrooper.Image = bmp;
}
private void SetData()
{
Random rnd = new Random();
_stormtrooper.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_stormtrooper.Stormtrooper.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_stormtrooper.Stormtrooper.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_stormtrooper.Stormtrooper.BodyColor.Name}";
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
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;
}
_stormtrooper = new DrawningStormtrooper(rnd.Next(100, 300), rnd.Next(1000, 2000),
color);
_stormtrooper.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
SetData();
Draw();
}
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
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;
}
_stormtrooper = new DrawningSuperStormtrooper(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)));
_stormtrooper.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
SetData();
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_stormtrooper?.MoveTransport(Direction.Up);
break;
case "buttonDown":
_stormtrooper?.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_stormtrooper?.MoveTransport(Direction.Left);
break;
case "buttonRight":
_stormtrooper?.MoveTransport(Direction.Right);
break;
}
Draw();
}
private void PictureBoxStormtrooper_Resize(object sender, EventArgs e)
{
_stormtrooper?.ChangeBorders(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
Draw();
}
private void ButtonSelectStormtrooper_Click(object sender, EventArgs e)
{
SelectedStormtrooper = _stormtrooper;
DialogResult = DialogResult.OK;
}
}
}

File diff suppressed because it is too large Load Diff

View 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();
}
}

View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class MapCollection
{
/// <summary>
/// Словарь (хранилище) с картами
/// </summary>
readonly Dictionary<string, MapWithSetStormtroopersGeneric<DrawningObjectStormtrooper, AbstractMap>> _mapStorages;
/// <summary>
/// Возвращение списка названий карт
/// </summary>
public List<string> Keys => _mapStorages.Keys.ToList();
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public MapCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetStormtroopersGeneric<DrawningObjectStormtrooper, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="name">Название карты</param>
/// <param name="map">Карта</param>
public void AddMap(string name, AbstractMap map)
{
if (name == null)
{
return;
}
foreach (var key in Keys)
{
if (key.Equals(name))
{
MessageBox.Show("Объект с таким именем существует!");
return;
}
}
_mapStorages.Add(name, new MapWithSetStormtroopersGeneric<DrawningObjectStormtrooper, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="name">Название карты</param>
public void DelMap(string name)
{
_mapStorages.Remove(name);
}
/// <summary>
/// Доступ к парковке
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public MapWithSetStormtroopersGeneric<DrawningObjectStormtrooper, AbstractMap> this[string ind]
{
get
{
if (_mapStorages.TryGetValue(ind, out var map))
{
return map;
}
return null;
}
}
}
}

View File

@ -0,0 +1,180 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class MapWithSetStormtroopersGeneric<T, U>
where T : class, IDrawningObject
where U : AbstractMap
{
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 120;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 160;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetStormtroopersGeneric<T> _setStormtroopers;
/// <summary>
/// Карта
/// </summary>
private readonly U _map;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="map"></param>
public MapWithSetStormtroopersGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setStormtroopers = new SetStormtroopersGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="map"></param>
/// <param name="stormtrooper"></param>
/// <returns></returns>
public static int operator + (MapWithSetStormtroopersGeneric<T, U> map, T stormtrooper)
{
return map._setStormtroopers.Insert(stormtrooper);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="map"></param>
/// <param name="position"></param>
/// <returns></returns>
public static T operator - (MapWithSetStormtroopersGeneric<T, U> map, int
position)
{
return map._setStormtroopers.Remove(position);
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
ShowOnMap();
DrawBackground(gr);
DrawStormtroopers(gr);
return bmp;
}
/// <summary>
/// Просмотр объекта на карте
/// </summary>
/// <returns></returns>
public Bitmap ShowOnMap()
{
Shaking();
foreach (var stormtrooper in _setStormtroopers.GetStormtroopers())
{
return _map.CreateMap(_pictureWidth, _pictureHeight, stormtrooper);
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// Перемещение объекта по крате
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary>
private void Shaking()
{
int j = _setStormtroopers.Count - 1;
for (int i = 0; i < _setStormtroopers.Count; i++)
{
if (_setStormtroopers[i] == null)
{
for (; j > i; j--)
{
var stormtrooper = _setStormtroopers[j];
if (stormtrooper != null)
{
_setStormtroopers.Insert(stormtrooper, i);
_setStormtroopers.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
g.FillRectangle(new SolidBrush(Color.Green), 0, 0, _pictureWidth, _pictureHeight);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight; ++j)
{//линия рамзетки места
g.FillRectangle(new SolidBrush(Color.Gray), i *_placeSizeWidth , j *_placeSizeHeight ,_placeSizeWidth / 2,_placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawStormtroopers(Graphics g)
{
int x = (_pictureWidth / _placeSizeWidth) * _placeSizeWidth - _placeSizeWidth;
int y = 5;
foreach (var stormtrooper in _setStormtroopers.GetStormtroopers())
{
stormtrooper?.SetObject(x, y, _pictureWidth, _pictureHeight);
stormtrooper?.DrawningObject(g);
x -= _placeSizeWidth;
if (x < 0)
{
y += _placeSizeHeight;
x = (_pictureWidth / _placeSizeWidth) * _placeSizeWidth - _placeSizeWidth;
}
}
}
}
}

View 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++;
}
}
}
}
}

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class MySecondMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Blue);
/// <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(2, _map.GetLength(0));
int y = _random.Next(2, _map.GetLength(1));
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
_map[x - 1, y] = _barrier;
_map[x, y - 1] = _barrier;
_map[x - 1, y - 1] = _barrier;
counter++;
}
}
}
}
}

View File

@ -0,0 +1,17 @@
namespace Stormtrooper
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormMapWithSetStormtroopers());
}
}
}

View File

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Stormtrooper.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Stormtrooper.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>
</root>

View File

@ -0,0 +1,129 @@
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class SetStormtroopersGeneric<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private readonly List<T> _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Count;
private readonly int _maxCount;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetStormtroopersGeneric(int count)
{
_maxCount = count;
_places = new List<T>();
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="stormtrooper">Добавляемый автомобиль</param>
/// <returns></returns>
public int Insert(T stormtrooper)
{
if(_places.Count < _maxCount)
{
_places.Add(stormtrooper);
for (int i = 0; i < _places.Count; i++)
{
if (_places[i] == stormtrooper)
{
return i;
}
}
}
return -1;
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="stormtrooper">Добавляемый автомобиль</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T stormtrooper, int position)
{
if (position < 0 || position > _places.Count)
{
return false;
}
_places.Insert(position, stormtrooper);
return true;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Remove(int position)
{
if (position < 0 || position > _places.Count)
{
return null;
}
if (_places[position] == null)
{
return null;
}
T removed = _places[position];
_places.RemoveAt(position);
return removed;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T this[int position]
{
get
{
if (position < 0 || position > _places.Count)
{
return null;
}
return _places[position];
}
set
{
if (position < 0 || position > _places.Count)
{
return;
}
_places.Insert(position, value);
}
}
/// <summary>
/// Проход по набору до первого пустого
/// </summary>
/// <returns></returns>
public IEnumerable<T> GetStormtroopers()
{
foreach (var stormtrooper in _places)
{
if (stormtrooper != null)
{
yield return stormtrooper;
}
else
{
yield break;
}
}
}
}
}

View 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++;
}
}
}
}
}

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>