public static CharacterCombat Generate() { int chosenClass; int level; int race; int feat; int res = 0; string[] races = { "Dwarf", "Elf", "Gnome", "Half Elf", "Halfling", "Half Orc", "Human" }; string[] stats = { "Strength", "Dexterity", "Constitution", "Intelligence", "Wisdom", "Charisma" }; DiceRoll dice = new DiceRoll(); dynamic character = null; Console.WriteLine("Welcome to the Random Generator option! Stand by while we let our monke.... our skilled engineer create your new class!"); // Choosing a class randomly chosenClass = dice.Roll(11); // Choosing a level randomly level = dice.Roll(5); // Select a race randomly race = dice.Roll(7); Console.WriteLine("\n----------------------------------------"); switch (chosenClass) { case 1: character = new Barbarian(level); character.UpdateBaseInfo(1, "Barbarian"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Barbarian!"); break; case 2: character = new Bard(level); character.UpdateBaseInfo(1, "Bard"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Bard!"); break; case 3: character = new Cleric(level); character.UpdateBaseInfo(1, "Cleric"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Cleric!"); break; case 4: character = new Druid(level); character.UpdateBaseInfo(1, "Druid"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Druid!"); break; case 5: character = new Fighter(level); character.UpdateBaseInfo(1, "Fighter"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Fighter!"); break; case 6: character = new Monk(level); character.UpdateBaseInfo(1, "Monk"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Monk!"); break; case 7: character = new Paladin(level); character.UpdateBaseInfo(1, "Paladin"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Paladin!"); break; case 8: character = new Ranger(level); character.UpdateBaseInfo(1, "Ranger"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Ranger!"); break; case 9: character = new Rogue(level); character.UpdateBaseInfo(1, "Rogue"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Rogue!"); break; case 10: character = new Sorcerer(level); character.UpdateBaseInfo(1, "Sorcerer"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Sorcerer!"); break; case 11: character = new Wizard(level); character.UpdateBaseInfo(1, "Wizard"); Console.WriteLine("You are a level " + level + " " + races.GetValue(race - 1) + " Wizard!"); break; default: Console.WriteLine("Seems like I've encountered a problem. Try again!"); break; }// Switch Case character.UpdateBaseInfo(3, level.ToString()); Console.WriteLine("\n----------------------------------------"); Console.WriteLine("How do you want to create your statistics? \n1- Generate it randomly\n2- Insert my own numbers\n"); do { try { level = Convert.ToInt32(Console.ReadLine()); // Level is now useless, so I will reuse it } catch (FormatException) { Console.WriteLine("It seems like you tried to insert one or more letters instead of an integer. You can't do that!"); Console.WriteLine(); } catch (OverflowException) { Console.WriteLine("It seems like something went wrong. Try contacting the developer, but he won't know much more."); Console.WriteLine(); } finally { if (level > 0 && level < 3) { res = 1; Console.WriteLine("Nice! We will now proceed!\n"); } else { Console.WriteLine("There was a problem selecting your input. Please, try again."); } } }while (res == 0); if (level == 1) { for (int i = 0; i < stats.Length; i++) { // Rolling 4 dices int[] roll = new int[4]; roll[0] = dice.Roll(6); roll[1] = dice.Roll(6); roll[2] = dice.Roll(6); roll[3] = dice.Roll(6); // Removing the lowest value int numToRemove = roll.Min(); int numIndex = Array.IndexOf(roll, numToRemove); roll = roll.Where((val, idx) => idx != numIndex).ToArray(); // Calculating stat value int value = roll.Sum(); // Adding stat value Console.WriteLine("\n---------------------------------"); Console.WriteLine("Your " + stats[i] + " is " + value + "."); character.ChangeBaseStat(stats[i], value); }// For Cycle } else if (level == 2) { character.InsertBaseStat(); } // Implementing the race Races.RndChoice(character, race); // Generating HP Console.WriteLine("\n---------------------------------"); character.HPrnd(); // Managing additional feats feat = character.GetBonusFeat(); FeatsManager featManager = new FeatsManager(); for (int i = 0; i < feat; i++) { string name = featManager.RandomFeat(); character.AddFeat(name); } Console.WriteLine("\n---------------------------------"); Console.WriteLine("Those are your feats!\n"); character.PrintTalents(); Console.WriteLine("\n---------------------------------"); Console.WriteLine("Spells!"); character.PrintCastableSpells(); return(character); }
public static CharacterCombat Generate() { int chosenClass = 0; int level = 0; int res = 0; int feat = 0; dynamic character = new CharacterCombat(); DiceRoll dice = new DiceRoll(); int[] rolledStats = new int[6]; //Starting by choosing the class Console.WriteLine("Welcome to the Guided Generation! My name is... well, I don't have a name, but it's fine anyway!"); Console.WriteLine("Now I will walk you through che creation of a new D&D character! Now, where did i put....."); Console.WriteLine("..."); Console.WriteLine("Yes, found it. First, I need to know what class you want to be. Classes are what specialize you, and we have a lot of them!."); Console.WriteLine("Do you want to be a mighty Paladin? We got it! A wise Wizard? Check. A sneaky Rogue? Just don't try to steal my code..."); Console.WriteLine("Now now, let's start. We have those classes avaibles, so pick carefully:\n1- Barbarian\n2- Bard\n3- Cleric\n4- Druid\n5- Fighter\n6- Monk\n7- Paladin\n8- Ranger\n9- Rogue\n10- Sorcerer\n11- Wizard\nYour choice is: "); do { try { chosenClass = Convert.ToInt32(Console.ReadLine()); } catch (FormatException) { Console.WriteLine("It seems like you tried to insert one or more letters instead of an integer. You can't do that!"); Console.WriteLine(); } catch (OverflowException) { Console.WriteLine("It seems like something went wrong. Try contacting the developer, but he won't know much more."); Console.WriteLine(); } finally { if (chosenClass > 0 && chosenClass < 12) { res = 1; Console.WriteLine("Ah, that is an amazing class! Now I will need to ask you a few more questions.."); } else { Console.WriteLine("There was a problem selecting your class. Please, try again."); } } } // Class while (res == 0); // Level choice Console.WriteLine("\n----------------------------------------"); res = 0; Console.WriteLine("Enter your character level! You can select any level from 1 to 5!"); do { try { level = Convert.ToInt32(Console.ReadLine()); } catch (FormatException) { Console.WriteLine("It seems like you tried to insert one or more letters instead of an integer. You can't do that!"); Console.WriteLine(); } catch (OverflowException) { Console.WriteLine("It seems like something went wrong. Try contacting the developer, but he won't know much more."); Console.WriteLine(); } finally { if (level > 0 && level < 6) { res = 1; Console.WriteLine("Nice! We will now proceed!\n"); } else { Console.WriteLine("There was a problem selecting your Level. Please, try again."); } } } // Level while (res == 0); //Updating the base class CharacterCombat to the proper selected class switch (chosenClass) { case 1: character = new Barbarian(level); character.UpdateBaseInfo(1, "Barbarian"); character.UpdateBaseInfo(3, level.ToString()); break; case 2: character = new Bard(level); character.UpdateBaseInfo(1, "Bard"); character.UpdateBaseInfo(3, level.ToString()); break; case 3: character = new Cleric(level); character.UpdateBaseInfo(1, "Cleric"); character.UpdateBaseInfo(3, level.ToString()); break; case 4: character = new Druid(level); character.UpdateBaseInfo(1, "Druid"); character.UpdateBaseInfo(3, level.ToString()); break; case 5: character = new Fighter(level); character.UpdateBaseInfo(1, "Fighter"); character.UpdateBaseInfo(3, level.ToString()); break; case 6: character = new Monk(level); character.UpdateBaseInfo(1, "Monk"); character.UpdateBaseInfo(3, level.ToString()); break; case 7: character = new Paladin(level); character.UpdateBaseInfo(1, "Paladin"); character.UpdateBaseInfo(3, level.ToString()); break; case 8: character = new Ranger(level); character.UpdateBaseInfo(1, "Ranger"); character.UpdateBaseInfo(3, level.ToString()); break; case 9: character = new Rogue(level); character.UpdateBaseInfo(1, "Rogue"); character.UpdateBaseInfo(3, level.ToString()); break; case 10: character = new Sorcerer(level); character.UpdateBaseInfo(1, "Sorcerer"); character.UpdateBaseInfo(3, level.ToString()); break; case 11: character = new Wizard(level); character.UpdateBaseInfo(1, "Wizard"); character.UpdateBaseInfo(3, level.ToString()); break; default: Console.WriteLine("Seems like I've encountered a problem. Try again!"); break; }// Switch Case //Base Statistics Insertion Console.WriteLine("\n----------------------------------------"); Console.WriteLine("How do you want to insert your statistics? \n1- Generate random numbers for me to insert\n2- Insert my own numbers\n"); res = 0; do { try { level = Convert.ToInt32(Console.ReadLine()); // Level is now useless, so I will reuse it } catch (FormatException) { Console.WriteLine("It seems like you tried to insert one or more letters instead of an integer. You can't do that!"); Console.WriteLine(); } catch (OverflowException) { Console.WriteLine("It seems like something went wrong. Try contacting the developer, but he won't know much more."); Console.WriteLine(); } finally { if (level > 0 && level < 3) { res = 1; Console.WriteLine("Nice! We will now proceed!\n"); } else { Console.WriteLine("There was a problem selecting your input. Please, try again."); } } } // Level while (res == 0); if (level == 1) { for (int i = 0; i < 6; i++) { // Rolling 4 dices int[] roll = new int[4]; roll[0] = dice.Roll(6); roll[1] = dice.Roll(6); roll[2] = dice.Roll(6); roll[3] = dice.Roll(6); // Removing the lowest value int numToRemove = roll.Min(); int numIndex = Array.IndexOf(roll, numToRemove); roll = roll.Where((val, idx) => idx != numIndex).ToArray(); rolledStats[i] = roll.Sum(); }// For Cycle Console.WriteLine("Those are your stats to allocate!\n"); foreach (int item in rolledStats) { Console.Write(item + " "); } Console.WriteLine(); character.InsertBaseStat(); } else if (level == 2) { character.InsertBaseStat(); } //Race choice Console.WriteLine("\n----------------------------------------"); Races.Choice(character); //Hp update Console.WriteLine("\n----------------------------------------"); character.HPInfo(); //Feats managing int featsNumber = character.GetBonusFeat(); FeatsManager featList = new FeatsManager(); for (int i = 0; i < character.GetBonusFeat(); i++) { Console.WriteLine("\n----------------------------------------"); Console.WriteLine("Current Feat(s): "); character.PrintTalents(); res = 0; Console.WriteLine("\n----------------------------------------"); Console.WriteLine("\n" + featsNumber + " feat(s) remaining."); Console.WriteLine("You can now: \n1- Search your feat\n2- Insert your feat\n3- Print the feat list\nYour choice: "); do { try { feat = Convert.ToInt32(Console.ReadLine()); } catch (FormatException) { Console.WriteLine("It seems like you tried to insert one or more letters instead of an integer. You can't do that!"); Console.WriteLine(); } catch (OverflowException) { Console.WriteLine("It seems like something went wrong. Try contacting the developer, but he won't know much more."); Console.WriteLine(); } finally { if (feat > 0 && feat < 4) { res = 1; } } } // Feat while (res == 0); if (feat == 1) { Console.WriteLine("Searching feat: "); featList.SearchFeat(Console.ReadLine()); featList.PrintInfo(); featList.PrintReq(); featList.PrintBonus(); } else if (feat == 2) { Console.WriteLine("Ok, I will now let you add the feat! Be sure to write it properly, as this part of the program doesn't have a validation... yet."); character.AddFeat(Console.ReadLine()); featsNumber--; } else { featList.PrintList(); } }// For Cycle Console.WriteLine("Total Feat(s)!"); character.PrintTalents(); // Print Spells Console.WriteLine("\n----------------------------------------"); Console.WriteLine("Spells!"); character.PrintCastableSpells(); return(character); }