Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
Merge branch 'main' into feature/path-finding
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander0542 committed Oct 28, 2021
2 parents 9e938f0 + 872b8c2 commit b93eebb
Show file tree
Hide file tree
Showing 50 changed files with 1,350 additions and 76 deletions.
24 changes: 20 additions & 4 deletions Avans.FlatGalaxy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avans.FlatGalaxy.Simulation
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avans.FlatGalaxy.Models", "src\Avans.FlatGalaxy.Models\Avans.FlatGalaxy.Models.csproj", "{CD0E92F8-3A94-42C9-A24A-0593C1D4230F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{AF26DE88-D3ED-40FC-BFA5-3F1B6785D335}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avans.FlatGalaxy.Persistence.Tests", "tests\Avans.FlatGalaxy.Persistence.Tests\Avans.FlatGalaxy.Persistence.Tests.csproj", "{9F26A102-93BD-4F60-9162-90EFA05F452E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avans.FlatGalaxy.Simulation.Tests", "tests\Avans.FlatGalaxy.Simulation.Tests\Avans.FlatGalaxy.Simulation.Tests.csproj", "{4F05D115-2360-4A21-A718-BFB014C61289}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -28,15 +34,25 @@ Global
{F4EE573C-B975-42A0-888A-456221CEE227}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4EE573C-B975-42A0-888A-456221CEE227}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4EE573C-B975-42A0-888A-456221CEE227}.Release|Any CPU.Build.0 = Release|Any CPU
{CD0E92F8-3A94-42C9-A24A-0593C1D4230F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD0E92F8-3A94-42C9-A24A-0593C1D4230F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD0E92F8-3A94-42C9-A24A-0593C1D4230F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD0E92F8-3A94-42C9-A24A-0593C1D4230F}.Release|Any CPU.Build.0 = Release|Any CPU
{CD0E92F8-3A94-42C9-A24A-0593C1D4230F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD0E92F8-3A94-42C9-A24A-0593C1D4230F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD0E92F8-3A94-42C9-A24A-0593C1D4230F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD0E92F8-3A94-42C9-A24A-0593C1D4230F}.Release|Any CPU.Build.0 = Release|Any CPU
{9F26A102-93BD-4F60-9162-90EFA05F452E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F26A102-93BD-4F60-9162-90EFA05F452E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F26A102-93BD-4F60-9162-90EFA05F452E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F26A102-93BD-4F60-9162-90EFA05F452E}.Release|Any CPU.Build.0 = Release|Any CPU
{4F05D115-2360-4A21-A718-BFB014C61289}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F05D115-2360-4A21-A718-BFB014C61289}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F05D115-2360-4A21-A718-BFB014C61289}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F05D115-2360-4A21-A718-BFB014C61289}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F47E1A6A-18B6-49FE-BC7A-B3583408E659} = {7996173C-8F81-4B28-A46A-0529C89FF0C8}
{89B5ABAF-73F2-4682-AB42-048DCA3C4BB7} = {7996173C-8F81-4B28-A46A-0529C89FF0C8}
{F4EE573C-B975-42A0-888A-456221CEE227} = {7996173C-8F81-4B28-A46A-0529C89FF0C8}
{CD0E92F8-3A94-42C9-A24A-0593C1D4230F} = {7996173C-8F81-4B28-A46A-0529C89FF0C8}
{9F26A102-93BD-4F60-9162-90EFA05F452E} = {AF26DE88-D3ED-40FC-BFA5-3F1B6785D335}
{4F05D115-2360-4A21-A718-BFB014C61289} = {AF26DE88-D3ED-40FC-BFA5-3F1B6785D335}
EndGlobalSection
EndGlobal
7 changes: 6 additions & 1 deletion src/Avans.FlatGalaxy.Models/CelestialBodies/Asteroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ public class Asteroid : CelestialBody
public Asteroid(double x, double y, double vx, double vy, int radius, Color color, ICollisionState collisionState) : base(x, y, vx, vy, radius, color, collisionState)
{
}

