-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreasure.java
More file actions
51 lines (49 loc) · 1.36 KB
/
Copy pathTreasure.java
File metadata and controls
51 lines (49 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
*Treasure.java
*Class Treasure contains the methods needed to build a Treasure object in the maze, which is also a random occupant.
*
*@author akramins
*@version 5/13/2013
*/
import java.util.Scanner;
public class Treasure extends RandomOccupant{
private boolean found;
//Treasure constructor builds and sets the treasure of the square it resides in.
public Treasure(Maze maze){
super(maze);
maze.getSquare(location().row(), location().col()).setTreasure(this);
found = false;
}
public Treasure(Maze maze, long seed){
super(maze, seed);
maze.getSquare(location().row(), location().col()).setTreasure(this);
found = false;
}
public Treasure(Maze maze, Square location){
super(maze, location);
found = false;
location.setTreasure(this);
}
//returns whether the treasure has been found.
public boolean found(){
return found;
}
//sets the found value to true.
public void setFound(){
this.found = true;
}
//overrides the move method to do nothing.
public void move(){}
public void moveTo(Square newLoc){
if(super.location().treasure() != null) super.location().setTreasure(null);
super.moveTo(newLoc);
super.location().setTreasure(this);
}
public String toText(char delimiter){
return super.toText(delimiter) + delimiter + found();
}
public void toObject(Scanner input){
super.toObject(input);
found = input.nextBoolean();
}
}