Сделаны все TODO

This commit is contained in:
Danil Markov 2022-10-09 17:13:54 +04:00
parent e4768be709
commit 6fa8023411
17 changed files with 1008 additions and 61 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

@ -8,4 +8,19 @@
<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,6 +8,7 @@ namespace ContainerShip
{
internal enum Direction
{
None = 0,
Up = 1,
Down = 2,
Left = 3,

View File

@ -65,11 +65,7 @@ namespace ContainerShip
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

@ -30,7 +30,7 @@ namespace ContainerShip
void IDrawingObject.DrawingObject(Graphics g)
{
// TODO
_ship?.DrawTransport(g);
}
}
}

View File

@ -0,0 +1,209 @@
namespace ContainerShip
{
partial class FormMap
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBoxShip = new System.Windows.Forms.PictureBox();
this.buttonCreate = 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.buttonDown = new System.Windows.Forms.Button();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
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(0);
this.pictureBoxShip.Name = "pictureBoxShip";
this.pictureBoxShip.Size = new System.Drawing.Size(800, 428);
this.pictureBoxShip.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxShip.TabIndex = 3;
this.pictureBoxShip.TabStop = false;
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(12, 402);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 4;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(722, 359);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 5;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.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(758, 395);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 6;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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(686, 395);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 7;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(722, 395);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 8;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// statusStrip
//
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusSpeed,
this.toolStripStatusWeight,
this.toolStripStatusBodyColor});
this.statusStrip.Location = new System.Drawing.Point(0, 428);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22);
this.statusStrip.TabIndex = 9;
//
// toolStripStatusSpeed
//
this.toolStripStatusSpeed.Name = "toolStripStatusSpeed";
this.toolStripStatusSpeed.Size = new System.Drawing.Size(65, 17);
this.toolStripStatusSpeed.Text = "Скорость: ";
//
// toolStripStatusWeight
//
this.toolStripStatusWeight.Name = "toolStripStatusWeight";
this.toolStripStatusWeight.Size = new System.Drawing.Size(32, 17);
this.toolStripStatusWeight.Text = "Вес: ";
//
// toolStripStatusBodyColor
//
this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor";
this.toolStripStatusBodyColor.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusBodyColor.Text = "Цвет: ";
//
// 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(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);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Острова",
"Скалы"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
this.comboBoxSelectorMap.TabIndex = 11;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// FormMap
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.comboBoxSelectorMap);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxShip);
this.Controls.Add(this.statusStrip);
this.Name = "FormMap";
this.Text = "FormMap";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxShip;
private Button buttonCreate;
private Button buttonUp;
private Button buttonRight;
private Button buttonLeft;
private Button buttonDown;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusSpeed;
private ToolStripStatusLabel toolStripStatusWeight;
private ToolStripStatusLabel toolStripStatusBodyColor;
private Button buttonCreateModif;
private ComboBox comboBoxSelectorMap;
}
}

View File

@ -0,0 +1,93 @@
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 FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
private void SetData(DrawingShip ship)
{
Random rnd = new();
toolStripStatusSpeed.Text = $"Скорость: {ship.Ship.Speed}";
toolStripStatusWeight.Text = $"Вес: {ship.Ship.Weight}";
toolStripStatusBodyColor.Text = $"Цвет: {ship.Ship.BodyColor.Name}";
pictureBoxShip.Image = _abstractMap.CreateMap(pictureBoxShip.Width, pictureBoxShip.Height,
new DrawingObjectShip(ship));
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
var ship = new DrawingShip(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)));
SetData(ship);
}
private void ButtonMove_Click(object sender, EventArgs e)
{
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBoxShip.Image = _abstractMap?.MoveObject(dir);
}
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
var ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(255, rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color.FromArgb(255, rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(ship);
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Острова":
_abstractMap = new IslandsMap();
break;
case "Скалы":
_abstractMap = new RocksMap();
break;
}
}
}
}

View File

@ -0,0 +1,63 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -28,7 +28,6 @@
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormShip));
this.pictureBoxShip = new System.Windows.Forms.PictureBox();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
@ -68,7 +67,7 @@
// buttonUp
//
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.Location = new System.Drawing.Point(722, 359);
this.buttonUp.Name = "buttonUp";
@ -80,7 +79,7 @@
// buttonRight
//
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.Location = new System.Drawing.Point(758, 395);
this.buttonRight.Name = "buttonRight";
@ -92,7 +91,7 @@
// buttonLeft
//
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.Location = new System.Drawing.Point(686, 395);
this.buttonLeft.Name = "buttonLeft";
@ -104,7 +103,7 @@
// buttonDown
//
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.Location = new System.Drawing.Point(722, 395);
this.buttonDown.Name = "buttonDown";
@ -167,6 +166,7 @@
this.Controls.Add(this.statusStrip);
this.Name = "FormShip";
this.Text = "FormShip";
this.Load += new System.EventHandler(this.FormShip_Load);
this.Resize += new System.EventHandler(this.PictureBoxShip_Resize);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit();
this.statusStrip.ResumeLayout(false);

View File

@ -84,5 +84,9 @@ namespace ContainerShip
Draw();
}
private void FormShip_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -57,55 +57,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</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
vAAADrwBlbxySQAAAVVJREFUaEPtz0ESgzAMQ9He/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
vAAADrwBlbxySQAAAStJREFUeF7t0NkKwzAMRNH8/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
vAAADrwBlbxySQAAAaVJREFUeF7tkEFuxDAMA/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
vAAADrwBlbxySQAAAVdJREFUeF7t0MsOgzAQQ1H+/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">
<value>17, 17</value>
</metadata>

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

@ -11,7 +11,7 @@ namespace ContainerShip
// 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 FormMap());
}
}
}

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,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++;
}
}
}
}
}