Explorer - //Is Explorer balanced? public boolean...

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

View Full Document Right Arrow Icon
/** * Class to model an explorer in a maze game. */ public class Explorer{ //Attributes private String name; private Room location; public int strength; public int tolerance; // Constructor /** Create a new Explorer, with name, location, strength, and tolerance. */ public Explorer (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;} /** * If tolerance is equal to strength, the Explorer is balanced. * If tolerance is less than strength, the Explorer is tolerant. * If strength is greater than tolerance, the Explorer is intolerant. */ //Is Explorer intolerant? public boolean isIntolerant () {return strength > 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: //Is Explorer balanced? public boolean isBalanced () {return strength == tolerance;} //Is Explorer tolerant? public boolean isTolerant () {return strength < tolerance;} // 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 (Denizen opponent) { Room oppLoc = opponent.location(); if ((oppLoc!= null) && oppLoc.equals(this.location)){ tolerance = tolerance - opponent.strength; } } /** * 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 Explorer as a String. */ public String toString() { return "Explorer " + name + " at " + location + ", strength: " + strength + ", tolerance: " + tolerance; } }...
View Full Document

Page1 / 2

Explorer - //Is Explorer balanced? public boolean...

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