diff --git a/Stormtrooper/Stormtrooper/AbstractMap.cs b/Stormtrooper/Stormtrooper/AbstractMap.cs new file mode 100644 index 0000000..f00311e --- /dev/null +++ b/Stormtrooper/Stormtrooper/AbstractMap.cs @@ -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); + } +} diff --git a/Stormtrooper/Stormtrooper/Direction.cs b/Stormtrooper/Stormtrooper/Direction.cs index 733d45e..2330eac 100644 --- a/Stormtrooper/Stormtrooper/Direction.cs +++ b/Stormtrooper/Stormtrooper/Direction.cs @@ -11,6 +11,7 @@ namespace Stormtrooper /// internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/Stormtrooper/Stormtrooper/Drawning.cs b/Stormtrooper/Stormtrooper/Drawning.cs index 93f4666..000a1d3 100644 --- a/Stormtrooper/Stormtrooper/Drawning.cs +++ b/Stormtrooper/Stormtrooper/Drawning.cs @@ -14,15 +14,15 @@ namespace Stormtrooper /// internal class Drawning { - public EntityStormtrooper Storm { get; private set; } + public EntityStormtrooper Storm { get; protected set; } /// /// Левая координата отрисовки самолёта /// - private float _startPosX; + protected float _startPosX; /// /// Нижняя кооридната отрисовки самолёта /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -45,10 +45,23 @@ namespace Stormtrooper /// Скорость /// Вес самолёта /// Цвет кузова - 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); + } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолёта + /// Цвет кузова + /// Ширина отрисовки самолёта + /// Высота отрисовки самолёта + protected Drawning(int speed, float weight, Color bodyColor, int stormWidth, int stormHeight) : + this(speed, weight, bodyColor) + { + _StormWidth = stormWidth; + _StormHeight = stormHeight; } /// /// Установка позиции самолёта @@ -117,7 +130,7 @@ namespace Stormtrooper /// Отрисовка штурмовика /// /// - 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); } + /// /// Смена границ формы отрисовки /// @@ -195,5 +209,13 @@ namespace Stormtrooper _startPosY = _pictureHeight.Value - _StormHeight; } } + /// + /// Получение текущей позиции объекта + /// + /// + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosX + _StormWidth, _startPosY - _StormHeight, _startPosY); + } } } diff --git a/Stormtrooper/Stormtrooper/DrawningMilitary.cs b/Stormtrooper/Stormtrooper/DrawningMilitary.cs new file mode 100644 index 0000000..0781a3f --- /dev/null +++ b/Stormtrooper/Stormtrooper/DrawningMilitary.cs @@ -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 + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолёта + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + 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); + } + + } + } +} diff --git a/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs b/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs new file mode 100644 index 0000000..6dac87e --- /dev/null +++ b/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs @@ -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); + } + + } +} diff --git a/Stormtrooper/Stormtrooper/EntityMilitaryStormtrooper.cs b/Stormtrooper/Stormtrooper/EntityMilitaryStormtrooper.cs new file mode 100644 index 0000000..e41946a --- /dev/null +++ b/Stormtrooper/Stormtrooper/EntityMilitaryStormtrooper.cs @@ -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 + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия обвеса + /// + public bool BodyKit { get; private set; } + /// + /// Признак наличия рокет + /// + public bool Rocket { get; private set; } + /// + /// Признак наличия полосы + /// + public bool SportLine { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес самолёта + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия рокет + /// Признак наличия гоночной полосы + 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; + } + } +} diff --git a/Stormtrooper/Stormtrooper/EntityStormtrooper.cs b/Stormtrooper/Stormtrooper/EntityStormtrooper.cs index 825e787..0d0be1f 100644 --- a/Stormtrooper/Stormtrooper/EntityStormtrooper.cs +++ b/Stormtrooper/Stormtrooper/EntityStormtrooper.cs @@ -34,7 +34,7 @@ namespace Stormtrooper /// /// /// - 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; diff --git a/Stormtrooper/Stormtrooper/FormMap.Designer.cs b/Stormtrooper/Stormtrooper/FormMap.Designer.cs new file mode 100644 index 0000000..3ca409c --- /dev/null +++ b/Stormtrooper/Stormtrooper/FormMap.Designer.cs @@ -0,0 +1,222 @@ +namespace Stormtrooper +{ + partial class FormMap + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/FormMap.cs b/Stormtrooper/Stormtrooper/FormMap.cs new file mode 100644 index 0000000..c87fe12 --- /dev/null +++ b/Stormtrooper/Stormtrooper/FormMap.cs @@ -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(); + } + /// + /// Заполнение информации по объекту + /// + /// + 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)); + } + /// + /// Обработка нажатия кнопки "Создать" + /// + /// + /// + 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); + } + /// + /// Перемещение + /// + /// + /// + 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); + } + + /// + /// Обработка нажатия кнопки "Модификация" + /// + /// + /// + 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; + } + + } + } +} diff --git a/Stormtrooper/Stormtrooper/FormMap.resx b/Stormtrooper/Stormtrooper/FormMap.resx new file mode 100644 index 0000000..30aae67 --- /dev/null +++ b/Stormtrooper/Stormtrooper/FormMap.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 25 + + \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs b/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs index 0bc4963..661a1a1 100644 --- a/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs +++ b/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/FormStormtrooper.cs b/Stormtrooper/Stormtrooper/FormStormtrooper.cs index a8633d4..1479266 100644 --- a/Stormtrooper/Stormtrooper/FormStormtrooper.cs +++ b/Stormtrooper/Stormtrooper/FormStormtrooper.cs @@ -3,12 +3,11 @@ namespace Stormtrooper public partial class FormStormtrooper : Form { private Drawning _storm; - + public FormStormtrooper() { InitializeComponent(); } - //private EntityStormtrooper Storm; /// /// /// @@ -19,6 +18,18 @@ namespace Stormtrooper _storm?.DrawTransport(gr); pictureBoxStormtrooper.Image = bmp; } + + /// + /// + /// + 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}"; + } /// /// "" /// @@ -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(); } /// @@ -71,5 +78,21 @@ namespace Stormtrooper _storm?.ChangeBorders(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); Draw(); } + + /// + /// "" + /// + /// + /// + 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(); + } } } \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/IDrawningObject.cs b/Stormtrooper/Stormtrooper/IDrawningObject.cs new file mode 100644 index 0000000..82df051 --- /dev/null +++ b/Stormtrooper/Stormtrooper/IDrawningObject.cs @@ -0,0 +1,43 @@ +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; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + void SetObject(int x, int y, int width, int height); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + void MoveObject(Direction direction); + /// + /// Отрисовка объекта + /// + /// + void DrawningObject(Graphics g); + /// + /// Получение текущей позиции объекта + /// + /// + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + + } +} diff --git a/Stormtrooper/Stormtrooper/Program.cs b/Stormtrooper/Stormtrooper/Program.cs index f56f0d8..a5278ed 100644 --- a/Stormtrooper/Stormtrooper/Program.cs +++ b/Stormtrooper/Stormtrooper/Program.cs @@ -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()); } } } \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/SecondMap.cs b/Stormtrooper/Stormtrooper/SecondMap.cs new file mode 100644 index 0000000..49aae09 --- /dev/null +++ b/Stormtrooper/Stormtrooper/SecondMap.cs @@ -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 + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.White); + /// + /// Цвет участка открытого + /// + 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++; + } + } + } + } +} diff --git a/Stormtrooper/Stormtrooper/SimpleMap.cs b/Stormtrooper/Stormtrooper/SimpleMap.cs new file mode 100644 index 0000000..07cb62a --- /dev/null +++ b/Stormtrooper/Stormtrooper/SimpleMap.cs @@ -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 + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// + /// Цвет участка открытого + /// + 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++; + } + } + } + } +} diff --git a/Stormtrooper/Stormtrooper/ThirdMap.cs b/Stormtrooper/Stormtrooper/ThirdMap.cs new file mode 100644 index 0000000..a12c413 --- /dev/null +++ b/Stormtrooper/Stormtrooper/ThirdMap.cs @@ -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 + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Gray); + /// + /// Цвет участка открытого + /// + 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++; + } + } + } + } +}