PIbd-23-Radaev-A.V.-20/Catamaran/DrawningCatamaran.cs
Аркадий Радаев 5ce4825742 res
2023-11-25 20:02:11 +04:00

158 lines
5.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran
{
public class DrawningCatamaran
{
public EntityCatamaran? EntityCatamaran { get; set; }
public int _pictureWidth = 800;
public int _pictureHeight = 450;
public int _startPosX = 0;
public int _startPosY = 0;
public readonly int _catamaranWidth = 120;
public readonly int _catamaranHeight = 80;
public IMoveableObject GetMoveableObject => new DrawningObjectCatamaran(this);
public DrawningCatamaran(int speed, double weight, Color bodyColor, int width, int height)
{
if (_pictureHeight < _catamaranWidth && _pictureWidth < _catamaranHeight) return;
_pictureWidth = width;
_pictureHeight = height;
EntityCatamaran = new EntityCatamaran(speed,weight,bodyColor);
}
protected DrawningCatamaran(int speed, double weight, Color bodyColor, int width, int height, int catWidth, int catHeight)
{
if (width <= _catamaranWidth || height <= _catamaranHeight) return;
_pictureWidth = width;
_pictureHeight = height;
_catamaranWidth = catWidth;
_catamaranHeight = catHeight;
EntityCatamaran = new EntityCatamaran(speed, weight, bodyColor);
}
public void ChangeColor(Color col)
{
if (EntityCatamaran == null)
return;
EntityCatamaran.BodyColor = col;
}
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
{
_pictureHeight = pictureBoxHeight;
_pictureWidth = pictureBoxWidth;
}
public void SetPosition(int x, int y)
{
if(EntityCatamaran == null) return;
_startPosX = x;
_startPosY = y;
if (x + _catamaranWidth >= _pictureWidth || y + _catamaranHeight >= _pictureHeight)
{
_startPosX = 1;
_startPosY = 1;
}
}
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,
};
}
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 virtual void DrawTransport(Graphics g)
{
if (EntityCatamaran is not EntityCatamaran Cat)
{
return;
}
Pen pen = new(Color.Black);
Brush bodyBrush = new SolidBrush(Cat.BodyColor);
Brush ellipseBrush = new SolidBrush(Color.AliceBlue);
g.FillRectangle(bodyBrush, _startPosX+10, _startPosY+10, _catamaranWidth - 50, 60);
g.DrawRectangle(pen, _startPosX+10, _startPosY+10, _catamaranWidth - 50, 60);
g.FillEllipse(ellipseBrush, _startPosX + 15, _startPosY + 25, 60, 30);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 25, 60, 30);
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);
Point[] pontf = { new Point(_startPosX + _catamaranWidth - 40, _startPosY+10), new Point(_startPosX + _catamaranWidth, _startPosY + 40), new Point(_startPosX + _catamaranWidth - 40, _startPosY + 70) };
g.DrawPolygon(pen, pontf);
}
}
}