Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c8d2e3c46d | |||
bfced67c39 | |||
b1a4a7ce49 | |||
d4ebff9421 |
158
Stormtrooper/Stormtrooper/AbstractMap.cs
Normal file
158
Stormtrooper/Stormtrooper/AbstractMap.cs
Normal file
@ -0,0 +1,158 @@
|
||||
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;
|
||||
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)
|
||||
{
|
||||
int LefTopX = Convert.ToInt32(_drawningObject.GetCurrentPosition().Left / _size_x);
|
||||
int LefTopY = Convert.ToInt32(_drawningObject.GetCurrentPosition().Top / _size_y);
|
||||
int objwidth = Convert.ToInt32(_drawningObject.GetCurrentPosition().Right / _size_x);
|
||||
int objheigh = Convert.ToInt32(_drawningObject.GetCurrentPosition().Bottom / _size_y);
|
||||
|
||||
bool CanStep = true;
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Left:
|
||||
for (int i = LefTopX; i >= Math.Abs(LefTopX - Convert.ToInt32(_drawningObject.Step / _size_x)); i--)
|
||||
{
|
||||
for (int j = LefTopY; j <= objheigh && j<_map.GetLength(1); j++)
|
||||
{
|
||||
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
CanStep = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Direction.Right:
|
||||
for (int i = objwidth; i <= objwidth + Convert.ToInt32(_drawningObject.Step / _size_x) && i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = LefTopY; j <= objheigh && j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
CanStep = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case Direction.Down:
|
||||
for (int i = LefTopX; i <= objwidth && i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = objheigh; j <= objheigh + Convert.ToInt32(_drawningObject.Step / _size_y) && j < _map.GetLength(1); j++)
|
||||
{
|
||||
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
CanStep = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case Direction.Up:
|
||||
for (int i = LefTopX; i <= objwidth && i<_map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = LefTopY; j >= Math.Abs(LefTopY - Convert.ToInt32(_drawningObject.Step / _size_y)) ; j--)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
CanStep = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (CanStep)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.Next(0, 150);
|
||||
int y = _random.Next(100, 300);
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (i * _size_x >= x && j * _size_y <= y &&
|
||||
i * _size_x <= x + _drawningObject.GetCurrentPosition().Right &&
|
||||
j * _size_y >= j - _drawningObject.GetCurrentPosition().Bottom && _map[i, j] == _barrier)
|
||||
{
|
||||
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)
|
||||
DrawRoadPart(gr, i, j);
|
||||
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
if (_map[i, j] == 1) 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);
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ namespace Stormtrooper
|
||||
/// </summary>
|
||||
internal enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
|
@ -14,15 +14,15 @@ namespace Stormtrooper
|
||||
/// </summary>
|
||||
internal class Drawning
|
||||
{
|
||||
public EntityStormtrooper Storm { get; private set; }
|
||||
public EntityStormtrooper Storm { get; protected set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки самолёта
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Нижняя кооридната отрисовки самолёта
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -45,10 +45,23 @@ namespace Stormtrooper
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолёта</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public Drawning(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Storm = new EntityStormtrooper();
|
||||
Storm.Init(speed, weight, bodyColor);
|
||||
Storm = new EntityStormtrooper(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолёта</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="carWidth">Ширина отрисовки самолёта</param>
|
||||
/// <param name="carHeight">Высота отрисовки самолёта</param>
|
||||
protected Drawning(int speed, float weight, Color bodyColor, int stormWidth, int stormHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_StormWidth = stormWidth;
|
||||
_StormHeight = stormHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции самолёта
|
||||
@ -117,7 +130,7 @@ namespace Stormtrooper
|
||||
/// Отрисовка штурмовика
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
@ -162,7 +175,7 @@ namespace Stormtrooper
|
||||
g.FillPolygon(brBl, N);
|
||||
|
||||
//фюзеляж
|
||||
Brush brGr = new SolidBrush(Color.Gray);
|
||||
Brush brGr = new SolidBrush(Color.White);
|
||||
g.FillRectangle(brGr, _startPosX + 20, _startPosY - 60, 100, 20);
|
||||
|
||||
//крыло и стаб
|
||||
@ -171,6 +184,7 @@ namespace Stormtrooper
|
||||
g.FillPolygon(br, S);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Смена границ формы отрисовки
|
||||
/// </summary>
|
||||
@ -195,5 +209,13 @@ namespace Stormtrooper
|
||||
_startPosY = _pictureHeight.Value - _StormHeight;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosX + _StormWidth, _startPosY - _StormHeight, _startPosY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
66
Stormtrooper/Stormtrooper/DrawningMilitary.cs
Normal file
66
Stormtrooper/Stormtrooper/DrawningMilitary.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class DrawningMilitary : Drawning
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолёта</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="rocket">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public DrawningMilitary(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool rocket, bool sportLine) :
|
||||
base(speed, weight, bodyColor, 135, 100)
|
||||
{
|
||||
Storm = new EntityMilitaryStormtrooper(speed, weight, bodyColor, dopColor, bodyKit, rocket, sportLine);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Storm is not EntityMilitaryStormtrooper militaryTrop)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(militaryTrop.DopColor);
|
||||
|
||||
if (militaryTrop.BodyKit)
|
||||
{
|
||||
|
||||
g.DrawEllipse(pen, _startPosX - 2, _startPosY - 70, 5, 20);
|
||||
g.DrawEllipse(pen, _startPosX - 2, _startPosY - 50, 5, 20);
|
||||
|
||||
g.FillEllipse(dopBrush, _startPosX - 2, _startPosY - 70, 5, 20);
|
||||
g.FillEllipse(dopBrush, _startPosX - 2, _startPosY - 50, 5, 20);
|
||||
}
|
||||
|
||||
_startPosX += 2;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 2;
|
||||
|
||||
if (militaryTrop.Rocket)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 70, 40, 3);
|
||||
g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 90, 40, 3);
|
||||
g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 30, 40, 3);
|
||||
g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 10, 40, 3);
|
||||
}
|
||||
|
||||
if (militaryTrop.SportLine)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 30, _startPosY - 60, 8, 20);
|
||||
g.FillRectangle(dopBrush, _startPosX + 100, _startPosY - 60, 8, 20);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
37
Stormtrooper/Stormtrooper/DrawningObjectStorm.cs
Normal file
37
Stormtrooper/Stormtrooper/DrawningObjectStorm.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class DrawningObjectStorm : IDrawningObject
|
||||
{
|
||||
private Drawning _storm = null;
|
||||
public DrawningObjectStorm(Drawning storm)
|
||||
{
|
||||
_storm = storm;
|
||||
}
|
||||
public float Step => _storm?.Storm?.Step ?? 0;
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _storm?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_storm?.MoveTransport(direction);
|
||||
}
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_storm.SetPosition(x, y, width, height);
|
||||
}
|
||||
void IDrawningObject.DrawningObject(Graphics g)
|
||||
{
|
||||
if (_storm is DrawningMilitary)
|
||||
((DrawningMilitary)_storm).DrawTransport(g);
|
||||
_storm.DrawTransport(g);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
47
Stormtrooper/Stormtrooper/EntityMilitaryStormtrooper.cs
Normal file
47
Stormtrooper/Stormtrooper/EntityMilitaryStormtrooper.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class EntityMilitaryStormtrooper : EntityStormtrooper
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия обвеса
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия рокет
|
||||
/// </summary>
|
||||
public bool Rocket { 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="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="rocket">Признак наличия рокет</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public EntityMilitaryStormtrooper(int speed, float weight, Color bodyColor, Color
|
||||
dopColor, bool bodyKit, bool rocket, bool sportLine) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
BodyKit = bodyKit;
|
||||
Rocket = rocket;
|
||||
SportLine = sportLine;
|
||||
}
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ namespace Stormtrooper
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityStormtrooper(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
|
222
Stormtrooper/Stormtrooper/FormMap.Designer.cs
generated
Normal file
222
Stormtrooper/Stormtrooper/FormMap.Designer.cs
generated
Normal file
@ -0,0 +1,222 @@
|
||||
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.statusStrip = 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.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = 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.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxStormtrooper
|
||||
//
|
||||
this.pictureBoxStormtrooper.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxStormtrooper.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.pictureBoxStormtrooper.Name = "pictureBoxStormtrooper";
|
||||
this.pictureBoxStormtrooper.Size = new System.Drawing.Size(1000, 500);
|
||||
this.pictureBoxStormtrooper.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxStormtrooper.TabIndex = 0;
|
||||
this.pictureBoxStormtrooper.TabStop = false;
|
||||
//
|
||||
// statusStrip
|
||||
//
|
||||
this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelBodyColor});
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 501);
|
||||
this.statusStrip.Name = "statusStrip";
|
||||
this.statusStrip.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0);
|
||||
this.statusStrip.Size = new System.Drawing.Size(1000, 26);
|
||||
this.statusStrip.TabIndex = 1;
|
||||
//
|
||||
// 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(14, 447);
|
||||
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(86, 31);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
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 = global::Stormtrooper.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(901, 389);
|
||||
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonUp.TabIndex = 6;
|
||||
this.buttonUp.Text = "\r\n";
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.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 = global::Stormtrooper.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(856, 437);
|
||||
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonLeft.TabIndex = 4;
|
||||
this.buttonLeft.Text = "\r\n";
|
||||
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 = global::Stormtrooper.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(944, 437);
|
||||
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonRight.TabIndex = 3;
|
||||
this.buttonRight.Text = "\r\n";
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.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 = global::Stormtrooper.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(901, 437);
|
||||
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(34, 40);
|
||||
this.buttonDown.TabIndex = 5;
|
||||
this.buttonDown.Text = "\r\n";
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(116, 447);
|
||||
this.buttonCreateModif.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(126, 31);
|
||||
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(14, 13);
|
||||
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(138, 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(1000, 527);
|
||||
this.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.pictureBoxStormtrooper);
|
||||
this.Controls.Add(this.statusStrip);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormMap";
|
||||
this.Text = "Карта";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxStormtrooper)).EndInit();
|
||||
this.statusStrip.ResumeLayout(false);
|
||||
this.statusStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private PictureBox pictureBoxStormtrooper;
|
||||
private StatusStrip statusStrip;
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private Button buttonCreate;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateModif;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
}
|
||||
}
|
103
Stormtrooper/Stormtrooper/FormMap.cs
Normal file
103
Stormtrooper/Stormtrooper/FormMap.cs
Normal file
@ -0,0 +1,103 @@
|
||||
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(Drawning storm)
|
||||
{
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {storm.Storm.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {storm.Storm.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {storm.Storm.BodyColor.Name}";
|
||||
pictureBoxStormtrooper.Image = _abstractMap.CreateMap(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height, new DrawningObjectStorm(storm));
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var storm = new Drawning(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
SetData(storm);
|
||||
}
|
||||
/// <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 storm = new DrawningMilitary(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(storm);
|
||||
}
|
||||
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
{
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Ясное небо":
|
||||
_abstractMap = new SecondMap();
|
||||
break;
|
||||
case "Пасмурное небо":
|
||||
_abstractMap = new ThirdMap();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
66
Stormtrooper/Stormtrooper/FormMap.resx
Normal file
66
Stormtrooper/Stormtrooper/FormMap.resx
Normal file
@ -0,0 +1,66 @@
|
||||
<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="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>25</value>
|
||||
</metadata>
|
||||
</root>
|
@ -38,6 +38,7 @@
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxStormtrooper)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -147,11 +148,23 @@
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(125, 396);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(120, 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(831, 461);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
@ -181,5 +194,6 @@
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -3,12 +3,11 @@ namespace Stormtrooper
|
||||
public partial class FormStormtrooper : Form
|
||||
{
|
||||
private Drawning _storm;
|
||||
|
||||
|
||||
public FormStormtrooper()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
//private EntityStormtrooper Storm;
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè ñàìîë¸òà
|
||||
/// </summary>
|
||||
@ -19,6 +18,18 @@ namespace Stormtrooper
|
||||
_storm?.DrawTransport(gr);
|
||||
pictureBoxStormtrooper.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_storm.SetPosition(rnd.Next(0, 150), rnd.Next(0, 300), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_storm.Storm.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_storm.Storm.Weight}";
|
||||
toolStripStatusLabelColor.Text = $"Öâåò: {_storm.Storm.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
@ -27,12 +38,8 @@ namespace Stormtrooper
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_storm = new Drawning();
|
||||
_storm.Init(rnd.Next(100,300), rnd.Next(1000,2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_storm.SetPosition(rnd.Next(0, 150), rnd.Next(0, 300), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_storm.Storm.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_storm.Storm.Weight}";
|
||||
toolStripStatusLabelColor.Text = $"Öâåò: {_storm.Storm.BodyColor.Name}";
|
||||
_storm = new Drawning(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -71,5 +78,21 @@ namespace Stormtrooper
|
||||
_storm?.ChangeBorders(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_storm = new DrawningMilitary(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();
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
43
Stormtrooper/Stormtrooper/IDrawningObject.cs
Normal file
43
Stormtrooper/Stormtrooper/IDrawningObject.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||
/// </summary>
|
||||
internal interface IDrawningObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
/// </summary>
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace Stormtrooper
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormStormtrooper());
|
||||
Application.Run(new FormMap());
|
||||
}
|
||||
}
|
||||
}
|
52
Stormtrooper/Stormtrooper/SecondMap.cs
Normal file
52
Stormtrooper/Stormtrooper/SecondMap.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class SecondMap:AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.White);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.LightBlue);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillEllipse(barrierColor, i * _size_x, j * _size_y, _size_x+3, _size_y+3);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
52
Stormtrooper/Stormtrooper/SimpleMap.cs
Normal file
52
Stormtrooper/Stormtrooper/SimpleMap.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class SimpleMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
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, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
69
Stormtrooper/Stormtrooper/ThirdMap.cs
Normal file
69
Stormtrooper/Stormtrooper/ThirdMap.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stormtrooper
|
||||
{
|
||||
internal class ThirdMap:AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Gray);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.LightGray);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillEllipse(barrierColor, i * _size_x, j * _size_y, _size_x + 3, _size_y + 3);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
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, 30);
|
||||
int y = _random.Next(0, 30);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
|
||||
x = _random.Next(70, 100);
|
||||
y = _random.Next(0, 30);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
|
||||
x = _random.Next(40, 60);
|
||||
y = _random.Next(50, 90);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user