Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
2bf617139e |
@ -1,183 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal abstract class AbstractMap : IEquatable<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 _freeRoad = 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 bool CheckAround(float Left, float Right, float Top, float Bottom)
|
||||
{
|
||||
int startX = (int)(Left / _size_x);
|
||||
int startY = (int)(Right / _size_y);
|
||||
int endX = (int)(Top / _size_x);
|
||||
int endY = (int)(Bottom / _size_y);
|
||||
|
||||
for (int i = startX; i <= endX; i++)
|
||||
{
|
||||
for (int j = startY; j <= endY; j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
|
||||
|
||||
if (CheckAround(Left, Right, Top, Bottom))
|
||||
{
|
||||
_drawningObject.MoveObject(MoveObjectBack(direction));
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
|
||||
}
|
||||
private Direction MoveObjectBack(Direction direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Up:
|
||||
return Direction.Down;
|
||||
case Direction.Down:
|
||||
return Direction.Up;
|
||||
case Direction.Left:
|
||||
return Direction.Right;
|
||||
case Direction.Right:
|
||||
return Direction.Left;
|
||||
}
|
||||
return Direction.None;
|
||||
}
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.Next(0, 10);
|
||||
int y = _random.Next(0, 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
|
||||
if (!CheckAround(Left, Right, Top, Bottom)) return true;
|
||||
float startX = Left;
|
||||
float startY = Right;
|
||||
float lengthX = Top - Left;
|
||||
float lengthY = Bottom - Right;
|
||||
while (CheckAround(startX, startY, startX + lengthX, startY + lengthY))
|
||||
{
|
||||
bool result;
|
||||
do
|
||||
{
|
||||
result = CheckAround(startX, startY, startX + lengthX, startY + lengthY);
|
||||
if (!result)
|
||||
{
|
||||
_drawningObject.SetObject((int)startX, (int)startY, _width, _height);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
startX += _size_x;
|
||||
}
|
||||
} while (result);
|
||||
startX = x;
|
||||
startY += _size_y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private Bitmap DrawMapWithObject()
|
||||
{
|
||||
Bitmap bmp = new(_width, _height);
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i, j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i, j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawningObject.DrawningObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
|
||||
public bool Equals(AbstractMap? other)
|
||||
{
|
||||
if(other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherMap = other as AbstractMap;
|
||||
if(otherMap == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(_width != otherMap._width)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(_height != otherMap._height)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_size_x != otherMap._size_x)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_size_y != otherMap._size_y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i, j] != otherMap._map[i, j])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,9 +6,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
public enum Direction
|
||||
internal enum Direction
|
||||
{
|
||||
None=0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
|
@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal class DrawningLiner : DrawingShip
|
||||
{
|
||||
public DrawningLiner(int speed, float weight, Color bodyColor, Color dopColor, bool dopDeck, bool pool) :
|
||||
base(speed, weight, bodyColor, 130, 45)
|
||||
{
|
||||
Ship = new EntityLiner(speed, weight, bodyColor, dopColor, dopDeck, pool);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Ship is not EntityLiner liner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopbrush = new SolidBrush(liner.DopColor);
|
||||
if (liner.DopDeck)
|
||||
{
|
||||
g.FillRectangle(dopbrush, (int)_startPosX + 50, (int)_startPosY + 15, 60, 5);
|
||||
g.DrawRectangle(pen, (int)_startPosX+ 50, (int)_startPosY + 15, 60, 5);
|
||||
}
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
base.DrawTransport(g);
|
||||
_startPosY -= 5;
|
||||
_startPosX -= 10;
|
||||
if (liner.Pool)
|
||||
{
|
||||
g.FillRectangle(dopbrush, (int)_startPosX + 15, (int)_startPosY + 25, 30, 3);
|
||||
g.DrawRectangle(pen, (int)_startPosX + 15, (int)_startPosY + 25, 30, 3);
|
||||
g.DrawLine(pen, _startPosX + 45, _startPosY + 25, _startPosX + 45, _startPosY + 20);
|
||||
g.DrawLine(pen, _startPosX + 45, _startPosY + 20, _startPosX + 35, _startPosY + 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
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 DrawingShip GetShip => _ship;
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_ship?.MoveTransport(direction);
|
||||
}
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_ship.SetPosition(x, y, width, height);
|
||||
}
|
||||
void IDrawingObject.DrawningObject(Graphics g)
|
||||
{
|
||||
_ship.DrawTransport(g);
|
||||
}
|
||||
public string GetInfo() => _ship?.GetDataForSave();
|
||||
public static IDrawingObject Create(string data) => new DrawingObjectShip(data.CreateDrawingShip());
|
||||
|
||||
public bool Equals(IDrawingObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherShip = other as DrawingObjectShip;
|
||||
if (otherShip == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var ship = _ship.Ship;
|
||||
var otherShipShip = otherShip._ship.Ship;
|
||||
if (ship.GetType().Name != otherShipShip.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship.Speed != otherShipShip.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship.Weight != otherShipShip.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship.BodyColor != otherShipShip.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship is EntityLiner liner && otherShipShip is EntityLiner otherLiner)
|
||||
{
|
||||
if (liner.DopColor != otherLiner.DopColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (liner.Pool != otherLiner.Pool)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (liner.DopDeck != otherLiner.DopDeck)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,25 +6,21 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
public class DrawingShip
|
||||
internal class DrawingShip
|
||||
{
|
||||
public EntityShip Ship { get; protected set; }
|
||||
protected float _startPosX;
|
||||
protected float _startPosY;
|
||||
public EntityShip Ship { get; set; }
|
||||
private float _startPosX;
|
||||
private float _startPosY;
|
||||
private int? _pictureWidth = null;
|
||||
private int? _pictureHeight = null;
|
||||
protected readonly int _ShipWidth = 120;
|
||||
protected readonly int _ShipHeight = 40;
|
||||
public DrawingShip(int speed, float weight, Color bodycolor)
|
||||
public void Init(int speed, float weight, Color bodycolor)
|
||||
{
|
||||
Ship = new EntityShip(speed, weight, bodycolor);
|
||||
}
|
||||
protected DrawingShip(int speed, float weight, Color bodyColor, int shipWidth, int shipHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_ShipWidth = shipWidth;
|
||||
_ShipHeight = shipHeight;
|
||||
Ship = new EntityShip();
|
||||
Ship.Init(speed, weight, bodycolor);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (width <= _ShipWidth + x || height <= _ShipHeight + y || x<0 || y<0)
|
||||
@ -38,6 +34,7 @@ namespace Liner
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||||
@ -71,9 +68,11 @@ namespace Liner
|
||||
_startPosY += Ship.Step;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0 || !_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||||
{
|
||||
@ -81,8 +80,8 @@ namespace Liner
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush br = new SolidBrush(Ship?.BodyColor ?? Color.Black);
|
||||
g.FillRectangle(br, _startPosX + 40, _startPosY + 15, 70, 5);
|
||||
g.DrawRectangle(pen, _startPosX + 40, _startPosY + 15, 70, 5);
|
||||
g.FillRectangle(br, _startPosX + 40, _startPosY, 30 * 2, 10 * 2);
|
||||
g.DrawRectangle(pen, _startPosX + 40, _startPosY, 30 * 2, 10 * 2);
|
||||
Point[] pointsdown = {
|
||||
new Point((int)_startPosX, (int)_startPosY+20),
|
||||
new Point((int)_startPosX + 60 * 2, (int)_startPosY+20),
|
||||
@ -92,11 +91,14 @@ namespace Liner
|
||||
|
||||
};
|
||||
g.FillPolygon(br, pointsdown);
|
||||
g.DrawLine(pen, _startPosX, _startPosY + 20, _startPosX + 60 * 2, _startPosY + 20);
|
||||
g.DrawLine(pen, _startPosX + 100, _startPosY + 20 * 2, _startPosX + 120, _startPosY + 10 * 2);
|
||||
g.DrawLine(pen, _startPosX, _startPosY + 20, _startPosX + 20, _startPosY + 40);
|
||||
g.DrawLine(pen, _startPosX, _startPosY+20, _startPosX + 60 * 2, _startPosY+20);
|
||||
g.DrawLine(pen, _startPosX+100, _startPosY+20*2, _startPosX + 120, _startPosY + 10 * 2);
|
||||
g.DrawLine(pen, _startPosX, _startPosY+20, _startPosX + 20, _startPosY + 40);
|
||||
g.DrawLine(pen, _startPosX + 20, _startPosY + 40, _startPosX + 100, _startPosY + 40);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
@ -117,9 +119,5 @@ namespace Liner
|
||||
}
|
||||
|
||||
}
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _ShipWidth, _startPosY + _ShipHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal class EntityLiner : EntityShip
|
||||
{
|
||||
public Color DopColor { get; set; }
|
||||
|
||||
public bool DopDeck { get; private set; }
|
||||
|
||||
public bool Pool { get; private set; }
|
||||
|
||||
public EntityLiner(int speed, float weight, Color bodyColor, Color dopColor, bool dopDeck, bool pool) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
DopDeck = dopDeck;
|
||||
Pool = pool;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,17 +6,17 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
public class EntityShip
|
||||
internal class EntityShip
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
|
||||
public float Weight { get; private set; }
|
||||
|
||||
public Color BodyColor { get; set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
public float Step => Speed * 100 / Weight;
|
||||
|
||||
public EntityShip(int speed, float weight, Color bodycolor)
|
||||
public void Init(int speed, float weight, Color bodycolor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
|
@ -1,38 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal static class ExtentionShip
|
||||
{
|
||||
public static readonly char _separatorForObject = ':';
|
||||
public static DrawingShip CreateDrawingShip(this string info)
|
||||
{
|
||||
string[] strs=info.Split(_separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingShip(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]),Color.FromName(strs[2]));
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawningLiner(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), Color.FromName(strs[3]), Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]));
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
public static string GetDataForSave(this DrawingShip drawingShip)
|
||||
{
|
||||
var ship = drawingShip.Ship;
|
||||
var str = $"{ship.Speed}{_separatorForObject}{ship.Weight}{_separatorForObject}{ship.BodyColor.Name}";
|
||||
if (ship is not EntityLiner liner)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{_separatorForObject}{liner.DopColor.Name}{_separatorForObject}{liner.DopDeck}{_separatorForObject}{liner.Pool}";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
361
Liner/Liner/FormMapWithSetShips.Designer.cs
generated
361
Liner/Liner/FormMapWithSetShips.Designer.cs
generated
@ -1,361 +0,0 @@
|
||||
namespace Liner
|
||||
{
|
||||
partial class FormMapWithSetShips
|
||||
{
|
||||
/// <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.groupBox = new System.Windows.Forms.GroupBox();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.ListBoxMaps = new System.Windows.Forms.ListBox();
|
||||
this.ButtonAddMap = new System.Windows.Forms.Button();
|
||||
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||
this.ComboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.ButtonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.ButtonShowStorage = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveShip = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.ButtonAddShip = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.FileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.buttonSortType = new System.Windows.Forms.Button();
|
||||
this.buttonSortColor = new System.Windows.Forms.Button();
|
||||
this.groupBox.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox
|
||||
//
|
||||
this.groupBox.Controls.Add(this.buttonSortColor);
|
||||
this.groupBox.Controls.Add(this.buttonSortType);
|
||||
this.groupBox.Controls.Add(this.groupBox1);
|
||||
this.groupBox.Controls.Add(this.buttonRight);
|
||||
this.groupBox.Controls.Add(this.buttonDown);
|
||||
this.groupBox.Controls.Add(this.buttonUp);
|
||||
this.groupBox.Controls.Add(this.buttonLeft);
|
||||
this.groupBox.Controls.Add(this.ButtonShowOnMap);
|
||||
this.groupBox.Controls.Add(this.ButtonShowStorage);
|
||||
this.groupBox.Controls.Add(this.ButtonRemoveShip);
|
||||
this.groupBox.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBox.Controls.Add(this.ButtonAddShip);
|
||||
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox.Location = new System.Drawing.Point(696, 28);
|
||||
this.groupBox.Name = "groupBox";
|
||||
this.groupBox.Size = new System.Drawing.Size(279, 746);
|
||||
this.groupBox.TabIndex = 0;
|
||||
this.groupBox.TabStop = false;
|
||||
this.groupBox.Text = "Инструменты";
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.ButtonDeleteMap);
|
||||
this.groupBox1.Controls.Add(this.ListBoxMaps);
|
||||
this.groupBox1.Controls.Add(this.ButtonAddMap);
|
||||
this.groupBox1.Controls.Add(this.textBoxNewMapName);
|
||||
this.groupBox1.Controls.Add(this.ComboBoxSelectorMap);
|
||||
this.groupBox1.Location = new System.Drawing.Point(6, 26);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(250, 300);
|
||||
this.groupBox1.TabIndex = 18;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Карты";
|
||||
//
|
||||
// ButtonDeleteMap
|
||||
//
|
||||
this.ButtonDeleteMap.Location = new System.Drawing.Point(10, 255);
|
||||
this.ButtonDeleteMap.Name = "ButtonDeleteMap";
|
||||
this.ButtonDeleteMap.Size = new System.Drawing.Size(222, 29);
|
||||
this.ButtonDeleteMap.TabIndex = 13;
|
||||
this.ButtonDeleteMap.Text = "Удалить карту";
|
||||
this.ButtonDeleteMap.UseVisualStyleBackColor = true;
|
||||
this.ButtonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||
//
|
||||
// ListBoxMaps
|
||||
//
|
||||
this.ListBoxMaps.FormattingEnabled = true;
|
||||
this.ListBoxMaps.ItemHeight = 20;
|
||||
this.ListBoxMaps.Location = new System.Drawing.Point(10, 136);
|
||||
this.ListBoxMaps.Name = "ListBoxMaps";
|
||||
this.ListBoxMaps.Size = new System.Drawing.Size(222, 104);
|
||||
this.ListBoxMaps.TabIndex = 12;
|
||||
this.ListBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// ButtonAddMap
|
||||
//
|
||||
this.ButtonAddMap.Location = new System.Drawing.Point(10, 101);
|
||||
this.ButtonAddMap.Name = "ButtonAddMap";
|
||||
this.ButtonAddMap.Size = new System.Drawing.Size(222, 29);
|
||||
this.ButtonAddMap.TabIndex = 11;
|
||||
this.ButtonAddMap.Text = "Добавить карту";
|
||||
this.ButtonAddMap.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(10, 34);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(222, 27);
|
||||
this.textBoxNewMapName.TabIndex = 10;
|
||||
//
|
||||
// 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(10, 67);
|
||||
this.ComboBoxSelectorMap.Name = "ComboBoxSelectorMap";
|
||||
this.ComboBoxSelectorMap.Size = new System.Drawing.Size(222, 28);
|
||||
this.ComboBoxSelectorMap.TabIndex = 9;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::Liner.Properties.Resources._3;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(233, 704);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 17;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Liner.Properties.Resources._2;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(197, 704);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 16;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.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::Liner.Properties.Resources._4;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(197, 668);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 15;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::Liner.Properties.Resources._1;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(161, 704);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 14;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// ButtonShowOnMap
|
||||
//
|
||||
this.ButtonShowOnMap.Location = new System.Drawing.Point(16, 633);
|
||||
this.ButtonShowOnMap.Name = "ButtonShowOnMap";
|
||||
this.ButtonShowOnMap.Size = new System.Drawing.Size(222, 29);
|
||||
this.ButtonShowOnMap.TabIndex = 13;
|
||||
this.ButtonShowOnMap.Text = "Посмотреть карту";
|
||||
this.ButtonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.ButtonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// ButtonShowStorage
|
||||
//
|
||||
this.ButtonShowStorage.Location = new System.Drawing.Point(16, 578);
|
||||
this.ButtonShowStorage.Name = "ButtonShowStorage";
|
||||
this.ButtonShowStorage.Size = new System.Drawing.Size(222, 29);
|
||||
this.ButtonShowStorage.TabIndex = 12;
|
||||
this.ButtonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.ButtonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.ButtonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// ButtonRemoveShip
|
||||
//
|
||||
this.ButtonRemoveShip.Location = new System.Drawing.Point(16, 543);
|
||||
this.ButtonRemoveShip.Name = "ButtonRemoveShip";
|
||||
this.ButtonRemoveShip.Size = new System.Drawing.Size(222, 29);
|
||||
this.ButtonRemoveShip.TabIndex = 11;
|
||||
this.ButtonRemoveShip.Text = "Удалить корабль";
|
||||
this.ButtonRemoveShip.UseVisualStyleBackColor = true;
|
||||
this.ButtonRemoveShip.Click += new System.EventHandler(this.ButtonRemoveShip_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(16, 510);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(222, 27);
|
||||
this.maskedTextBoxPosition.TabIndex = 10;
|
||||
//
|
||||
// ButtonAddShip
|
||||
//
|
||||
this.ButtonAddShip.Location = new System.Drawing.Point(16, 462);
|
||||
this.ButtonAddShip.Name = "ButtonAddShip";
|
||||
this.ButtonAddShip.Size = new System.Drawing.Size(222, 29);
|
||||
this.ButtonAddShip.TabIndex = 2;
|
||||
this.ButtonAddShip.Text = "Добавить корабль";
|
||||
this.ButtonAddShip.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddShip.Click += new System.EventHandler(this.ButtonAddShip_Click);
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(696, 746);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.FileToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(975, 28);
|
||||
this.menuStrip.TabIndex = 2;
|
||||
//
|
||||
// FileToolStripMenuItem
|
||||
//
|
||||
this.FileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.SaveToolStripMenuItem,
|
||||
this.LoadToolStripMenuItem});
|
||||
this.FileToolStripMenuItem.Name = "FileToolStripMenuItem";
|
||||
this.FileToolStripMenuItem.Size = new System.Drawing.Size(59, 24);
|
||||
this.FileToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(177, 26);
|
||||
this.SaveToolStripMenuItem.Text = "Сохранение";
|
||||
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(177, 26);
|
||||
this.LoadToolStripMenuItem.Text = "Загрузка";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// buttonSortType
|
||||
//
|
||||
this.buttonSortType.Location = new System.Drawing.Point(16, 355);
|
||||
this.buttonSortType.Name = "buttonSortType";
|
||||
this.buttonSortType.Size = new System.Drawing.Size(222, 29);
|
||||
this.buttonSortType.TabIndex = 19;
|
||||
this.buttonSortType.Text = "Сортировать по типу";
|
||||
this.buttonSortType.UseVisualStyleBackColor = true;
|
||||
this.buttonSortType.Click += new System.EventHandler(this.ButtonSortType_Click);
|
||||
//
|
||||
// buttonSortColor
|
||||
//
|
||||
this.buttonSortColor.Location = new System.Drawing.Point(16, 390);
|
||||
this.buttonSortColor.Name = "buttonSortColor";
|
||||
this.buttonSortColor.Size = new System.Drawing.Size(222, 29);
|
||||
this.buttonSortColor.TabIndex = 20;
|
||||
this.buttonSortColor.Text = "Сортировать по цвету";
|
||||
this.buttonSortColor.UseVisualStyleBackColor = true;
|
||||
this.buttonSortColor.Click += new System.EventHandler(this.ButtonSortColor_Click);
|
||||
//
|
||||
// FormMapWithSetShips
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(975, 774);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormMapWithSetShips";
|
||||
this.Text = "FormMapWithSetShips";
|
||||
this.groupBox.ResumeLayout(false);
|
||||
this.groupBox.PerformLayout();
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox;
|
||||
private PictureBox pictureBox;
|
||||
private ComboBox ComboBoxSelectorMap;
|
||||
private Button ButtonShowOnMap;
|
||||
private Button ButtonShowStorage;
|
||||
private Button ButtonRemoveShip;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button ButtonAddShip;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private GroupBox groupBox1;
|
||||
private Button ButtonDeleteMap;
|
||||
private ListBox ListBoxMaps;
|
||||
private Button ButtonAddMap;
|
||||
private TextBox textBoxNewMapName;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem FileToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortColor;
|
||||
private Button buttonSortType;
|
||||
}
|
||||
}
|
@ -1,264 +0,0 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
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;
|
||||
using static System.Windows.Forms.DataFormats;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
public partial class FormMapWithSetShips : Form
|
||||
{
|
||||
private readonly Dictionary<string, AbstractMap> _mapDict = new()
|
||||
{
|
||||
{"Простая карта", new SimpleMap() },
|
||||
{"Море и айсберги", new SeaMap() },
|
||||
{"Болото",new SwampMap() }
|
||||
};
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
|
||||
private ILogger _logger;
|
||||
public FormMapWithSetShips(ILogger<FormMapWithSetShips>logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
ComboBoxSelectorMap.Items.Clear();
|
||||
foreach (var elem in _mapDict)
|
||||
{
|
||||
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 ButtonAddShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
var formShipConfig = new FormShipConfig();
|
||||
formShipConfig.AddEvent(AddShip);
|
||||
formShipConfig.Show();
|
||||
}
|
||||
private void AddShip(DrawingShip ship)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ListBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectShip(ship) != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
_logger.LogInformation("Добавлен объект {@Ship}", ship);
|
||||
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogWarning("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
_logger.LogWarning("Ошибка, переполнение хранилища :{0}", ex.Message);
|
||||
MessageBox.Show($"Ошибка хранилище переполнено: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonRemoveShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
try
|
||||
{
|
||||
var deletedShip = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
|
||||
if (deletedShip != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
_logger.LogInformation("Из текущей карты удалён объект {@Ship}", deletedShip);
|
||||
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Не удалось удалить объект по позиции {0}. Объект равен null", pos);
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
catch (ShipNotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning("Ошибка удаления: {0}", ex.Message);
|
||||
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Неизвестная ошибка удаления: {0}", ex.Message);
|
||||
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].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 ButtonAddMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ComboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("При добавлении карты {0}", ComboBoxSelectorMap.SelectedIndex == -1 ? "Не была выбрана карта" : "Не была названа карта");
|
||||
return;
|
||||
}
|
||||
if (!_mapDict.ContainsKey(ComboBoxSelectorMap.Text))
|
||||
{
|
||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Отсутствует карта с типом {0}", ComboBoxSelectorMap.Text);
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapDict[ComboBoxSelectorMap.Text]);
|
||||
ReloadMaps();
|
||||
_logger.LogInformation($"Добавлена карта: {textBoxNewMapName.Text}");
|
||||
}
|
||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
_logger.LogInformation("Осуществлён переход на карту под названием {0}", ListBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
}
|
||||
private void ButtonDeleteMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить карту {ListBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_logger.LogInformation("Удалена карта {0}", ListBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
_mapsCollection.DelMap(ListBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
_logger.LogInformation("Сохранение прошло успешно. Расположение файла: {0}", saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
MessageBox.Show($"Не сохранилось:{ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Не удалось сохранить файл '{0}'. Текст ошибки: {1}", saveFileDialog.FileName, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||
_logger.LogInformation("Загрузка данных из файла '{0}' прошла успешно", openFileDialog.FileName);
|
||||
ReloadMaps();
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Не удалось загрузить файл '{0}'. Текст ошибки: {1}", openFileDialog.FileName, ex.Message);
|
||||
MessageBox.Show($"Не загрузилось:{ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonSortType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new ShipCompareByType());
|
||||
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
private void ButtonSortColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new ShipCompareByColor());
|
||||
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
<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="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>144, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>311, 17</value>
|
||||
</metadata>
|
||||
</root>
|
28
Liner/Liner/FormShip.Designer.cs
generated
28
Liner/Liner/FormShip.Designer.cs
generated
@ -38,8 +38,6 @@
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.ButtonSelectShip = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -145,35 +143,11 @@
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(138, 373);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(118, 29);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// ButtonSelectShip
|
||||
//
|
||||
this.ButtonSelectShip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonSelectShip.Location = new System.Drawing.Point(552, 373);
|
||||
this.ButtonSelectShip.Name = "ButtonSelectShip";
|
||||
this.ButtonSelectShip.Size = new System.Drawing.Size(94, 29);
|
||||
this.ButtonSelectShip.TabIndex = 8;
|
||||
this.ButtonSelectShip.Text = "Выбрать";
|
||||
this.ButtonSelectShip.UseVisualStyleBackColor = true;
|
||||
this.ButtonSelectShip.Click += new System.EventHandler(this.ButtonSelectShip_Click);
|
||||
//
|
||||
// FormShip
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.ButtonSelectShip);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
@ -203,7 +177,5 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonCreateModif;
|
||||
private Button ButtonSelectShip;
|
||||
}
|
||||
}
|
@ -5,11 +5,12 @@ namespace Liner
|
||||
{
|
||||
|
||||
private DrawingShip _ship;
|
||||
public DrawingShip SelectedShip { get; private set; }
|
||||
|
||||
public FormShip()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(pictureBoxShip.Width, pictureBoxShip.Height);
|
||||
@ -18,24 +19,16 @@ namespace Liner
|
||||
pictureBoxShip.Image = bmp;
|
||||
|
||||
}
|
||||
private void SetData()
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
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)));
|
||||
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship?.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship?.Weight}";
|
||||
toolStripStatusLabelColor.Text = $"Öâåò: {_ship.Ship?.BodyColor.Name}";
|
||||
_ship.SetPosition(rnd.Next(100, 500), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
||||
}
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color myColor = new Color();
|
||||
ColorDialog MyDialog = new ColorDialog();
|
||||
if (MyDialog.ShowDialog() == DialogResult.OK)
|
||||
myColor = MyDialog.Color;
|
||||
_ship = new DrawingShip(random.Next(30, 50), random.Next(1000, 2000),
|
||||
myColor);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
@ -59,32 +52,11 @@ namespace Liner
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void PictureBoxShip_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height);
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color firstColor = new Color();
|
||||
Color secondColor = new Color();
|
||||
ColorDialog MyDialog = new ColorDialog();
|
||||
if (MyDialog.ShowDialog() == DialogResult.OK)
|
||||
firstColor = MyDialog.Color;
|
||||
MyDialog = new ColorDialog();
|
||||
if (MyDialog.ShowDialog() == DialogResult.OK)
|
||||
secondColor = MyDialog.Color;
|
||||
_ship = new DrawningLiner(random.Next(30, 50), random.Next(1000, 2000),
|
||||
firstColor, secondColor, Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
private void ButtonSelectShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedShip = _ship;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
381
Liner/Liner/FormShipConfig.Designer.cs
generated
381
Liner/Liner/FormShipConfig.Designer.cs
generated
@ -1,381 +0,0 @@
|
||||
namespace Liner
|
||||
{
|
||||
partial class FormShipConfig
|
||||
{
|
||||
/// <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.groupBoxConfig = new System.Windows.Forms.GroupBox();
|
||||
this.labelModifObject = new System.Windows.Forms.Label();
|
||||
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||
this.groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||
this.panelBlack = new System.Windows.Forms.Panel();
|
||||
this.panelPurple = new System.Windows.Forms.Panel();
|
||||
this.panelCyan = new System.Windows.Forms.Panel();
|
||||
this.panelWhite = new System.Windows.Forms.Panel();
|
||||
this.panelBlue = new System.Windows.Forms.Panel();
|
||||
this.panelGreen = new System.Windows.Forms.Panel();
|
||||
this.panelYellow = new System.Windows.Forms.Panel();
|
||||
this.panelRed = new System.Windows.Forms.Panel();
|
||||
this.checkBoxDopDeck = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxPool = new System.Windows.Forms.CheckBox();
|
||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.labelWeight = new System.Windows.Forms.Label();
|
||||
this.labelSpeed = new System.Windows.Forms.Label();
|
||||
this.panelObject = new System.Windows.Forms.Panel();
|
||||
this.LabelDopColor = new System.Windows.Forms.Label();
|
||||
this.LabelBaseColor = new System.Windows.Forms.Label();
|
||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.groupBoxConfig.SuspendLayout();
|
||||
this.groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||
this.panelObject.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxConfig
|
||||
//
|
||||
this.groupBoxConfig.Controls.Add(this.labelModifObject);
|
||||
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
|
||||
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
|
||||
this.groupBoxConfig.Controls.Add(this.checkBoxDopDeck);
|
||||
this.groupBoxConfig.Controls.Add(this.checkBoxPool);
|
||||
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
|
||||
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
|
||||
this.groupBoxConfig.Controls.Add(this.labelWeight);
|
||||
this.groupBoxConfig.Controls.Add(this.labelSpeed);
|
||||
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBoxConfig.Name = "groupBoxConfig";
|
||||
this.groupBoxConfig.Size = new System.Drawing.Size(492, 243);
|
||||
this.groupBoxConfig.TabIndex = 0;
|
||||
this.groupBoxConfig.TabStop = false;
|
||||
this.groupBoxConfig.Text = "Параметры";
|
||||
//
|
||||
// labelModifObject
|
||||
//
|
||||
this.labelModifObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelModifObject.Location = new System.Drawing.Point(366, 159);
|
||||
this.labelModifObject.Name = "labelModifObject";
|
||||
this.labelModifObject.Size = new System.Drawing.Size(115, 46);
|
||||
this.labelModifObject.TabIndex = 8;
|
||||
this.labelModifObject.Text = "Продвинутый";
|
||||
this.labelModifObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelModifObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelSimpleObject.Location = new System.Drawing.Point(258, 159);
|
||||
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||
this.labelSimpleObject.Size = new System.Drawing.Size(102, 46);
|
||||
this.labelSimpleObject.TabIndex = 7;
|
||||
this.labelSimpleObject.Text = "Простой";
|
||||
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// groupBoxColors
|
||||
//
|
||||
this.groupBoxColors.Controls.Add(this.panelBlack);
|
||||
this.groupBoxColors.Controls.Add(this.panelPurple);
|
||||
this.groupBoxColors.Controls.Add(this.panelCyan);
|
||||
this.groupBoxColors.Controls.Add(this.panelWhite);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlue);
|
||||
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||
this.groupBoxColors.Controls.Add(this.panelYellow);
|
||||
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||
this.groupBoxColors.Location = new System.Drawing.Point(258, 23);
|
||||
this.groupBoxColors.Name = "groupBoxColors";
|
||||
this.groupBoxColors.Size = new System.Drawing.Size(223, 134);
|
||||
this.groupBoxColors.TabIndex = 6;
|
||||
this.groupBoxColors.TabStop = false;
|
||||
this.groupBoxColors.Text = "Цвета";
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||
this.panelBlack.Location = new System.Drawing.Point(172, 75);
|
||||
this.panelBlack.Name = "panelBlack";
|
||||
this.panelBlack.Size = new System.Drawing.Size(45, 45);
|
||||
this.panelBlack.TabIndex = 1;
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||
this.panelPurple.Location = new System.Drawing.Point(121, 77);
|
||||
this.panelPurple.Name = "panelPurple";
|
||||
this.panelPurple.Size = new System.Drawing.Size(45, 45);
|
||||
this.panelPurple.TabIndex = 1;
|
||||
//
|
||||
// panelCyan
|
||||
//
|
||||
this.panelCyan.BackColor = System.Drawing.Color.Cyan;
|
||||
this.panelCyan.Location = new System.Drawing.Point(57, 77);
|
||||
this.panelCyan.Name = "panelCyan";
|
||||
this.panelCyan.Size = new System.Drawing.Size(45, 45);
|
||||
this.panelCyan.TabIndex = 1;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||
this.panelWhite.Location = new System.Drawing.Point(6, 76);
|
||||
this.panelWhite.Name = "panelWhite";
|
||||
this.panelWhite.Size = new System.Drawing.Size(45, 45);
|
||||
this.panelWhite.TabIndex = 1;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||
this.panelBlue.Location = new System.Drawing.Point(172, 25);
|
||||
this.panelBlue.Name = "panelBlue";
|
||||
this.panelBlue.Size = new System.Drawing.Size(45, 45);
|
||||
this.panelBlue.TabIndex = 2;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
||||
this.panelGreen.Location = new System.Drawing.Point(121, 25);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(45, 45);
|
||||
this.panelGreen.TabIndex = 1;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||
this.panelYellow.Location = new System.Drawing.Point(57, 26);
|
||||
this.panelYellow.Name = "panelYellow";
|
||||
this.panelYellow.Size = new System.Drawing.Size(45, 45);
|
||||
this.panelYellow.TabIndex = 1;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||
this.panelRed.Location = new System.Drawing.Point(6, 25);
|
||||
this.panelRed.Name = "panelRed";
|
||||
this.panelRed.Size = new System.Drawing.Size(45, 45);
|
||||
this.panelRed.TabIndex = 0;
|
||||
//
|
||||
// checkBoxDopDeck
|
||||
//
|
||||
this.checkBoxDopDeck.AutoSize = true;
|
||||
this.checkBoxDopDeck.Location = new System.Drawing.Point(6, 159);
|
||||
this.checkBoxDopDeck.Name = "checkBoxDopDeck";
|
||||
this.checkBoxDopDeck.Size = new System.Drawing.Size(243, 24);
|
||||
this.checkBoxDopDeck.TabIndex = 5;
|
||||
this.checkBoxDopDeck.Text = "Признак наличия доп. палубы";
|
||||
this.checkBoxDopDeck.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxPool
|
||||
//
|
||||
this.checkBoxPool.AutoSize = true;
|
||||
this.checkBoxPool.Location = new System.Drawing.Point(6, 119);
|
||||
this.checkBoxPool.Name = "checkBoxPool";
|
||||
this.checkBoxPool.Size = new System.Drawing.Size(223, 24);
|
||||
this.checkBoxPool.TabIndex = 4;
|
||||
this.checkBoxPool.Text = "Признак наличия бассейна";
|
||||
this.checkBoxPool.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
this.numericUpDownWeight.Location = new System.Drawing.Point(88, 66);
|
||||
this.numericUpDownWeight.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownWeight.Minimum = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
this.numericUpDownWeight.Size = new System.Drawing.Size(150, 27);
|
||||
this.numericUpDownWeight.TabIndex = 3;
|
||||
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(88, 33);
|
||||
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
this.numericUpDownSpeed.Size = new System.Drawing.Size(150, 27);
|
||||
this.numericUpDownSpeed.TabIndex = 2;
|
||||
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
this.labelWeight.AutoSize = true;
|
||||
this.labelWeight.Location = new System.Drawing.Point(6, 73);
|
||||
this.labelWeight.Name = "labelWeight";
|
||||
this.labelWeight.Size = new System.Drawing.Size(36, 20);
|
||||
this.labelWeight.TabIndex = 1;
|
||||
this.labelWeight.Text = "Вес:";
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
this.labelSpeed.AutoSize = true;
|
||||
this.labelSpeed.Location = new System.Drawing.Point(0, 40);
|
||||
this.labelSpeed.Name = "labelSpeed";
|
||||
this.labelSpeed.Size = new System.Drawing.Size(76, 20);
|
||||
this.labelSpeed.TabIndex = 0;
|
||||
this.labelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
this.panelObject.AllowDrop = true;
|
||||
this.panelObject.Controls.Add(this.LabelDopColor);
|
||||
this.panelObject.Controls.Add(this.LabelBaseColor);
|
||||
this.panelObject.Controls.Add(this.pictureBoxObject);
|
||||
this.panelObject.Location = new System.Drawing.Point(510, 21);
|
||||
this.panelObject.Name = "panelObject";
|
||||
this.panelObject.Size = new System.Drawing.Size(250, 204);
|
||||
this.panelObject.TabIndex = 1;
|
||||
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||
//
|
||||
// LabelDopColor
|
||||
//
|
||||
this.LabelDopColor.AllowDrop = true;
|
||||
this.LabelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.LabelDopColor.Location = new System.Drawing.Point(130, 8);
|
||||
this.LabelDopColor.Name = "LabelDopColor";
|
||||
this.LabelDopColor.Size = new System.Drawing.Size(117, 46);
|
||||
this.LabelDopColor.TabIndex = 8;
|
||||
this.LabelDopColor.Text = "Доп. цвет";
|
||||
this.LabelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.LabelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
|
||||
this.LabelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
//
|
||||
// LabelBaseColor
|
||||
//
|
||||
this.LabelBaseColor.AllowDrop = true;
|
||||
this.LabelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.LabelBaseColor.Location = new System.Drawing.Point(3, 8);
|
||||
this.LabelBaseColor.Name = "LabelBaseColor";
|
||||
this.LabelBaseColor.Size = new System.Drawing.Size(117, 46);
|
||||
this.LabelBaseColor.TabIndex = 8;
|
||||
this.LabelBaseColor.Text = "Цвет";
|
||||
this.LabelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.LabelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
||||
this.LabelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
this.pictureBoxObject.Location = new System.Drawing.Point(3, 57);
|
||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||
this.pictureBoxObject.Size = new System.Drawing.Size(244, 144);
|
||||
this.pictureBoxObject.TabIndex = 0;
|
||||
this.pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(513, 231);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonAdd.TabIndex = 2;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(663, 231);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCancel.TabIndex = 3;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormShipConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(770, 267);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.panelObject);
|
||||
this.Controls.Add(this.groupBoxConfig);
|
||||
this.Name = "FormShipConfig";
|
||||
this.Text = "Создание объекта";
|
||||
this.groupBoxConfig.ResumeLayout(false);
|
||||
this.groupBoxConfig.PerformLayout();
|
||||
this.groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||
this.panelObject.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxConfig;
|
||||
private Label labelModifObject;
|
||||
private Label labelSimpleObject;
|
||||
private GroupBox groupBoxColors;
|
||||
private Panel panelBlack;
|
||||
private Panel panelPurple;
|
||||
private Panel panelCyan;
|
||||
private Panel panelWhite;
|
||||
private Panel panelBlue;
|
||||
private Panel panelGreen;
|
||||
private Panel panelYellow;
|
||||
private Panel panelRed;
|
||||
private CheckBox checkBoxDopDeck;
|
||||
private CheckBox checkBoxPool;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelWeight;
|
||||
private Label labelSpeed;
|
||||
private Panel panelObject;
|
||||
private Label LabelDopColor;
|
||||
private Label LabelBaseColor;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Button buttonAdd;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
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 Liner
|
||||
{
|
||||
public partial class FormShipConfig : Form
|
||||
{
|
||||
DrawingShip _ship=null;
|
||||
private event Action<DrawingShip> EventAddShip;
|
||||
public FormShipConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||
panelCyan.MouseDown += PanelColor_MouseDown;
|
||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||
panelRed.MouseDown += PanelColor_MouseDown;
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
buttonCancel.Click += (s, a) => Close();
|
||||
}
|
||||
public void DrawShip()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_ship?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
_ship?.DrawTransport(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
public void AddEvent(Action<DrawingShip> ev)
|
||||
{
|
||||
if (EventAddShip == null)
|
||||
{
|
||||
EventAddShip = new Action<DrawingShip>(ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddShip += ev;
|
||||
}
|
||||
}
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_ship = new DrawingShip((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
|
||||
break;
|
||||
case "labelModifObject":
|
||||
_ship = new DrawningLiner((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||||
checkBoxDopDeck.Checked, checkBoxPool.Checked);
|
||||
break;
|
||||
}
|
||||
DrawShip();
|
||||
}
|
||||
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_ship == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_ship.Ship.BodyColor=(Color)e.Data.GetData(typeof(Color));
|
||||
DrawShip();
|
||||
}
|
||||
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_ship == null || _ship.Ship is not EntityLiner liner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
liner.DopColor=(Color)e.Data.GetData(typeof(Color));
|
||||
DrawShip();
|
||||
}
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddShip?.Invoke(_ship);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<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>
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||
{
|
||||
public float Step { get; }
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
void MoveObject(Direction direction);
|
||||
void DrawningObject(Graphics g);
|
||||
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
string GetInfo();
|
||||
}
|
||||
}
|
@ -8,19 +8,6 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
@ -1,147 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal class MapWithSetShipsGeneric<T, U>
|
||||
where T : class, IDrawingObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 170;
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
private readonly SetShipsGeneric<T> _setShips;
|
||||
private readonly U _map;
|
||||
public MapWithSetShipsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setShips = new SetShipsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
public static int operator +(MapWithSetShipsGeneric<T, U> map, T ship)
|
||||
{
|
||||
return map._setShips.Insert(ship);
|
||||
}
|
||||
public static T operator -(MapWithSetShipsGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setShips.Remove(position);
|
||||
}
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawShips(gr);
|
||||
return bmp;
|
||||
}
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
foreach (var ship in _setShips.GetShips())
|
||||
{
|
||||
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);
|
||||
}
|
||||
public string GetData(char separatorType, char separatorData)
|
||||
{
|
||||
string data = $"{_map.GetType().Name}{separatorType}";
|
||||
foreach (var ship in _setShips.GetShips())
|
||||
{
|
||||
data += $"{ship.GetInfo()}{separatorData}";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
public void LoadData(string[] records)
|
||||
{
|
||||
foreach (var rec in records)
|
||||
{
|
||||
_setShips.Insert(DrawingObjectShip.Create(rec) as T);
|
||||
}
|
||||
}
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setShips.SortSet(comparer);
|
||||
}
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setShips.Count - 1;
|
||||
for (int i = 0; i < _setShips.Count; i++)
|
||||
{
|
||||
if (_setShips[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var ship = _setShips[j];
|
||||
if (ship != null)
|
||||
{
|
||||
_setShips.Insert(ship, i);
|
||||
_setShips.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Sienna, 3);
|
||||
Brush brush = new SolidBrush(Color.DodgerBlue);
|
||||
g.FillRectangle(brush, 0, 0, _pictureWidth, _pictureHeight);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 40, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth - 4, 0, i * _placeSizeWidth - 4, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
private void DrawShips(Graphics g)
|
||||
{
|
||||
int widthEl = _pictureWidth / _placeSizeWidth;
|
||||
int heightEl = _pictureHeight / _placeSizeHeight;
|
||||
int curWidth = 1;
|
||||
int curHeight = 0;
|
||||
foreach (var ship in _setShips.GetShips())
|
||||
{
|
||||
ship?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 10,
|
||||
curHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
ship?.DrawningObject(g);
|
||||
|
||||
if (curWidth < widthEl)
|
||||
curWidth++;
|
||||
else
|
||||
{
|
||||
curWidth = 1;
|
||||
curHeight++;
|
||||
}
|
||||
if (curHeight > heightEl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
readonly Dictionary<string, MapWithSetShipsGeneric<IDrawingObject, AbstractMap>> _mapStorages;
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly char separatorDict = '|';
|
||||
private readonly char separatorData = ';';
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetShipsGeneric<IDrawingObject, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (!_mapStorages.ContainsKey(name))
|
||||
{
|
||||
_mapStorages.Add(name, new MapWithSetShipsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
}
|
||||
public void DelMap(string name)
|
||||
{
|
||||
if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name);
|
||||
}
|
||||
public MapWithSetShipsGeneric<IDrawingObject, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mapStorages.ContainsKey(ind))
|
||||
{
|
||||
return _mapStorages[ind];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
using (StreamWriter sw = new(filename))
|
||||
{
|
||||
sw.Write($"MapsCollection{Environment.NewLine}");
|
||||
foreach (var storage in _mapStorages)
|
||||
{
|
||||
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
string str = "";
|
||||
if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection"))
|
||||
{
|
||||
throw new FileFormatException("Формат данных в файле не правильный");
|
||||
}
|
||||
_mapStorages.Clear();
|
||||
while ((str = sr.ReadLine()) != null)
|
||||
{
|
||||
var tempElem = str.Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (tempElem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "SeaMap":
|
||||
map = new SeaMap();
|
||||
break;
|
||||
case "SwampMap":
|
||||
map = new SwampMap();
|
||||
break;
|
||||
|
||||
}
|
||||
_mapStorages.Add(tempElem[0], new MapWithSetShipsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[tempElem[0]].LoadData(tempElem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,8 +1,3 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal static class Program
|
||||
@ -16,27 +11,7 @@ namespace Liner
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetShips>());
|
||||
}
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormMapWithSetShips>();
|
||||
|
||||
var serilogLogger = new LoggerConfiguration()
|
||||
.WriteTo.RollingFile("Logs\\log.txt")
|
||||
.CreateLogger();
|
||||
|
||||
services.AddLogging(builder =>
|
||||
{
|
||||
builder.SetMinimumLevel(LogLevel.Information);
|
||||
builder.AddSerilog(logger: serilogLogger, dispose: true);
|
||||
});
|
||||
|
||||
Application.Run(new FormShip());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal class SeaMap : AbstractMap
|
||||
{
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.White);
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Blue);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 25)
|
||||
{
|
||||
int x = _random.Next(0, 97);
|
||||
int y = _random.Next(0, 97);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y + 1] = _barrier;
|
||||
_map[x + 1, y + 1] = _barrier;
|
||||
_map[x + 2, y + 1] = _barrier;
|
||||
_map[x + 1, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal class SetShipsGeneric<T>
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
private readonly List<T> _places;
|
||||
public int Count => _places.Count;
|
||||
private readonly int _maxCount;
|
||||
public SetShipsGeneric(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 (_places.Contains(ship))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
if (position < 0 || position > _maxCount) return -1;
|
||||
_places.Insert(position, ship);
|
||||
return position;
|
||||
}
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
{
|
||||
throw new ShipNotFoundException(position);
|
||||
}
|
||||
T ship = _places[position];
|
||||
_places.RemoveAt(position);
|
||||
return ship;
|
||||
}
|
||||
public T this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Insert(value, position);
|
||||
|
||||
}
|
||||
}
|
||||
public IEnumerable<T> GetShips()
|
||||
{
|
||||
foreach (var ship in _places)
|
||||
{
|
||||
if (ship != null)
|
||||
{
|
||||
yield return ship;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal class ShipCompareByColor : IComparer<IDrawingObject>
|
||||
{
|
||||
public int Compare(IDrawingObject? x, IDrawingObject? y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xShip= x as DrawingObjectShip;
|
||||
var yShip = y as DrawingObjectShip;
|
||||
if (xShip == null && yShip == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xShip == null && yShip != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xShip != null && yShip == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
string xShipColor = xShip.GetShip.Ship.BodyColor.Name;
|
||||
string yShipColor = yShip.GetShip.Ship.BodyColor.Name;
|
||||
if (xShipColor != yShipColor)
|
||||
{
|
||||
return xShipColor.CompareTo(yShipColor);
|
||||
}
|
||||
if (xShip.GetShip.GetType().Name != yShip.GetShip.GetType().Name)
|
||||
{
|
||||
if (xShip.GetShip.GetType().Name == "DrawingShip")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (xShip.GetShip.Ship is EntityLiner xLiner && yShip.GetShip.Ship is EntityLiner yLiner)
|
||||
{
|
||||
string xShipDopColor = xLiner.DopColor.Name;
|
||||
string yShipDopColor = yLiner.DopColor.Name;
|
||||
var dopColorCompare = xShipDopColor.CompareTo(yShipDopColor);
|
||||
if (dopColorCompare != 0)
|
||||
{
|
||||
return dopColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = xShip.GetShip.Ship.Speed.CompareTo(yShip.GetShip.Ship.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xShip.GetShip.Ship.Weight.CompareTo(yShip.GetShip.Ship.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal class ShipCompareByType : IComparer<IDrawingObject>
|
||||
{
|
||||
public int Compare(IDrawingObject? x, IDrawingObject? y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xShip = x as DrawingObjectShip;
|
||||
var yShip = y as DrawingObjectShip;
|
||||
if (xShip == null && yShip == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xShip == null && yShip != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xShip != null && yShip == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (xShip.GetShip.GetType().Name != yShip.GetShip.GetType().Name)
|
||||
{
|
||||
if (xShip.GetShip.GetType().Name == "DrawingShip")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
var speedCompare = xShip.GetShip.Ship.Speed.CompareTo(yShip.GetShip.Ship.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xShip.GetShip.Ship.Weight.CompareTo(yShip.GetShip.Ship.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
[Serializable]
|
||||
internal class ShipNotFoundException: ApplicationException
|
||||
{
|
||||
public ShipNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public ShipNotFoundException() : base() { }
|
||||
public ShipNotFoundException(string message) : base(message) { }
|
||||
public ShipNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected ShipNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal class SimpleMap : AbstractMap
|
||||
{
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
[Serializable]
|
||||
internal class StorageOverflowException: ApplicationException
|
||||
{
|
||||
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||
public StorageOverflowException():base(){}
|
||||
public StorageOverflowException(string message):base(message){}
|
||||
public StorageOverflowException(string message, Exception exception):base(message, exception){}
|
||||
protected StorageOverflowException(SerializationInfo info, StreamingContext context): base(info, context){}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal class SwampMap : AbstractMap
|
||||
{
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.DarkGreen);
|
||||
private readonly Brush roadColor = new SolidBrush(Color.AliceBlue);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 25)
|
||||
{
|
||||
int x = _random.Next(0, 97);
|
||||
int y = _random.Next(0, 97);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
_map[x + 2, y] = _barrier;
|
||||
_map[x, y + 2] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user