123 lines
4.2 KiB
C#
123 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Catamaran
|
|
{
|
|
internal class DrawningCatamaran
|
|
{
|
|
public EntityCatamaran? EntityCatamaran { get; private set; }
|
|
|
|
private int _pictureWidth = 800;
|
|
|
|
private int _pictureHeight = 450;
|
|
|
|
private int _startPosX = 0;
|
|
|
|
private int _startPosY = 0;
|
|
|
|
private readonly int _catamaranWidth = 120;
|
|
|
|
private readonly int _catamaranHeight = 80;
|
|
|
|
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, int width, int height)
|
|
{
|
|
if (_pictureHeight < _catamaranWidth && _pictureWidth < _catamaranHeight) return false;
|
|
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
EntityCatamaran = new EntityCatamaran();
|
|
EntityCatamaran.Init(speed, weight, bodyColor, additionalColor, bodyKit);
|
|
return true;
|
|
|
|
}
|
|
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
if (EntityCatamaran == null) return;
|
|
while (x + _catamaranWidth > _pictureWidth)
|
|
{
|
|
x-= (int)EntityCatamaran.Step;
|
|
}
|
|
while (x < 0)
|
|
{
|
|
x+= (int)EntityCatamaran.Step;
|
|
}
|
|
while (y + _catamaranHeight > _pictureHeight)
|
|
{
|
|
y-= (int)EntityCatamaran.Step;
|
|
}
|
|
while (y < 0)
|
|
{
|
|
y+= (int)EntityCatamaran.Step;
|
|
}
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
}
|
|
|
|
public void MoveTransport(DirectionType direction)
|
|
{
|
|
if (EntityCatamaran == null)
|
|
{
|
|
return;
|
|
}
|
|
switch (direction)
|
|
{
|
|
|
|
case DirectionType.Left:
|
|
if (_startPosX - EntityCatamaran.Step > 0)
|
|
{
|
|
_startPosX -= (int)EntityCatamaran.Step;
|
|
}
|
|
break;
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
public void DrawTransport(Graphics g)
|
|
{
|
|
if (EntityCatamaran == null)
|
|
{
|
|
return;
|
|
}
|
|
Pen pen = new(Color.Black);
|
|
|
|
Point[] pontf = { new Point(_startPosX + _catamaranWidth - 40, _startPosY+10), new Point(_startPosX + _catamaranWidth, _startPosY + 40), new Point(_startPosX + _catamaranWidth - 40, _startPosY + 70) };
|
|
|
|
g.DrawRectangle(pen, _startPosX, _startPosY, _catamaranWidth - 20, 10);
|
|
g.DrawRectangle(pen, _startPosX+10, _startPosY+10, _catamaranWidth - 50, 60);
|
|
g.DrawRectangle(pen, _startPosX, _startPosY + 70, _catamaranWidth - 20, 10);
|
|
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 25, 60, 30);
|
|
g.DrawPolygon(pen, pontf);
|
|
|
|
Point[] trig1 = { new Point(_startPosX + _catamaranWidth -20, _startPosY), new Point(_startPosX + _catamaranWidth, _startPosY + 5), new Point(_startPosX+_catamaranWidth - 20, _startPosY+10) };
|
|
g.DrawPolygon(pen, trig1);
|
|
Point[] trig2 = { new Point(_startPosX + _catamaranWidth - 20, _startPosY + 70 ), new Point(_startPosX + _catamaranWidth, _startPosY + 75), new Point(_startPosX + _catamaranWidth - 20, _startPosY + 80) };
|
|
g.DrawPolygon(pen, trig2);
|
|
}
|
|
|
|
}
|
|
}
|