Compare commits

...

2 Commits

Author SHA1 Message Date
f051754b49 lab_2 2022-10-03 00:47:26 +04:00
33a595e4b2 Lab1 2022-09-12 10:09:08 +04:00
21 changed files with 5966 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,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);
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal 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 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);
}
}
}

View File

@ -0,0 +1,277 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class DrowningStormtrooper
{
/// <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 = 90;
/// <summary>
/// Высота отрисовки автомобиля
/// </summary>
private readonly int _stormtrooperHeight = 120;
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
public DrowningStormtrooper(int speed, float weight, Color 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>
/// <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, _startPosY, _startPosX + _stormtrooperWidth, _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 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;
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal 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,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;
}
}

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

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

View File

@ -0,0 +1,196 @@
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();
((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);
//
// 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);
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;
}
}

View File

@ -0,0 +1,95 @@
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 DrowningStormtrooper _stormtrooper;
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(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(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);
toolStripStatusLabelSpeed.Text = $"Скорость: {_stormtrooper.Stormtrooper.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_stormtrooper.Stormtrooper.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет:{ _stormtrooper.Stormtrooper.BodyColor.Name}";
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 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);
}
}
}

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

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,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>