Compare commits

...

12 Commits

25 changed files with 1772 additions and 74 deletions

View File

@ -0,0 +1,221 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal abstract class AbstractMap
{
private IDrawingObject _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 _water = 0;
protected readonly int _barrier = 1;
public Bitmap CreateMap(int width, int height, IDrawingObject
drawningObject)
{
_width = width;
_height = height;
_drawningObject = drawningObject;
GenerateMap();
while (!SetObjectOnMap())
{
GenerateMap();
}
return DrawMapWithObject();
}
public Bitmap MoveObject(Direction direction)
{
bool moveAccept = true;
(float Left, float Top, float Right, float Bottom) = _drawningObject.GetCurrentPosition();
int xObjWidth = (int)Math.Ceiling((Right - Left) / _size_x);
int yObjHeight = (int)Math.Ceiling((Bottom - Top) / _size_y);
int vertStep = (int)Math.Ceiling(_drawningObject.Step / _size_y);
int horizStep = (int)Math.Ceiling(_drawningObject.Step / _size_x);
int xObjLeftBorder = (int)Math.Floor(Left / _size_x);
int xObjRightBorder = (int)Math.Ceiling(Right / _size_x);
int yObjTopBorder = (int)Math.Floor(Top / _size_y);
int yObjBottomBorder = (int)Math.Ceiling(Bottom / _size_y);
switch (direction)
{
case Direction.Up:
for (int i = 0; i < vertStep; i++)
{
if (!moveAccept)
{
break;
}
for (int j = 0; j < xObjWidth; j++)
{
if (yObjTopBorder - i < 0 || xObjLeftBorder + j >= _map.GetLength(1))
{
break;
}
if (_map[xObjLeftBorder + j, yObjTopBorder - i] == _barrier)
{
moveAccept = false;
break;
}
}
}
break;
case Direction.Down:
for (int i = 0; i < vertStep; i++)
{
if (!moveAccept)
{
break;
}
for (int j = 0; j < xObjWidth; j++)
{
if (yObjBottomBorder + i >= _map.GetLength(0) || xObjLeftBorder + j >= _map.GetLength(1))
{
break;
}
if (_map[xObjLeftBorder + j, yObjBottomBorder + i] == _barrier)
{
moveAccept = false;
break;
}
}
}
break;
case Direction.Left:
for (int i = 0; i < yObjHeight; i++)
{
if (!moveAccept)
{
break;
}
for (int j = 0; j < horizStep; j++)
{
if (yObjTopBorder + i >= _map.GetLength(0) || xObjLeftBorder - j < 0)
{
break;
}
if (_map[xObjLeftBorder - j, yObjTopBorder + i] == _barrier)
{
moveAccept = false;
break;
}
}
}
break;
case Direction.Right:
for (int i = 0; i < yObjHeight; i++)
{
if (!moveAccept)
{
break;
}
for (int j = 0; j < horizStep; j++)
{
if (yObjTopBorder + i >= _map.GetLength(0) || xObjRightBorder + j >= _map.GetLength(1))
{
break;
}
if (_map[xObjRightBorder + j, yObjTopBorder + i] == _barrier)
{
moveAccept = false;
break;
}
}
}
break;
}
if (moveAccept)
{
_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);
(float Left, float Top, float Right, float Bottom) = _drawningObject.GetCurrentPosition();
int xObjWidth = (int)Math.Ceiling((Right - Left) / _size_x);
int yObjHeight = (int)Math.Ceiling((Bottom - Top) / _size_y);
int xObjLeftBorder = (int)Math.Floor(Left / _size_x);
int yObjTopBorder = (int)Math.Floor(Top / _size_y);
while (y < _height - (Bottom - Top))
{
while (x < _width - (Right - Left))
{
if (CheckSpawnArea(xObjWidth, yObjHeight, xObjLeftBorder, yObjTopBorder))
{
_drawningObject.SetObject(x, y, _width, _height);
return true;
}
x += (int)_size_x;
xObjLeftBorder = (int)(x / _size_x);
}
x = 0;
y += (int)_size_y;
yObjTopBorder = (int)(y / _size_y);
}
return false;
}
private bool CheckSpawnArea(int xObjWidth, int yObjHeight, int xObjLeftBorder, int yObjTopBorder)
{
for (int i = 0; i <= yObjHeight; i++)
{
for (int j = 0; j <= xObjWidth; j++)
{
if (yObjTopBorder + i >= _map.GetLength(0) || xObjLeftBorder + j >= _map.GetLength(1) || _map[xObjLeftBorder + j, yObjTopBorder + i] == _barrier)
{
return false;
}
}
}
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] == _water)
{
DrawWaterPart(gr, i, j);
}
else if (_map[i, j] == _barrier)
{
DrawBarrierPart(gr, i, j);
}
}
}
_drawningObject.DrawingObject(gr);
return bmp;
}
protected abstract void GenerateMap();
protected abstract void DrawWaterPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
}
}

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project> </Project>

