Ejemplo n.º 1
0
        public override void Execute(string[] commandArgs)
        {
            string type = commandArgs[1];
            string shipName = commandArgs[2];
            string locationName = commandArgs[3];

            bool shipAlreadyExists =
                this.GameEngine.Starships.Any(s => s.Name == shipName);

            if (shipAlreadyExists)
            {
                throw new ShipException("The ship already Exist!");
            }

            var location =
                this.GameEngine.Galaxy.GetStarSystemByName(locationName);

            StarshipType shipType = (StarshipType) Enum.Parse(typeof (StarshipType), type);

            ShipFactory newShip = new ShipFactory();
            IStarship ship = newShip.CreateShip(shipType, "Salcho's Ship", location);

            this.GameEngine.Starships.Add(ship);

            for (int i = 4; i < commandArgs.Length; i++)
            {
                var enhencementType = (EnhancementType) Enum.Parse(typeof (EnhancementType), commandArgs[i]);

                EnhancementFactory newEnhancement = new EnhancementFactory();
                Enhancement enhancement = newEnhancement.Create(enhencementType);
                ship.AddEnhancement(enhancement);
            }

            Console.WriteLine(Messages.CreatedShip, shipType, shipName);
        }
Ejemplo n.º 2
0
        public override void Execute(string[] commandArgs)
        {
            //create {shipType} {shipName} {starSystem} {enhancement1 enhancements2 ...}

            StarshipType starshipType = CastStringToStarshipType(commandArgs[1]);
            string starshipName = commandArgs[2];

            if (GetStarshipByName(starshipName) != null)
            {
                Console.WriteLine(Messages.DuplicateShipName);
            }

            string starshipLocation = commandArgs[3];

            var ship = new ShipFactory();

            IStarship starship = ship.CreateShip(starshipType, starshipName, this.GameEngine.Galaxy.GetStarSystemByName(starshipLocation));

            if (commandArgs.Length > 3)
            {
                var enhancementFactory = new EnhancementFactory();
                for (int i = 4; i < commandArgs.Length; i++)
                {
                    starship.AddEnhancement(
                        enhancementFactory
                        .Create(CastStringToEnhancementType(commandArgs[i])));
                }
            }

            this.GameEngine.Starships.Add(starship);

            Console.WriteLine(Messages.CreatedShip, starshipType, starshipName);
        }
Ejemplo n.º 3
0
        public override void Execute(string[] commArgs)
        {
            ShipFactory sFactory = new ShipFactory();
            EnhancementFactory eFactory = new EnhancementFactory();
            var shipType = commArgs[1];
            var shipName = commArgs[2];
            if (GetStarshipByName(shipName) != null)
            {
                throw new ShipException(Messages.DuplicateShipName);
            }
            var starSystem = commArgs[3];
            var newShip = sFactory.CreateShip(CastStringToStarshipType(shipType), shipName, this.GameEngine.Galaxy.GetStarSystemByName(starSystem));
            for (int i = 4; i < commArgs.Length; i++)
            {
                newShip.AddEnhancement(eFactory.Create(CastStringToEnhancementType(commArgs[i])));
            }

            this.GameEngine.Starships.Add(newShip);
            Console.WriteLine(Messages.CreatedShip, shipType, shipName);
        }