feat(model): track visited rooms on Player for the map
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,9 @@ import lombok.Setter;
|
||||
import thb.jeanluc.adventure.model.item.Item;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The player avatar. Tracks the current room, an ordered inventory, and a
|
||||
@@ -15,9 +17,11 @@ import java.util.Optional;
|
||||
public class Player {
|
||||
|
||||
/** Room the player is currently standing in. */
|
||||
@Setter
|
||||
private Room currentRoom;
|
||||
|
||||
/** Ids of rooms the player has entered, in first-visit order (for the map). */
|
||||
private final Set<String> visitedRoomIds = new LinkedHashSet<>();
|
||||
|
||||
/**
|
||||
* Inventory keyed by item id. {@link LinkedHashMap} keeps insertion
|
||||
* order for stable {@code inventory} listings while still providing
|
||||
@@ -44,6 +48,17 @@ public class Player {
|
||||
}
|
||||
this.currentRoom = startRoom;
|
||||
this.gold = startGold;
|
||||
this.visitedRoomIds.add(startRoom.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the player into a room and records it as visited.
|
||||
*
|
||||
* @param room the room now occupied; must not be null
|
||||
*/
|
||||
public void setCurrentRoom(Room room) {
|
||||
this.currentRoom = room;
|
||||
this.visitedRoomIds.add(room.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user