View File

@ -6,8 +6,9 @@ using System.Threading.Tasks;
namespace ContainerShip namespace ContainerShip
{ {
internal enum Direction public enum Direction
{ {
None = 0,
Up = 1, Up = 1,
Down = 2, Down = 2,
Left = 3, Left = 3,

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal class DrawingContainerShip : DrawingShip
{
public DrawingContainerShip(int speed, float weight, Color bodyColor, Color
dopColor, bool crane, bool containers) :
base(speed, weight, bodyColor, 110, 60)
{
Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers);
}
public override void DrawTransport(Graphics g)
{
if (Ship is not EntityContainerShip containerShip)
{
return;
}
Pen pen = new(Color.Black);
Brush dopBrush = new SolidBrush(containerShip.DopColor);
Brush brOrange = new SolidBrush(Color.Orange);
base.DrawTransport(g);
if (containerShip.Containers)
{
//Границы контейнеров
g.DrawRectangle(pen, _startPosX + 15, _startPosY + 15, 30, 15);
g.DrawRectangle(pen, _startPosX + 55, _startPosY + 15, 30, 15);
//Заливка контейнеров
g.FillRectangle(dopBrush, _startPosX + 16, _startPosY + 16, 29, 14);
g.FillRectangle(dopBrush, _startPosX + 56, _startPosY + 16, 29, 14);
//Заливка центральных полос на контейнерах
g.FillRectangle(brOrange, _startPosX + 16, _startPosY + 20, 29, 5);
g.FillRectangle(brOrange, _startPosX + 56, _startPosY + 20, 29, 5);
}
if (containerShip.Crane)
{
//Граница стрелы крана
PointF point1 = new PointF(_startPosX + 50, _startPosY + 10);
PointF point2 = new PointF(_startPosX + 90, _startPosY + 13);
PointF point3 = new PointF(_startPosX + 50, _startPosY + 16);
PointF[] craneArrowBorder = new PointF[3] { point1, point2, point3 };
//Граница заливки стрелы крана
PointF point4 = new PointF(_startPosX + 51, _startPosY + 10);
PointF point5 = new PointF(_startPosX + 84, _startPosY + 13);
PointF point6 = new PointF(_startPosX + 51, _startPosY + 16);
PointF[] craneArrowFill = new PointF[3] { point4, point5, point6 };
g.DrawRectangle(pen, _startPosX + 45, _startPosY, 10, 30);
g.FillRectangle(brOrange, _startPosX + 46, _startPosY + 1, 9, 29);
g.DrawPolygon(pen, craneArrowBorder);
g.FillPolygon(dopBrush, craneArrowFill);
//Трос и крепление
g.DrawLine(pen, _startPosX + 90, _startPosY + 14, _startPosX + 90, _startPosY + 40);
g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 85, _startPosY + 43);
g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 90, _startPosY + 45);
g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 95, _startPosY + 43);
}
}
}
}

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal class DrawingObjectShip : IDrawingObject
{
private DrawingShip _ship = null;
public DrawingObjectShip(DrawingShip ship)
{
_ship = ship;
}
public float Step => _ship?.Ship?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _ship?.GetCurrentPosition() ?? default;
}
public void MoveObject(Direction direction)
{
_ship?.MoveShip(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_ship?.SetPosition(x, y, width, height);
}
void IDrawingObject.DrawingObject(Graphics g)
{
_ship?.DrawTransport(g);
}
}
}

View File

