示例#1
0
        /// <summary>
        /// Builds a new life form.
        /// </summary>
        /// <param name="lifeFormType">The life form type to build.</param>
        /// <returns>A newly instantiated life form object.</returns>
        public static LifeFormBase Build(LifeForm lifeFormType)
        {
            LifeFormBase lifeForm = null;
            switch (lifeFormType)
            {
                case LifeForm.Empty:
                    lifeForm = new Empty();
                    break;

                case LifeForm.Acorn:
                    lifeForm = new Acorn();
                    break;

                case LifeForm.AircraftCarrier:
                    lifeForm = new AircraftCarrier();
                    break;

                case LifeForm.FivePoint:
                    lifeForm = new FivePoint();
                    break;

                default:
                    lifeForm = new RandomPattern(
                        rows: RANDOMPATTERNHEIGHT,
                        cols: RANDOMPATTERNWIDTH);
                    break;
            }

            return lifeForm;
        }
        public void Constructor_WhenInvoked_PreparesAircraftCarrierCorrectly()
        {
            // act
            var carrier = new AircraftCarrier();

            int oneSide = carrier.GetPattern().Length;
            int otherSide = carrier.GetPattern().Max(x => x.Length);

            // assert
            Assert.IsTrue(
                oneSide == 4 && oneSide == otherSide,
                message: "The aircraft carrier pattern was not of size 4x4.");

            Assert.IsTrue(
                carrier.IsStable,
                message: "The aircraft carrier pattern was not stable.");

            Assert.AreEqual(
                expected: 0,
                actual: carrier.StabilizesAt,
                message: "The aircraft carrier pattern stabilizes at the wrong time.");

            Assert.AreEqual(
                expected: 6,
                actual: carrier.StablePopulation,
                message: "The aircraft carrier pattern has wrong number of cells in the stable population.");
        }
        public void Constructor_WhenInvoked_PreparesAircraftCarrierCorrectly()
        {
            // act
            var carrier = new AircraftCarrier();

            int oneSide   = carrier.GetPattern().Length;
            int otherSide = carrier.GetPattern().Max(x => x.Length);

            // assert
            Assert.IsTrue(
                oneSide == 4 && oneSide == otherSide,
                message: "The aircraft carrier pattern was not of size 4x4.");

            Assert.IsTrue(
                carrier.IsStable,
                message: "The aircraft carrier pattern was not stable.");

            Assert.AreEqual(
                expected: 0,
                actual: carrier.StabilizesAt,
                message: "The aircraft carrier pattern stabilizes at the wrong time.");

            Assert.AreEqual(
                expected: 6,
                actual: carrier.StablePopulation,
                message: "The aircraft carrier pattern has wrong number of cells in the stable population.");
        }
示例#4
0
        /// <summary>
        /// Builds a new life form.
        /// </summary>
        /// <param name="lifeFormType">The life form type to build.</param>
        /// <returns>A newly instantiated life form object.</returns>
        public static LifeFormBase Build(LifeForm lifeFormType)
        {
            LifeFormBase lifeForm = null;

            switch (lifeFormType)
            {
            case LifeForm.Empty:
                lifeForm = new Empty();
                break;

            case LifeForm.Acorn:
                lifeForm = new Acorn();
                break;

            case LifeForm.AircraftCarrier:
                lifeForm = new AircraftCarrier();
                break;

            case LifeForm.FivePoint:
                lifeForm = new FivePoint();
                break;

            default:
                lifeForm = new RandomPattern(
                    rows: RANDOMPATTERNHEIGHT,
                    cols: RANDOMPATTERNWIDTH);
                break;
            }

            return(lifeForm);
        }
        public void AddingSameShipTwiceThrowsException()
        {
            var position        = new Position(0, 0, Orientation.Vertical);
            var aircraftCarrier = new AircraftCarrier(position);

            board.AddShip(aircraftCarrier);
            Assert.Throws <ShipAlreadyPlacedException>(() => board.AddShip(aircraftCarrier));
        }
