Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
6b03666b60 | |||
2ad3451337 | |||
4d14fe77e5 |
157
WarmlyShip/WarmlyShip/AbstractMap.cs
Normal file
157
WarmlyShip/WarmlyShip/AbstractMap.cs
Normal file
@ -0,0 +1,157 @@
|
||||
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();
|
||||
}
|
||||
|
||||
public bool CheckAround(float Left, float Right, float Top, float Bottom)
|
||||
{
|
||||
int startX = (int)(Left / _size_x);
|
||||
int startY = (int)(Right / _size_y);
|
||||
int endX = (int)(Top / _size_x);
|
||||
if (endX > 100)
|
||||
{
|
||||
endX = 100;
|
||||
}
|
||||
int endY = (int)(Bottom / _size_y);
|
||||
if (endY > 100)
|
||||
{
|
||||
endY = 100;
|
||||
}
|
||||
|
||||
for (int i = startX; i < endX; i++)
|
||||
{
|
||||
for (int j = startY; j < endY; j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
|
||||
|
||||
if (CheckAround(Left, Right, Top, Bottom))
|
||||
{
|
||||
_drawningObject.MoveObject(MoveObjectBack(direction));
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private Direction MoveObjectBack(Direction direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Up:
|
||||
return Direction.Down;
|
||||
case Direction.Down:
|
||||
return Direction.Up;
|
||||
case Direction.Left:
|
||||
return Direction.Right;
|
||||
case Direction.Right:
|
||||
return Direction.Left;
|
||||
}
|
||||
return Direction.None;
|
||||
}
|
||||
|
||||
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);
|
||||
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
|
||||
if (!CheckAround(Left, Right, Top, Bottom)) return true;
|
||||
float startX = Left;
|
||||
float startY = Right;
|
||||
float lengthX = Top - Left;
|
||||
float lengthY = Bottom - Right;
|
||||
while (CheckAround(startX, startY, startX + lengthX, startY + lengthY))
|
||||
{
|
||||
bool result;
|
||||
do
|
||||
{
|
||||
result = CheckAround(startX, startY, startX + lengthX, startY + lengthY);
|
||||
if (!result)
|
||||
{
|
||||
_drawningObject.SetObject((int)startX, (int)startY, _width, _height);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
startX += _size_x;
|
||||
}
|
||||
} while (result);
|
||||
startX = x;
|
||||
startY += _size_y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -6,8 +6,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyShip
|
||||
{
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
|
40
WarmlyShip/WarmlyShip/DrawningObjectShip.cs
Normal file
40
WarmlyShip/WarmlyShip/DrawningObjectShip.cs
Normal 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 DrawningWarmlyShip _ship;
|
||||
|
||||
public DrawningObjectShip(DrawningWarmlyShip ship)
|
||||
{
|
||||
_ship = ship;
|
||||
}
|
||||
|
||||
public float Step => _ship.Ship.Step;
|
||||
|
||||
public void DrawningObject(Graphics g)
|
||||
{
|
||||
_ship.DrawTransport(g);
|
||||
}
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _ship?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_ship.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_ship.SetPosition(x, y, width, height);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +1,19 @@
|
||||
namespace WarmlyShip
|
||||
{
|
||||
internal class DrawningWarmlyShip
|
||||
public class DrawningWarmlyShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityWarmlyShip Ship { get; private set; }
|
||||
public EntityWarmlyShip Ship { get; protected set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки коробля
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки коробля
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -36,10 +36,14 @@
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес коробля</param>
|
||||
/// <param name="bodyColor">Цвет основной части</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawningWarmlyShip(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Ship = new EntityWarmlyShip();
|
||||
Ship.Init(speed, weight, bodyColor);
|
||||
Ship = new EntityWarmlyShip(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawningWarmlyShip(int speed, float weight, Color bodyColor, int shipWight, int shipHeight) : this(speed, weight, bodyColor)
|
||||
{
|
||||
_shipWidth = shipWight;
|
||||
_shipHeight = shipHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции коробля
|
||||
@ -105,17 +109,21 @@
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DrawCheck()
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовка корабля
|
||||
/// </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)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush br = new SolidBrush(Ship.BodyColor);
|
||||
Brush brWindow = new SolidBrush(Color.FromArgb(79, 209, 204));
|
||||
@ -127,7 +135,7 @@
|
||||
PointF point2;
|
||||
PointF point3;
|
||||
point1 = new PointF(_startPosX, _startPosY + 30);
|
||||
point2 = new PointF(_startPosX + 50, _startPosY +30);
|
||||
point2 = new PointF(_startPosX + 50, _startPosY + 30);
|
||||
point3 = new PointF(_startPosX + 50, _startPosY + 65);
|
||||
PointF[] curvePoints =
|
||||
{
|
||||
@ -137,7 +145,7 @@
|
||||
};
|
||||
g.FillPolygon(br, curvePoints);
|
||||
|
||||
point1 = new PointF(_startPosX+150, _startPosY + 30);
|
||||
point1 = new PointF(_startPosX + 150, _startPosY + 30);
|
||||
point2 = new PointF(_startPosX + 200, _startPosY + 30);
|
||||
point3 = new PointF(_startPosX + 150, _startPosY + 65);
|
||||
PointF[] curvePoints2 =
|
||||
@ -173,5 +181,10 @@
|
||||
_startPosY = _pictureHeight.Value - _shipHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + _shipHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
36
WarmlyShip/WarmlyShip/DrawningWarmlyShipMod.cs
Normal file
36
WarmlyShip/WarmlyShip/DrawningWarmlyShipMod.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyShip
|
||||
{
|
||||
internal class DrawningWarmlyShipMod : DrawningWarmlyShip
|
||||
{
|
||||
public DrawningWarmlyShipMod(int speed, float weight, Color bodyColor, Color dopColor) : base(speed, weight, bodyColor, 200, 90)
|
||||
{
|
||||
Ship = new EntityModofiedWarmlyShip(speed, weight, bodyColor, dopColor);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Ship is not EntityModofiedWarmlyShip modifShip)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_startPosY += 25;
|
||||
base.DrawTransport(g);
|
||||
_startPosY -= 25;
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush br = new SolidBrush(Ship.BodyColor);
|
||||
Brush dopBr = new SolidBrush(modifShip.DopColor);
|
||||
Brush brWindow = new SolidBrush(Color.FromArgb(79, 209, 204));
|
||||
g.FillRectangle(dopBr, _startPosX + 90, _startPosY, 15, 25);
|
||||
g.FillRectangle(dopBr, _startPosX + 115, _startPosY, 15, 25);
|
||||
g.FillEllipse(dopBr, _startPosX + 50, _startPosY + 55, 50, 35);
|
||||
}
|
||||
}
|
||||
}
|
23
WarmlyShip/WarmlyShip/EntityModofiedWarmlyShip.cs
Normal file
23
WarmlyShip/WarmlyShip/EntityModofiedWarmlyShip.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyShip
|
||||
{
|
||||
internal class EntityModofiedWarmlyShip : EntityWarmlyShip
|
||||
{
|
||||
/// Дополнительный цвет
|
||||
public Color DopColor { get; private set; }
|
||||
/// Инициализация свойств
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес трактора</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
public EntityModofiedWarmlyShip(int speed, float weight, Color bodyColor, Color dopColor) : base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyShip
|
||||
{
|
||||
internal class EntityWarmlyShip
|
||||
public class EntityWarmlyShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -31,7 +31,7 @@ namespace WarmlyShip
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityWarmlyShip(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
|
214
WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.Designer.cs
generated
Normal file
214
WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.Designer.cs
generated
Normal file
@ -0,0 +1,214 @@
|
||||
namespace WarmlyShip
|
||||
{
|
||||
partial class FormMapWithSetWarmlyShip
|
||||
{
|
||||
/// <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.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRemoveTraktor = new System.Windows.Forms.Button();
|
||||
this.buttonAddTraktor = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.buttonRight);
|
||||
this.groupBox1.Controls.Add(this.buttonDown);
|
||||
this.groupBox1.Controls.Add(this.buttonLeft);
|
||||
this.groupBox1.Controls.Add(this.buttonUp);
|
||||
this.groupBox1.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBox1.Controls.Add(this.buttonShowStorage);
|
||||
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBox1.Controls.Add(this.buttonRemoveTraktor);
|
||||
this.groupBox1.Controls.Add(this.buttonAddTraktor);
|
||||
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox1.Location = new System.Drawing.Point(750, 0);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(250, 495);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.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.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(95, 451);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonRight.TabIndex = 10;
|
||||
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::WarmlyShip.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(55, 451);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonDown.TabIndex = 9;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::WarmlyShip.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(15, 451);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonLeft.TabIndex = 8;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::WarmlyShip.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(55, 411);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonUp.TabIndex = 7;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(6, 281);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(193, 29);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(6, 246);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(193, 29);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 122);
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(100, 27);
|
||||
this.maskedTextBoxPosition.TabIndex = 11;
|
||||
//
|
||||
// buttonRemoveTraktor
|
||||
//
|
||||
this.buttonRemoveTraktor.Location = new System.Drawing.Point(6, 155);
|
||||
this.buttonRemoveTraktor.Name = "buttonRemoveTraktor";
|
||||
this.buttonRemoveTraktor.Size = new System.Drawing.Size(151, 32);
|
||||
this.buttonRemoveTraktor.TabIndex = 2;
|
||||
this.buttonRemoveTraktor.Text = "Удалить корабль";
|
||||
this.buttonRemoveTraktor.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveTraktor.Click += new System.EventHandler(this.ButtonRemoveShip_Click);
|
||||
//
|
||||
// buttonAddTraktor
|
||||
//
|
||||
this.buttonAddTraktor.Location = new System.Drawing.Point(6, 83);
|
||||
this.buttonAddTraktor.Name = "buttonAddTraktor";
|
||||
this.buttonAddTraktor.Size = new System.Drawing.Size(151, 33);
|
||||
this.buttonAddTraktor.TabIndex = 1;
|
||||
this.buttonAddTraktor.Text = "Добавить корабль";
|
||||
this.buttonAddTraktor.UseVisualStyleBackColor = true;
|
||||
this.buttonAddTraktor.Click += new System.EventHandler(this.ButtonAddShip_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Море"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 26);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// 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(750, 495);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetWarmlyShip
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1000, 495);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Name = "FormMapWithSetWarmlyShip";
|
||||
this.Text = "Автобус";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox1;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonShowOnMap;
|
||||
private Button buttonShowStorage;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonRemoveTraktor;
|
||||
private Button buttonAddTraktor;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
}
|
||||
}
|
145
WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs
Normal file
145
WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs
Normal file
@ -0,0 +1,145 @@
|
||||
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 FormMapWithSetWarmlyShip : Form
|
||||
{
|
||||
private MapWithSetWarmlyShipGeneric<DrawningObjectShip, AbstractMap> _mapShipCollectionGeneric;
|
||||
|
||||
public FormMapWithSetWarmlyShip()
|
||||
{
|
||||
InitializeComponent();
|
||||
AbstractMap map = new SimpleMap();
|
||||
_mapShipCollectionGeneric = new MapWithSetWarmlyShipGeneric<DrawningObjectShip, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Море":
|
||||
map = new SeeMap();
|
||||
break;
|
||||
}
|
||||
|
||||
if (map != null)
|
||||
{
|
||||
_mapShipCollectionGeneric = new MapWithSetWarmlyShipGeneric<DrawningObjectShip, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
_mapShipCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAddShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapShipCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormShip form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.SelectedShip == null)
|
||||
{
|
||||
MessageBox.Show("Сначала создайте объект");
|
||||
return;
|
||||
}
|
||||
|
||||
DrawningObjectShip bus = new(form.SelectedShip);
|
||||
|
||||
if (_mapShipCollectionGeneric + bus != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapShipCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemoveShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapShipCollectionGeneric - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapShipCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapShipCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapShipCollectionGeneric.ShowSet();
|
||||
}
|
||||
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapShipCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapShipCollectionGeneric.ShowOnMap();
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapShipCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapShipCollectionGeneric.MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
120
WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.resx
Normal file
120
WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
193
WarmlyShip/WarmlyShip/FormShip.Designer.cs
generated
193
WarmlyShip/WarmlyShip/FormShip.Designer.cs
generated
@ -29,148 +29,163 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxShip = new System.Windows.Forms.PictureBox();
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
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.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = 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.buttonUP = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.buttonSelectedShip = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxShip
|
||||
//
|
||||
this.pictureBoxShip.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxShip.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxShip.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.pictureBoxShip.Name = "pictureBoxShip";
|
||||
this.pictureBoxShip.Size = new System.Drawing.Size(700, 316);
|
||||
this.pictureBoxShip.Size = new System.Drawing.Size(800, 425);
|
||||
this.pictureBoxShip.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxShip.TabIndex = 0;
|
||||
this.pictureBoxShip.TabStop = false;
|
||||
//
|
||||
// statusStrip1
|
||||
// statusStrip
|
||||
//
|
||||
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
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.statusStrip1.Location = new System.Drawing.Point(0, 316);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0);
|
||||
this.statusStrip1.Size = new System.Drawing.Size(700, 22);
|
||||
this.statusStrip1.TabIndex = 1;
|
||||
this.statusStrip1.Text = "statusStrip1";
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 425);
|
||||
this.statusStrip.Name = "statusStrip";
|
||||
this.statusStrip.Size = new System.Drawing.Size(800, 26);
|
||||
this.statusStrip.TabIndex = 1;
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17);
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(80, 20);
|
||||
this.toolStripStatusLabelSpeed.Text = "Скорость: ";
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17);
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(40, 20);
|
||||
this.toolStripStatusLabelWeight.Text = "Вес: ";
|
||||
//
|
||||
// toolStripStatusLabelBodyColor
|
||||
//
|
||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Цвет: ";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(95, 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(10, 275);
|
||||
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonCreate.Location = new System.Drawing.Point(29, 363);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(82, 22);
|
||||
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
//
|
||||
// buttonDown
|
||||
// buttonLEFT
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::WarmlyShip.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(613, 275);
|
||||
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonDown.TabIndex = 3;
|
||||
this.buttonDown.Text = " ";
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
this.buttonLEFT.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLEFT.BackgroundImage = global::WarmlyShip.Properties.Resources.arrowLeft;
|
||||
this.buttonLEFT.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLEFT.Location = new System.Drawing.Point(673, 361);
|
||||
this.buttonLEFT.Name = "buttonLEFT";
|
||||
this.buttonLEFT.Size = new System.Drawing.Size(30, 29);
|
||||
this.buttonLEFT.TabIndex = 3;
|
||||
this.buttonLEFT.UseVisualStyleBackColor = true;
|
||||
this.buttonLEFT.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
// buttonRIGHT
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::WarmlyShip.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(613, 248);
|
||||
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonUp.TabIndex = 4;
|
||||
this.buttonUp.Text = " ";
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
this.buttonRIGHT.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRIGHT.BackgroundImage = global::WarmlyShip.Properties.Resources.arrowRight;
|
||||
this.buttonRIGHT.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRIGHT.Location = new System.Drawing.Point(745, 361);
|
||||
this.buttonRIGHT.Name = "buttonRIGHT";
|
||||
this.buttonRIGHT.Size = new System.Drawing.Size(30, 29);
|
||||
this.buttonRIGHT.TabIndex = 4;
|
||||
this.buttonRIGHT.UseVisualStyleBackColor = true;
|
||||
this.buttonRIGHT.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
// buttonDOWN
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::WarmlyShip.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(645, 275);
|
||||
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonRight.TabIndex = 5;
|
||||
this.buttonRight.Text = " ";
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
this.buttonDOWN.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDOWN.BackgroundImage = global::WarmlyShip.Properties.Resources.arrowDown;
|
||||
this.buttonDOWN.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDOWN.Location = new System.Drawing.Point(709, 379);
|
||||
this.buttonDOWN.Name = "buttonDOWN";
|
||||
this.buttonDOWN.Size = new System.Drawing.Size(30, 29);
|
||||
this.buttonDOWN.TabIndex = 5;
|
||||
this.buttonDOWN.UseVisualStyleBackColor = true;
|
||||
this.buttonDOWN.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
// buttonUP
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::WarmlyShip.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(582, 276);
|
||||
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonLeft.TabIndex = 6;
|
||||
this.buttonLeft.Text = " ";
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
this.buttonUP.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUP.BackgroundImage = global::WarmlyShip.Properties.Resources.arrowUp;
|
||||
this.buttonUP.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUP.Location = new System.Drawing.Point(709, 343);
|
||||
this.buttonUP.Name = "buttonUP";
|
||||
this.buttonUP.Size = new System.Drawing.Size(30, 29);
|
||||
this.buttonUP.TabIndex = 6;
|
||||
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(129, 363);
|
||||
this.buttonCreateModif.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(126, 29);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||
//
|
||||
// buttonSelectedShip
|
||||
//
|
||||
this.buttonSelectedShip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonSelectedShip.Location = new System.Drawing.Point(261, 363);
|
||||
this.buttonSelectedShip.Name = "buttonSelectedShip";
|
||||
this.buttonSelectedShip.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonSelectedShip.TabIndex = 8;
|
||||
this.buttonSelectedShip.Text = "Выбор";
|
||||
this.buttonSelectedShip.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectedShip.Click += new System.EventHandler(this.buttonSelectedTraktor_Click);
|
||||
//
|
||||
// FormShip
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(700, 338);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.ClientSize = new System.Drawing.Size(800, 451);
|
||||
this.Controls.Add(this.buttonSelectedShip);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonUP);
|
||||
this.Controls.Add(this.buttonDOWN);
|
||||
this.Controls.Add(this.buttonRIGHT);
|
||||
this.Controls.Add(this.buttonLEFT);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.pictureBoxShip);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Controls.Add(this.statusStrip);
|
||||
this.Name = "FormShip";
|
||||
this.Text = "Корабль";
|
||||
this.Text = "Трактор";
|
||||
this.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit();
|
||||
this.statusStrip1.ResumeLayout(false);
|
||||
this.statusStrip1.PerformLayout();
|
||||
this.statusStrip.ResumeLayout(false);
|
||||
this.statusStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@ -179,14 +194,16 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxShip;
|
||||
private StatusStrip statusStrip1;
|
||||
private StatusStrip statusStrip;
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private Button buttonCreate;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonLEFT;
|
||||
private Button buttonRIGHT;
|
||||
private Button buttonDOWN;
|
||||
private Button buttonUP;
|
||||
private Button buttonCreateModif;
|
||||
private Button buttonSelectedShip;
|
||||
}
|
||||
}
|
@ -3,6 +3,9 @@ namespace WarmlyShip
|
||||
public partial class FormShip : Form
|
||||
{
|
||||
private DrawningWarmlyShip _ship;
|
||||
|
||||
public DrawningWarmlyShip SelectedShip { get; private set; }
|
||||
|
||||
public FormShip()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -14,6 +17,13 @@ namespace WarmlyShip
|
||||
_ship?.DrawTransport(gr);
|
||||
pictureBoxShip.Image = bmp;
|
||||
}
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
toolStripStatusLabelSpeed.Text = $"Ńęîđîńňü: {_ship.Ship.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âĺń: {_ship.Ship.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâĺň: {_ship.Ship.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
@ -22,12 +32,14 @@ namespace WarmlyShip
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_ship = new DrawningWarmlyShip();
|
||||
_ship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_ship = new DrawningWarmlyShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
@ -52,5 +64,33 @@ namespace WarmlyShip
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialogDop = new();
|
||||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialogDop.Color;
|
||||
}
|
||||
|
||||
_ship = new DrawningWarmlyShipMod(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonSelectedTraktor_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedShip = _ship;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
28
WarmlyShip/WarmlyShip/IDrawningObject.cs
Normal file
28
WarmlyShip/WarmlyShip/IDrawningObject.cs
Normal file
@ -0,0 +1,28 @@
|
||||
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; }
|
||||
/// Установка позиции объекта
|
||||
/// <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);
|
||||
/// Изменение направления пермещения объекта
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(Direction direction);
|
||||
/// Отрисовка объекта
|
||||
/// <param name="g"></param>
|
||||
void DrawningObject(Graphics g);
|
||||
/// Получение текущей позиции объекта
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
}
|
||||
}
|
130
WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs
Normal file
130
WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs
Normal file
@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyShip
|
||||
{
|
||||
internal class MapWithSetWarmlyShipGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 180;
|
||||
private readonly int _placeSizeHeight = 150;
|
||||
private readonly SetWarmlyShipGeneric<T> _setWarmlyShip;
|
||||
private readonly U _map;
|
||||
|
||||
public MapWithSetWarmlyShipGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setWarmlyShip = new SetWarmlyShipGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public static int operator +(MapWithSetWarmlyShipGeneric<T, U> map, T bus)
|
||||
{
|
||||
return map._setWarmlyShip.Insert(bus);
|
||||
}
|
||||
|
||||
public static T operator -(MapWithSetWarmlyShipGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setWarmlyShip.Remove(position);
|
||||
}
|
||||
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawTraktors(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setWarmlyShip.Count; i++)
|
||||
{
|
||||
var bus = _setWarmlyShip.Get(i);
|
||||
if (bus != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, bus);
|
||||
}
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setWarmlyShip.Count - 1;
|
||||
for (int i = 0; i < _setWarmlyShip.Count; i++)
|
||||
{
|
||||
if (_setWarmlyShip.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var bus = _setWarmlyShip.Get(j);
|
||||
if (bus != null)
|
||||
{
|
||||
_setWarmlyShip.Insert(bus, i);
|
||||
_setWarmlyShip.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
for (int x = 0; x < _pictureWidth; x++)
|
||||
{
|
||||
for (int y = 0; y < _pictureWidth; y++)
|
||||
{
|
||||
Brush waterColor = new SolidBrush(Color.LightSkyBlue);
|
||||
g.FillRectangle(waterColor, x * x, y * y, x * (x + 1), y * (y + 1));
|
||||
}
|
||||
}
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawTraktors(Graphics g)
|
||||
{
|
||||
int countInLine = _pictureWidth / _placeSizeWidth;
|
||||
int maxLeft = (countInLine - 1) * _placeSizeWidth;
|
||||
for (int i = 0; i < _setWarmlyShip.Count; i++)
|
||||
{
|
||||
var ship = _setWarmlyShip.Get(i);
|
||||
ship?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, i / countInLine * _placeSizeHeight + 3, _pictureWidth, _pictureHeight);
|
||||
ship?.DrawningObject(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace WarmlyShip
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormShip());
|
||||
Application.Run(new FormMapWithSetWarmlyShip());
|
||||
}
|
||||
}
|
||||
}
|
52
WarmlyShip/WarmlyShip/SeeMap.cs
Normal file
52
WarmlyShip/WarmlyShip/SeeMap.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyShip
|
||||
{
|
||||
internal class SeeMap : AbstractMap
|
||||
{
|
||||
/// Цвет участка закрытого
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.White);
|
||||
/// Цвет участка открытого
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Blue);
|
||||
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 20)
|
||||
{
|
||||
int x = _random.Next(0, 97);
|
||||
int y = _random.Next(0, 97);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
_map[x + 2, y] = _barrier;
|
||||
_map[x, y + 2] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
62
WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs
Normal file
62
WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WarmlyShip
|
||||
{
|
||||
internal class SetWarmlyShipGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly T[] _places;
|
||||
public int Count => _places.Length;
|
||||
private int WarmlyShipPlaces = 0;
|
||||
|
||||
public SetWarmlyShipGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
|
||||
public int Insert(T ship)
|
||||
{
|
||||
return Insert(ship, 0);
|
||||
}
|
||||
|
||||
public int Insert(T ship, int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length || WarmlyShipPlaces == _places.Length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
WarmlyShipPlaces++;
|
||||
while (_places[position] != null)
|
||||
{
|
||||
for (int i = _places.Length - 1; i > 0; --i)
|
||||
{
|
||||
if (_places[i] == null && _places[i - 1] != null)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
_places[i - 1] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
_places[position] = ship;
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length) return null;
|
||||
T savedWarmlyShip = _places[position];
|
||||
_places[position] = null;
|
||||
return savedWarmlyShip;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length) return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
50
WarmlyShip/WarmlyShip/SimpleMap.cs
Normal file
50
WarmlyShip/WarmlyShip/SimpleMap.cs
Normal file
@ -0,0 +1,50 @@
|
||||
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, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 33)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user