Submission 6: Interfaces
Objective: Utilize interfaces to define common behaviors across unrelated classes.
Instructions:
Create an
Interactable
Interface:Methods:
void interact(Player player)
Implement
Interactable
in Classes:NPC
Class:NPCs provide quests or information.
Implement
interact(Player player)
to start a dialogue.
Chest
Class:Represents treasure chests.
Implement
interact(Player player)
to open the chest and collect items.
"NPC" stands for "Non-Player Character."
An NPC is a character within the game that is not controlled by the player but can interact with the player in various ways. NPCs are used to enhance the game's narrative and interactivity. They can provide:
Quests or Missions: Assign tasks for the player to complete.
Information or Dialogue: Offer hints, backstory, or engage in conversations.
Trade Opportunities: Buy or sell items with the player.
Environmental Interaction: Affect the game world in ways that impact the player's experience.
Update the Game World:
Create an
ArrayList<Interactable>
to manage various interactable objects in the game.Place
NPCs
andChests
in different locations.
Modify the Game Loop:
Allow the player to encounter and interact with different
Interactable
objects.Use polymorphism to handle interactions seamlessly.
Deliverables:
Final source code files.
Screenshot of the program running
COSC-1437 / ITSE-2457 Computer Science Dept. - Author: Dr. Kevin Roark