Tuesday, September 6, 2016

JAVA 19 - RPG Character Class

The following example is a class which allows you to create a role playing (RPG) character.  Below are the rules ...

Character attributes and skills
Character are given a name on creation, they are also set the following attributes,
  • Fighting - how good they are at close combat
  • Shooting - how good they are at ranged combat
  • Strength - how hard they can hit/pull back a bow
  • Health - their maximum health

In addition, they can have a list of skills or advantages that they've gained.
Character Level And Experience
All characters start at level 1, and as they go through they gain experience (XP).
Characters can spend 1000 XP to "level up" where they can either,
  • Increase an attribute by 1, to a maximum of 18.
  • Add a skill/advantage

This will increase their level by 1.
Taking damage/recovery
Characters have a status called current health.  This can only ever be the maximum of their health attribute.  However if they take damage, it will decrease.
If it falls to 0, they die.  However characters with the "cheat death" skill can fake their death, they have a 50% chance of being only mostly dead, and merely pining for the ffordes.  In which case they retain their last health point.
Characters can regenerate, gaining 2 x D6 current health back.  But this costs 100XP.  So don't spent it all, keep some in reserve.

Not surprisingly, this is our most complex piece of code yet ...

Attributes


Constructor



Not surprisingly, the constructor sets much of the attributes.  After creation, fighting/shooting/strength/health can only be changed through experience.

Print character sheet

It's useful to be able to see all the attributes ...


Add experience

Pretty simple - this adds experience to the character's pool.


Level up

Probably our most complex method to date - first of all it makes sure you have the 1000 experience to do this.

Then, if you've selected "Fighting", "Shooting", "Strength" or "Health", and these values are below 18, then they're increased.  In the case of health, your current health is also increased.

If you provide something other than these keywords, it assumes you are adding a skill, so adds to the list of skills.

You then have 1000 experience deducted, and your level increased by 1.



Add skill method is defined here ...


Wounds/healing/regeneration

Finally we have taking a wound, healing and regeneration, which are all here.  By now you should be getting good at reading this ...












The Disney Avenger Initiative

The world of the Disney comics is under threat from a whole lot of extraterrestrial threat - yeah, worse than this guy ...


So, agent Cobra Bubbles is calling in his own Avengers Initiative, and recruiting people with extra-ordinary abilities to be Planet Earth's first line of defense!



I'm going to use @Test methods to simulate some familiar Disney heroes for this RPG.

Mulan


Thanks to her extensive training, she is a highly skilled warrior,

  • Her fighting skill increases twice
  • She is proficient at cross-dressing
  • She has the martial arts skill
  • She is resilient, not taking defeat easily
  • She is a natural leader



Merida


A deadly shot with a bow, to put Robin Hood to shame ...



Tinkerbell


One of the lowest characters in terms of health, however her high strength reflects the increased damage from her magic.

She also has access to a magic wand and can fly.  Don't make her think unhappy thoughts.




Pocahontas

Give the girl a break, she was involved with Mel Gibson at one point.

Pocahontas excels at tracking, running and understanding foreign languages.  She's a pretty mean fighter when she wants to be as well.



Snow White

Because, y'know, kissing a supposedly "dead girl" isn't at all creepy is it?  Seriously, didn't your parents bring you up better than this?

No possum on earth can fake death quite like Snow White, she's also able to make animals do her bidding.  What kind of superpower is that?  I guess you've never seen The Birds then ...



Princess Jasmine



Her strength and health might seem abnormal, but this reflects how her pet tiger Rajah is always by her side protecting her.  She's also borrowed Aladdin's flying carpet.



Princess Ariel


Not only can she breath under water, she's really good at swimming.  She can also talk to the animals ... well the marine ones anyway.  Don't be surprised if her dad's got his very own Kraken - best be on her good side.



Queen Elsa


She has superb powers to control the realm of the ice and snow.  From the midnight sun, where the hot springs flow.

As you're probably aware, the cold doesn't bother her anyway.




The code for this can be found here on Github.

Does this need more tests?

Well, you might have noticed, I've got so swept up in character creation, that there are a lot more @Test methods especially using assertTrue and assertFalse needed to check some of that behaviour.

You're right - it needs them.  And guess who's going to do it?

1 comment:

  1. Millions of dollars from online gambling.
    Gclub Slot It's a web-based online gambling game that is famous. Because the G-Club service. This casino is open for a long time to know the meaning of the gambler's requirements that the gamblers need anything from playing online gambling.

    So, the site team. Casinos have developed a style of online casino games to make it so that online gaming is becoming acceptable and very popular in the current period, all players can. Join the fun and play all online gambling games that you just want to play with only the Internet. You can play the game online every risk that you want to play it.

    Greetings and excitement challenges on the G-Club website. This casino provides online gambling games become a pleasure that the player can not refuse because of the game, all online gambling can make the player rich enough that players can join. Have fun and play the online gambling games that you want to play today at the web today Holiday Palace

    ReplyDelete