Демонстрационные примеры по ООП
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

namespace speedLight.BL.Models;
public class Ball
{
public long PathCount { get; set; }
public Point Location { get;set; } = new Point(0,0);
public Point From { get; set; } = new Point(0,0);
public Point To { get; set; } = new Point(0,0);
public double SpeedX { get; set; }
public double SpeedY { get; set; }
public void Init(Point from, Point to, double speed)
{
Location = new Point(from.X, from.Y);
From = new Point(from.X, from.Y);
To = new Point(to.X, to.Y);
double sin = (From.Y - To.Y) / (From.X - To.X);
SpeedY = speed * sin;
SpeedX = speed * (1 / sin);
}
public void Move()
{
double minX = From.X < To.X ? From.X : To.X;
double minY = From.Y < To.Y ? From.Y : To.Y;
double maxX = From.X > To.X ? From.X : To.X;
double maxY = From.Y > To.Y ? From.Y : To.Y;
if ((minX > Location.X) || (maxX < Location.X))
{
SpeedX = -SpeedX;
PathCount++;
}
if ((minY > Location.Y) || (maxY < Location.Y))
{
SpeedY = -SpeedY;
PathCount++;
}
Location.X += SpeedX;
Location.Y += SpeedY;
}
}