From the course: Object-Oriented Programming with C#
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Creating a chest - C# Tutorial
From the course: Object-Oriented Programming with C#
Creating a chest
- [Lecturer] It's time to create an item that contains other items. The Chest will extend item but implement the IInventory interface as well so we can leverage all the same APIs. This way we can have a Chest inside of a room that contains additional items. Let's create a new class called Chest. The Chest is going to be our first item in the game so we'll make a public class that extends item and we'll have it implement the IInventory interface. Before we have Visual Studio add all of the properties and methods from the interface, let's go ahead and add a few fields. The first field we're going to create is a reference to the house. We'll use this to find the player and add items to the player once they take them out of the Chest. The second field is going to be an inventory and we'll create a new instance of the inventory. Now that we have our field for the inventory, we can go ahead and implement all the other methods…