1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 beta is now available for download.
    Dismiss Notice

Unity Multiplayer BlackJack sample

Discussion in 'Multiplayer Networking' 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
    Hassan-Kanso likes this.
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    628
    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.
     
  3. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    628
    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:
    828
    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:
    628
    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. Annonumous

    Annonumous

    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:
    608
    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:
    52
    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:
    8
    I hope you make a tutorial about this game dev steps