@ -6,21 +6,25 @@ using System.Threading.Tasks;
namespace ContainerShip namespace ContainerShip
{ {
internal class DrawingShip public class DrawingShip
{ {
public EntityShip Ship { get; private set; } public EntityShip Ship { get; protected set; }
private float _startPosX; protected float _startPosX;
private float _startPosY; protected float _startPosY;
private int? _pictureWidth = null; private int? _pictureWidth = null;
private int? _pictureHeight = null; private int? _pictureHeight = null;
protected readonly int _shipWidth = 100; private readonly int _shipWidth = 100;
protected readonly int _shipHeight = 60; private readonly int _shipHeight = 60;
public DrawingShip(int speed, float weight, Color bodyColor)
public void Init(int speed, float weight, Color bodyColor)
{ {
Ship = new EntityShip(); Ship = new EntityShip(speed, weight, bodyColor);
Ship.Init(speed, weight, bodyColor); }
protected DrawingShip(int speed, float weight, Color bodyColor, int shipWidth,
int shipHeight) : this(speed, weight, bodyColor)
{
_shipWidth = shipWidth;
_shipHeight = shipHeight;
} }
public void SetPosition(int x, int y, int width, int height) public void SetPosition(int x, int y, int width, int height)
@ -77,7 +81,7 @@ namespace ContainerShip
} }
} }
public void DrawTransport(Graphics g) public virtual void DrawTransport(Graphics g)
{ {
if (_startPosX < 0 || _startPosY < 0 if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue) || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@ -124,5 +128,9 @@ namespace ContainerShip
_startPosY = _pictureHeight.Value - _shipHeight; _startPosY = _pictureHeight.Value - _shipHeight;
} }
} }
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + _shipHeight);
}
} }
} }

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal class EntityContainerShip : EntityShip
{
public Color DopColor { get; private set; }
public bool Crane { get; private set; }
public bool Containers { get; private set; }
public EntityContainerShip(int speed, float weight, Color bodyColor, Color
dopColor, bool crane, bool containers) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
Crane = crane;
Containers = containers;
}
}
}

View File

