Merge pull request 'Bondarenko M.S. Lab Work 2' (#6) from LabWork_02 into LabWork_01

Reviewed-on: http://student.git.athene.tech/maxnes3/PIbd-22_Bondarenko_M.S._WarmlyShip_Base/pulls/6
This commit is contained in:
Евгений Эгов 2022-10-21 09:12:47 +04:00
commit e47808c2f8
17 changed files with 825 additions and 17 deletions

View File

@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
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();
}
private bool CanMove(Direction direction, (float Left, float Right, float Top, float Bottom) position) //Проверка на возможность шага
{
for (int i = (int)(position.Top / _size_y); i <= (int)(position.Bottom / _size_y); ++i)
{
for (int j = (int)(position.Left / _size_x); j <= (int)(position.Right / _size_x); ++j)
{
if (i >= 0 && j >= 0 && i < _map.GetLength(0) && j < _map.GetLength(1) && _map[i, j] == _barrier) return false;
}
}
return true;
}
public Bitmap MoveObject(Direction direction)
{
(float Left, float Right, float Top, float Bottom) position = _drawningObject.GetCurrentPosition();
if (direction == Direction.Left)
{
position.Left -= _drawningObject.Step;
}
else if (direction == Direction.Right)
{
position.Right += _drawningObject.Step;
}
else if (direction == Direction.Up)
{
position.Top -= _drawningObject.Step;
}
else if (direction == Direction.Down)
{
position.Bottom += _drawningObject.Step;
}
if (CanMove(direction, position))
{
_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);
for (int i = (int)(_drawningObject.GetCurrentPosition().Top / _size_y); i <= (int)(_drawningObject.GetCurrentPosition().Bottom / _size_y); ++i)
{
for (int j = (int)(_drawningObject.GetCurrentPosition().Left / _size_x); j <= (int)(_drawningObject.GetCurrentPosition().Right / _size_x); ++j)
{
if (_map[i, j] == _barrier) _map[i, j] = _freeRoad;
}
}
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

@ -8,6 +8,7 @@ namespace WarmlyShip
{ {
internal enum Direction //Направление при перемещении internal enum Direction //Направление при перемещении
{ {
None = 0,
Left = 1, //Влево Left = 1, //Влево
Up = 2, //Вверх Up = 2, //Вверх
Right = 3, //Вправо Right = 3, //Вправо

View File

@ -8,19 +8,24 @@ namespace WarmlyShip
{ {
internal class DrawingWarmlyShip internal class DrawingWarmlyShip
{ {
public EntityWarmlyShip warmlyShip { private set; get; } //Класс-сущность public EntityWarmlyShip warmlyShip { protected set; get; } //Класс-сущность
public float _startPosX; //Координаты отрисовки по оси x protected float _startPosX; //Координаты отрисовки по оси x
public float _startPosY; //Координаты отрисовки по оси y protected float _startPosY; //Координаты отрисовки по оси y
private int? _pictureWidth = null; //Ширина окна private int? _pictureWidth = null; //Ширина окна
private int? _pictureHeight = null; //Высота окна private int? _pictureHeight = null; //Высота окна
private readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля protected readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля
private readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля protected readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля
//Инициализация //Инициализация
public void Init(int speed, float weight, Color bodyColor) public DrawingWarmlyShip(int speed, float weight, Color bodyColor)
{ {
warmlyShip = new EntityWarmlyShip(); warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor);
warmlyShip.Init(speed, weight, bodyColor); }
protected DrawingWarmlyShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight) : this(speed, weight, bodyColor)
{
_warmlyShipWidth = warmlyWidth;
_warmlyShipHeight = warmlyHeight;
} }
//Начальные коордитанты //Начальные коордитанты
@ -56,7 +61,7 @@ namespace WarmlyShip
} }
//Отрисовка транспорта //Отрисовка транспорта
public void DrawTransport(Graphics g) public virtual void DrawTransport(Graphics g)
{ {
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{ {
@ -109,5 +114,10 @@ namespace WarmlyShip
} }
} }
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosX + _warmlyShipWidth, _startPosY, _startPosY + _warmlyShipHeight);
}
} }
} }

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
internal class DrawningMotorShip : DrawingWarmlyShip
{
public DrawningMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor, 150, 75)
{
warmlyShip = new EntityMotorShip(speed, weight, bodyColor, dopColor, tubes , cistern);
}
public override void DrawTransport(Graphics g)
{
if (warmlyShip is not EntityMotorShip motorShip)
{
return;
}
Pen pen = new(Color.Black, 2);
Brush dopBrush = new SolidBrush(motorShip.DopColor);
if (motorShip.Tubes)
{
g.FillRectangle(dopBrush, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
g.DrawRectangle(pen, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
g.FillRectangle(dopBrush, _startPosX + _warmlyShipWidth * 3 / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
g.DrawRectangle(pen, _startPosX + _warmlyShipWidth * 3 / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
}
_startPosY += 25;
base.DrawTransport(g);
_startPosY -= 25;
if (motorShip.Cistern)
{
g.FillEllipse(dopBrush, _startPosX, _startPosY + 25, 25, 20);
g.DrawEllipse(pen, _startPosX, _startPosY + 25, 25, 20);
}
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
internal class DrawningObjectShip : IDrawningObject
{
private DrawingWarmlyShip _warmlyShip = null;
public DrawningObjectShip(DrawingWarmlyShip warmlyShip)
{
_warmlyShip = warmlyShip;
}
public float Step => _warmlyShip?.warmlyShip?.Step ?? 0;
public void DrawningObject(Graphics g)
{
_warmlyShip?.DrawTransport(g);
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _warmlyShip?.GetCurrentPosition() ?? default;
}
public void MoveObject(Direction direction)
{
_warmlyShip?.MoveTransport(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_warmlyShip?.SetPosition(x, y, width, height);
}
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
internal class EntityMotorShip : EntityWarmlyShip
{
public Color DopColor { get; private set; }
public bool Tubes { get; private set; }
public bool Cistern { get; private set; }
public EntityMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor)
{
DopColor = dopColor;
Tubes = tubes;
Cistern = cistern;
}
}
}

View File

@ -14,7 +14,7 @@ namespace WarmlyShip
public float Step => Speed * 100 / Weight; //Шаг при перемещении public float Step => Speed * 100 / Weight; //Шаг при перемещении
//Инициализация //Инициализация
public void Init(int speed, float weight, Color bodyColor) public EntityWarmlyShip(int speed, float weight, Color bodyColor)
{ {
Random random = new Random(); Random random = new Random();
Speed = speed <= 0 ? random.Next(50, 150) : speed; Speed = speed <= 0 ? random.Next(50, 150) : speed;

View File

@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.ButtonCreate = new System.Windows.Forms.Button(); this.ButtonCreate = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.statusStrip.SuspendLayout(); this.statusStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -142,11 +143,23 @@
this.ButtonCreate.UseVisualStyleBackColor = true; this.ButtonCreate.UseVisualStyleBackColor = true;
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_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(93, 402);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(101, 23);
this.buttonCreateModif.TabIndex = 8;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// FormClass // FormClass
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.ButtonCreate); this.Controls.Add(this.ButtonCreate);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonLeft);
@ -176,5 +189,6 @@
private Button buttonLeft; private Button buttonLeft;
private Button buttonDown; private Button buttonDown;
private Button ButtonCreate; private Button ButtonCreate;
private Button buttonCreateModif;
} }
} }

View File

@ -17,15 +17,20 @@ namespace WarmlyShip
pictureBox.Image = bmp; pictureBox.Image = bmp;
} }
private void SetData()
{
Random random = new Random();
_warmlyShip.SetPosition(random.Next(0, 100), random.Next(0, 100), pictureBox.Width, pictureBox.Height);
toolStripStatusSpeed.Text = $"Ñêîðîñòü: { _warmlyShip.warmlyShip?.Speed}";
toolStripStatusWeight.Text = $"Âåñ: {_warmlyShip.warmlyShip?.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_warmlyShip.warmlyShip?.BodyColor}";
}
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random random = new Random(); Random random = new Random();
_warmlyShip = new DrawingWarmlyShip(); _warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
_warmlyShip.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); SetData();
_warmlyShip.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBox.Width, pictureBox.Height);
toolStripStatusSpeed.Text = $"Ñêîðîñòü: {_warmlyShip.warmlyShip?.Speed}";
toolStripStatusWeight.Text = $"Âåñ: {_warmlyShip.warmlyShip?.Weight}";
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_warmlyShip.warmlyShip?.BodyColor}";
Draw(); Draw();
} }
@ -55,5 +60,16 @@ namespace WarmlyShip
_warmlyShip?.ChangeBorders(pictureBox.Width, pictureBox.Height); _warmlyShip?.ChangeBorders(pictureBox.Width, pictureBox.Height);
Draw(); Draw();
} }
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random random = new Random();
_warmlyShip = new DrawningMotorShip(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
SetData();
Draw();
}
} }
} }

