PIbd-23-Radaev-A.V.-20/Catamaran/DrawningCatamaran.cs

157 lines
5.5 KiB
C#
Raw Normal View History

2023-10-31 12:23:01 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran
{
2023-10-31 12:27:43 +04:00
public class DrawningCatamaran
2023-10-31 12:23:01 +04:00
{
2023-10-31 12:27:43 +04:00
public EntityCatamaran? EntityCatamaran { get; set; }
2023-10-31 12:23:01 +04:00
2023-10-31 12:27:43 +04:00
public int _pictureWidth = 800;
public int _pictureHeight = 450;
2023-10-31 12:23:01 +04:00
2023-10-31 12:27:43 +04:00
public int _startPosX = 0;
public int _startPosY = 0;
public readonly int _catamaranWidth = 120;
public readonly int _catamaranHeight = 80;
2023-10-31 12:23:01 +04:00
2023-10-31 12:27:43 +04:00
public DrawningCatamaran(int speed, double weight, Color bodyColor, Color additioncolor, int width, int height, bool seats)
2023-10-31 12:23:01 +04:00
{
2023-10-31 12:27:43 +04:00
if (_pictureHeight < _catamaranWidth && _pictureWidth < _catamaranHeight) return;
2023-10-31 12:23:01 +04:00
_pictureWidth = width;
_pictureHeight = height;
2023-10-31 12:27:43 +04:00
EntityCatamaran = new EntityCatamaran(speed,weight,bodyColor,additioncolor,seats);
2023-10-31 12:23:01 +04:00
}
2023-10-31 12:27:43 +04:00
protected DrawningCatamaran(int speed, double weight, Color bodyColor, Color additioncolor, int width, int height, int catWidth, int catHeight, bool seats)
{
if (width <= _catamaranWidth || height <= _catamaranHeight) return;
_pictureWidth = width;
_pictureHeight = height;
_catamaranWidth = catWidth;
_catamaranHeight = catHeight;
EntityCatamaran = new EntityCatamaran(speed, weight, bodyColor, additioncolor, seats);
}
2023-10-31 12:23:01 +04:00
public void SetPosition(int x, int y)
{
2023-10-31 12:27:43 +04:00
if(EntityCatamaran == null) return;
while(x + _catamaranWidth > _pictureWidth)
2023-10-31 12:23:01 +04:00
{
x-= (int)EntityCatamaran.Step;
}
while (x < 0)
2023-10-31 12:27:43 +04:00
{
2023-10-31 12:23:01 +04:00
x+= (int)EntityCatamaran.Step;
}
while (y + _catamaranHeight > _pictureHeight)
{
y-= (int)EntityCatamaran.Step;
}
while (y < 0)
{
y+= (int)EntityCatamaran.Step;
}
_startPosX = x;
_startPosY = y;
}
2023-10-31 12:27:43 +04:00
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _catamaranWidth;
public int GetHeight => _catamaranHeight;
public bool CanMove(DirectionType direction)
{
if (EntityCatamaran == null)
{
return false;
}
return direction switch
{
DirectionType.Left => _startPosX - EntityCatamaran.Step > 0,
DirectionType.Up => _startPosY - EntityCatamaran.Step > 0,
DirectionType.Right => _startPosX + EntityCatamaran.Step < _pictureWidth,
DirectionType.Down => _startPosY -+EntityCatamaran.Step < _pictureHeight,
_ => false,
};
}
2023-10-31 12:23:01 +04:00
2023-10-31 12:27:43 +04:00
2023-10-31 12:23:01 +04:00
public void MoveTransport(DirectionType direction)
{
if (EntityCatamaran == null)
{
return;
}
switch (direction)
2023-10-31 12:27:43 +04:00
{
2023-10-31 12:23:01 +04:00
case DirectionType.Left:
if (_startPosX - EntityCatamaran.Step > 0)
{
_startPosX -= (int)EntityCatamaran.Step;
}
break;
2023-10-31 12:27:43 +04:00
2023-10-31 12:23:01 +04:00
case DirectionType.Up:
if (_startPosY - EntityCatamaran.Step > 0)
{
_startPosY -= (int)EntityCatamaran.Step;
}
break;
case DirectionType.Right:
if (_startPosX + _catamaranWidth + EntityCatamaran.Step < _pictureWidth)
{
_startPosX += (int)EntityCatamaran.Step;
}
break;
case DirectionType.Down:
if (_startPosY + _catamaranHeight + EntityCatamaran.Step < _pictureHeight)
{
_startPosY += (int)EntityCatamaran.Step;
}
break;
}
}
2023-10-31 12:27:43 +04:00
public virtual void DrawTransport(Graphics g)
2023-10-31 12:23:01 +04:00
{
2023-10-31 12:27:43 +04:00
if (EntityCatamaran is not EntityCatamaran Cat)
2023-10-31 12:23:01 +04:00
{
return;
}
Pen pen = new(Color.Black);
2023-10-31 12:27:43 +04:00
Brush bodyBrush = new SolidBrush(EntityCatamaran.BodyColor);
Brush ellipseBrush = new SolidBrush(EntityCatamaran.AdditionalColor);
2023-10-31 12:23:01 +04:00
Point[] pontf = { new Point(_startPosX + _catamaranWidth - 40, _startPosY+10), new Point(_startPosX + _catamaranWidth, _startPosY + 40), new Point(_startPosX + _catamaranWidth - 40, _startPosY + 70) };
2023-10-31 12:27:43 +04:00
g.DrawPolygon(pen, pontf);
2023-10-31 12:23:01 +04:00
2023-10-31 12:27:43 +04:00
g.FillRectangle(bodyBrush, _startPosX+10, _startPosY+10, _catamaranWidth - 50, 60);
2023-10-31 12:23:01 +04:00
g.DrawRectangle(pen, _startPosX+10, _startPosY+10, _catamaranWidth - 50, 60);
2023-10-31 12:27:43 +04:00
g.FillEllipse(ellipseBrush, _startPosX + 15, _startPosY + 25, 60, 30);
2023-10-31 12:23:01 +04:00
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 25, 60, 30);
2023-10-31 12:27:43 +04:00
if (Cat.Seats)
{
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 35, 10, 10);
g.DrawEllipse(pen, _startPosX + 35, _startPosY + 35, 10, 10);
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 35, 10, 10);
}
2023-10-31 12:23:01 +04:00
}
}
}