Denizen - Commands Move to another room public void...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/** * Class to model a Denizen of a maze game. */ public class Denizen { p //Attributes private String name; private Room location; public int strength; public int tolerance; // Constructor /** Create a new Denizen, with name, location, strength, and tolerance. */ public Denizen (String name, Room location, int strength, int tolerance) { this.name = name; this.location = location; location.enter(); this.strength = strength; this.tolerance = tolerance; } //Queries /** What is your name? */ public String name() { return name;} /** Where are you? */ public Room location() { return location;} /** * How strong are you? */ public int strength () {return strength;} /** * How healthy are you? */ public int tolerance() {return tolerance;}
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Commands /** * Move to another room */ public void move (Room newRoom) { location.exit(); //Leave the old room. location = newRoom; location.enter(); //Enter the new room. } /** * Get hit. */ public void takeThat (int hitStrength) { tolerance = tolerance - hitStrength;} /** * Hit--er, poke--back. */ public void poke (Denizen opponent) { Room oppLoc = opponent.location(); if ((oppLoc!= null) && oppLoc.equals(this.location)){ opponent.takeThat(strength); } } /** * Represent the Denizen as a String. */ public String toString() { return "Denizen " + name + " at " + location + ", strength: " + strength + ", tolerance: " + tolerance; } }...
View Full Document

This document was uploaded on 10/23/2009.

Page1 / 2

Denizen - Commands Move to another room public void...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online