BlackJack sample

Attached is a sample project that is a multiplayer black jack card game written using the UNet HLAPI. It uses the Unity UI system, but the user interface is very primitive.

It is missing some features, such as “spit” and “double down”, but the game is functional multiplayer blackjack.

There is a CardManager object in the scene that handles the game turn states and which player’s turn it is.

There are Player objects for each player.

There is a special player object for the dealer - which not associated with a client. Players use commands to perform actions on the server such as “Hit Me”.

Each player has an attached “playerPanel” UI object that holds their cards.

There is a button panel on the right that has buttons that enabled based on the current player and turn state.

The cards themselves are not networked game objects, they are just structs that identify the particular card.

This is of course not the only way to make a card game with Unity, but hopefully it will serve as a useful framework.

2460788–169242–cardsbj.zip (738 KB)

3 Likes

Very nice!

It will be interesting to compare this with a multiplayer connect4 game I am currently working on and see if I’m working along the right lines.

1 Like

One thing that immediately stands out is that whilst I’m using [SyncVar], [Command] and [ClientRpc] attributes I haven’t found the need to use any [Server] or [Client] attributes on any of my methods and functions.

Does this suggest I’m missing something important in my understanding of how UNet works?

Client and Server attributes are a security measure. In this way if you try to call a method decorated with [Server] on client, the code will not execute and in editor a warning will be issued. It’s a good thing to use them.

Okay, so I’m not actually missing out on any networking functionality though, just the extra security and visual clarity that those code tags give?

I’ll start using them in that case, thanks for the info.

.

I wanna understand the code that is written in this game.
Can you give me the referenced video tutorials where each step describe
Thanks in Advance.:slight_smile:

thank you for sharing~:roll_eyes::roll_eyes:

Holy moly! @seanr is alive!

Great Example for networking turn-based game. Thank you so much, @seanr .
I’m not completley through in your coding, but i have a couple of questions for now.

  1. I’m not that familliar with network messages. Could you please explain what does the function OnCardMsg() in CardNetworkManager really do?
  2. Why do you use a hook function OnMoney() in Player script, that changes the money amount for all the players if somebody makes a bet? Is it not better to place the money amount for each player on it’s own playerPanel and then use the hook function? Or just update the money amount in CardsManager localy?
  3. How long did it take for you to make this game?

I’m also very new to this project and also to the whole networking but for your question 2 the hook-function is not called on every player but on every client. If the money changes for that special player (gameobject) then it gets synchronized to the same gameobject on the other clients. Then the hook is called but also only on that gameobject (not on ALL player gameobjects) locally and on all clients so that the money is updated in the GUI.

Maybe I’m completely wrong here but htis is how I understand it so far.

I hope you make a tutorial about this game dev steps

Let me know if you find anything good in 2018…
Yeah I know it’s 2018 now, but I am going back to basics, and trying out different methods and samples to find a good one to build on too. I tried Netmarble’s newest update of Marvel Future Fight (made with Unity), and I’m disappointed, they have even more problems with app crashing, and not much has been improved in gameplay, content or graphics. Their main problem is that they use an extremely complicated and highly secure setup. If the app even loses focus, the server will disconnect you and the app will reset (or crash), that’s intentional to maintain security, or supposed to be. I’m looking to these types of samples to build on.

will be nice to update the project with the new functionalities, it’s hard to implement a game controller like a card-based game without any example v.v

Seanr hasn’t worked for Unity for a while now, so it is unlikely he will be posting any updates to this project.

It is an old topic but is working for me, I need to update the library for mirror.

7708459–966076–black_jack.zip (5.27 MB)

2 Likes