Results 1 to 5 of 5
Thread: Java Class Writer
-
2015-06-07, 07:32 PM (ISO 8601)
- Join Date
- Dec 2013
- Gender
Java Class Writer
Hello everyone! So, I've participated in a few of the Homebrew class design competitions, and I got bored of making that table really quickly. You know, the one with the BAB and stuff/level? So, I wrote a java program to do it for me. Here's the code.
I know it looks ugly, but I had to use the noparse tag. Sorry!
Spoiler: CodeCode:import java.util.Scanner; public class ClassWriter { private static Scanner s = new Scanner(System.in); private static String extraTitle="",extra=""; private static int l=1; private static int[] stats = new int[4]; //BAB, fort, ref, will tracker private static int[] improve = new int[4]; //rate at which the saves improve private static int[] lt = {0,0,0,0}; //level tracker, DON'T CHANGE! public static void main(String[] args) { //extraTitle = "\n[th][center] {extra column's header} [/center][/th]"; String temp; boolean isMed = false; int maxlevel; System.out.print("Welcome to somebody27else's class writer!" + "\nMake sure to type carefully, and good luck!" + "\n========================================" + "\nHow many levels does your class have? "); maxlevel = s.nextInt(); System.out.print("Slow, medium, or fast BAB progression? "); temp = s.next(); s.nextLine(); if(temp.equalsIgnoreCase("slow") || temp.equalsIgnoreCase("s")) { stats[0] = 0; improve[0] = 2; } else if(temp.equalsIgnoreCase("medium") || temp.equalsIgnoreCase("m")) { stats[0] = 0; improve[0] = 1; isMed = true; } else if(temp.equalsIgnoreCase("fast") || temp.equalsIgnoreCase("f")) { stats[0] = 0; improve[0] = 1; } setSave(1,"Fort"); setSave(2,"Ref"); setSave(3,"Will"); char q = 0x22; System.out.println("\n\n" + "\n[table=" + q + "class:grid head" + q + "]" + "\n" + "\n[tr]" + "\n[th][center]Level[/center][/th]" + "\n[th][center]BAB[/center][/th]" + "\n[th][center]Fort[/center][/th]" + "\n[th][center]Ref[/center][/th]" + "\n[th][center]Will[/center][/th]" + "\n[th][center]Special[/center][/th]" + extraTitle + "\n[/tr]\n"); String babstr; for(l=1; l <= maxlevel; l++) { for(int n=0; n<4; n++) { lt[n]++; if(lt[n]==improve[n]) { lt[n] = 0; stats[n]++; } } if(((l-1)%4==0) && isMed) { stats[0]--; } babstr="+"+stats[0]; if(stats[0]>5) babstr += "/+"+(stats[0]-5); if(stats[0]>10) babstr += "/+"+(stats[0]-10); if(stats[0]>15) babstr += "/+"+(stats[0]-15); setExtra(); System.out.println("[tr]" + "\n[td][center] "+l+" [/center][/td]" + "\n[td][center] "+babstr+" [/center][/td]" + "\n[td][center] +"+stats[1]+" [/center][/td]" + "\n[td][center] +"+stats[2]+" [/center][/td]" + "\n[td][center] +"+stats[3]+" [/center][/td]" + "\n[td][center][/center][/td]" + extra + "\n[/tr]\n"); } System.out.println("[/table]"); } public static void setSave(int stat,String sName) { String temp; System.out.print("Slow or fast " + sName + " save progression? "); temp = s.nextLine(); if(temp.equalsIgnoreCase("slow") || temp.equalsIgnoreCase("s")) { stats[stat] = 0; improve[stat] = 3; } else if(temp.equalsIgnoreCase("fast") || temp.equalsIgnoreCase("f")) { stats[stat] = 2; improve[stat] = 2; } } public static void setExtra() { /** place to write extra conditions/columns **/ //extra = "\n[td][center]"+ {insert whatever you want here} +"[/center][/td]"; } }
Spoiler: How to use itMost of this is self-explanatory. You can copy the code into an online compiler, or whatever java compiler you have on your computer. It runs from the terminal.
This will create the basic table with class level, BAB, fort, ref, and will. Yes, the program will ask you for those.
If you want to add extra columns, like for spells known or maneuvers or such, it gets a little more complicated. Either follow these instruction if you know some java, or just ask me if you don't.
- Go to the first line in the main. The extraTitle line should be commented out. De-comment it.
- You should get an error because, in fact, {extra column's header} is not valid java code. Replace that with what you want your new column to be named.
- OPTIONAL: To add more columns, copy everything inside the quotes and paste it into the end of the quotes. Each paste will add a new line you can change the title of.
- Go to the setExtra() method. The line which gives extra a value should be commented. De-comment it.
- Do whatever shenanigans you want to put in the by-level extra data. Ex: If I want to give my class 1 maneuver every 4 levels, I could write this: extra = "\n[td]"+ (l/4 + 1) +"[/td]";
This is the basic guide. Any questions on usage, problems, feedback, or anything in general, please reply!Last edited by 1pwny; 2015-06-08 at 04:22 PM.
I do stuff.
I usually log on, look at some threads, post, watch for few minutes, then leave and come back the next day. If I don't respond to your replies immediately, don't take offence.
My Homebrewer's Signature
-
2015-06-07, 09:28 PM (ISO 8601)
- Join Date
- Dec 2010
- Location
- Where I live.
Re: Java Class Writer
Why are you storing the save progressions and BAB as Integers? Switch statements and for-loops are your friends.
I remember next to nothing of Java at the moment, but you can just take the input and use a Switch statement to pick the right formula for both BAB and your Saves. I know that would be easier in both C++ and Javascript, but again, I no remember Java good.
EDIT: Also, for future reference, you can hit the blue button on the upper-left corner to switch to WYSIWYG mode; it really speeds up tables, but you should switch back if you need to do any other formatting.
EDIT TO THE EDIT: Also for future reference, <CODE></CODE> tags should conserve indenting (replace the <> with [], as normal).
-
2015-06-08, 04:01 PM (ISO 8601)
- Join Date
- Oct 2012
- Location
- In the Playground, duh.
Re: Java Class Writer
Or, of course, you could use PifRO (Set it to PIFBB, not GITP).
Last edited by Jormengand; 2015-06-08 at 04:02 PM.
-
2015-06-08, 04:15 PM (ISO 8601)
- Join Date
- Dec 2013
- Gender
Re: Java Class Writer
Well, maybe. But that's not really how I structured the program. I don't know, it just seems easier to edit and understand for the general populace as it is right now. But this is my first time getting feedback on it, so
]EDIT: Also, for future reference, you can hit the blue button on the upper-left corner to switch to WYSIWYG mode; it really speeds up tables, but you should switch back if you need to do any other formatting.
EDIT TO THE EDIT: Also for future reference, <CODE></CODE> tags should conserve indenting (replace the <> with [], as normal).
...I totally knew about that. Welp, now we have 2 options.Last edited by 1pwny; 2015-06-08 at 04:26 PM.
I do stuff.
I usually log on, look at some threads, post, watch for few minutes, then leave and come back the next day. If I don't respond to your replies immediately, don't take offence.
My Homebrewer's Signature
-
2015-06-08, 06:27 PM (ISO 8601)
- Join Date
- Oct 2012
- Location
- In the Playground, duh.