QuestionQuestion

3.9 Game mechanics
The last task is to construct the basis of a simple game mechanic.
The mechanic will involve two opponents fighting each others – if you feel at all uncomfortable with this, you may change the parts you do not like. You could, for instance, make this about cars avoiding obstacles or horses trying to jump over fences. The important part is that the behaviour is the same.
We are also not giving you a class diagram or any of the classes as such. In this task you must define what classes with what properties and behaviours are useful to solve the task. To help you, we will provide you with a description of what the game is about as well as a print out of a possible test run of the program.
You will probably need to make assumptions, and that is okay.
The important part is that you think in an object oriented way in your solution.
In this game there will be heroes and enemies fighting each others in a fantasy environment. The fighting mechanics is loosely based on old time role playing games where ordinary six sided dice were used to decided the outcome of an encounter. Both heroes and enemies have a set of dice for attacking and defending themselves.
The difference is that the hero uses six sided dice while we want the enemy to only have five sided
dice (most of the time we want the hero to win). In a fight the attack of one part is set against the defence
of the other part. The number of dice for each property must be set at instantiation.
An example, an hero has three dice for attack and with them he hits 9 (for example 3 + 5 + 1). The enemy has four dice for defence and with them he hits 8 (for example 1 + 4 + 2 + 1). This means that the attack from the hero goes through and the hero can roll damage. Damage is done in the same way, namely with a number of dice. The number of dice is decided by the weapon that the hero has. There can be any number of weapons in the game, but they are all having the same basic structure; a name and a power which is the number of six sided dice to roll for the damage. As the hero in our example hit the
enemy, the damage from the weapon is calculated, for example if the power of the weapon is three, three six sided dice are rolled – say to 8 (1 + 6 + 1). This amount is reduced from the XP (experience points) that the enemy has. If the number of XP is below zero, the enemy is
defeated. When it comes to weapons, only heroes can have them, with the emphasis on can, as they can be without weapons. An hero can pick up a weapon and then, and only then, does he/she have the weapon. If the hero does not have a weapon, the damage should be a random number between two and four. The enemies do not carry any weapons at all and therefore only has a simple random number between 1 and 14 for damage.
Sketch on the classes needed (you don’t need to hand your sketches in) and what each of them need to be useful (and provide the behaviour necessary). The classes need constructors and it is quite okay to only create constructors with parameters.
Notice that you may not use inheritance in this task as we have not covered that yet.
A part from the different classes you also need to provide a class with a main method called GameManager.java in which you prove that the classes work by creating one hero and one enemy
and at least one weapon. The opponents should fight each others in a number of rounds (where each round is one attack from the hero, defence from the enemy, one attack from the enemy and defence from the hero). You may include more, but you must show at least one fight till one of the opponents is defeated. You can look at the following example run of a test program to know more or less what you need to provide. In the example, Lord Gurka is the hero and Prince Purjo is the enemy. The hero has a weapon, a Steel Sallad, that he uses to fight the prince. By commenting out that Lord Gurka is using the weapon, he is instead using his fists.
Lord Gurkan has 50 XP and a Steel Sallad to fight with.
Prince Purjo has 30 XP and uses his fists to fight with.
Round 1:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 2:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 3:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 4:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 5:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 6:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 7:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 8:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 9:
Lord Gurkan gives Prince Purjo a powerful blow!
Prince Purjo is still alive!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 10:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo manages to hit Lord Gurkan!
Lord Gurkan is still well and kicking!
Round 11:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 12:
Lord Gurkan gives Prince Purjo a powerful blow!
Prince Purjo is still alive!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 13:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 14:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo manages to hit Lord Gurkan!
Lord Gurkan is still well and kicking!
Round 15:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo manages to hit Lord Gurkan!
Lord Gurkan is still well and kicking!
Round 16:
Lord Gurkan gives his all, but Prince Purjo dodges!
Prince Purjo tries his best but Lord Gurkan dodges the blow!
Round 17:
Lord Gurkan gives Prince Purjo a powerful blow!
Prince Purjo is defeated!

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/**
*
* @author
*/
public class GameHero {

    protected String name;
    /**
    * Both heroes and enemies have a set of dice for attacking and defending
    * themselves. The difference is that the hero uses six sided dice while we
    * want the enemy to only have five sided dice (most of the time we want the
    * hero to win).
    */
    private final int diceSide = 6;
    protected int HP;
    protected GameWeapon weapon;

    /**
    * constructor
    *
    * @param name
    * @param HP
    * @param weapon
    */
    public GameHero(String name, int HP, GameWeapon weapon) {
       this.name = name;
       this.HP = HP;
       this.weapon = weapon;
    }

    /**
    * getter
    *
    * @return name
    */
    public String getName() {
       return name;
    }

    /**
    * get weapon
    *
    * @return
    */
    public GameWeapon getWeapon() {
       return weapon;
    }

    /**
    *
    * @return hero's status
    */
    public boolean isAlive() {
       return HP...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$35.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats