Search Unity

How to create turn base system for tic tac toe game

Discussion in 'Multiplayer' started by alexdevAo, Feb 4, 2020.

  1. alexdevAo

    alexdevAo

    Joined:
    Apr 26, 2013
    Posts:
    30
    Hello people
    I'm doing the multiplayer tic tac toe game. I already made the intelligence system against the bot. But now I plan to do multiplayer. I'm using the photon network. I don't know where it starts. I need to make the system to check which is the player's turn to play.

    Any idea?
     
    TheDevloper likes this.
  2. MrsPiggy

    MrsPiggy

    Joined:
    Jun 13, 2018
    Posts:
    154
    I am familiar with the implementation done in SmartFoxServer. It's the same game but the logic is implemented on the server side, which is better, since client side logic is vulnerable to cheating.
    If you're just looking for the game logic you can take a look at their tutorial:
    http://docs2x.smartfoxserver.com/ExamplesUnity/tris
     
  3. alexdevAo

    alexdevAo

    Joined:
    Apr 26, 2013
    Posts:
    30
  4. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
  5. alexdevAo

    alexdevAo

    Joined:
    Apr 26, 2013
    Posts:
    30
    @Tiny-Tree I haven't found any tutorial that talks about photon turn based.
    But thanks
     
  6. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
    before jumping into networking you need to learn how to implement script into your game, learn basic c#
     
  7. tenzolinho

    tenzolinho

    Joined:
    Jul 26, 2019
    Posts:
    6
    alexlukanga did you find a proper tutorial for turn based system? I am interested as well and there is a lack of information on the Internet regarding this topic ...
     
  8. alexdevAo

    alexdevAo

    Joined:
    Apr 26, 2013
    Posts:
    30
    I didn't find anything on the internet. I had to develop it myself.
    See the final result here -> Jogo do Galo Multiplayer - Tic Tac Toe Demo - YouTube
    It's very simple. Just work with CustomProperties
     
    Last edited: Jan 19, 2021
    tenzolinho likes this.
  9. tenzolinho

    tenzolinho

    Joined:
    Jul 26, 2019
    Posts:
    6
    alexlukanga But you know what I don't understand? How can I pass the turn to the other player.
    Let's say one player is the chosen to start and he will have a CustomProperty ("Turn", true). He does stuff x, y, z and then how can he pass the turn to the next player? Just modify his CustomProperty to ("Turn", false) and modify also another's player Custom property to ("Turn", true)? Could this work? (I'm asking because I want to create a boardgame and I have more than 2 players)
     
    Last edited: Jan 19, 2021
  10. alexdevAo

    alexdevAo

    Joined:
    Apr 26, 2013
    Posts:
    30
    Using customProperties and OnPlayerPropertiesUpdate

    Code (CSharp):
    1.  
    2.  
    3. // Create a player Properties
    4.  
    5. ExitGames.Client.Photon.Hashtable playerProperties = new ExitGames.Client.Photon.Hashtable ();
    6.  
    7.  
    8. // When a player plays, the turn changes
    9.  
    10.  turn = newTurnValue
    11. playerProperties.Add ("Turn", newTurnValue);
    12. PhotonNetwork.LocalPlayer.SetCustomProperties (playerProperties)
    13. ´
    14.  
    15. // On callbacks, this method is called for all players
    16. void OnPlayerPropertiesUpdate (Player targetPlayer, Hashtable changedProps)
    17. {
    18. if ((int) targetPlayer.CostumeProperties ["Turn"] == newTurnValue))
    19. {
    20. // Will be updated for all players in the room
    21. turn = newValueTurn;
    22. }
    23. }
     
    corneliusgames2k and tenzolinho like this.
  11. tenzolinho

    tenzolinho

    Joined:
    Jul 26, 2019
    Posts:
    6
    I see, thanks a bunch!
     
  12. Nikil07

    Nikil07

    Joined:
    Jul 6, 2020
    Posts:
    2
    Sorry, but how would I do the same using Mirror instead of Photon?
     
  13. Senthil2k2

    Senthil2k2

    Joined:
    Jul 4, 2022
    Posts:
    1
    I want to create tictactoe game with multiplayer using Mirror Networking. I am finding lack of internet reference. Can please you help me out on this ?
     
  14. oceanofsoftwares3

    oceanofsoftwares3

    Joined:
    Nov 17, 2021
    Posts:
    3
    You can actually try to go to the mirror forum and ask there. Thank You :)
     
  15. oceanofsoftwares3

    oceanofsoftwares3

    Joined:
    Nov 17, 2021
    Posts:
    3


    It's very good. But can you tell me what are these turn and new turn variables? Thank You