ветка
This commit is contained in:
parent
342a5b4f01
commit
c0643d7736
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectSportCar
|
||||
{
|
||||
public class EntitySportcar
|
||||
public class EntitySportCar
|
||||
{
|
||||
//скорость
|
||||
public int Speed { get; private set; }
|
||||
|
@ -1,13 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectSportCar
|
||||
{
|
||||
public class DrawningSportcar
|
||||
{
|
||||
namespace ProjectSportCar;
|
||||
|
||||
public class DrawningSportCar
|
||||
{
|
||||
|
||||
public EntitySportCar? EntitySportCar { get; private set; }
|
||||
|
||||
private int? _pictureWidth;
|
||||
|
||||
private int? _pictureHeight;
|
||||
|
||||
private int? _startPosX;
|
||||
|
||||
private int? _startPosY;
|
||||
|
||||
private readonly int _drawningCarWidth = 110;
|
||||
|
||||
private readonly int _drawningCarHeight = 60;
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
{
|
||||
EntitySportCar = new EntitySportCar();
|
||||
EntitySportCar.Init(speed, weight, bodyColor, additionalColor,
|
||||
bodyKit, wing, sportLine);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// Задаём размеры
|
||||
int addWidth = 120;
|
||||
int addHeight = 100;
|
||||
|
||||
if (_startPosX.HasValue && _startPosY.HasValue) // проверка на вшивость №1
|
||||
{
|
||||
if (_startPosX.Value >= 0 && _startPosY.Value >= 0 && // проверка на вшивость №2
|
||||
_startPosX.Value + addWidth <= width &&
|
||||
_startPosY.Value + addHeight <= height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int addX = 60;
|
||||
int addY = 50;
|
||||
|
||||
if (addX+x>_pictureWidth.Value || addX + x < 0
|
||||
|| addY+y>_pictureHeight.Value || addY+y< 0)
|
||||
{
|
||||
_startPosX = _pictureWidth.Value/2;
|
||||
_startPosY = _pictureHeight.Value / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntitySportCar == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntitySportCar.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntitySportCar.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntitySportCar.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntitySportCar.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntitySportCar.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntitySportCar.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntitySportCar.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntitySportCar.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// public void DrawTransport(Graphics g)
|
||||
// {
|
||||
// if (EntitySportCar == null || !_startPosX.HasValue ||
|
||||
// !_startPosY.HasValue)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Pen pen = new(Color.Black);
|
||||
// Brush additionalBrush = new
|
||||
// SolidBrush(EntitySportCar.AdditionalColor);
|
||||
|
||||
|
||||
|
||||
//if (EntitySportCar.BodyKit)
|
||||
// {
|
||||
// g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 40,
|
||||
// 70, 40);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user