Borschevskaya A.A. Lab Work 8 #10
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||
{
|
||||
private IDrawningObject _drawningObject = null;
|
||||
protected int[,] _map = null;
|
||||
@ -31,7 +31,7 @@ namespace ArmoredCar
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
{
|
||||
bool flag = true;
|
||||
float step = _drawningObject.Step;
|
||||
(float left, float right, float top, float bottom) = _drawningObject.GetCurrentPosition();
|
||||
@ -40,7 +40,7 @@ namespace ArmoredCar
|
||||
int y1_obj_next = (int)((top - step) / _size_y);
|
||||
int x2_obj_next = (int)((right + step) / _size_x);
|
||||
int y2_obj_next = (int)((bottom + step) / _size_y);
|
||||
|
||||
|
||||
int x1_obj_current = (int)(left / _size_x);
|
||||
int y1_obj_current = (int)(top / _size_y);
|
||||
int x2_obj_current = (int)(right / _size_x);
|
||||
@ -53,7 +53,7 @@ namespace ArmoredCar
|
||||
{
|
||||
if (x1_obj_next < 0)
|
||||
{
|
||||
flag = false;
|
||||
flag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -132,9 +132,9 @@ namespace ArmoredCar
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
@ -151,9 +151,9 @@ namespace ArmoredCar
|
||||
int y = _random.Next(0, 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
(float left, float right, float top, float bottom) = _drawningObject.GetCurrentPosition();
|
||||
for (int i = (int)(x / _size_x); i <= (int) (right / _size_x); i++)
|
||||
for (int i = (int)(x / _size_x); i <= (int)(right / _size_x); i++)
|
||||
{
|
||||
for (int j = (int)(y / _size_y); j <= (int) (bottom / _size_y); j++)
|
||||
for (int j = (int)(y / _size_y); j <= (int)(bottom / _size_y); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
@ -171,7 +171,7 @@ namespace ArmoredCar
|
||||
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)
|
||||
@ -193,5 +193,43 @@ namespace ArmoredCar
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user