public DetectorRail(RailDirections directions = RailDirections.NorthSouth, bool isActive = false) : base(directions) { if ((int)directions > 5) { throw new System.ArgumentOutOfRangeException(nameof(directions), $"Only simple rails can turn."); } IsActive = isActive; }
public static Rotation[] RailDirectionToRotation(RailDirections rd) { List <Rotation> result = new List <Rotation>(); foreach (Rotation rot in RotationValues) { if (result.Count < RotationValues.Length) //we still have more possible rotations to add. If we're on the same length we have all rotations available to us { result = RailDirectionToRotationRaw(rd, rot, result); } } return(result.ToArray()); }
private void GenerateBitmap(RailDirections rd) { Bitmap foreGround = new Bitmap(GlobalVars.GRIDSIZE, GlobalVars.GRIDSIZE), backGround = new Bitmap(GlobalVars.GRIDSIZE, GlobalVars.GRIDSIZE); using (Graphics fore = Graphics.FromImage(foreGround), back = Graphics.FromImage(backGround)) { foreach (RailDirections r in Enum.GetValues(rd.GetType())) { if (r != RailDirections.All && (r & rd) == r) { fore.DrawImage(bitmaps[r].ForeGround, 0, 0); back.DrawImage(bitmaps[r].BackGround, 0, 0); } } } bitmaps.Add(rd, new Texture(foreGround, backGround)); }
public void It_should_round_trip_simple_rails(RailDirections directions, int expectedId, byte expectedData) { // Create the block from IBlock Properties Rail original = new Rail(directions); var javaBlock = JavaBlock.From(original); javaBlock.TypeId.Should().Be(expectedId); javaBlock.Data.Should().Be(expectedData); // Create Block from id and data var actual = JavaBlock.Create(expectedId, expectedData) as Rail; // Ensure the properties are equivalent coming from the other direction actual.IsAscending.Should().Be(original.IsAscending); actual.IsTurning.Should().Be(original.IsTurning); actual.Directions.Should().Be(original.Directions); }
private static List <Rotation> RailDirectionToRotationRaw(RailDirections rd, Rotation from, List <Rotation> list = null) { if (list == null) { list = new List <Rotation>(); } int railBits = (int)rd; byte value = (byte)(((int)(rd)) >> ((int)from * 4)); foreach (Rotation rotation in RotationValues) { byte rotationValue = (byte)(1 << (byte)rotation); if ((rotationValue & value) == rotationValue && !list.Contains(rotation)) { list.Add(rotation); } } return(list); }
public Rail(RailDirections directions = RailDirections.NorthSouth) { if ((int)directions < 2) { IsAscending = false; IsTurning = false; } else if ((int)directions < 6) { IsAscending = true; IsTurning = false; } else { IsAscending = false; IsTurning = true; } Directions = directions; }
public void It_should_round_trip_activatable_rails(RailDirections directions, Type t, bool isActive, int expectedId, byte expectedData) { // Create the block from IBlock Properties Activator.CreateInstance(t, directions, isActive); var original = Activator.CreateInstance(t, directions, isActive) as IActivatableRail; var javaBlock = JavaBlock.From((IBlock)original); // Create Block from id and data javaBlock.TypeId.Should().Be(expectedId); javaBlock.Data.Should().Be(expectedData); // Ensure the properties are equivalent coming from the other direction var actual = JavaBlock.Create(expectedId, expectedData) as IActivatableRail; actual.IsAscending.Should().Be(original.IsAscending); actual.IsTurning.Should().Be(original.IsTurning); actual.IsActive.Should().Be(original.IsActive); actual.Directions.Should().Be(original.Directions); // Verify the right types come from both directions. actual.GetType().Should().Be(original.GetType()); }
public static Rotation[] RailDirectionToRotation(RailDirections rd, Rotation from) { return(RailDirectionToRotationRaw(rd, from).ToArray()); }
public static bool IsRailDirectionValid(RailDirections rd) { return((rd & ~RailDirections.All) == 0); }