-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mikedegeofroy/lab-1
Lab 1
- Loading branch information
Showing
56 changed files
with
994 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Router; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships.Engines; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Environments; | ||
|
||
public class Cosmos : IEnvironment | ||
{ | ||
private readonly List<ICosmosObstacle> _obstacles; | ||
|
||
public Cosmos(IEnumerable<ICosmosObstacle> obstacles) | ||
{ | ||
_obstacles = obstacles.ToList(); | ||
} | ||
|
||
public Cosmos() | ||
: this(Enumerable.Empty<ICosmosObstacle>()) | ||
{ | ||
} | ||
|
||
public TraversalResult TraverseEnvironment(IShip ship, int length) | ||
{ | ||
foreach (ICosmosObstacle highDensityObstacle in _obstacles) | ||
{ | ||
highDensityObstacle.GiveDamage(ship); | ||
} | ||
|
||
EngineConsumption consumption = ship.DriveEngine.GetConsumption(length); | ||
return new TraversalResult.Success(consumption.Time, new[] { consumption.Consumption }); | ||
} | ||
|
||
public void AddObstacle(IObstacle obstacle) | ||
{ | ||
if (obstacle is not ICosmosObstacle cosmosObstacle) | ||
throw new ArgumentException("You can't add this obstacle to this environment."); | ||
_obstacles.Add(cosmosObstacle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Obstacles; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Router; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships.Engines; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Environments; | ||
|
||
public class HighDensity : IEnvironment | ||
{ | ||
private readonly List<IHighDensityObstacle> _obstacles; | ||
|
||
public HighDensity(IEnumerable<IHighDensityObstacle> obstacles) | ||
{ | ||
_obstacles = obstacles.ToList(); | ||
} | ||
|
||
public HighDensity() | ||
: this(Enumerable.Empty<IHighDensityObstacle>()) | ||
{ | ||
} | ||
|
||
public TraversalResult TraverseEnvironment(IShip ship, int length) | ||
{ | ||
if (ship.JumpEngine == null || ship.JumpEngine.GetRange() < length) | ||
return new TraversalResult.LostShip("Ship lost in a channel"); | ||
|
||
foreach (IHighDensityObstacle highDensityObstacle in _obstacles) | ||
{ | ||
if (highDensityObstacle is AntimatterFlare && !ship.PhotonDeflector) | ||
return new TraversalResult.DeathOfCrew(); | ||
highDensityObstacle.GiveDamage(ship); | ||
} | ||
|
||
EngineConsumption consumption = ship.JumpEngine.GetConsumption(length); | ||
return new TraversalResult.Success(consumption.Time, new[] { consumption.Consumption }); | ||
} | ||
|
||
public void AddObstacle(IObstacle obstacle) | ||
{ | ||
if (obstacle is not IHighDensityObstacle highDensityObstacle) | ||
throw new ArgumentException("You can't add this obstacle to this environment."); | ||
_obstacles.Add(highDensityObstacle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Router; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Environments; | ||
|
||
public interface IEnvironment | ||
{ | ||
void AddObstacle(IObstacle obstacle); | ||
|
||
TraversalResult TraverseEnvironment(IShip ship, int length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Router; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships.Engines; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships.Engines.DriveEngines; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Environments; | ||
|
||
public class NitrineNebula : IEnvironment | ||
{ | ||
private readonly List<INitrineParticleObstacle> _obstacles; | ||
|
||
public NitrineNebula(IEnumerable<INitrineParticleObstacle> obstacles) | ||
{ | ||
_obstacles = obstacles.ToList(); | ||
} | ||
|
||
public NitrineNebula() | ||
: this(Enumerable.Empty<INitrineParticleObstacle>()) | ||
{ | ||
} | ||
|
||
public TraversalResult TraverseEnvironment(IShip ship, int length) | ||
{ | ||
if (ship.DriveEngine is not ExponentialDriveEngine) | ||
return new TraversalResult.LostShip("The engines weren't powerful enough."); | ||
|
||
foreach (INitrineParticleObstacle x in _obstacles) | ||
{ | ||
x.GiveDamage(ship); | ||
} | ||
|
||
EngineConsumption consumption = ship.DriveEngine.GetConsumption(length); | ||
return new TraversalResult.Success(consumption.Time, new[] { consumption.Consumption }); | ||
} | ||
|
||
public void AddObstacle(IObstacle obstacle) | ||
{ | ||
if (obstacle is not INitrineParticleObstacle nitrineParticleObstacle) | ||
throw new ArgumentException("You can't add this obstacle to this environment."); | ||
_obstacles.Add(nitrineParticleObstacle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Obstacles; | ||
|
||
public class AntimatterFlare : IHighDensityObstacle | ||
{ | ||
private const double Damage = 10; | ||
|
||
public void GiveDamage(IShip ship) | ||
{ | ||
ship.TakeDamage(Damage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Obstacles; | ||
|
||
public class Asteroid : ICosmosObstacle | ||
{ | ||
private const double Damage = 10; | ||
|
||
public void GiveDamage(IShip ship) | ||
{ | ||
ship.TakeDamage(Damage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Obstacles; | ||
|
||
public class CosmoWhale : INitrineParticleObstacle | ||
{ | ||
private const double Damage = 200; | ||
private readonly int _population; | ||
|
||
public CosmoWhale(int population) | ||
{ | ||
_population = population; | ||
} | ||
|
||
public void GiveDamage(IShip ship) | ||
{ | ||
if (!ship.AntiNitrineEmitter) | ||
ship.TakeDamage(Damage * _population); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
|
||
public interface ICosmosObstacle : IObstacle | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
|
||
public interface IHighDensityObstacle : IObstacle | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
|
||
public interface INitrineParticleObstacle : IObstacle | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
|
||
public interface IObstacle | ||
{ | ||
void GiveDamage(IShip ship); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Itmo.ObjectOrientedProgramming.Lab1.Obstacles.Interfaces; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Obstacles; | ||
|
||
public class Meteorite : ICosmosObstacle | ||
{ | ||
private const double Damage = 10; | ||
|
||
public void GiveDamage(IShip ship) | ||
{ | ||
ship.TakeDamage(Damage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Itmo.ObjectOrientedProgramming.Lab1.Environments; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Router; | ||
|
||
public class Path | ||
{ | ||
private readonly IEnvironment _environment; | ||
private readonly int _length; | ||
|
||
public Path(IEnvironment environment, int length) | ||
{ | ||
_environment = environment; | ||
_length = length; | ||
} | ||
|
||
public TraversalResult TraversePath(IShip ship) | ||
{ | ||
return _environment.TraverseEnvironment(ship, _length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships.Engines; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Router; | ||
|
||
public class Route | ||
{ | ||
private readonly List<Path> _paths; | ||
|
||
public Route(IEnumerable<Path> paths) | ||
{ | ||
_paths = paths.ToList(); | ||
} | ||
|
||
public TraversalResult Traverse(IShip ship) | ||
{ | ||
int time = 0; | ||
List<Fuel> fuels = new(); | ||
|
||
foreach (TraversalResult result in _paths.Select(path => path.TraversePath(ship))) | ||
{ | ||
if (result is not TraversalResult.Success success) | ||
return result; | ||
time += success.Time; | ||
fuels.AddRange(success.Fuel); | ||
} | ||
|
||
return new TraversalResult.Success(time, fuels); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships.Engines; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Router; | ||
|
||
public abstract record TraversalResult | ||
{ | ||
public record Success(int Time, IEnumerable<Fuel> Fuel) : TraversalResult; | ||
|
||
public record LostShip(string Reason) : TraversalResult; | ||
|
||
public record DeathOfCrew : TraversalResult; | ||
|
||
public record DestroyedShip : TraversalResult; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Itmo.ObjectOrientedProgramming.Lab1.Ships.Engines; | ||
|
||
namespace Itmo.ObjectOrientedProgramming.Lab1.Services; | ||
|
||
public static class FuelExchange | ||
{ | ||
public static double GetFuelPrice(Fuel fuel) | ||
{ | ||
return fuel.Amount * fuel.Rarity; | ||
} | ||
} |
Oops, something went wrong.