In this assignment, you will implement a simple MUD (Multi-User Dungeon) Controller that processes basic player commands (e.g. look, move, pick up, inventory, etc.). You will fill in the logic within the MUDController skeleton so that it interacts with the rest of your MUD classes (like Player, Room, Item, etc.) to create a simple, playable command-line experience.
-
Command Parsing:
- Read textual commands (like
move forward,pick up sword,inventory) and identify the main command plus any arguments (e.g.,forward,sword).
- Read textual commands (like
-
Room & Movement Logic:
- When the player types
move forward, the controller should check if the current room has a “forward” connection and move the player there if possible. - If the direction is invalid or blocked, display an appropriate message.
- When the player types
-
Interaction with Entities:
look: Describe the current room (e.g., name, description, items on the ground, NPCs).pick up <itemName>: Search for an item in the room, remove it from the room, and add it to the player’s inventory.inventory: List the items the player is carrying.
-
Help & Exit:
- Display a simple help menu for available commands.
- Allow the user to quit/exit the loop.
-
SOLID & Clean Code:
- Keep your implementation clear, concise, and properly commented.
- Adhere to single-responsibility for each method (no overly massive methods).
-
You Must Use the Provided Skeleton:
- The
MUDControllerclass has placeholders (methods, attributes) with// TODO:comments. - Do not change method signatures or remove essential fields; however, you can add supporting helper methods if needed.
- The
-
Integrate with Existing Classes:
- Make sure the controller uses your existing
Player,Room,Item, etc. - Confirm that
player.getCurrentRoom()gives you the room object where the player stands, which is essential forlook,move, andpick up.
- Make sure the controller uses your existing
-
Minimal Set of Commands:
look– Describes the current room.move <forward|back|left|right>– Moves in a specified direction if possible.pick up <itemName>– Picks up an item from the ground.inventory– Lists items the player is carrying.help– Shows command usage.quitorexit– Ends the loop.
-
Handle Errors Gracefully:
- If a direction is invalid, print “You can’t go that way!”
- If an item doesn’t exist in the room, print “No item named X here!”
- If a command is unknown, print “Unknown command.”
-
Write at Least Basic Tests or a Main Method:
- Make sure you can compile and run your code, then enter commands to test each feature.
-
Start with the Skeleton
- Open
MUDController.javain your editor. - Note the attributes (
player,running) and the methods (runGameLoop(),handleInput(...),lookAround(), etc.).
- Open
-
Implement
runGameLoop()- Create a simple loop that repeatedly reads user input and calls
handleInput(...). - If the user types
quitorexit, setrunning = falseto break the loop.
- Create a simple loop that repeatedly reads user input and calls
-
Implement
handleInput(...)- Split the command line into
[command, argument]. - Use a
switch(orif/else) to calllookAround(),move(...),pickUp(...), etc.
- Split the command line into
-
Implement the Command Methods
lookAround(): Print the current room’s description (room.describe()), occupant info, etc.move(String direction): Check room connections (e.g.,getForward()). If valid, update the player’s room; else print an error.pickUp(String arg): Parse out the item name, remove the item from the room, add to player inventory.checkInventory(): Loop through the player’s inventory to display items.showHelp(): Print usage info for each command.
-
Testing
- Write a small
main()class that creates aRoomwith some items, aPlayerin that room, and a newMUDController(player). - Call
controller.runGameLoop()and type commands to see if they behave correctly.
- Write a small
Here’s how your game might look in the console after you implement the controller:
look Room: A small stone chamber Items here: sword, shield No NPCs present
pick up sword You pick up the sword
inventory You are carrying:
sword move forward You can't go that way!
help Available commands:
look move <forward|back|left|right> pick up inventory help quit/exit
(Outputs and wording may differ based on your actual code.)
-
Completeness
- Does your controller handle the required commands properly?
-
Correctness
- Are errors handled gracefully?
- Does
moveonly succeed if there’s a connected room?
-
Code Quality
- Are methods short and readable?
- Are you consistent with naming and minor details like logging messages?
-
Testing Effort
- Have you tested the commands thoroughly?
- Do you demonstrate various scenarios (e.g., picking up a non-existent item)?
-
Implement the methods in
MUDController.javawithout modifying method signatures. -
Provide instructions (or a short
Mainmethod) showing how to compile/run your code. -
Submit your github link to Canvas
-
For extra credit, add at least one new command (like
attack,open door, ortalk) to demonstrate extension.
Good luck, and have fun building your MUD controller!