using System.Collections.Generic;
using Amphora;
namespace Ariadne.Vellum.UnitTests
{
///
/// Rolls a die on each tick it waits, from a Rand it is given.
///
public partial class RollingScript : Arc
{
public readonly Rand Rand;
public readonly List Rolls = new List();
public RollingScript(Rand rand)
{
Rand = rand;
}
protected override void Run(Gates gates)
{
wait:
while (!gates.Open.Contains("go"))
{
Rolls.Add(Rand.NextInt(1, 7));
Yield();
}
}
}
///
/// Waits for the next event of something that happens about every ten seconds by default, drawn from a Rand it is
/// given.
///
public partial class EventWaitScript : Arc
{
public readonly Rand Rand;
public bool Woke;
public Duration Mean = Duration.FromSeconds(10);
public EventWaitScript(Rand rand)
{
Rand = rand;
}
protected override void Run(Gates gates)
{
wait:
Wait(Rand.NextEvent(Mean));
Woke = true;
}
}
///
/// Offers a passage for other arcs to run, which rolls on its own Rand.
///
public partial class RollerScript : Arc
{
public readonly Rand Rand;
public readonly List Rolls = new List();
public RollerScript(Rand rand)
{
Rand = rand;
}
public void Roll(Gates gates)
{
wait:
while (!gates.Open.Contains("go"))
{
Rolls.Add(Rand.NextInt(1, 7));
Yield();
}
}
protected override void Run(Gates gates)
{
}
}
///
/// Runs the passage of another arc, and has a Rand of its own.
///
public partial class CallingRollerScript : Arc
{
public readonly Rand Rand;
public readonly RollerScript Roller;
public CallingRollerScript(Rand rand, RollerScript roller)
{
Rand = rand;
Roller = roller;
}
protected override void Run(Gates gates)
{
roll:
Roller.Roll(gates);
}
}
}