0
\$\begingroup\$

So I am making a game with a similar content progression to Clash Royale. Essentially u have ranking points (Identified as Trophies), and the number of trophies you have will determine what content you will have access to in the game. So for example every 100 ranking points, you will be able to find new types of cards in chests, new chests in general or new maps. In my game, I want it to be somewhat similar, but I also have some other data that changes based on rank points that is more specific to my game, such as army supply. I'm trying to figure out how I can implement this in a manageable way.

Maybe this is overkill, but this is my design so far:

enter image description here

Basically I have my RankContentItemBase class which has a ranking points int and an IsUnlocked method that returns whether or not the passed in rank is > than the rank passed in. Then I extend this with classes with classes that add the data type I wanna work with (Int, Troop, Map, w/e).

I then have a Generic base container class that has a method for getting all unlocked item in the list of T contents that is extended to contain the concrete RankUnlockItembase types.

I've basically structured things this way so it's easy for me to add new types of items that I want unlocked by rank without having to do much work. Also it prevents things from being coupled together.

Just curious what ppl think of this setup, and what kinda setup you would go with? One concern I have with this design was that if I wanted to see whether a troop was unlocked or not, I can't just say troop.IsUnlocked(). Instead I have to create a new means of determining whether or not a troop is unlocked yet, like for example maybe a method on the RankUnlockedTroopContainer that determines this. Maybe this is ok? I feel like I'm sacrificing simplicity for the sake of maintainability/flexibility.

Thanks

\$\endgroup\$
2
  • 1
    \$\begingroup\$ It looks to me like you have a working solution here. Have you experienced any specific pain points with this solution that we can help you solve? If not, and the code is performing its task correctly as-is, and you just want open-ended feedback on your approach, the Code Review StackExchange would be a more appropriate place to ask instead. \$\endgroup\$
    – DMGregory
    Jul 9, 2020 at 0:19
  • \$\begingroup\$ @DMGregory Hi DMGregory, I probably would have posted in code review, however since my question was unity specific, I thought it wouldn't get much attention there. One concern I have with this design was that if I wanted to see whether a troop was unlocked or not, I can't just say troop.IsUnlocked(). Instead I have to create a new means of determining whether or not a troop is unlocked yet, like for example maybe a method on the RankUnlockedTroopContainer that determines this. Maybe this is ok? I feel like I'm sacrificing simplicity for the sake of maintainability/flexibility. \$\endgroup\$ Jul 9, 2020 at 1:09

1 Answer 1

2
\$\begingroup\$

When you have a data-structure which fits your design workflow but is bad for runtime, then you always have the option to convert it into a more runtime-appropriate data structure at game startup.

Your current architecture seems to allow you to quickly see which rank unlocks what content. But you might also require the reverse: On which rank is a specific piece of content unlocked?

You can easily enumerate that information at startup by going through all the ranks and determining the unlock-rank for each item. That information could be stored in RankUnlockedItemBase, or it could be stored in a lookup-table (Dictionary<RankUnlockedItemBase, int>).

You could also use this as an opportunity for a sanity-check. Currently it looks to me as if nothing stops you from adding the same item as an unlock to multiple ranks. This could easily happen if you move a lot of items around between ranks over the course of your development. This could lead to confused players at best and weird bugs at worst. So this would be a good opportunity to log a warning if a piece of content gets a rank assignment even though it already has one. And after finding the unlock rank of each item, you can check if there are any items which are unobtainable because they don't have an unlock-rank and also log that as a warning.

\$\endgroup\$
1
  • \$\begingroup\$ Hey, thanks for the suggestion philipp and thanks for improving my question! It really helps me understand more clearly what I'm trying to express. You mentioned that my architecture allows me to see which rank unlocks what content (GetAllUnlockedItemsUpToRank()?) but not what rank a specific item unlocks. My RankUnlockedItemBase already stores the rank the content is unlocked, so I think that problem is already solved? Were you perhaps referring to getting the rank of a type of item? Like the troop for example? Because that would make more sense to me. \$\endgroup\$ Jul 9, 2020 at 18:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .