Search Unity

BlackJack sample

Discussion in 'Multiplayer' started by seanr, Jan 12, 2016.

  1. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    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.

    upload_2016-1-12_14-6-53.png

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

    Attached Files:

    Last edited: Jan 12, 2016
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    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.
     
    Honorsoft likes this.
  3. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    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?
     
  4. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,124
    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.
     
  5. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    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.
     
  6. Mr.Mille

    Mr.Mille

    Joined:
    Sep 17, 2015
    Posts:
    21
    .
     
    Last edited: Jan 25, 2016
  7. Anonymous789

    Anonymous789

    Joined:
    Nov 29, 2015
    Posts:
    6
    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.:)
     
  8. buzheteng

    buzheteng

    Joined:
    Feb 29, 2016
    Posts:
    4
    thank you for sharing~:rolleyes::rolleyes:
     
  9. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Holy moly! @seanr is alive!
     
  10. xdimax

    xdimax

    Joined:
    Apr 18, 2016
    Posts:
    1
    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?
     
  11. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    322
    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.
     
  12. khalidhex

    khalidhex

    Joined:
    Apr 13, 2016
    Posts:
    11
    I hope you make a tutorial about this game dev steps
     
  13. Honorsoft

    Honorsoft

    Joined:
    Oct 31, 2016
    Posts:
    81
    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.
     
  14. L0tan

    L0tan

    Joined:
    Jul 16, 2017
    Posts:
    75
    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
     
  15. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Seanr hasn't worked for Unity for a while now, so it is unlikely he will be posting any updates to this project.
     
  16. devcoachecom

    devcoachecom

    Joined:
    Nov 18, 2021
    Posts:
    2
    It is an old topic but is working for me, I need to update the library for mirror.
     

    Attached Files:

    Deleted User and Honorsoft like this.