diff --git a/Liner/Liner/AbstractMap.cs b/Liner/Liner/AbstractMap.cs index 94a906b..faa99df 100644 --- a/Liner/Liner/AbstractMap.cs +++ b/Liner/Liner/AbstractMap.cs @@ -17,7 +17,6 @@ namespace Liner 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; @@ -111,8 +110,6 @@ namespace Liner startY += _size_y; } return false; - - } private Bitmap DrawMapWithObject() { @@ -139,7 +136,6 @@ namespace Liner _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); diff --git a/Liner/Liner/DrawingObjectShip.cs b/Liner/Liner/DrawingObjectShip.cs index 39ade25..3686c49 100644 --- a/Liner/Liner/DrawingObjectShip.cs +++ b/Liner/Liner/DrawingObjectShip.cs @@ -9,7 +9,6 @@ namespace Liner internal class DrawingObjectShip : IDrawingObject { private DrawingShip _ship = null; - public DrawingObjectShip(DrawingShip ship) { _ship = ship; @@ -23,17 +22,13 @@ namespace Liner { _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); } - } } diff --git a/Liner/Liner/DrawingShip.cs b/Liner/Liner/DrawingShip.cs index 848019b..6a68c2a 100644 --- a/Liner/Liner/DrawingShip.cs +++ b/Liner/Liner/DrawingShip.cs @@ -38,7 +38,6 @@ namespace Liner _pictureWidth = width; _pictureHeight = height; } - public void MoveTransport(Direction direction) { if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) @@ -72,10 +71,8 @@ namespace Liner _startPosY += Ship.Step; } break; - } } - public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureWidth.HasValue || !_pictureHeight.HasValue) @@ -100,7 +97,6 @@ namespace Liner 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; diff --git a/Liner/Liner/FormMapWithSetShips.cs b/Liner/Liner/FormMapWithSetShips.cs index ee40e34..500b974 100644 --- a/Liner/Liner/FormMapWithSetShips.cs +++ b/Liner/Liner/FormMapWithSetShips.cs @@ -18,7 +18,6 @@ namespace Liner { InitializeComponent(); } - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) { AbstractMap map = null; @@ -44,7 +43,6 @@ namespace Liner _mapShipsCollectionGeneric = null; } } - private void ButtonAddShip_Click(object sender, EventArgs e) { if (_mapShipsCollectionGeneric == null) @@ -55,7 +53,7 @@ namespace Liner if (form.ShowDialog() == DialogResult.OK) { DrawingObjectShip ship = new(form.SelectedShip); - if (_mapShipsCollectionGeneric + ship) + if (_mapShipsCollectionGeneric + ship != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); @@ -66,7 +64,6 @@ namespace Liner } } } - private void ButtonRemoveShip_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) @@ -78,7 +75,7 @@ namespace Liner return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapShipsCollectionGeneric - pos) + if (_mapShipsCollectionGeneric - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); @@ -88,7 +85,6 @@ namespace Liner MessageBox.Show("Не удалось удалить объект"); } } - private void ButtonShowStorage_Click(object sender, EventArgs e) { if (_mapShipsCollectionGeneric == null) @@ -97,7 +93,6 @@ namespace Liner } pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); } - private void ButtonShowOnMap_Click(object sender, EventArgs e) { if (_mapShipsCollectionGeneric == null) diff --git a/Liner/Liner/IDrawingObject.cs b/Liner/Liner/IDrawingObject.cs index d849ded..aad8465 100644 --- a/Liner/Liner/IDrawingObject.cs +++ b/Liner/Liner/IDrawingObject.cs @@ -13,8 +13,6 @@ namespace Liner void MoveObject(Direction direction); void DrawningObject(Graphics g); - - (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); } } diff --git a/Liner/Liner/MapWithSetShipsGeneric.cs b/Liner/Liner/MapWithSetShipsGeneric.cs index e76dee0..b8e16b9 100644 --- a/Liner/Liner/MapWithSetShipsGeneric.cs +++ b/Liner/Liner/MapWithSetShipsGeneric.cs @@ -25,27 +25,13 @@ namespace Liner _pictureHeight = picHeight; _map = map; } - public static bool operator +(MapWithSetShipsGeneric map, T ship) + public static int operator +(MapWithSetShipsGeneric map, T ship) { - if (map._setShips.Insert(ship) == -1) - { - return false; - } - else - { - return true; - } + return map._setShips.Insert(ship); } - public static bool operator -(MapWithSetShipsGeneric map, int position) + public static T operator -(MapWithSetShipsGeneric map, int position) { - if (map._setShips.Remove(position) == null) - { - return false; - } - else - { - return true; - } + return map._setShips.Remove(position); } public Bitmap ShowSet() { @@ -85,10 +71,10 @@ namespace Liner { for (; j > i; j--) { - var car = _setShips.Get(j); - if (car != null) + var ship = _setShips.Get(j); + if (ship != null) { - _setShips.Insert(car, i); + _setShips.Insert(ship, i); _setShips.Remove(j); break; } diff --git a/Liner/Liner/SeaMap.cs b/Liner/Liner/SeaMap.cs index 43b2616..d47ed86 100644 --- a/Liner/Liner/SeaMap.cs +++ b/Liner/Liner/SeaMap.cs @@ -9,9 +9,7 @@ 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)); diff --git a/Liner/Liner/SetShipsGeneric.cs b/Liner/Liner/SetShipsGeneric.cs index e311083..0f4b0f0 100644 --- a/Liner/Liner/SetShipsGeneric.cs +++ b/Liner/Liner/SetShipsGeneric.cs @@ -31,7 +31,7 @@ namespace Liner return position; } int emptyIndex = -1; - for (int i = position + 1; i < _places.Length; i++) + for (int i = position + 1; i < Count; i++) { if (_places[i] == null) { diff --git a/Liner/Liner/SimpleMap.cs b/Liner/Liner/SimpleMap.cs index cec355f..97d2731 100644 --- a/Liner/Liner/SimpleMap.cs +++ b/Liner/Liner/SimpleMap.cs @@ -9,9 +9,7 @@ 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)); diff --git a/Liner/Liner/SwampMap.cs b/Liner/Liner/SwampMap.cs index 6d19977..fb46fad 100644 --- a/Liner/Liner/SwampMap.cs +++ b/Liner/Liner/SwampMap.cs @@ -9,9 +9,7 @@ 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));