I'm a self-taught Engineer, a beginner in Java and I am trying to create a Dungeons and Dragons character creation module for a bigger game to solidify my understanding of core concepts while learning best practices for given scenarios. I have an implementation outline below, but I believe that there are better design choices that I could make.
I am trying to follow SOLID and Composition over Inheritance; I think this plan follows those concepts.
How can I make this implementation design better?
Implementation
It would contain
An Interface for character that contain getters and setters for Name, Age, Height, etc...
An Interface for character races to encapsulate racial traits into a portable template
Multiple classes that implement the Character Interface and the Race Interface for the goal of creating the Character and Class(RPG) of the Character via a Class Factory.
- This May be a lot of classes to define due to the possibilities of combinations. Is there a better way to instantiate a character object which abstracts the Class and Race into one object.
A Class Factory class would have 2 arguments, one for Race and one for Class to create a character object and a switch case statement would take the Race and the Class to determine the Race-Class combination and return a race-class object (character).
- Same bottle-neck as above.
The Execution
- The Main class would take user input for the character's Race and the character's Class to call the Class Factory which returns a character object.
- It might be worth creating a character abstract class that I can use to extend the unique class combination classes so it is easier to understand when handling the character objects.
Like so:
Character character = new ElfWizard();
Then it would prompt the user for the characters Name which will be used to call a Setter method for the character.
Prompts again for the size specifications(Tiny, Small, Medium, Large, Extra Large) which will also call a setter.
- Dependening on Race, size choices will be limited via some conditional flow.
Base attribute stats at 10 and gives stat points for allocation with a hard cap at 20 which call setters for each input provided.
- May be tricky to implement in a console application. It would be cool to find out how to do this.
Then calls the character object methods for abilities to test.
Summary of Concerns
Is there a better way than sticking everything in Main? Would it be better to create a Character Creation class which will be instantiated in main to call a user creation method which prompts the user for input to create the character object and then prompts for inputs to set the character info?
Are there any current UI frameworks that I can use to prompt input instead of the Console?
I have interest in transforming this into a API later to store values into a database. This is so that I can create a Web Application to work with these methods.
Thank you for any feedback.
ElfMage
fromHumanMage
fromHumanCleric
fromGnomeCleric
fromDwarfFighter
and so on. So much simpler is to consider a character's race and class as just data.Character
which isn't even very object-oriented, just a class with public data members and no functions (just a data aggregate). And you can model all the data you need likestr
,dex
,int
,wis
,cha
, the name of the character, their race, their class (possibly dual-class), maybe their backpack/inventory, things like that -- just data. Then a separate subsystem in you codebase might enforce rules like that dwarves have +2 to their constitution and have size constraints.Character character = new Character(Race.Elf, CharacterClass.Wizzard);