Last active
September 12, 2015 01:31
-
-
Save Unix-Code/c651d9a82a4653bf6c0f to your computer and use it in GitHub Desktop.
DnD Character
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
public class Character { | |
private String charName; | |
private String charRace; | |
private String gender; | |
private int age; | |
private String charClass; | |
private int strength; | |
private int constitution; | |
private int dexterity; | |
private int intelligence; | |
private int wisdom; | |
private int charisma; | |
private int hitpoints; | |
private int armour; | |
public Character() { | |
charName = "Legolas"; | |
charRace = "Elf"; | |
age = 2931; | |
gender = "Male"; | |
charClass = "Ranger"; | |
strength = 12; | |
constitution = 10; | |
dexterity = 18; | |
intelligence = 12; | |
wisdom = 12; | |
charisma = 12; | |
armour = 5; | |
hitpoints = constitution + armour; | |
} | |
public Character(String name, String race, int charAge, String sClass, String sex, int str, int con, int dex, int intel, int wis, int cha, int arm) { | |
charName = name; | |
charRace = race; | |
age = charAge; | |
charClass = sClass; | |
armour = arm; | |
gender = sex; | |
if (strength < 21 || constitution < 21 || dexterity < 21 || intelligence < 21 || wisdom < 21 || charisma < 21) { | |
strength = str; | |
constitution = con; | |
dexterity = dex; | |
intelligence = intel; | |
wisdom = wis; | |
charisma = cha; | |
hitpoints = constitution + armour; | |
} | |
else { | |
System.err.print("Error: Attributes Exceed Limit, Cheater."); | |
} | |
} | |
public String getname() { | |
return charName; | |
} | |
public int getstr(){ | |
return strength; | |
} | |
public int getcon(){ | |
return constitution; | |
} | |
public int getdex(){ | |
return dexterity; | |
} | |
public int getintel() { | |
return intelligence; | |
} | |
public int gethealth() { | |
return hitpoints; | |
} | |
public int getarm() { | |
return armour; | |
} | |
public void printCharacterSheet() { | |
System.out.format("\f%s, the %d year old %s %s", charName, age, charRace, charClass); | |
System.out.println((gender.equalsIgnoreCase("Male")) ? "\n\nHis Stats:" : "\n\nHer Stats:"); | |
System.out.format("\nStrength: %d\nConstitution: %d\nDexterity: %d\nIntelligence: %d\nWisdom: %d\nCharisma: %d\nHitpoints: %d\nArmour: %d\n", | |
strength, constitution, dexterity, intelligence, wisdom, charisma, hitpoints, armour); | |
/** below Make sure to include your own personal file location layout after FileOutputStream **/ | |
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("\\Computer Science_Java\\DnD Character Generator\\Saves\\" + charName + "_Save.txt"), "utf-8"))) { | |
writer.write(charName + ", the " + age + " year old " + charRace + " " + charClass); | |
writer.write((gender.equalsIgnoreCase("Male")) ? "\r\n\r\nHis Stats:" : "\r\n\r\nHer Stats:"); | |
writer.write("\r\n\r\n\tStrength: " + strength + "\r\n\tConstitution: " + constitution + "\r\n\tDexterity: " + dexterity | |
+ "\r\n\tIntelligence: " + intelligence + "\r\n\tWisdom: " + wisdom | |
+ "\r\n\tCharisma: " + charisma + "\r\n\tHitpoints: " + hitpoints + "\r\n\tArmour: " + armour + "\r\n"); | |
writer.close(); | |
} catch (IOException e) { | |
System.err.print("Error: Could not write save"); | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Creator { | |
private String name; | |
private String race; | |
private int charAge; | |
private String sex; | |
private String sClass; | |
private int str; | |
private int con; | |
private int dex; | |
private int intel; | |
private int wis; | |
private int cha; | |
private int arm; | |
public void create() { | |
Random RandomNum = new Random(); | |
int[] randValue = new int[6]; | |
for (int i = 0; i < randValue.length; i++) { | |
randValue[i] = (RandomNum.nextInt(21) == 0) ? RandomNum.nextInt(21) : RandomNum.nextInt(21) + 1; | |
} | |
str = randValue[0]; | |
con = randValue[1]; | |
dex = randValue[2]; | |
intel = randValue[3]; | |
wis = randValue[4]; | |
cha = randValue[5]; | |
Scanner Scan = new Scanner(System.in); | |
System.out.println("\fWhat is your Character's Name?"); | |
name = Scan.nextLine(); | |
boolean validInput = false; | |
while (validInput != true) { | |
System.out.println("\fWhat is " + name + "'s Gender?"); | |
sex = Scan.nextLine(); | |
if (sex.equalsIgnoreCase("Male") || sex.equalsIgnoreCase("Female") || name.equalsIgnoreCase("Prazzly Dazzling")) { | |
validInput = true; | |
} | |
else { | |
validInput = false; | |
} | |
} | |
System.out.println("\fWhat is " + name + "'s Race?"); | |
race = Scan.nextLine(); | |
validInput = false; | |
while (validInput != true) { | |
try { | |
System.out.println("\r\fWhat is " + name + "'s Age?"); | |
charAge = Integer.parseInt(Scan.nextLine()); | |
validInput = true; | |
} catch (NumberFormatException e) { | |
validInput = false; | |
} | |
} | |
System.out.println("\fWhat is " + name + "'s Class?"); | |
sClass = Scan.nextLine(); | |
System.out.println("\fWhat level of armour is " + name + " wearing?"); | |
arm = Scan.nextInt(); | |
Character PlayerChar = new Character(name, race, charAge, sClass, sex, | |
str, con, dex, intel, wis, cha, arm); | |
PlayerChar.printCharacterSheet(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Creator Program = new Creator(); | |
Program.create(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment