Beispiel #1
0
        public Ship GetShip()
        {
            //var builder = new ShipBuilder(Owner, Battle, x, endx, y, endy, isHorizontal);
            IShipBuilder        shipabstractbuilder = new ShipBuilder(Owner, Battle, x, endx, y, endy, isHorizontal);
            AbstractShipBuilder builder             = new AbstractShipBuilder(shipabstractbuilder);

            ShipChain buildReset       = new BuildReset(builder);
            ShipChain buildBase        = new BuildBase(builder);
            ShipChain buildCoordinates = new BuildCoordinates(builder);
            ShipChain buildSize        = new BuildSize(builder);

            buildReset.SetNextChain(buildBase);
            buildBase.SetNextChain(buildCoordinates);
            buildCoordinates.SetNextChain(buildSize);
            buildSize.SetNextChain(null);

            ShipChain mainBuild = buildReset;

            mainBuild.Build();
            System.Diagnostics.Debug.WriteLine("Chain of responsibility: shipbuilding chain executed");

            //builder.BuildBase();
            //builder.BuildCoordinates();
            //builder.BuildSize();

            return(builder.GetShip());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            IBuildRover       iBUildRover       = new BuildRover();
            IMoveRover        iMoveRover        = new MoveRover();
            IBuildCoordinates iBuildCoordinates = new BuildCoordinates();

            var plateauSize = new PlateauSize(4, 4);

            //Create coordinates for the first rover
            var roverLocations    = new Locations(1, 2);
            var cardinalDirection = CardinalDirections.N;
            var movements         = "LMLMLMLMM";

            //Create coordinates for the second rover
            var rover2Locations    = new Locations(3, 3);
            var cardinalDirection2 = CardinalDirections.E;
            var movements2         = "MMRMMRMRRM";

            //Build first rover
            var coordinates   = iBuildCoordinates.Build(roverLocations, cardinalDirection);
            var startingRover = iBUildRover.Build(coordinates, movements);

            startingRover.Id = 1;

            //Build second rover
            var coordinates2   = iBuildCoordinates.Build(rover2Locations, cardinalDirection2);
            var startingRover2 = iBUildRover.Build(coordinates2, movements2);

            startingRover2.Id = 2;

            var startingRovers = new List <Rover>()
            {
                startingRover, startingRover2
            };

            //Move rovers
            var arrivedRovers = iMoveRover.Move(startingRovers, plateauSize);

            foreach (var rover in arrivedRovers)
            {
                Console.WriteLine(string.Format("Rover {0} final position: ", rover.Id) + rover.Location.X.ToString() + rover.Location.Y.ToString() + rover.direction);
            }


            Console.ReadKey();
        }