-
-
Save Quantumplation/2995a35ebd7c85d28aba 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); | |
// Github interpreter, provide a more baked in one for release versions of the game | |
var ruleProvider = new GithubInterpreter("project", "hash", "credentials"); | |
var time = ctx.Get(ruleProvider).TravelTime; | |
} | |
public abstract class BaseContext<T, TSelf> | |
where T : BaseConstants<TSelf, T> | |
where TSelf: BaseContext<T, TSelf> | |
{ | |
public T Get(IRuleProvider rules) | |
{ | |
// Note: don't even have to implement it on each class! :P | |
return rules.Get<T, TSelf>((TSelf)this); | |
} | |
} | |
public class TravelContext : BaseContext<TravelConstants, TravelContext> | |
{ | |
public decimal Distance { get; set; } | |
} | |
public abstract class BaseConstants<T, TSelf> | |
where T : BaseContext<TSelf, T> | |
where TSelf : BaseConstants<T, TSelf> | |
{ | |
protected T _context; | |
public BaseConstants(T context) | |
{ | |
_context = context; | |
} | |
} | |
public abstract class TravelConstants : BaseConstants<TravelContext, TravelConstants> | |
{ | |
public static TravelConstants Token => null; | |
protected TravelConstants(TravelContext context) : base(context) { } | |
public abstract decimal BaseRange { get; } | |
public abstract decimal BaseLinkTime { get; } | |
public abstract decimal BasePayloadTime { get; } | |
public abstract decimal BaseLoadingTime { get; } | |
public abstract decimal Range { get; } | |
public abstract decimal LinkTime { get; } | |
public abstract decimal PayloadTime { get; } | |
} | |
// On Github | |
public class ConcreteTravelConstants : TravelConstants | |
{ | |
public ConcreteTravelConstants(TravelContext context) : base(context) { } | |
public override decimal BaseRange => 1; | |
public override decimal BaseLinkTime => 1; | |
public override decimal BasePayloadTime => 1; | |
public override decimal BaseLoadingTime => 1; | |
private decimal DistanceWeightedLinkTime => BaseLinkTime * (_context.Distance / Range); | |
public override decimal Range => BaseRange; | |
public override decimal LinkTime { get { Console.WriteLine("HAHA"); return BaseLinkTime + DistanceWeightedLinkTime*DistanceWeightedLinkTime; } } | |
public override decimal PayloadTime => BaseLoadingTime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment