Last active
November 15, 2015 03:11
-
-
Save martindevans/bfe80272eedeb4cfce70 to your computer and use it in GitHub Desktop.
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
public void Main() | |
{ | |
Gate a = new Gate(0); | |
Gate b = new Gate(100); | |
var ctx = new TravelContext(a, b); | |
var time = ctx.Get().TravelTime; | |
} | |
/// <summary> | |
/// Implement a context to extract values from the game. In this case a travel context is a conenction between 2 gates | |
/// </summary> | |
public class TravelContext | |
: ITravelContext | |
{ | |
private readonly Gate _a; | |
private readonly Gate _b; | |
public TravelContext(Gate a, Gate b) | |
{ | |
_a = a; | |
_b = b; | |
} | |
public decimal Distance | |
{ | |
get { return _a.Position - _b.Position; } | |
} | |
public ITravelConstants Get() | |
{ | |
return DesignValues.Get<ITravelConstants, ITravelContext>(this); | |
} | |
} | |
public static class DesignValues | |
{ | |
public static TOutput Get<TOutput, TInput>(TInput travelContext) | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
public interface ITravelContext | |
{ | |
decimal Distance { get; } | |
ITravelConstants Get(); | |
} | |
public static class Travel | |
{ | |
public static Func<ITravelConstants, decimal> Distance = a => a.TravelTime; | |
} | |
public interface ITravelConstants | |
{ | |
decimal TravelTime { get; } | |
} | |
/// <summary> | |
/// This is loaded up from the github repo using roslyn | |
/// </summary> | |
class TravelValues | |
: ITravelConstants | |
{ | |
private readonly ITravelContext _ctx; | |
public TravelValues(ITravelContext ctx) | |
{ | |
_ctx = ctx; | |
} | |
public decimal TravelTime | |
{ | |
get { return _ctx.Distance * 10; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment