Submission 5: Arrays
Objective:
Incorporate arrays into your game to manage collections of related data, such as an inventory system. Arrays enable you to store and manipulate multiple items of the same data type, which is essential for handling lists or sequences in programming.
Instructions:
Implement an Inventory System:
Create an Array for Inventory:
Declare an array to hold items that the player can collect during the game. Decide on a reasonable maximum size for the inventory.
Add Items to Inventory:
When the player acquires an item, add it to the array. Ensure you keep track of the number of items currently in the inventory.
Prevent Overfilling:
Implement logic to check if the inventory has space before adding a new item. Inform the player if the inventory is full.
Display Inventory:
Create a Function to Show Inventory:
Develop a function that iterates through the inventory array and displays the items to the player. Include this option in the game menu.
Provide Item Details:
Along with item names, consider displaying additional information such as item descriptions or quantities, if applicable.
Handle Inventory Limits:
Manage Inventory Capacity:
Ensure that your program correctly handles cases where the inventory reaches its maximum capacity. This might involve removing items, denying new items, or expanding capacity (advanced).
User Feedback:
Clearly communicate with the player regarding the status of their inventory and any actions they can take if it's full.
Submission Requirements:
An updated program that uses arrays to manage the player's inventory.
Functions to add items to and display the inventory.
Proper handling of array indices to avoid errors such as out-of-bounds access.
Code is well-commented, explaining how arrays are used within the game context.
Example:
Example
COSC-1336 / ITSE-1302 Computer Science - Author: Dr. Kevin Roark