2022-09-12 22:13:20 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-09-26 19:55:09 +04:00
|
|
|
|
using System.Drawing;
|
2022-09-12 22:13:20 +04:00
|
|
|
|
using System.Linq;
|
2022-09-26 19:55:09 +04:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2022-09-12 22:13:20 +04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Artilleries
|
|
|
|
|
{
|
|
|
|
|
internal class DrawingArtillery
|
|
|
|
|
{
|
2022-09-26 19:55:09 +04:00
|
|
|
|
public EntityArtillery Artillery { protected set; get; }
|
|
|
|
|
protected float _startPosX;
|
|
|
|
|
protected float _startPosY;
|
2022-09-12 22:13:20 +04:00
|
|
|
|
private int? _pictureWidth = null;
|
|
|
|
|
private int? _pictureHeight = null;
|
2022-09-26 19:55:09 +04:00
|
|
|
|
protected readonly int _artilleryWidth = 80;
|
|
|
|
|
protected readonly int _artilleryHeight = 50;
|
2022-09-26 18:36:46 +04:00
|
|
|
|
|
2022-09-26 17:35:01 +04:00
|
|
|
|
public DrawingArtillery(int speed, float weight, Color bodyColor)
|
2022-09-12 22:13:20 +04:00
|
|
|
|
{
|
2022-09-26 17:35:01 +04:00
|
|
|
|
Artillery = new EntityArtillery(speed, weight, bodyColor);
|
2022-09-12 22:13:20 +04:00
|
|
|
|
}
|
2022-09-26 18:36:46 +04:00
|
|
|
|
|
|
|
|
|
protected DrawingArtillery(int speed, float weight, Color bodyColor, int artilleryWidth, int artilleryHeight) : this(speed, weight, bodyColor)
|
|
|
|
|
{
|
|
|
|
|
_artilleryWidth = artilleryWidth;
|
|
|
|
|
_artilleryHeight = artilleryHeight;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-12 22:13:20 +04:00
|
|
|
|
public void SetPosition(int x, int y, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
if (x < 0 || x + _artilleryWidth >= width)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (y < 0 || y + _artilleryHeight >= height)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveTransport(Direction direction)
|
|
|
|
|
{
|
|
|
|
|
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case Direction.Right:
|
|
|
|
|
if (_startPosX + _artilleryWidth + Artillery.Step < _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX += Artillery.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Direction.Left:
|
|
|
|
|
if (_startPosX - Artillery.Step >= 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosX -= Artillery.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Direction.Up:
|
|
|
|
|
if (_startPosY - Artillery.Step >= 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosY -= Artillery.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Direction.Down:
|
|
|
|
|
if (_startPosY + _artilleryHeight + Artillery.Step < _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY += Artillery.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 18:36:46 +04:00
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
2022-09-12 22:13:20 +04:00
|
|
|
|
{
|
|
|
|
|
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Brush brush = new SolidBrush(Artillery?.BodyColor ?? Color.Black);
|
2022-09-26 19:55:09 +04:00
|
|
|
|
g.FillRectangle(brush, _startPosX + _artilleryWidth / 8 * 2, _startPosY, _artilleryWidth / 8 * 4, _artilleryHeight / 5);
|
2022-09-12 22:13:20 +04:00
|
|
|
|
g.FillRectangle(brush, _startPosX, _startPosY + _artilleryHeight / 5, _artilleryWidth, _artilleryHeight / 3);
|
|
|
|
|
|
2022-09-13 16:50:19 +04:00
|
|
|
|
Brush blackBrush = new SolidBrush(Color.Black);
|
|
|
|
|
Brush grayBrush = new SolidBrush(Color.Gray);
|
|
|
|
|
g.FillEllipse(grayBrush, _startPosX, _startPosY + _artilleryHeight * 2 / 5, _artilleryWidth, _artilleryHeight * 2 / 5);
|
|
|
|
|
g.FillEllipse(blackBrush, _startPosX + _artilleryWidth / 20, _startPosY + _artilleryHeight * 7 / 15, _artilleryWidth * 4 / 20, _artilleryHeight * 10 / 32);
|
|
|
|
|
g.FillEllipse(blackBrush, _startPosX + _artilleryWidth * 5 / 20, _startPosY + _artilleryHeight * 9 / 16, _artilleryWidth * 3 / 20, _artilleryHeight * 8 / 32);
|
|
|
|
|
g.FillEllipse(blackBrush, _startPosX + _artilleryWidth * 8 / 20, _startPosY + _artilleryHeight * 10 / 16, _artilleryWidth * 2 / 20, _artilleryHeight * 6 / 32);
|
|
|
|
|
g.FillEllipse(blackBrush, _startPosX + _artilleryWidth * 10 / 20, _startPosY + _artilleryHeight * 10 / 16, _artilleryWidth * 2 / 20, _artilleryHeight * 6 / 32);
|
|
|
|
|
g.FillEllipse(blackBrush, _startPosX + _artilleryWidth * 12 / 20, _startPosY + _artilleryHeight * 9 / 16, _artilleryWidth * 3 / 20, _artilleryHeight * 8 / 32);
|
|
|
|
|
g.FillEllipse(blackBrush, _startPosX + _artilleryWidth * 15 / 20, _startPosY + _artilleryHeight * 7 / 15, _artilleryWidth * 4 / 20, _artilleryHeight * 10 / 32);
|
2022-09-12 22:13:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeBorders(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
if (_pictureWidth <= _artilleryWidth || _pictureHeight <= _artilleryHeight)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = null;
|
|
|
|
|
_pictureHeight = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (_startPosX + _artilleryWidth > _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = _pictureWidth.Value - _artilleryWidth;
|
|
|
|
|
}
|
|
|
|
|
if (_startPosY + _artilleryHeight > _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY = _pictureHeight.Value - _artilleryHeight;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-26 19:55:09 +04:00
|
|
|
|
|
|
|
|
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
|
|
|
|
{
|
|
|
|
|
return (_startPosX, _startPosX + _artilleryWidth - 1, _startPosY, _startPosY + _artilleryHeight - 1);
|
|
|
|
|
}
|
2022-09-12 22:13:20 +04:00
|
|
|
|
}
|
|
|
|
|
}
|