@ -6,14 +6,14 @@ using System.Threading.Tasks;
namespace ContainerShip namespace ContainerShip
{ {
internal class EntityShip public class EntityShip
{ {
public int Speed { get; private set; } public int Speed { get; private set; }
public float Weight { get; private set; } public float Weight { get; private set; }
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
public int Step => (int)Speed * 100 / (int)Weight; public int Step => (int)Speed * 100 / (int)Weight;
public void Init(int speed, float weight, Color bodyColor) public EntityShip(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

@ -0,0 +1,281 @@
namespace ContainerShip
{
partial class FormMapWithSetShip
{
/// <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.groupBox2 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.buttonAddMap = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddShip = new System.Windows.Forms.Button();
this.buttonRemoveShip = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonAddShip);
this.groupBox1.Controls.Add(this.buttonRemoveShip);
this.groupBox1.Controls.Add(this.buttonShowStorage);
this.groupBox1.Controls.Add(this.buttonShowOnMap);
this.groupBox1.Controls.Add(this.buttonDown);
this.groupBox1.Controls.Add(this.buttonLeft);
this.groupBox1.Controls.Add(this.buttonRight);
this.groupBox1.Controls.Add(this.buttonUp);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(600, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 525);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button2);
this.groupBox2.Controls.Add(this.listBoxMaps);
this.groupBox2.Controls.Add(this.textBoxNewMapName);
this.groupBox2.Controls.Add(this.buttonAddMap);
this.groupBox2.Controls.Add(this.comboBoxSelectorMap);
this.groupBox2.Location = new System.Drawing.Point(6, 22);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(188, 237);
this.groupBox2.TabIndex = 20;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Карты";
//
// button2
//
this.button2.Location = new System.Drawing.Point(6, 208);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(176, 23);
this.button2.TabIndex = 22;
this.button2.Text = "Удалить карту";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 15;
this.listBoxMaps.Location = new System.Drawing.Point(6, 109);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(176, 94);
this.listBoxMaps.TabIndex = 21;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 22);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(176, 23);
this.textBoxNewMapName.TabIndex = 20;
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(6, 80);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(176, 23);
this.buttonAddMap.TabIndex = 19;
this.buttonAddMap.Text = "Добавить карту";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_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(6, 51);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(176, 23);
this.comboBoxSelectorMap.TabIndex = 18;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 294);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23);
this.maskedTextBoxPosition.TabIndex = 19;
//
// buttonAddShip
//
this.buttonAddShip.Location = new System.Drawing.Point(6, 265);
this.buttonAddShip.Name = "buttonAddShip";
this.buttonAddShip.Size = new System.Drawing.Size(188, 23);
this.buttonAddShip.TabIndex = 17;
this.buttonAddShip.Text = "Добавить корабль";
this.buttonAddShip.UseVisualStyleBackColor = true;
this.buttonAddShip.Click += new System.EventHandler(this.ButtonAddShip_Click);
//
// buttonRemoveShip
//
this.buttonRemoveShip.Location = new System.Drawing.Point(6, 323);
this.buttonRemoveShip.Name = "buttonRemoveShip";
this.buttonRemoveShip.Size = new System.Drawing.Size(188, 23);
this.buttonRemoveShip.TabIndex = 15;
this.buttonRemoveShip.Text = "Удалить корабль";
this.buttonRemoveShip.UseVisualStyleBackColor = true;
this.buttonRemoveShip.Click += new System.EventHandler(this.ButtonRemoveShip_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(6, 376);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(188, 23);
this.buttonShowStorage.TabIndex = 14;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(6, 405);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(188, 23);
this.buttonShowOnMap.TabIndex = 13;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(89, 483);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 12;
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::ContainerShip.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(53, 483);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 11;
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::ContainerShip.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(125, 483);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 10;
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::ContainerShip.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(89, 447);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 9;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// 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(600, 525);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetShip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 525);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
this.Name = "FormMapWithSetShip";
this.Text = "FormMapWithSetShip";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private PictureBox pictureBox;
private Button buttonAddShip;
private Button buttonRemoveShip;
private Button buttonShowStorage;
private Button buttonShowOnMap;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
private Button buttonUp;
private ComboBox comboBoxSelectorMap;
private MaskedTextBox maskedTextBoxPosition;
private GroupBox groupBox2;
private Button button2;
private ListBox listBoxMaps;
private TextBox textBoxNewMapName;
private Button buttonAddMap;
}
}

View File

@ -0,0 +1,215 @@
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 ContainerShip
{
public partial class FormMapWithSetShip : Form
{
private MapWithSetShipGeneric<DrawingObjectShip, AbstractMap> _mapShipCollectionGeneric;
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap()},
{ "Острова", new IslandsMap()},
{ "Скалы", new RocksMap()}
};
private readonly MapsCollection _mapsCollection;
public FormMapWithSetShip()
{
InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach(var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
private void ReloadMaps()
{
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for(int i = 0; i < _mapsCollection.Keys.Count; ++i)
{
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if(listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
}else if(listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{
listBoxMaps.SelectedIndex = index;
}
}
private void ButtonAddMap_Click(object sender, EventArgs e)
{
if (comboBoxSelectorMap.SelectedIndex == -1 ||
string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(textBoxNewMapName.Text,
_mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Острова":
map = new IslandsMap();
break;
case "Скалы":
map = new RocksMap();
break;
}
if (map != null)
{
_mapShipCollectionGeneric = new
MapWithSetShipGeneric<DrawingObjectShip, 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)
{
DrawingObjectShip ship = new(form.SelectedShip);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + ship != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].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 (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image =
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
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 = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?",
"Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ??
string.Empty);
ReloadMaps();
}
}
}
}

View File

@ -0,0 +1,60 @@
<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>
</root>

View File

@ -28,7 +28,6 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormShip));
this.pictureBoxShip = new System.Windows.Forms.PictureBox(); this.pictureBoxShip = new System.Windows.Forms.PictureBox();
this.buttonCreate = new System.Windows.Forms.Button(); this.buttonCreate = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
@ -39,6 +38,8 @@
this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.buttonSelectShip = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
this.statusStrip.SuspendLayout(); this.statusStrip.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -67,7 +68,7 @@
// buttonUp // buttonUp
// //
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage"))); this.buttonUp.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(722, 359); this.buttonUp.Location = new System.Drawing.Point(722, 359);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
@ -79,7 +80,7 @@
// buttonRight // buttonRight
// //
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage"))); this.buttonRight.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(758, 395); this.buttonRight.Location = new System.Drawing.Point(758, 395);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
@ -91,7 +92,7 @@
// buttonLeft // buttonLeft
// //
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage"))); this.buttonLeft.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(686, 395); this.buttonLeft.Location = new System.Drawing.Point(686, 395);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
@ -103,7 +104,7 @@
// buttonDown // buttonDown
// //
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage"))); this.buttonDown.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(722, 395); this.buttonDown.Location = new System.Drawing.Point(722, 395);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
@ -141,11 +142,33 @@
this.toolStripStatusBodyColor.Size = new System.Drawing.Size(39, 17); this.toolStripStatusBodyColor.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusBodyColor.Text = "Цвет: "; this.toolStripStatusBodyColor.Text = "Цвет: ";
// //
// buttonCreateModif
//
this.buttonCreateModif.Location = new System.Drawing.Point(94, 402);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(110, 23);
this.buttonCreateModif.TabIndex = 10;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// buttonSelectShip
//
this.buttonSelectShip.Location = new System.Drawing.Point(605, 399);
this.buttonSelectShip.Name = "buttonSelectShip";
this.buttonSelectShip.Size = new System.Drawing.Size(75, 23);
this.buttonSelectShip.TabIndex = 11;
this.buttonSelectShip.Text = "Выбрать";
this.buttonSelectShip.UseVisualStyleBackColor = true;
this.buttonSelectShip.Click += new System.EventHandler(this.ButtonSelectShip_Click);
//
// FormShip // FormShip
// //
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.buttonSelectShip);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonRight);
@ -176,5 +199,7 @@
private ToolStripStatusLabel toolStripStatusSpeed; private ToolStripStatusLabel toolStripStatusSpeed;
private ToolStripStatusLabel toolStripStatusWeight; private ToolStripStatusLabel toolStripStatusWeight;
private ToolStripStatusLabel toolStripStatusBodyColor; private ToolStripStatusLabel toolStripStatusBodyColor;
private Button buttonCreateModif;
private Button buttonSelectShip;
} }
} }

