Exemple #1
0
        public static bool[][][] GetSurfaceDiagram(this SizingBox box, ShipShape shape)
        {
            switch (shape)
            {
            case ShipShape.Boat:
                return(_boatSurfaceDiagram(box));

            default:
                return(new bool[][][] {});
            }
        }
Exemple #2
0
        public static double GetSurfaceArea(this SizingBox box, ShipShape shape, int decks = 0)
        {
            switch (shape)
            {
            case ShipShape.Boat:
                return(_boatSurfaceArea(box, decks));

            default:
                return(0.0);
            }
        }
        GenerateShipOfSize_Input4RandomReturnsLineOrZigzagShipShape_ReturnsFourDeckShipWithShapeAndRotationGeneratedByRandom(
            ShipShape shipShapeGeneratedByRandom, ShipRotation shipRotationGeneratedByRandom)
        {
            var randomIndexGeneratorStub = new Mock <IRandomGenerator>();
            var fourDeckShipShapes       = Enum.GetValues(typeof(ShipShape));
            var lineOrZigzagShapeFourDeckShipRotations = new[] { ShipRotation._0, ShipRotation._90 };

            randomIndexGeneratorStub.Setup(r => r.GetRandomElementFromArrayAsInt(fourDeckShipShapes))
            .Returns((int)shipShapeGeneratedByRandom);
            randomIndexGeneratorStub.Setup(r => r.GetRandomElementFromArrayAsInt(lineOrZigzagShapeFourDeckShipRotations))
            .Returns((int)shipRotationGeneratedByRandom);
            var randomShipGenerator = new RandomShipGenerator(randomIndexGeneratorStub.Object);

            var result = randomShipGenerator.GenerateShipOfSize(4);

            Assert.Multiple(() =>
            {
                Assert.That(result, Is.TypeOf <FourDeckShip>());
                Assert.That(result.Shape, Is.EqualTo(shipShapeGeneratedByRandom));
                Assert.That(result.Rotation, Is.EqualTo(shipRotationGeneratedByRandom));
            });
        }
        public void GenerateShipOfSize_Input3_ReturnsThreeDeckShipWithShapeAndRotationGeneratedByRandom(
            ShipShape shipShapeGeneratedByRandom, ShipRotation shipRotationGeneratedByRandom)
        {
            var randomIndexGeneratorStub          = new Mock <IRandomGenerator>();
            var possibleShapesForThreeDeckShip    = new[] { ShipShape.Line, ShipShape.LShaped };
            var possibleRotationsForThreeDeckShip = new[] { ShipRotation._0, ShipRotation._90 };

            randomIndexGeneratorStub.Setup(r => r.GetRandomElementFromArrayAsInt(possibleShapesForThreeDeckShip))
            .Returns((int)shipShapeGeneratedByRandom);
            randomIndexGeneratorStub.Setup(r => r.GetRandomElementFromArrayAsInt(possibleRotationsForThreeDeckShip))
            .Returns((int)shipRotationGeneratedByRandom);
            var randomShipGenerator = new RandomShipGenerator(randomIndexGeneratorStub.Object);

            var result = randomShipGenerator.GenerateShipOfSize(3);

            Assert.Multiple(() =>
            {
                Assert.That(result, Is.TypeOf <ThreeDeckShip>());
                Assert.That(result.Shape, Is.EqualTo(shipShapeGeneratedByRandom));
                Assert.That(result.Rotation, Is.EqualTo(shipRotationGeneratedByRandom));
            });
        }
 public FourDeckShip(ShipShape shape, ShipRotation shipRotation)
 {
     Size     = 4;
     Shape    = shape;
     Rotation = shipRotation;
 }
 public ThreeDeckShip(ShipShape shape, ShipRotation shipRotation)
 {
     Size     = 3;
     Shape    = shape;
     Rotation = shipRotation;
 }