示例#6
0
        public void IsDestroyed_With_Intact_AircraftCarrier_Should_Return_False()
        {
            Ship ship = new AircraftCarrier();

            var res = ship.IsDestroyed;

            Assert.False(res);
        }
示例#7
0
        public void GetShip_From_ShipFactory_Of_Type_AircraftCarrier_Should_Return_new_AircraftCarrier()
        {
            ShipFactory     factory = new AircraftCarrierFactory();
            AircraftCarrier newShip = new AircraftCarrier();

            var res = factory.GetShip();

            Assert.True(res.Name == newShip.Name && res.Size == newShip.Size && res.ShipType == newShip.ShipType);
        }
示例#8
0
        public static void FlyStrategyUsage()
        {
            Vehicle car = new AircraftCarrier();

            System.Console.WriteLine($"Move: {car.MovingType.Move()}");
            car.Move <DriveStrategy>();
            System.Console.WriteLine($"Move: {car.MovingType.Move()}");

            System.Console.Read();
        }
        private static void MainMenu()
        {
            List <IShipable> ships          = new List <IShipable>(1);
            bool             mainmenulooped = false;

            while (!mainmenulooped)
            {
                Console.WriteLine("Input number of action:\n 1: Add Ship. \n 2: Work with one ship \n 3: Delete Ship \n  4: Exit");
                int number = WasNumberInputted(Console.ReadLine(), ref mainmenulooped);
                if (mainmenulooped)
                {
                    switch (number)
                    {
                    case 1:
                        AircraftCarrier ship = new AircraftCarrier();
                        NewShip(ref ship);
                        ships.Add(ship);
                        break;

                    case 2:
                        Console.WriteLine("Choose a ship to work with");
                        DisplayAllShips(ref ships);
                        bool success   = true;
                        int  shipindex = WasNumberInputted(Console.ReadLine(), ref success);
                        if (success)
                        {
                            WorkWithShip(ships[shipindex - 1]);
                        }
                        break;

                    case 3:
                        bool successed = true;
                        Console.WriteLine("input index of a ship to delete");
                        int deleteidx = WasNumberInputted(Console.ReadLine(), ref successed);
                        if (successed)
                        {
                            ships.RemoveAt(deleteidx);
                        }
                        else
                        {
                            Console.WriteLine("incorrect index input, try again.");
                        }
                        break;

                    case 4:
                        mainmenulooped = true;
                        break;

                    default: Console.WriteLine("Wrong number input");
                        break;
                    }
                    mainmenulooped = false;
                }
            }
        }
示例#10
0
            public async void Should_support_cool_stuff()
            {
                SideCarrier <B> factorySideCarrier = new FactorySideCarrier <B>();
                var             carrier            = new AircraftCarrier();

                Payload <A> payload = new PayloadImpl <A>(new A());

                Task <Payload <A> > task = ComposerFactory.Compose(payload, composer => { factorySideCarrier.Compose(composer, carrier); });

                await task;
            }
