Beispiel #1
0
        public override void Execute(string[] commandArgs)
        {
            string shipType     = commandArgs[1];
            string shipName     = commandArgs[2];
            string shipLocation = commandArgs[3];

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

            if (isShipCreatedAlready)
            {
                throw new ShipException(Messages.DuplicateShipName);
            }

            StarshipType type     = (StarshipType)Enum.Parse(typeof(StarshipType), shipType);
            StarSystem   location = GameEngine.Galaxy.GetStarSystemByName(shipLocation);

            IStarship starship = GameEngine.ShipFactory.CreateShip(type, shipName, location);

            GameEngine.Starships.Add(starship);

            for (int i = 4; i < commandArgs.Length; i++)
            {
                EnhancementType enhancementType = (EnhancementType)Enum.Parse(typeof(EnhancementType), commandArgs[i]);
                Enhancement     enhancement     = GameEngine.EnhancementFactory.Create(enhancementType);
                starship.AddEnhancement(enhancement);
            }

            Console.WriteLine(string.Format(Messages.CreatedShip, shipType, shipName));
        }
Beispiel #2
0
        public override void Execute(string[] commandArgs)
        {
            string type         = commandArgs[1];
            string shipName     = commandArgs[2];
            string locationName = commandArgs[3];

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

            if (shipAlredyExists)
            {
                throw new ArgumentException(Messages.DuplicateShipName);
            }

            var          location     = this.GameEngine.Galaxy.GetStarSystemByName(locationName);
            StarshipType starshipType = (StarshipType)Enum.Parse(typeof(StarshipType), type);

            var ship = this.GameEngine.ShipFactory.CreateShip(starshipType, shipName, location);

            this.GameEngine.Starships.Add(ship);

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

                var enhancement = this.GameEngine.EnhancementFactory.Create(enhancementType);
                ship.AddEnhancement(enhancement);
            }

            Console.WriteLine(Messages.CreatedShip, starshipType, shipName);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public IStarship CreateShip(StarshipType type, string name, StarSystem location)
        {
            IStarship ship;

            switch (type)
            {
            case StarshipType.Frigate:
                ship = new Frigate(name, location);
                break;

            case StarshipType.Cruiser:
                ship = new Cruiser(name, location);
                break;

            case StarshipType.Dreadnought:
                ship = new Dreadnought(name, location);
                break;

            default:
                throw new NotSupportedException("Starship type not supported.");
            }

            Console.WriteLine(Messages.CreatedShip, ship.GetType().Name, ship.Name);
            return(ship);
        }
Beispiel #5
0
        public async Task TestBasicQueries()
        {
            string query;

            query = " query { starships {id, name, length coordinates} } ";
            var response = await TestEnv.Client.PostAsync(query);

            var ships = response.data.starships;

            Assert.AreEqual(4, ships.Count, "expected 4 ships");
            var ship0Name = ships[0].name;

            Assert.IsNotNull(ship0Name, "expected name");
            foreach (var sh in ships)
            {
                Trace.WriteLine($"Starship {sh.name}, length: {sh.length}");
            }
            // Strongly typed objects
            var          shipArr = response.GetTopField <StarshipType[]>("starships");
            StarshipType s0      = shipArr[0];

            Assert.IsNotNull(s0, "Expected starship object.");

            query = @" query ($id: ID) { 
        starship(id: $id) {name, length} 
       } ";
            var vars = new Dictionary <string, object>()
            {
                { "id", "3001" }
            };

            response = await TestEnv.Client.PostAsync(query, vars);

            var shipName = response.data.starship.name;

            Assert.AreEqual("X-Wing", shipName);

            // character query with friends, using variable
            query      = @" query($id: ID!) {
  leia: character(id: $id) { 
    name
    friends { name }
  }
}";
            vars       = new Dictionary <string, object>();
            vars["id"] = "1003";
            response   = await TestEnv.Client.PostAsync(query, vars);

            var lname = response.data.leia.name;

            Assert.AreEqual("Leia Organa", lname);
            var leiaFriends = response.data.leia.friends;

            Assert.AreEqual(4, leiaFriends.Count, "Expected 4 friends");
        }
Beispiel #6
0
    public static StarshipData GetStarshipData(StarshipType starship)
    {
        switch (starship)
        {
        case StarshipType.PlayerStarship_D: return(datas[0]);

        case StarshipType.PlayerStarship_C: return(datas[1]);

        default: return(datas[0]);
        }
    }
Beispiel #7
0
 public IStarship CreateShip(StarshipType type, string name, StarSystem location)
 {
     switch (type)
     {
         case StarshipType.Frigate:
             // TODO:
         case StarshipType.Cruiser:
             // TODO:
         case StarshipType.Dreadnought:
             // TODO:
         default:
             throw new NotSupportedException("Starship type not supported.");
     }
 }
 /// <summary>
 /// The create ship.
 /// </summary>
 /// <param name="type">
 /// The type.
 /// </param>
 /// <param name="name">
 /// The name.
 /// </param>
 /// <param name="location">
 /// The location.
 /// </param>
 /// <returns>
 /// The <see cref="IStarship"/>.
 /// </returns>
 /// <exception cref="NotSupportedException">
 /// </exception>
 public IStarship CreateShip(StarshipType type, string name, StarSystem location)
 {
     switch (type)
     {
         case StarshipType.Frigate:
             return new Frigate(name, location);
         case StarshipType.Cruiser:
             return new Cruiser(name, location);
         case StarshipType.Dreadnought:
             return new Dreadnought(name, location);
         default:
             throw new NotSupportedException("Starship type not supported.");
     }
 }
