private Character selectTarget() { string[] t = new string[characters.Count - 1]; for (int i = 0; i < enemies.Count; i++) { Console.WriteLine((i + 1) + ": " + enemies[i].name); } int choice = Helper.processChoice(true); try { return(enemies[choice]); } catch { DebugLog.invalidInputError("Not a valid target"); Helper.space(2); return(selectTarget()); } }
/// <summary> /// Processes the choice of the user. Returns the number pressed - 1 if startAtZero is true /// </summary> /// <returns></returns> internal static int processChoice(bool startAtZero) { int choice = 0; try { choice = int.Parse(Console.ReadLine()); } catch { DebugLog.invalidInputError("Input must me numerical"); choice = processChoice(startAtZero); } if (startAtZero) { return(choice - 1); } return(choice); }
/// <summary> /// Outputs the abilities of a character /// </summary> /// <param name="character">The character.</param> internal static int viewAbilities(Character character) { Console.Clear(); Console.Write(" "); Console.WriteLine("{0, -20} {1, -8} {2, -12} {3, -12} {4, -12} {5, -12} {6, -12} {7, -12} {8, -12} " , "Ability Name", "Level", "Passive", "Strength", "Mana", "Health", "Buildup", "Duration", "Skills"); Console.WriteLine("________________________________________________________________________________________________________________________"); Ability[] abilities = character.spells.ToArray(); foreach (Ability ability in abilities) { string passive = ability.passive == false ? "No" : "Yes"; Console.Write(" "); Console.Write("{0, -20} {1, -8} {2, -12} {3, -12} {4, -12} {5, -12} {6, -12} {7, -12}" , ability.name, ability.getXP, passive, ability.strength, ability.manaCost, ability.healthCost, ability.buildUp, ability.duration); try { for (int i = 0; i < ability.effects.Length; i++) { Console.Write("{0, -120}", ability.effects[i].skill.name); } } catch { Console.WriteLine("{0, -120}", "No effects"); } Console.WriteLine(); } Console.WriteLine("Available Ability Points: " + character.getAbilityPoints); Console.WriteLine(@" 1. Spend Ability Points 2. Acquire New Abilities 3. Go Back"); int choice = Helper.processChoice(false); switch (choice) { case 1: CharacterCreator.distributeAbilityPoints(character); break; case 2: CharacterCreator.addNewAbility(character); break; case 3: break; default: DebugLog.invalidInputError(choice + " is not valid"); break; } return(choice); }
/// <summary> /// Outputs the list of abilities not in the character's spells List /// and allows the adding of them provided the character has ability points /// </summary> /// <param name="character">The character.</param> /// <returns></returns> internal static int addNewAbility(Character character) { Console.Clear(); List <Ability> abilityList = Helper.getAbilityList().ToList(); StatViewer.viewAbilityArray(abilityList.ToArray()); Helper.space(2); Console.WriteLine("Select spell: "); //Iterate through abilityList variable and list all ability names for (int i = 0; i < abilityList.Count; i++) { if (character.spells.Contains(abilityList[i])) //If the character has the ability { abilityList.RemoveAt(i); //Remove it and continue i--; continue; } Console.WriteLine((i + 1) + ": " + abilityList[i].name); //List it } Console.WriteLine((abilityList.Count + 1) + ": Go back"); int choice = Helper.processChoice(true); if (choice == abilityList.Count) { return(choice); } else { try { //Output choice to the user Console.WriteLine("Are you sure you want to add: " + abilityList[choice].name + "? (y/n)"); } catch { DebugLog.invalidInputError(choice + " is not a valid input"); choice = addNewAbility(character); } //If user enters y if (Console.ReadLine() == "y") { //If the user has enough ability points to acquire the ability, add it if (character.getAbilityPoints >= abilityList[choice].acquireCost) { character.spells.Add(abilityList[choice]); character.subAbilityPoint(); } //Otherwise let the user know that they have insufficient points else { Console.WriteLine("Not enough ability points"); } } //Else recall the function else { choice = addNewAbility(character); } } return(choice); }
internal static void distributeAbilityPoints(Character character) { if (!character.hasAbilityPoints) { Console.WriteLine("No Ability Points"); Console.WriteLine("Enter to continue"); Console.ReadLine(); return; } int choice = -1; Console.WriteLine(); Console.WriteLine("Select spell to upgrade: "); while (choice != 0 && character.hasAbilityPoints) { for (int i = 0; i < character.spells.Count; i++) { Console.WriteLine((i + 1) + ": " + character.spells[i].name); } choice = Helper.processChoice(true); if (character.spells.ElementAtOrDefault(choice) != null) { Console.WriteLine(@" Viewing {0}: What would you like to upgrade? 1: Strength 2: Duration 3: Build up 4: Mana Cost 5: Health Cost 6: Go Back"); int choice2 = Helper.processChoice(false); switch (choice2) { case 1: character.spells[choice].strength++; character.subAbilityPoint(); break; case 2: character.spells[choice].duration++; character.subAbilityPoint(); break; case 3: if (Ability.isBuildUpCostValid(character.spells[choice].buildUp)) { character.spells[choice].buildUp++; character.subAbilityPoint(); } break; case 4: if (Ability.isManaCostValid(character.spells[choice].manaCost)) { character.spells[choice].manaCost--; character.subAbilityPoint(); } break; case 5: if (Ability.isHealthCostValid(character.spells[choice].healthCost)) { character.spells[choice].healthCost--; character.subAbilityPoint(); } break; case 6: break; default: choice = -1; break; } } else { DebugLog.invalidInputError(choice + " is not valid"); } } }