示例#11
0
        public void IsDestroyed_With_Destroyed_AircraftCarrier_Should_Return_True()
        {
            Ship ship = new AircraftCarrier()
            {
                Damages = 5
            };

            var res = ship.IsDestroyed;

            Assert.True(res);
        }
        public void PlaceShipAtCoordinates_AircraftCarrier_At_Too_Short_Should_Return_False()
        {
            BoardGame boardGame = new BoardGame();

            boardGame.InitBoardGame();
            var A1Coordinate = new BoardCoordinates(1, 1);
            var A2Coordinate = new BoardCoordinates(1, 2);
            var ship         = new AircraftCarrier();

            var res = boardGame.PlaceShipAtCoordinates(ship, A1Coordinate, A2Coordinate);

            Assert.False(res);
        }
        public void PlaceShipAtCoordinates_AircraftCarrier_At_Not_Parrallel_Coordinates_Should_Return_False()
        {
            BoardGame boardGame = new BoardGame();

            boardGame.InitBoardGame();
            var A1Coordinate = new BoardCoordinates(1, 1);
            var D5Coordinate = new BoardCoordinates(4, 5);
            var ship         = new AircraftCarrier();

            var res = boardGame.PlaceShipAtCoordinates(ship, A1Coordinate, D5Coordinate);

            Assert.False(res);
        }
        public void PlaceShipAtCoordinates_AircraftCarrier_From_A5_Coordinates_To_A1_Coordinates_Should_Return_True()
        {
            BoardGame boardGame = new BoardGame();

            boardGame.InitBoardGame();
            var A1Coordinate = new BoardCoordinates(1, 1);
            var A5Coordinate = new BoardCoordinates(1, 5);
            var ship         = new AircraftCarrier();

            var res = boardGame.PlaceShipAtCoordinates(ship, A5Coordinate, A1Coordinate);

            Assert.True(res);
        }
        public void PlaceShipAtCoordinates_AircraftCarrier_At_Occuped_Should_Return_False()
        {
            BoardGame boardGame = new BoardGame();

            boardGame.InitBoardGame();
            var A1Coordinate   = new BoardCoordinates(1, 1);
            var A3Coordinate   = new BoardCoordinates(1, 3);
            var B3Coordinate   = new BoardCoordinates(2, 3);
            var A5Coordinate   = new BoardCoordinates(1, 5);
            var ship           = new AircraftCarrier();
            var occupationShip = new TorpedoBoat();

            boardGame.PlaceShipAtCoordinates(occupationShip, A3Coordinate, B3Coordinate);

            var res = boardGame.PlaceShipAtCoordinates(ship, A1Coordinate, A5Coordinate);

            Assert.False(res);
        }
        private static void NewShip(ref AircraftCarrier ship)
        {
            Console.WriteLine("Enter new ship's name");
            string name        = Console.ReadLine();
            bool   anothreloop = false;

            while (!anothreloop)
            {
                Console.WriteLine("Enter ship's maximum cannon capacity");
                int capacity = WasNumberInputted(Console.ReadLine(), ref anothreloop);
                if (anothreloop)
                {
                    ship = new AircraftCarrier(name, capacity);
                    Console.WriteLine("Ship " + ship.ModelName.ToString() + " has been added.");
                }
                else
                {
                    Console.WriteLine("Incorrect input for cannon capacity, try again");
                }
            }
        }
示例#17
0
        /// <summary>
        /// Allows the app to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            IsMouseVisible = true; // easier for debugging not to "lose" mouse
            SetWindowOnSurface();
            InitializeSurfaceInput();

            // Set the application's orientation based on the orientation at launch
            currentOrientation = ApplicationServices.InitialOrientation;

            // Subscribe to surface window availability events
            ApplicationServices.WindowInteractive    += OnWindowInteractive;
            ApplicationServices.WindowNoninteractive += OnWindowNoninteractive;
            ApplicationServices.WindowUnavailable    += OnWindowUnavailable;

            // Setup the UI to transform if the UI is rotated.
            // Create a rotation matrix to orient the screen so it is viewed correctly
            // when the user orientation is 180 degress different.
            Matrix inverted = Matrix.CreateRotationZ(MathHelper.ToRadians(180)) *
                              Matrix.CreateTranslation(graphics.GraphicsDevice.Viewport.Width,
                                                       graphics.GraphicsDevice.Viewport.Height,
                                                       0);

            if (currentOrientation == UserOrientation.Top)
            {
                screenTransform = inverted;
            }

            //Objet à initialiser


            _charlesDeGaule = new AircraftCarrier(Window.ClientBounds.Width, Window.ClientBounds.Height);


            base.Initialize();
        }
        public void FlyMoveStrategyTest()
        {
            var vehicle = new AircraftCarrier();

            Assert.AreEqual("Flying high", vehicle.MovingType.Move());
        }