How best to structure code for a card game with map

I’m new to Unreal, but have experience programming in various languages including C++, C#, VB.NET, etc.
I’m trying to re-implement/convert a multi-player game that I previously wrote in VB.NET. It’s a turn-based fantasy game that involves each player having a hand of cards and a common board with characters and objects on it that are affected by the cards.
In my original implementation, I had a number of game classes defined that implemented basic game objects and logic, so things like Cards, Items, Objects, Characters, Floor squares, Walls, etc. These objects were on the server and were also replicated to all clients where the rending logic was implemented.

If I were to do this in Unreal, how would you suggest to organize the code?
I’m nominally thinking that I can re-implement all my game classes in C++, have them derive from UObject and then use Blueprints to get information from these classes to render them (e.g. I would have a “Card” class that has all the properties and information of a card as well as the logic to execute the power of the card when its played, then I would have a “CardWidget” Widget implemented in Blueprints that would take information from “Card” and display it, as well as trigger the Card’s “OnPlayed” event, which would have been implemented in the “Card” definition.

If I do this, should my “Cards” and other game objects all be attached to the GameState to ensure they’re replicated to clients? Also, do I need the game objects to inherit from UActor rather than UObject in order to be replicatable?

I’ll appreciate any advice you can give me.
Thanks.

Hi there,

If I were you I would probably start with the Game Mode, the Player Pawn and the Level to create the turn based nature of the game. Start requesting end turns, etc.

UObjects are just registered with the garbage collector. Unlike AActor they have no representation in game (no position), no components and can’t be replicated. (unless you add all that that manually). I would suggest to use actors for almost everything except maybe for some data only objects.

Also which part of the game do you actually need replicated? In terms of communication I can imagine you can make the game with only RPCs and Multicasts. In my head you have only 3 maybe 4 actions none of which need replication:

  • End turn player has ended a turn
  • Draw a card / request next card from the server
  • Play a card (at a slot maybe) / try playing card from hand

You can replicate trivial things like the turn time remaining, the health maybe, the number of cards in hand etc. but I don’t see it as vital for the game-play at least in the begining.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.