Browse Source

initial commit

master
Sergey Verevkin 2 years ago
parent
commit
695de7f6d2
  1. 8
      speedLight/speedLight.BL/Intf/IMechanicProvider.cs
  2. 8
      speedLight/speedLight.BL/Intf/IPictureSourceProvider.cs
  3. 42
      speedLight/speedLight.BL/Models/Ball.cs
  4. 15
      speedLight/speedLight.BL/Models/Mechanic.cs
  5. 15
      speedLight/speedLight.BL/Models/Picture.cs
  6. 6
      speedLight/speedLight.BL/Models/PictureList.cs
  7. 13
      speedLight/speedLight.BL/Models/Point.cs
  8. 39
      speedLight/speedLight.BL/Providers/DataProvider.cs
  9. 33
      speedLight/speedLight.UI/Helpers/ImageHelper.cs
  10. 13
      speedLight/speedLight.UI/Models/ScreenPoint.cs

8
speedLight/speedLight.BL/Intf/IMechanicProvider.cs

@ -0,0 +1,8 @@
using speedLight.BL.Models;
namespace speedLight.BL.Intf;
public interface IMechanicProvider
{
IEnumerable<Mechanic> GetMechanics();
}

8
speedLight/speedLight.BL/Intf/IPictureSourceProvider.cs

@ -0,0 +1,8 @@
using speedLight.BL.Models;
namespace speedLight.BL.Intf;
public interface IPictureSourceProvider
{
IEnumerable<Picture> GetPictureItems();
}

42
speedLight/speedLight.BL/Models/Ball.cs

@ -0,0 +1,42 @@
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;
}
}

15
speedLight/speedLight.BL/Models/Mechanic.cs

@ -0,0 +1,15 @@
namespace speedLight.BL.Models;
public class Mechanic
{
public Mechanic(double speed, string title)
{
Speed = speed;
Title = title;
}
public string Title { get; set; }
public double Speed { get; set; }
}

15
speedLight/speedLight.BL/Models/Picture.cs

@ -0,0 +1,15 @@
namespace speedLight.BL.Models;
public class Picture
{
public override string ToString()
{
return $"{Name} ({Distance} м.)";
}
public Point PointFrom { get; set; }
public Point PointTo { get; set; }
public double Distance { get; set; }
public string Name { get; set; }
public string Url { get; set; }
}

6
speedLight/speedLight.BL/Models/PictureList.cs

@ -0,0 +1,6 @@
namespace speedLight.BL.Models;
public class PictureList
{
public List<Picture> Items { get; private set; } = new List<Picture>();
}

13
speedLight/speedLight.BL/Models/Point.cs

@ -0,0 +1,13 @@
namespace speedLight.BL.Models;
public class Point
{
public Point(double x, double y)
{
X = x;
Y = y;
}
public double X { get; set; }
public double Y { get; set; }
}

39
speedLight/speedLight.BL/Providers/DataProvider.cs

@ -0,0 +1,39 @@
using speedLight.BL.Intf;
using speedLight.BL.Models;
namespace speedLight.BL.Providers;
public class DataProvider: IMechanicProvider, IPictureSourceProvider
{
public IEnumerable<Mechanic> GetMechanics()
{
return new List<Mechanic>()
{
new Mechanic(300, "Звук"),
new Mechanic(300000000, "Свет"),
};
}
public IEnumerable<Picture> GetPictureItems()
{
return new List<Picture>()
{
new Picture()
{
Name = "Эйфелева башня",
PointFrom = new Point(100, 100),
PointTo = new Point(100, 200),
Distance = 330,
Url = "https://cdn2.tu-tu.ru/image/pagetree_node_data/1/13d18a14f7afddb06f546aa1aba237cc/",
},
new Picture()
{
Name = "Камп Ноу",
PointFrom = new Point(100, 100),
PointTo = new Point(100, 200),
Distance = 120,
Url = "https://footballtravel.com/uploads/2020/06/Camp-Nou-1024x683.jpg"
},
};
}
}

33
speedLight/speedLight.UI/Helpers/ImageHelper.cs

@ -0,0 +1,33 @@
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
namespace speedLight.UI.Helpers;
public class ImageHelper
{
public static Bitmap LoadFromResource(Uri resourceUri)
{
return new Bitmap(AssetLoader.Open(resourceUri));
}
public static async Task<Bitmap?> LoadFromWeb(Uri url)
{
using var httpClient = new HttpClient();
try
{
var response = await httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
var data = await response.Content.ReadAsByteArrayAsync();
return new Bitmap(new MemoryStream(data));
}
catch (HttpRequestException ex)
{
Console.WriteLine($"An error occurred while downloading image '{url}' : {ex.Message}");
return null;
}
}
}

13
speedLight/speedLight.UI/Models/ScreenPoint.cs

@ -0,0 +1,13 @@
namespace speedLight.UI.Models;
public class ScreenPoint
{
public ScreenPoint(int x, int y)
{
X = x;
Y = y;
}
public int X { get; set; }
public int Y { get; set; }
}
Loading…
Cancel
Save