top of page

How I Used Design Patterns in Arcane Lands (Part IV)

  • Writer: Justin San Juan
    Justin San Juan
  • Oct 28, 2019
  • 1 min read

Composite Pattern

Following the concept of Loot Tables in Loot Tables in Daniel Cook's Blog here , I apply the structural design pattern called Composite to implement ILootItem and LootTables.

Each ILootItem would have a private ItemCard and BaseWeight, as well as a public Weight. It also has main functions: Insert(), GetResult(). Decrement() and GetTotalWeight() are shown just for reminder purposes.

Insert() allows LootTables to have multiple ILootItems in its Loots reference. GetResult() for a basic LootItem would then only return its ItemCard, while a LootTable will randomly select an ILootItem from its Loots array and return that ILootItem’s GetResult(). This inheritance-based composite effectively allows LootTables to reference inner LootTables.

Comments


Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square

JUSTIN SAN JUAN ♦ 526L, UG Hall I, HKUST, HK ♦ (+852 9815 5514)

  • facebook
  • LinkedIn Social Icon
  • close-envelope

©2017 BY JUSTIN SAN JUAN. PROUDLY CREATED WITH WIX.COM

bottom of page