COMP1400 – Programming for Designers

Class announcements for Programming for Designers

COMP1400 – Programming for Designers random header image

Assignment 1: RPG Player

Posted by on August 1st, 2011 · Assignments

NOTE: This assignment is for COMP1400 students ONLY.

If you are an INFS1609 or 2609 student you should look at the assignment on the INFS1609 blog.

Due Date: Friday week 5 (23:59:59 19 August 2011)

Your first assignment is to implement a class to represent a simple player in a role-playing game like World of Warcraft. Your class will need to implement the following features:

  • A health counter which drops as the player takes damage.
  • A potion counter which can be spent to heal damage.
  • An attack method to allow players to hit each other with weapons.

Background

To start the project, download the BlueJ package for Assignment 1. In it you will find three classes:

  • Weapon – This class represents a weapon in the game which has a random chance of hitting and doing damage.
  • Battle – This class implements a fight to the death between two players.

You should NOT change the source of either of these classes. Your job is to create a third class, Player, which represents a player.

The Weapon class

A Weapon implements a constructor and two public methods:

  1. Weapon(int hit, int dam) – a constructor. The first argument is the hit probability (a percentage) the second is the maximum damage it will inflict.
  2. hit() – which returns true if the weapon successful hits the opponent
  3. damage() – which returns the amount of damage done (in health points)

The Battle class

A Battle implements a constructor and one public method:

  1. Battle(Player p1, Player p2) – creates a battle between the two designated players
  2. fight() – The two players fight until one of them is dead.

Implementing the Player

Your task is to implement the Player class needed to make the Battle work.

Your class should include the following parts:

State

Each player needs to track the following state:

  • The player’s name.
  • The player’s current health as an integer.
  • The player’s maximum health.
  • The number of potions the player is carrying.
  • The player’s current weapon.

Constructor

You will need to implement a Player constructor with parameters:

  1. The name to give the player
  2. The player’s initial health (which is also their starting maximum health).
  3. The player’s weapon.

The player’s number of potions should be initally zero.

Accessor Methods

You will need to implement four accessor methods:

  1. getName() which returns the player’s name.
  2. getHealth() which returns the player’s current health.
  3. isAlive() which returns a boolean that is true if the player’s health is greater than zero.
  4. getPotions() which returns the player’s number of potions

Mutator methods

You will need to implement four mutator methods:

  1. takeDamage(int damage) which reduces the player’s heath by the specified number of points
  2. gainPotion() which adds a potion to the player’s inventory
  3. drinkPotion() if the player has any potions, this method should use one up to add 10 points of health to the player (but the health should never excede the starting health given in the constructor)
  4. attack(Player victim) is more complex than the rest. It should
    1. Call the hit() method on the player’s weapon to see if it hits.
    2. If it was successful, call the damage() method on the weapon to determine the damage.
    3. Call takeDamage() on the other player to cause this amount of damage.
    4. Return the amount of damage done (zero if the weapon did not hit).

Marking

Your mark will be based 50% on the correctness of you code and 50% on style.

Breakdown:

Constructor and Accessor Methods 25%
takeDamage() 5%
gainPotion() 5%
drinkPotion() 10%
attack() 5%
Style – Layout and Naming 25%
Style – Comments 25%

If the assignment is submitted late, 10% will be taken off the maximum make per day, to a maximum of 5 days.

Submission

We are currently experiencing problems with the submission system. Do not panic if you cannot submit. If the problem persists we will extend the deadline.

You will be submitting your solutions online, by the following steps:

  1. Select “Create Jar File…” In the Project menu in BlueJ.
  2. In the dialog box make sure the “Include source” box is checked.
  3. Press Continue
  4. Save with the filename “ass1.jar
  5. Go to https://cgi.cse.unsw.edu.au/~give/Student/give.php
  6. Login with your CSE username and password
  7. Type COMP1400 in the Course field and press Search
  8. Select ass1 from the list of assignments and press Upload my assignment
  9. Select Browse to locate your ass1.jar file.
  10. Press Submit my files.
  11. Check the response to make sure your submission was processed correctly.

NOTE: You can submit as often as you like. Only the last submission will be marked. Do NOT leave it to the last minute. No sympathy will be given if you leave submission until midnight Sunday and something goes wrong. It is good practice to make multiple submissions as you go.

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.