View File

@ -14,6 +14,8 @@ namespace ContainerShip
{ {
private DrawingShip _ship; private DrawingShip _ship;
public DrawingShip SelectedShip { get; private set; }
public FormShip() public FormShip()
{ {
InitializeComponent(); InitializeComponent();
@ -48,22 +50,63 @@ namespace ContainerShip
Draw(); Draw();
} }
private void ButtonCreate_Click(object sender, EventArgs e) private void SetData()
{ {
Random rnd = new(); Random rnd = new();
_ship = new DrawingShip();
_ship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256),
rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(60, 100), pictureBoxShip.Width, pictureBoxShip.Height);
toolStripStatusSpeed.Text = $"Скорость: {_ship.Ship.Speed}"; toolStripStatusSpeed.Text = $"Скорость: {_ship.Ship.Speed}";
toolStripStatusWeight.Text = $"Вес: {_ship.Ship.Weight}"; toolStripStatusWeight.Text = $"Вес: {_ship.Ship.Weight}";
toolStripStatusBodyColor.Text = $"Цвет: {_ship.Ship.BodyColor.Name}"; toolStripStatusBodyColor.Text = $"Цвет: {_ship.Ship.BodyColor.Name}";
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(60, 100), pictureBoxShip.Width, pictureBoxShip.Height);
}
private void ButtonCreate_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;
}
_ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw(); 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 DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
private void PictureBoxShip_Resize(object sender, EventArgs e) private void PictureBoxShip_Resize(object sender, EventArgs e)
{ {
_ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height); _ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height);
Draw(); Draw();
} }
private void ButtonSelectShip_Click(object sender, EventArgs e)
{
if(_ship != null)
{
SelectedShip = _ship;
DialogResult = DialogResult.OK;
}
}
} }
} }

View File

