//confirmSelection: Confirmation window. Returns "0" if the loadout is correct, returns 1 if not. public static int confirmSelection(string shipNameInp, List <IShipComponentInterface> chosenComponents, IShipClassInterface chosenClass) { List <IShipComponentInterface> confirmComponents = chosenComponents; IShipClassInterface confirmClass = chosenClass; Console.WriteLine("Confirm your choices:"); Console.WriteLine("Ship Name: " + shipNameInp); Console.WriteLine("Ship Class: " + chosenClass.shipClassName); Console.WriteLine("Itemized List of Ship Components: "); int counter = 1; foreach (IShipComponentInterface thisComponent in chosenComponents) { Console.WriteLine("SLOT: " + counter + " COMPONENT: " + thisComponent.Name); counter++; } Console.Write("Is this loadout correct? Y/N"); string response = Console.ReadLine(); response.ToUpper(); if (response.Equals("Y")) { return(0); } else { return(1); } }
//selectComponents: For every slot, asks the user what component to insert. public static List <IShipComponentInterface> selectComponents(IShipClassInterface selectedClass) { List <IShipComponentInterface> chosenComponents = new List <IShipComponentInterface>(selectedClass.numComponents); for (int i = 0; i < chosenComponents.Capacity; i++) { Console.WriteLine("Please select a component for slot " + i); Console.WriteLine("Select 1 for Cockpit. "); Console.WriteLine("Select 2 for Ion Engine. "); string response = Console.ReadLine(); int responseInt = Int32.Parse(response); if (responseInt == 1) { Console.WriteLine("Selecting Cockpit."); chosenComponents.Add(new Components.Cockpit()); Console.WriteLine("Component Slot " + i + " set to Cockpit."); } if (responseInt == 2) { Console.WriteLine("Selecting Ion Engine."); chosenComponents.Add(new Components.IonEngines()); Console.WriteLine("Component Slot " + i + " set to Ion Engine."); } } return(chosenComponents); }
//Ship asssembly constructor. Requires ship class, ship component list, and location col/row as input. //TODO: Figure out default ship positions, continue making static methods for determining has<Flags>, and eventually figure out ToString AssembledShip(string shipNameInp, IShipClassInterface shipClass, int locationRowInp, int locationColInp, List <IShipComponentInterface> shipComponentList) { shipName = shipNameInp; shipHealth = shipClass.hullHealth; currentShipClass = shipClass; currentShipComponents = shipComponentList; locationRow = locationRowInp; locationCol = locationColInp; isDestroyed = false; isDisabled = false; hasPropulsion = ClassComponentSelect.hasPropulsion(shipComponentList); hasWeapon = ClassComponentSelect.hasWeapons(shipComponentList); hasLifeSupport = ClassComponentSelect.hasLifeSupport(shipComponentList); hasControl = ClassComponentSelect.hasControl(shipComponentList); hasComms = ClassComponentSelect.hasComms(shipComponentList); }
//Default ship constructor: Will construct a simple frigate. //TODO: Go through each member and create defaults public AssembledShip(IShipClassInterface selectedShipClass, int locationRowInput, int locationColInput) { //ERROR-CATCH: // If the input class is null, or otherwise erroneous, this method will fail. if (selectedShipClass == null) { throw new ArgumentException("CreateDefaultShip: selectedShipClass cannot be null!"); } currentShipClass = selectedShipClass; shipName = $"Default {currentShipClass}"; shipHealth = currentShipClass.hullHealth; currentShipComponents = new List <IShipComponentInterface>(currentShipClass.numComponents); //Populting Default Ship: //Interrupting object creation flow in order to populate the default ship with components dynamically. int numComponents = currentShipComponents.Capacity; for (int i = 0; i < numComponents - 1; i++) { currentShipComponents.Add(new Components.IonEngines()); } currentShipComponents.Add(new Components.Cockpit()); locationRow = locationRowInput; locationCol = locationColInput; isDestroyed = false; isDisabled = false; hasPropulsion = ClassComponentSelect.hasPropulsion(currentShipComponents); hasWeapon = ClassComponentSelect.hasWeapons(currentShipComponents); hasLifeSupport = ClassComponentSelect.hasLifeSupport(currentShipComponents); hasControl = ClassComponentSelect.hasControl(currentShipComponents); hasComms = ClassComponentSelect.hasComms(currentShipComponents); }