Логика+графика
This commit is contained in:
parent
d8b20b7584
commit
b607da6c9b
@ -32,62 +32,58 @@ namespace Locomative
|
||||
}
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (CheckCollision(direction))
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private bool CheckCollision(Direction direction)
|
||||
{
|
||||
(float left, float right, float top, float bottom) = _drawningObject.GetCurrentPosition();
|
||||
float step = _drawningObject?.Step ?? 0;
|
||||
int startX = 0, startY = 0, finishX = 0, finishY = 0;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Up:
|
||||
for (int i = 0; i < _map?.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Left < i * _size_x && _drawningObject.GetCurrentPosition().Top > i * _size_x) || (_drawningObject.GetCurrentPosition().Left < i * (_size_x + 1) && _drawningObject.GetCurrentPosition().Top > i * (_size_x + 1))) && j * (_size_y + 1) < _drawningObject.GetCurrentPosition().Right && _drawningObject.GetCurrentPosition().Right - j * (_size_y + 1) <= _drawningObject.Step)
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
}
|
||||
startX = (int)left;
|
||||
startY = (int)(top - step);
|
||||
finishX = (int)right;
|
||||
finishY = (int)top;
|
||||
break;
|
||||
case Direction.Down:
|
||||
for (int i = 0; i < _map?.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Left < i * _size_x && _drawningObject.GetCurrentPosition().Top > i * _size_x) ||
|
||||
(_drawningObject.GetCurrentPosition().Left < i * (_size_x + 1) && _drawningObject.GetCurrentPosition().Top > i * (_size_x + 1))) &&
|
||||
j * _size_y > _drawningObject.GetCurrentPosition().Bottom && j * _size_y - _drawningObject.GetCurrentPosition().Bottom <= _drawningObject.Step)
|
||||
return DrawMapWithObject();
|
||||
|
||||
}
|
||||
}
|
||||
startX = (int)left;
|
||||
startY = (int)bottom;
|
||||
finishX = (int)right;
|
||||
finishY = (int)(bottom + step);
|
||||
break;
|
||||
case Direction.Left:
|
||||
for (int i = 0; i < _map?.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Right < j * _size_y && _drawningObject.GetCurrentPosition().Bottom > j * _size_y) ||
|
||||
(_drawningObject.GetCurrentPosition().Right < j * (_size_y + 1) && _drawningObject.GetCurrentPosition().Bottom > j * (_size_y + 1))) &&
|
||||
i * (_size_x + 1) < _drawningObject.GetCurrentPosition().Left && _drawningObject.GetCurrentPosition().Left - i * (_size_x + 1) <= _drawningObject.Step)
|
||||
return DrawMapWithObject();
|
||||
|
||||
}
|
||||
}
|
||||
startX = (int)(left - step);
|
||||
startY = (int)top;
|
||||
finishX = (int)left;
|
||||
finishY = (int)bottom;
|
||||
break;
|
||||
case Direction.Right:
|
||||
for (int i = 0; i < _map?.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Right < j * _size_y && _drawningObject.GetCurrentPosition().Bottom > j * _size_y) ||
|
||||
(_drawningObject.GetCurrentPosition().Right < j * (_size_y + 1) && _drawningObject.GetCurrentPosition().Bottom > j * (_size_y + 1))) &&
|
||||
i * (_size_x) > _drawningObject.GetCurrentPosition().Top && i * (_size_x) - _drawningObject.GetCurrentPosition().Top <= _drawningObject.Step)
|
||||
return DrawMapWithObject();
|
||||
|
||||
}
|
||||
}
|
||||
startX = (int)right;
|
||||
startY = (int)top;
|
||||
finishX = (int)(right + step);
|
||||
finishY = (int)bottom;
|
||||
break;
|
||||
}
|
||||
_drawningObject?.MoveObject(direction);
|
||||
return DrawMapWithObject();
|
||||
if (startX < 0 || finishX > _width || startY < 0 || finishY > _height) return false;
|
||||
|
||||
startX = (int)(startX / _size_x);
|
||||
startY = (int)(startY / _size_y);
|
||||
finishX = (int)(finishX / _size_x);
|
||||
finishY = (int)(finishY / _size_y);
|
||||
for (int i = startX; i < finishX; i++)
|
||||
for (int j = startY; j < finishY; j++)
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
|
@ -2,10 +2,10 @@
|
||||
{
|
||||
internal class DrawningFastLoco : DrawningLocomative
|
||||
{
|
||||
public DrawningFastLoco(int speed, float weight, Color bodyColor, Color dopColor, bool widow, bool room) :
|
||||
public DrawningFastLoco(int speed, float weight, Color bodyColor, Color dopColor, bool line, bool garmoshka) :
|
||||
base(speed, weight, bodyColor, 110, 60)
|
||||
{
|
||||
Locomative = new EntityFastLocomative(speed, weight, bodyColor, dopColor, widow, room);
|
||||
Locomative = new EntityFastLocomative(speed, weight, bodyColor, dopColor, line, garmoshka);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
@ -16,54 +16,62 @@
|
||||
|
||||
//кисти
|
||||
Pen pen = new(Color.Black);
|
||||
Pen dopPen = new(fastLocomative.BodyColor);
|
||||
Brush brWhite = new SolidBrush(Color.White);
|
||||
Brush bodyBrush = new SolidBrush(fastLocomative.BodyColor);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
//вид слева
|
||||
Point point1 = new Point(Convert.ToInt32(_startPosX), Convert.ToInt32(_startPosY));
|
||||
Point point2 = new Point(Convert.ToInt32(_startPosX+90), Convert.ToInt32(_startPosY + 2));
|
||||
Point point3 = new Point(Convert.ToInt32(_startPosX+100), Convert.ToInt32(_startPosY + 42));
|
||||
Point point4 = new Point(Convert.ToInt32(_startPosX), Convert.ToInt32(_startPosY + 40));
|
||||
Point[] points = { point1, point2, point3, point4 };
|
||||
g.FillPolygon(brWhite, points);
|
||||
g.DrawPolygon(pen, points);
|
||||
//окна
|
||||
Point p_1_1 = new Point(Convert.ToInt32(_startPosX + 5), Convert.ToInt32(_startPosY + 10));
|
||||
Point p_1_2 = new Point(Convert.ToInt32(_startPosX + 45), Convert.ToInt32(_startPosY + 11));
|
||||
Point p_1_3 = new Point(Convert.ToInt32(_startPosX + 45), Convert.ToInt32(_startPosY + 31));
|
||||
Point p_1_4 = new Point(Convert.ToInt32(_startPosX + 5), Convert.ToInt32(_startPosY + 30));
|
||||
Point[] points1 = { p_1_1, p_1_2, p_1_3, p_1_4 };
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
Brush Aque = new SolidBrush(Color.Aquamarine);
|
||||
//крыша
|
||||
Point point1_1 = new Point(Convert.ToInt32(_startPosX + 30), Convert.ToInt32(_startPosY + 5));
|
||||
Point point1_2 = new Point(Convert.ToInt32(_startPosX + 32), Convert.ToInt32(_startPosY));
|
||||
Point point1_3 = new Point(Convert.ToInt32(_startPosX + 60), Convert.ToInt32(_startPosY));
|
||||
Point point1_4 = new Point(Convert.ToInt32(_startPosX + 62), Convert.ToInt32(_startPosY + 5));
|
||||
Point[] points1 = { point1_1, point1_2, point1_3, point1_4 };
|
||||
g.FillPolygon(brWhite, points1);
|
||||
g.DrawPolygon(pen, points1);
|
||||
Point p_2_1 = new Point(Convert.ToInt32(_startPosX + 55), Convert.ToInt32(_startPosY + 11));
|
||||
Point p_2_2 = new Point(Convert.ToInt32(_startPosX + 89), Convert.ToInt32(_startPosY + 12));
|
||||
Point p_2_3 = new Point(Convert.ToInt32(_startPosX + 95), Convert.ToInt32(_startPosY + 32));
|
||||
Point p_2_4 = new Point(Convert.ToInt32(_startPosX + 55), Convert.ToInt32(_startPosY + 31));
|
||||
Point[] points2 = { p_2_1, p_2_2, p_2_3, p_2_4 };
|
||||
//основная часть
|
||||
Point point2_1 = new Point(Convert.ToInt32(_startPosX), Convert.ToInt32(_startPosY+5));
|
||||
Point point2_2 = new Point(Convert.ToInt32(_startPosX + 90), Convert.ToInt32(_startPosY + 5));
|
||||
Point point2_3 = new Point(Convert.ToInt32(_startPosX + 100), Convert.ToInt32(_startPosY + 35));
|
||||
Point point2_4 = new Point(Convert.ToInt32(_startPosX), Convert.ToInt32(_startPosY + 35));
|
||||
Point[] points2 = { point2_1, point2_2, point2_3, point2_4 };
|
||||
g.FillPolygon(brWhite, points2);
|
||||
g.DrawPolygon(pen, points2);
|
||||
//поезд спереди
|
||||
Point p_3_1 = new Point(Convert.ToInt32(_startPosX + 90), Convert.ToInt32(_startPosY + 2));
|
||||
Point p_3_2 = new Point(Convert.ToInt32(_startPosX + 110), Convert.ToInt32(_startPosY));
|
||||
Point p_3_3 = new Point(Convert.ToInt32(_startPosX + 120), Convert.ToInt32(_startPosY + 40));
|
||||
Point p_3_4 = new Point(Convert.ToInt32(_startPosX + 100), Convert.ToInt32(_startPosY + 42));
|
||||
Point[] points3 = { p_3_1, p_3_2, p_3_3, p_3_4 };
|
||||
g.FillPolygon(brWhite, points3);
|
||||
//нижняя часть
|
||||
Point point3_1 = new Point(Convert.ToInt32(_startPosX), Convert.ToInt32(_startPosY + 35));
|
||||
Point point3_2 = new Point(Convert.ToInt32(_startPosX + 100), Convert.ToInt32(_startPosY + 35));
|
||||
Point point3_3 = new Point(Convert.ToInt32(_startPosX + 95), Convert.ToInt32(_startPosY + 40));
|
||||
Point point3_4 = new Point(Convert.ToInt32(_startPosX + 5), Convert.ToInt32(_startPosY + 40));
|
||||
Point[] points3 = { point3_1, point3_2, point3_3, point3_4 };
|
||||
g.FillPolygon(brBlue, points3);
|
||||
g.DrawPolygon(pen, points3);
|
||||
//окно спереди
|
||||
Point p_4_1 = new Point(Convert.ToInt32(_startPosX + 90), Convert.ToInt32(_startPosY + 2));
|
||||
Point p_4_2 = new Point(Convert.ToInt32(_startPosX + 110), Convert.ToInt32(_startPosY));
|
||||
Point p_4_3 = new Point(Convert.ToInt32(_startPosX + 120), Convert.ToInt32(_startPosY + 40));
|
||||
Point p_4_4 = new Point(Convert.ToInt32(_startPosX + 100), Convert.ToInt32(_startPosY + 42));
|
||||
Point[] points4 = { p_4_1, p_4_2, p_4_3, p_4_4 };
|
||||
g.DrawPolygon(pen, points4);////////////////////////////////////
|
||||
//окно зараска
|
||||
if (fastLocomative.bodyKit) {
|
||||
|
||||
}
|
||||
//вторая кабина
|
||||
if (fastLocomative.room)
|
||||
//стекла
|
||||
Point point4_1 = new Point(Convert.ToInt32(_startPosX), Convert.ToInt32(_startPosY + 10));
|
||||
Point point4_2 = new Point(Convert.ToInt32(_startPosX + 75), Convert.ToInt32(_startPosY + 10));
|
||||
Point point4_3 = new Point(Convert.ToInt32(_startPosX + 75), Convert.ToInt32(_startPosY + 23));
|
||||
Point point4_4 = new Point(Convert.ToInt32(_startPosX), Convert.ToInt32(_startPosY + 23));
|
||||
Point[] points4 = { point4_1, point4_2, point4_3, point4_4 };
|
||||
g.FillPolygon(brBlack, points4);
|
||||
g.FillRectangle(Aque, _startPosX + 5, _startPosY + 11, 15, 11);
|
||||
g.FillRectangle(Aque, _startPosX + 25, _startPosY + 11, 15, 11);
|
||||
g.FillRectangle(Aque, _startPosX + 45, _startPosY + 11, 15, 11);
|
||||
//переднее окно
|
||||
Point point5_1 = new Point(Convert.ToInt32(_startPosX + 75), Convert.ToInt32(_startPosY + 10));
|
||||
Point point5_2 = new Point(Convert.ToInt32(_startPosX + 88), Convert.ToInt32(_startPosY + 10));
|
||||
Point point5_3 = new Point(Convert.ToInt32(_startPosX + 93), Convert.ToInt32(_startPosY + 23));
|
||||
Point point5_4 = new Point(Convert.ToInt32(_startPosX + 75), Convert.ToInt32(_startPosY + 23));
|
||||
Point[] poits5 = { point5_1, point5_2, point5_3, point5_4 };
|
||||
g.FillPolygon(Aque, poits5);
|
||||
|
||||
if (fastLocomative.Line)//окна с дверьми
|
||||
{
|
||||
|
||||
|
||||
g.DrawLine(dopPen, _startPosX, _startPosY + 25, _startPosX + 87, _startPosY + 25);
|
||||
g.DrawLine(dopPen, _startPosX + 85, _startPosY + 25, _startPosX + 95, _startPosY + 35);
|
||||
}
|
||||
if (fastLocomative.Garmoshka)
|
||||
{
|
||||
g.FillRectangle(brBlack, _startPosX + 40, _startPosY+ 5, 5,35);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,36 @@ namespace Locomative
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void MoveTransportOnX(Direction direction, int x)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Right:
|
||||
if (_startPosX + _locoWidth + x < _pictureWidth)
|
||||
{
|
||||
_startPosX += x;
|
||||
}
|
||||
break;
|
||||
case Direction.Left:
|
||||
if (_startPosX - x > 0)
|
||||
{
|
||||
_startPosX -=x;
|
||||
}
|
||||
break;
|
||||
case Direction.Up:
|
||||
if (_startPosY - x > 0)
|
||||
{
|
||||
_startPosY -= x;
|
||||
}
|
||||
break;
|
||||
case Direction.Down:
|
||||
if (_startPosY + _locoHeight + x < _pictureHeight)
|
||||
{
|
||||
_startPosY += x;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX <= 0 || _startPosY <= 0 || !_pictureWidth.HasValue || !_pictureHeight.HasValue) return;
|
||||
@ -132,7 +162,7 @@ namespace Locomative
|
||||
}
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _locoWidth, _startPosY + _locoHeight);
|
||||
return (_startPosX, _startPosX + _locoWidth, _startPosY, _startPosY + _locoHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,10 @@ namespace Locomative
|
||||
{
|
||||
_loco?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public void MoveObjectOnX(Direction direction, int x)
|
||||
{
|
||||
_loco?.MoveTransportOnX(direction, x);
|
||||
}
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_loco?.SetPosition(x, y, width, height);
|
||||
|
@ -9,16 +9,14 @@ namespace Locomative
|
||||
internal class EntityFastLocomative : EntityLocomative
|
||||
{
|
||||
public Color dopColor { get; private set; }
|
||||
public bool wing { get; private set; }
|
||||
public bool bodyKit { get; private set; }
|
||||
public bool room { get; private set; }
|
||||
public EntityFastLocomative(int speed, float weight, Color bodyColor, Color dopColor, bool widow, bool room) :
|
||||
public bool Line { get; private set; }
|
||||
public bool Garmoshka { get; private set; }
|
||||
public EntityFastLocomative(int speed, float weight, Color bodyColor, Color dopColor, bool line, bool garmoshka) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
this.dopColor = dopColor;
|
||||
this.bodyKit = widow;
|
||||
this.wing = wing;
|
||||
this.room = room;
|
||||
Line = line;
|
||||
Garmoshka = garmoshka;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace Locomative
|
||||
private void buttonСreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var car = new DrawningLocomative(rnd.Next(50, 150), rnd.Next(100, 200), Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)));
|
||||
var car = new DrawningLocomative(rnd.Next(40, 50), rnd.Next(100, 200), Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)));
|
||||
SetData(car);
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ namespace Locomative
|
||||
private void ButtonFastCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
var loco = new DrawningFastLoco(rnd.Next(50, 250), rnd.Next(100, 300),
|
||||
var loco = new DrawningFastLoco(rnd.Next(40, 50), rnd.Next(100, 300),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
|
@ -11,6 +11,7 @@ namespace Locomative
|
||||
public float Step { get; }
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
void MoveObject(Direction direction);
|
||||
void MoveObjectOnX(Direction direction, int x);
|
||||
void DrawningObject(Graphics g);
|
||||
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user