210
WarmlyShip/WarmlyShip/FormMap.Designer.cs generated Normal file
View File

@ -0,0 +1,210 @@
namespace WarmlyShip
{
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.pictureBox = new System.Windows.Forms.PictureBox();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.ButtonCreate = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(800, 428);
this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
//
// statusStrip
//
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusSpeed,
this.toolStripStatusWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip.Location = new System.Drawing.Point(0, 428);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22);
this.statusStrip.TabIndex = 1;
this.statusStrip.Text = "statusStrip1";
//
// toolStripStatusSpeed
//
this.toolStripStatusSpeed.Name = "toolStripStatusSpeed";
this.toolStripStatusSpeed.Size = new System.Drawing.Size(62, 17);
this.toolStripStatusSpeed.Text = "Скорость:";
//
// toolStripStatusWeight
//
this.toolStripStatusWeight.Name = "toolStripStatusWeight";
this.toolStripStatusWeight.Size = new System.Drawing.Size(29, 17);
this.toolStripStatusWeight.Text = "Вес:";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::WarmlyShip.Properties.Resources.toright;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(738, 375);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(50, 50);
this.buttonRight.TabIndex = 3;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::WarmlyShip.Properties.Resources.totop;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(682, 319);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(50, 50);
this.buttonUp.TabIndex = 4;
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::WarmlyShip.Properties.Resources.toleft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(626, 375);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(50, 50);
this.buttonLeft.TabIndex = 5;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.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::WarmlyShip.Properties.Resources.todown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(682, 375);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(50, 50);
this.buttonDown.TabIndex = 6;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// 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(12, 402);
this.ButtonCreate.Name = "ButtonCreate";
this.ButtonCreate.Size = new System.Drawing.Size(75, 23);
this.ButtonCreate.TabIndex = 7;
this.ButtonCreate.Text = "Создать";
this.ButtonCreate.UseVisualStyleBackColor = true;
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_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(93, 402);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(100, 23);
this.buttonCreateModif.TabIndex = 8;
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(12, 12);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
this.comboBoxSelectorMap.TabIndex = 9;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.СomboBoxSelectorMap_SelectedIndexChanged);
//
// FormMap
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
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.ButtonCreate);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.statusStrip);
this.Name = "FormMap";
this.Text = "FormMap";
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBox;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusSpeed;
private ToolStripStatusLabel toolStripStatusWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonRight;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDown;
private Button ButtonCreate;
private Button buttonCreateModif;
private ComboBox comboBoxSelectorMap;
}
}