Beispiel #9
0
 public IStarship CreateShip(StarshipType type, string name, StarSystem location)
 {
     switch (type)
     {
     case StarshipType.Frigate:
     // TODO:
     case StarshipType.Cruiser:
     // TODO:
     case StarshipType.Dreadnought:
     // TODO:
     default:
         throw new NotSupportedException("Starship type not supported.");
     }
 }
        /// <summary>
        /// The create ship.
        /// </summary>
        /// <param name="type">
        /// The type.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="location">
        /// The location.
        /// </param>
        /// <returns>
        /// The <see cref="IStarship"/>.
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// </exception>
        public IStarship CreateShip(StarshipType type, string name, StarSystem location)
        {
            switch (type)
            {
            case StarshipType.Frigate:
                return(new Frigate(name, location));

            case StarshipType.Cruiser:
                return(new Cruiser(name, location));

            case StarshipType.Dreadnought:
                return(new Dreadnought(name, location));

            default:
                throw new NotSupportedException("Starship type not supported.");
            }
        }
Beispiel #11
0
        public IStarship CreateShip(StarshipType type, string name, StarSystem location)
        {
            switch (type)
            {
            case StarshipType.Frigate:
                Frigate frigate = new Frigate(name, location);
                return(frigate);

            case StarshipType.Cruiser:
                Cruiser crusier = new Cruiser(name, location);
                return(crusier);

            case StarshipType.Dreadnought:
                Dreadnought dreadnought = new Dreadnought(name, location);
                return(dreadnought);

            default:
                throw new NotSupportedException("Starship type not supported.");
            }
        }
Beispiel #12
0
        public override void Execute(string[] commandArgs)
        {
            StarshipType shipType           = (StarshipType)Enum.Parse(typeof(StarshipType), commandArgs[1], true);
            var          shipName           = commandArgs[2];
            StarSystem   system             = this.GameEngine.Galaxy.GetStarSystemByName(commandArgs[3]);
            var          enchans            = new List <Enhancement>();
            var          enchansmentFactory = new EnhancementFactory();

            for (int i = 4; i < commandArgs.Length; i++)
            {
                var ench = enchansmentFactory.Create((EnhancementType)Enum.Parse(typeof(EnhancementType), commandArgs[i], true));
                enchans.Add(ench);
            }

            var shipFactory = new ShipFactory();
            var ship        = shipFactory.CreateShip(shipType, shipName, system);

            enchans.ForEach(e => ship.AddEnhancement(e));

            this.GameEngine.Starships.Add(ship);
        }
Beispiel #13
0
        public IStarship CreateShip(StarshipType type, string name, StarSystem location)
        {
            IStarship ship;
            switch (type)
            {
                case StarshipType.Frigate:
                    ship = new Frigate(name, location);
                    break;
                case StarshipType.Cruiser:
                    ship = new Cruiser(name, location);
                    break;
                case StarshipType.Dreadnought:
                    ship = new Dreadnought(name, location);
                    break;
                default:
                    throw new NotSupportedException("Starship type not supported.");
            }

            Console.WriteLine(Messages.CreatedShip, ship.GetType().Name, ship.Name);
            return ship;
        }
Beispiel #14
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);

            // validating that the ship does not exist already
            if (shipAlreadyExists)
            {
                throw new ShipException(Messages.DuplicateShipName);
            }

            var          location = this.GameEngine.Galaxy.GetStarSystemByName(locationName);
            StarshipType shipType = (StarshipType)Enum.Parse(typeof(StarshipType), type);

            // creating the ship using the ShipFactory CreateShip method
            IStarship ship = this.GameEngine.ShipFactory.CreateShip(shipType, shipName, location);

            // creating the enhancements
            for (int i = 4; i < commandArgs.Length; i++)
            {
                var enhancementType = (EnhancementType)
                                      Enum.Parse(typeof(EnhancementType), commandArgs[i]);

                Enhancement enhancement = null;
                enhancement = this.GameEngine.EnhancementFactory.Create(enhancementType);

                // adding the freshly created enhancement to the ship
                ship.AddEnhancement(enhancement);
            }
            // adding ship to starships
            this.GameEngine.Starships.Add(ship);

            Console.WriteLine(Messages.CreatedShip, shipType, shipName);
        }
        public override void Execute(string[] commandArgs)
        {
            string shipType       = commandArgs[1];
            string shipName       = commandArgs[2];
            string starSystemName = commandArgs[3];

            if (base.GameEngine.Starships.Any(ship => ship.Name == shipName))
            {
                throw new ShipException(Messages.DuplicateShipName);
            }

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

            StarSystem starSystem = base.GameEngine.Galaxy.GetStarSystemByName(starSystemName);

            IStarship starship = base.GameEngine.ShipFactory.CreateShip(starshipType, shipName, starSystem);

            if (commandArgs.Length > 4)
            {
                string[] enhancements = commandArgs.Skip(4).ToArray();

                foreach (string enhancementStr in enhancements)
                {
                    EnhancementType enhancementType = (EnhancementType)Enum.Parse(typeof(EnhancementType), enhancementStr);

                    Enhancement enhancement = base.GameEngine.EnhancementFactory.Create(enhancementType);

                    starship.AddEnhancement(enhancement);
                }
            }

            base.GameEngine.Starships.Add(starship);
            starSystem.Starships.Add(starship);

            Console.WriteLine(string.Format(Messages.CreatedShip, shipType, shipName));
        }