Sorokin P.V. Lab work 3 #3
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -13,8 +13,6 @@ namespace Liner
|
||||
void MoveObject(Direction direction);
|
||||
void DrawningObject(Graphics g);
|
||||
|
||||
|
||||
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
}
|
||||
}
|
||||
|
@ -25,27 +25,13 @@ namespace Liner
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
public static bool operator +(MapWithSetShipsGeneric<T, U> map, T ship)
|
||||
public static int operator +(MapWithSetShipsGeneric<T, U> map, T ship)
|
||||
{
|
||||
if (map._setShips.Insert(ship) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return map._setShips.Insert(ship);
|
||||
}
|
||||
public static bool operator -(MapWithSetShipsGeneric<T, U> map, int position)
|
||||
public static T operator -(MapWithSetShipsGeneric<T, U> 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;
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user