Submission 6: Structures

Objective:

Introduce structures to define complex data types, enabling you to represent detailed game entities like items, characters, or enemies. Structures allow you to group related variables under one name, providing a way to manage more intricate data and enhance the richness of your game.

Instructions:

  1. Define a Structure:

    • Create a Struct for Items:

      • Define a structure that represents an item in your game, including attributes such as name, description, and any relevant properties like power or value.

    • Initialize Game Items:

      • Create instances of these structures to represent different items that can be found or used within the game.

  2. Use Structures in the Game:

    • Modify Inventory to Hold Structures:

      • Update your inventory array to store these item structures instead of simple data types like strings.

    • Add Structured Items to Inventory:

      • When the player acquires an item, add the corresponding structure to the inventory array.

  3. Interact with Structured Data:

    • Update Inventory Display Function:

      • Modify your function that displays the inventory to include the additional details provided by the item's structure, such as descriptions or stats.

    • Utilize Item Attributes:

      • Incorporate the attributes of items into gameplay mechanics. For example, an item's power could affect combat outcomes or unlock new areas.

  4. Player or Enemy Structures (Optional Advanced Feature):

    • Create a Struct for Characters:

      • Define structures for the player and potential enemies, including attributes like health, strength, and defense.

    • Implement Character Interactions:

      • Use these structures to manage interactions such as combat, where the attributes influence the results of encounters.

Submission Requirements:

  • An updated program that defines and uses at least one structure.

  • The inventory system now stores and manages structured item data.

  • The game correctly manipulates structures and accesses their attributes.

  • Code is well-commented, explaining how structures enhance data management and gameplay.

Example:

 

image-20240921-221829.png

 

COSC-1336 / ITSE-1302 Computer Science - Author: Dr. Kevin Roark