public override CelestialBody Clone()
{
return new Asteroid(X, Y, VX, VY, Radius, Color, CollisionState.Clone());
}
}
}
}
4 changes: 3 additions & 1 deletion src/Avans.FlatGalaxy.Models/CelestialBodies/CelestialBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Avans.FlatGalaxy.Models.CelestialBodies
{
public abstract class CelestialBody : IObservable<CelestialBody>
public abstract class CelestialBody : IObservable<CelestialBody>, ICloneable<CelestialBody>
{
private readonly IList<IObserver<CelestialBody>> _observers;

Expand Down Expand Up @@ -70,5 +70,7 @@ public void TriggerStateEvent()
observer.OnNext(this);
}
}

public abstract CelestialBody Clone();
}
}
5 changes: 5 additions & 0 deletions src/Avans.FlatGalaxy.Models/CelestialBodies/Planet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public Planet(string name, double x, double y, double vx, double vy, int radius,
{
Name = name;
}

public override CelestialBody Clone()
{
return new Planet(Name, X, Y, VX, VY, Radius, Color, CollisionState.Clone());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ public void Collide(CelestialBody self, CelestialBody other)
});
}
}

public ICollisionState Clone()
{
return new BlinkState();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
public class BounceState : ICollisionState
{
private int _collisions;


public BounceState() {}

private BounceState(int collisions)
{
_collisions = collisions;
}

public void Collide(CelestialBody self, CelestialBody other)
{
self.VX = -self.VX;
Expand All @@ -14,5 +21,10 @@ public void Collide(CelestialBody self, CelestialBody other)
self.TriggerStateEvent();
}
}

public ICollisionState Clone()
{
return new BounceState(_collisions);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ public void Collide(CelestialBody self, CelestialBody other)
{
self.TriggerStateEvent();
}

public ICollisionState Clone()
{
return new DisappearState();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ public void Collide(CelestialBody self, CelestialBody other)
{
self.TriggerStateEvent();
}

public ICollisionState Clone()
{
return new ExplodeState();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public void Collide(CelestialBody self, CelestialBody other)
self.TriggerStateEvent();
}
}

public ICollisionState Clone()
{
return new GrowState();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Avans.FlatGalaxy.Models.CelestialBodies.States
{
public interface ICollisionState
public interface ICollisionState : ICloneable<ICollisionState>
{
public void Collide(CelestialBody self, CelestialBody other);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ public void Collide(CelestialBody self, CelestialBody other)
{
// do nothing
}

public ICollisionState Clone()
{
return new NullCollisionState();
}
}
}
14 changes: 13 additions & 1 deletion src/Avans.FlatGalaxy.Models/Galaxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@ public Galaxy()
_celestialBodies = new Dictionary<CelestialBody, IDisposable>();
}

public Galaxy(IEnumerable<CelestialBody> celestialBodies) : this()
{
foreach (var body in celestialBodies)
{
Add(body);
}
}

public void Add(CelestialBody celestialBody)
{
_celestialBodies.Add(celestialBody, celestialBody.Subscribe(this));
if (_celestialBodies.ContainsKey(celestialBody))
{
_celestialBodies[celestialBody]?.Dispose();
}
_celestialBodies[celestialBody] = celestialBody.Subscribe(this);
}

public void Remove(CelestialBody celestialBody)
Expand Down
14 changes: 14 additions & 0 deletions src/Avans.FlatGalaxy.Models/ICloneable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Avans.FlatGalaxy.Models
{
public interface ICloneable<T> : ICloneable
{
new T Clone();

object ICloneable.Clone()
{
return Clone();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@
<ProjectReference Include="..\Avans.FlatGalaxy.Models\Avans.FlatGalaxy.Models.csproj" />
</ItemGroup>

<ItemGroup>
<None Remove="planetsExtended.csv" />
<Content Include="planetsExtended.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="planetsExtended.xml" />
<Content Include="planetsExtended.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Avans.FlatGalaxy.Persistence.Loaders
{
class FileSystemFileLoader : IFileLoader
public class FileSystemFileLoader : IFileLoader
{
public string[] SupportedSchemas => new[]
{
Expand All @@ -16,7 +16,12 @@ public string GetContent(Uri source)

if (!File.Exists(path))
{
throw new FileNotFoundException("The file does not exist.", path);
var localPath = Path.Combine(Environment.CurrentDirectory, source.Host);
if (File.Exists(localPath))
{
path = localPath;
}
else throw new FileNotFoundException("The file does not exist.", path);
}

try
Expand Down
2 changes: 1 addition & 1 deletion src/Avans.FlatGalaxy.Persistence/Loaders/HttpFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Avans.FlatGalaxy.Persistence.Loaders
{
class HttpFileLoader : IFileLoader
public class HttpFileLoader : IFileLoader
{
public string[] SupportedSchemas => new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ namespace Avans.FlatGalaxy.Persistence.Parsers
{
public class CsvConfigurationParser : ConfigurationParserBase
{
private const char Separator = ';';

public CsvConfigurationParser(ICelestialBodyFactory celestialBodyFactory) : base(celestialBodyFactory)
{
}

public override bool CanParse(string content)
{
var lines = content.Split(Environment.NewLine);
var columns = lines[0].Split(',').Length;
var columns = lines[0].Split(Separator).Length;

return lines.All(line => line.Split(',').Length == columns);
return lines.All(line => string.IsNullOrWhiteSpace(line) || line.Split(Separator).Length == columns);
}

public override Galaxy Parse(string content)
Expand All @@ -33,7 +35,7 @@ public override Galaxy Parse(string content)
{
if (line != "")
{
var attributes = line.Split(';');
var attributes = line.Split(Separator);

var name = attributes[0];
var type = attributes[1];
Expand Down
24 changes: 24 additions & 0 deletions src/Avans.FlatGalaxy.Persistence/planetsExtended.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name;type;x;y;vx;vy;neighbours;radius;color;oncollision
Kobol;Planet;45;310;0.3;-0.6;Unicron,Koarth;7;blue;blink
Namek;Planet;60;102;0.1;0.2;Helicon,Synnax,Xenex,Alderaan;15;orange;blink
Monea;Planet;105;290;-0.5;-0.1;Koarth,Solaria;7;grey;blink
Alderaan;Planet;110;400;-1;0.2;Unicron,Namek;7;brown;blink
Unicron;Planet;145;379;0.01;0.5;Kobol,Alderaan;7;blue;blink
Twinsum;Planet;195;480;0.2;0.1;Solaria,Trantor;7;purple;blink
Koarth;Planet;210;190;0.1;0.99;Kobol,Monea,Synnax;7;blue;blink
Helicon;Planet;219;95;0.01;0.2;Namek,Synnax;7;brown;blink
Solaria;Planet;240;322;0.3;-0.5;Monea,Twinsum,Xenex;15;orange;blink
Synnax;Planet;405;202;0.9;0.2;Namek,Koarth,Helicon,Trantor;7;pink;blink
Trantor;Planet;501;130;-0.5;-0.1;Twinsum,Synnax;7;purple;blink
Xenex;Planet;711;580;0.3;0.2;Solaria,Namek;7;blue;blink
;Asteroid;85;56;0;-1.5;;5;black;blink
;Asteroid;705;112;2;1;;5;black;bounce
;Asteroid;28;507;1;3;;5;black;disappear
;Asteroid;478;380;0;1;;5;black;bounce
;Asteroid;636;392;5;-1;;5;black;explode
;Asteroid;47;255;-2;-3;;5;black;explode
;Asteroid;320;250;-1;3;;5;black;bounce
;Asteroid;408;432;2;1;;5;black;bounce
;Asteroid;422;557;1;-1;;5;black;blink
;Asteroid;601;276;2;-2;;5;black;grow
;Asteroid;626;464;3;1;;5;black;disappear
Loading

0 comments on commit b93eebb

Please sign in to comment.