@ -57,55 +57,6 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAEMAAABHCAIAAADTOW0yAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
vgAADr4B6kKxwAAAAVVJREFUaEPtz0ESgzAMQ9He/9J08zsDNECUWMVl/HYtsWS/lqeoS/KpS/q8Pvjt
ZOzgiA/+tXEVsP4W3zws6SzewguD+GhWPsa7aMG5LHuF16EiQ1mzDzNxwhJZUMFkkJg4VtMxHyEgi6VG
kTJtNoh15pA1ZyqFRSKQOGE8ghXikDtqcJ7yaKQPGRmm1oMOnTxJoRNNIm2MKj/6FMIMJb9Ca7feAeJ/
i+4+Xa8JvgMbdLh+SuR92OPKxTvC7sY2p84eEZMDOx07fEFAJmx2oP2Z0XzYr6XxjaGs2PLL/gPPc2PX
rc2/PPwHbLxSl9yNjVf2f/EwN3bdav97jjwPOnR1iQ0durrEhg5dXWJDh64usaFDV5fY0KGrS2zo0NUl
NnTo6hIbOnR1iQ0durrEhg5dXWJDh64usaFDNzhJbTTSh0wNp1KX5FOX5FOX5FOX5POUS5blDVXxX38K
WOldAAAAAElFTkSuQmCC
</value>
</data>
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAEcAAABDCAYAAADOIRgJAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
vQAADr0BR/uQrQAAAStJREFUeF7t0NkKwzAMRNH8/0+nHSjFBFvxIsvaDsyrsO91p6aMQ8g4hIxDUBnn
uq7/TlIXpwxzOpCJONgJZuJg0kzFwSSZi4NJMRkHk2A2Drab6TjYTubjYLu4iIPt4CYOxs1VHIzT0LXa
YzSOS/el2iM0j4PbONgq13GwFe7jYLNCxMFmhImDjQoVBxsRLg7WK2QcrEfYONib0HEwSvg4WEvG+a0m
4xR7yjjFnjJOsaeM81tNxvmuJXwcSug4b8LG6REyTq9wcUaEijMqTJwZIeLMch9nhes4q9zG4TB0pfYI
jePCd4lJ7bMj4+QqDjc3cXZwEWcX83F2Mh1nN7NxJJiMI8VcHEmm4kgzE+cEE3FOURcHNIQBlXG0yDiE
jEPIOISMQ8g4Tff9AfqQ4vhbQUgmAAAAAElFTkSuQmCC
</value>
</data>
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAEcAAABDCAYAAADOIRgJAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
vQAADr0BR/uQrQAAAaVJREFUeF7tkEFuxDAMA/P/T6f1YYtgO1HoxHYowwPMTZAobvvilFVOwConYJUT
sMoJWOUEvFrOtm1/OvJaqmMxrgW9koiKKboxPBGV8tGNoYmokKNuDEtEZXzrxpBEVATpRvdEVMKZbnRN
RAVEutEtET1/pRtdEtHjim40T0RPq7rRNBE9XKMbzRLRs47W0KQcCuGsyuNy6Li7Ko/KocMZVLldDh3N
osqtcuhgJlWqy6Fj2VSpKocOZVRFnqQjWVWRJulAZlUuJ2l5dlXCSVo8gyqnk7R0FlVwkhbOpMq/SVo2
myqrnIBVTgBO0sKZVDmdpKWzqBJO0uIZVLmcpOXZVZEm6UBmVeRJOpJVFX3yFzqUUZWqcgp0LJsq1eUU
6GAmVW6VU6CjWVS5XU6BDmdQ5VE5BTrursrjcgoUwFmVJuUUKISjNTQrp0BhanSjeSJ6WtWNLonocUU3
uiWi5690o2siKiDSje6JqIQz3RiSiIog3RiWiMr41o2hiaiQo24MT0SlfHTjlURUTNGN1xKtci5wLqbg
mcqEVU7AKidglXPKvv8AlW/i+GiZZt4AAAAASUVORK5CYII=
</value>
</data>
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAEMAAABHCAYAAABcW/plAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
vQAADr0BR/uQrQAAAVdJREFUeF7t0MsOgzAQQ1H+/6epvGhlVQYSMjMJyEfyNo+77fbjGMQxiGMQxyCO
QRyDOAZxDOIYJDzGtm3lixIaQz20ahEcgzgGcQziGMQxiGMQxyCOQRyDOAZxDOIYxDGIYxDHII5BHIM4
BnEM4hjEMYhjEMcgjkFOT1GXvmXKYQx1wNv2zzGIY5DDGKAOeMuU0xigDnr6jlzGAHXgU3emKQaog5+2
K80xQF3wlLXoigHqotXXqjsGqAtXXY9bMUBdvNp63Y4B6gGr7I6hGKAeMnt3DccA9aBZGxESA9TDqjcq
LAaoB1YtQmgMUA/NXpTwGKAenLVIKTFAPTx60dJigPpA1DKkxgD1kdFlSY8B6kN3l6kkBqiP9S5bWQxQ
H2xdhdIYoD56tSrlMUB9+GiVpsQA9fH/VZsWA1SA72aYGgNWCQHTY8AKIWCJGKtwDOIYxDF+9v0DSS3i
+O80JVAAAAAASUVORK5CYII=
</value>
</data>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal interface IDrawingObject
{
public float Step { get; }
void SetObject(int x, int y, int width, int height);
void MoveObject(Direction direction);
void DrawingObject(Graphics g);
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
}
}

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal class IslandsMap : AbstractMap
{
private readonly Brush islandColor = new SolidBrush(Color.Yellow);
private readonly Brush waterColor = new SolidBrush(Color.Aqua);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(islandColor, i * _size_x, j * _size_y, _size_x, _size_y);
}
protected override void DrawWaterPart(Graphics g, int i, int j)
{
g.FillRectangle(waterColor, 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] = _water;
}
}
while (counter < 10)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _water && x < 97 && y < 97)
{
_map[x + 1, y] = _barrier;
_map[x + 2, y] = _barrier;
_map[x, y + 1] = _barrier;
_map[x + 1, y + 1] = _barrier;
_map[x + 2, y + 1] = _barrier;
_map[x + 3, y + 1] = _barrier;
_map[x, y + 2] = _barrier;
_map[x + 1, y + 2] = _barrier;
_map[x + 2, y + 2] = _barrier;
_map[x + 3, y + 2] = _barrier;
_map[x + 1, y + 3] = _barrier;
_map[x + 2, y + 3] = _barrier;
counter++;
}
}
}
}
}