View File

@ -0,0 +1,88 @@
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 WarmlyShip
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
private void SetData(DrawingWarmlyShip warmlyShip)
{
toolStripStatusSpeed.Text = $"Скорость: {warmlyShip.warmlyShip?.Speed}";
toolStripStatusWeight.Text = $"Вес: {warmlyShip.warmlyShip?.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {warmlyShip.warmlyShip?.BodyColor}";
pictureBox.Image = _abstractMap.CreateMap(pictureBox.Width, pictureBox.Height, new DrawningObjectShip(warmlyShip));
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new Random();
var warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
SetData(warmlyShip);
}
private void ButtonMove_Click(object sender, EventArgs e)
{
string name = ((Button)sender)?.Name ?? string.Empty;
Direction direction = Direction.None;
switch (name)
{
case "buttonLeft":
direction = Direction.Left;
break;
case "buttonUp":
direction = Direction.Up;
break;
case "buttonRight":
direction = Direction.Right;
break;
case "buttonDown":
direction = Direction.Down;
break;
}
pictureBox.Image = _abstractMap?.MoveObject(direction);
}
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random random = new Random();
var warmlyShip = new DrawningMotorShip(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
SetData(warmlyShip);
}
private void СomboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Вторая карта":
_abstractMap = new SecondMap();
break;
case "Последняя карта":
_abstractMap = new LastMap();
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="statusStrip.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,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
internal interface IDrawningObject
{
public float Step { get; }
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();
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
internal class LastMap : AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.Red);
private readonly Brush roadColor = new SolidBrush(Color.Green);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, j * _size_x, i * _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 < 45)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
if (x > 0 && y > 0 && x < _map.GetLength(0) - 1 && y < _map.GetLength(1) - 1)
{
_map[x - 1, y] = _barrier;
_map[x + 1, y] = _barrier;
_map[x, y - 1] = _barrier;
_map[x, y + 1] = _barrier;
}
counter++;
}
}
}
}
}

View File

@ -11,7 +11,7 @@ namespace WarmlyShip
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormClass()); Application.Run(new FormMap());
} }
} }
} }

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
internal class SecondMap : AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.Gold);
private readonly Brush roadColor = new SolidBrush(Color.Black);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, j * _size_x, i * _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;
}
}
for (int i = 0; i < _map.GetLength(0); ++i)
{
_map[i, _map.GetLength(1) / 2] = _barrier;
_map[i, _map.GetLength(1) - 1] = _barrier;
}
for (int j = 0; j < _map.GetLength(1); ++j)
{
_map[_map.GetLength(0) - 1, j] = _barrier;
}
while (counter < 45)
{
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,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
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, j * _size_x, i * _size_y, _size_x, _size_y);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, j * _size_x, i * _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++;
}
}
}
}
}