View File

@ -0,0 +1,163 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal class MapWithSetShipGeneric<T, U>
where T : class, IDrawingObject
where U : AbstractMap
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeHeight = 90;
private readonly SetShipGeneric<T> _setShip;
private readonly U _map;
public MapWithSetShipGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setShip = new SetShipGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
public static int operator +(MapWithSetShipGeneric<T, U> map, T ship)
{
return map._setShip.Insert(ship);
}
public static T operator -(MapWithSetShipGeneric<T, U> map, int
position)
{
return map._setShip.Remove(position);
}
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawShip(gr);
return bmp;
}
public Bitmap ShowOnMap()
{
Shaking();
foreach (var ship in _setShip.GetShip())
{
return _map.CreateMap(_pictureWidth, _pictureHeight, ship);
}
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 = _setShip.Count - 1;
for (int i = 0; i < _setShip.Count; i++)
{
if (_setShip[i] == null)
{
for (; j > i; j--)
{
var ship = _setShip[j];
if (ship != null)
{
_setShip.Insert(ship, i);
_setShip.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
private void DrawBackground(Graphics g)
{
SolidBrush brWater = new SolidBrush(Color.LightSkyBlue);
g.FillRectangle(brWater, 0,0,_pictureWidth, _pictureHeight);
Pen pen = new(Color.Brown, 3);
Pen penBold = new(Color.Brown, 5);
Pen penThin = new(Color.Black, 1);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight/2, i *
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight + _placeSizeHeight / 2);
for(int k = 1; k < 3; ++k)
{
g.DrawLine(penThin, i * _placeSizeWidth, j * _placeSizeHeight + k * 21, i *
_placeSizeWidth + 3 * _placeSizeWidth / 10, j * _placeSizeHeight + k * 21);
}
for (int k = 0; k < 4; ++k)
{
g.DrawLine(penBold, i * _placeSizeWidth + k * _placeSizeWidth / 10, j * _placeSizeHeight + 20, i * _placeSizeWidth + k * _placeSizeWidth / 10,
(j + 1) * _placeSizeHeight - 20);
}
}
}
}
private void DrawShip(Graphics g)
{
int yNumOfPlaces = _pictureHeight / _placeSizeHeight;
int xNumOfPlaces = _pictureWidth / _placeSizeWidth;
int RowIndex = yNumOfPlaces - 1;
int ColumnIndex = xNumOfPlaces - 1;
foreach (var ship in _setShip.GetShip())
{
if (ship != null)
{
(float Left, float Top, float Right, float Bottom) = ship.GetCurrentPosition();
ship.SetObject(ColumnIndex * _placeSizeWidth,
RowIndex * _placeSizeHeight + (_placeSizeHeight - (int)(Bottom - Top)),
_pictureWidth, _pictureHeight);
ship.DrawingObject(g);
}
if (ColumnIndex == 0)
{
ColumnIndex = xNumOfPlaces - 1;
RowIndex--;
}
else
{
ColumnIndex--;
}
}
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal class MapsCollection
{
readonly Dictionary<string, MapWithSetShipGeneric<DrawingObjectShip, AbstractMap>> _mapStorages;
public List<string> Keys => _mapStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetShipGeneric<DrawingObjectShip, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddMap(string name, AbstractMap map)
{
if (_mapStorages.ContainsKey(name))
{
return;
}
MapWithSetShipGeneric<DrawingObjectShip, AbstractMap> newMap = new(_pictureWidth, _pictureHeight, map);
_mapStorages.Add(name, newMap);
}
public void DelMap(string name)
{
if (_mapStorages.ContainsKey(name))
{
_mapStorages.Remove(name);
}
}
public MapWithSetShipGeneric<DrawingObjectShip, AbstractMap> this[string
ind]
{
get
{
if (_mapStorages.ContainsKey(ind))
{
return _mapStorages[ind];
}
return null;
}
}
}
}

View File

@ -11,7 +11,7 @@ namespace ContainerShip
// 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 FormShip()); Application.Run(new FormMapWithSetShip());
} }
} }
} }

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ContainerShip.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ContainerShip.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap ArrowDown {
get {
object obj = ResourceManager.GetObject("ArrowDown", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap ArrowLeft {
get {
object obj = ResourceManager.GetObject("ArrowLeft", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap ArrowRight {
get {
object obj = ResourceManager.GetObject("ArrowRight", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap ArrowUp {
get {
object obj = ResourceManager.GetObject("ArrowUp", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,133 @@
<?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>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ArrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\img\ArrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ArrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\img\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ArrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\img\ArrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ArrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\img\ArrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal class RocksMap : AbstractMap
{
private readonly Brush rockColor = new SolidBrush(Color.Gray);
private readonly Brush waterColor = new SolidBrush(Color.Aqua);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(rockColor, i * _size_x, j * _size_y, i * (_size_x +
1), j * (_size_y + 1));
}
protected override void DrawWaterPart(Graphics g, int i, int j)
{
g.FillRectangle(waterColor, 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] = _water;
}
}
while (counter < 10)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _water && x < 98 && y < 99)
{
_map[x, y] = _barrier;
_map[x + 1, y] = _barrier;
_map[x + 2, y] = _barrier;
_map[x + 1, y + 1] = _barrier;
counter++;
}
}
}
}
}

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal class SetShipGeneric<T>
where T : class
{
private readonly List<T> _places;
public int Count => _places.Count;
private readonly int _maxCount;
public SetShipGeneric(int count)
{
_maxCount = count;
_places = new List<T>();
}
public int Insert(T ship)
{
return Insert(ship, 0);
}
public int Insert(T ship, int position)
{
if (position < 0 || position > Count || Count == _maxCount)
{
return -1;
}
_places.Insert(position, ship);
return position;
}
public T Remove(int position)
{
if (position >= Count || position < 0)
{
return null;
}
T removedObject = _places[position];
_places.RemoveAt(position);
return removedObject;
}
public T this[int position]
{
get
{
if (position < 0 || position >= Count)
{
return null;
}
return _places[position];
}
set
{
if (position < 0 || position >= Count)
{
return;
}
Insert(value, position);
}
}
public IEnumerable<T> GetShip()
{
foreach (var ship in _places)
{
if (ship != null)
{
yield return ship;
}
else
{
yield break;
}
}
}
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContainerShip
{
internal class SimpleMap : AbstractMap
{
private readonly Brush bombColor = new SolidBrush(Color.Black);
private readonly Brush waterColor = new SolidBrush(Color.Aqua);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(bombColor, i * _size_x, j * _size_y, i * (_size_x +
1), j * (_size_y + 1));
}
protected override void DrawWaterPart(Graphics g, int i, int j)
{
g.FillRectangle(waterColor, 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 = _width / _map.GetLength(0);
_size_y = _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] = _water;
}
}
while (counter < 20)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _water)
{
_map[x, y] = _barrier;
counter++;
}
}
}
}
}