How to switch turns ?

Options
Mamul
edited November 2013 in DotNet
I want to know how to make this.For example Player1 starts he does something his turn finished its player2 turn.It seems a bit hard to me.I would appreciate any help!

Comments

  • Tobias
    Options
    If you don't mind, I would suggest you use Unity and Photon Unity Networking with that. In there, we implemented "RPC"s and those are very simple to use and a fine fit for your turn-based game.
    In the LoadBalancing API you can use OpRaiseEvent and or set a Custom Property for your room. The first would send your turn, the second would make the server remember that your turn was done.
  • Tobias wrote:
    If you don't mind, I would suggest you use Unity and Photon Unity Networking with that. In there, we implemented "RPC"s and those are very simple to use and a fine fit for your turn-based game.
    In the LoadBalancing API you can use OpRaiseEvent and or set a Custom Property for your room. The first would send your turn, the second would make the server remember that your turn was done.

    Thank you for the reply.I'm using OnPhotonSerializeView but I'm not sure if it works.Can you look at the code tell me if I have mistakes.
    [code2=csharp]using UnityEngine;
    using System.Collections;

    public class SwitchTurns : Photon.MonoBehaviour {

    public static bool Player1Turn;
    private static bool Player2Turn;
    private PhotonView photonView;
    private bool receiveData;
    private bool sendData;


    // Use this for initialization
    void Start () {
    if(PhotonNetwork.isMasterClient){
    Shooting.isMyTurn=true;
    }
    else{
    Shooting.isMyTurn=false;
    }


    }
    // Update is called once per frame
    void Update () {
    sendData=Shooting.isMyTurn;



    }

    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)

    {
    if (stream.isWriting)
    {
    //We own this player: send the others our data
    stream.SendNext((bool)sendData);
    Debug.Log("Streaming!!!");
    }
    else
    {
    //Network player, receive data
    receiveData = (bool)stream.ReceiveNext();
    Debug.Log(receiveData);
    }
    }

    void switchTurns(){
    if(Shooting.isMyTurn==true){
    //enable the script FirstPersonControls
    Debug.Log("It's my turn!");
    }
    else{
    //disable the script
    Debug.Log("Not my turn!");
    }

    if(Player2Turn){
    //enable the script FirstPersonControls
    }
    else{
    //disable the script
    }
    }

    }[/code2]

    So the idea is if I'm the masterclient I'll be the first one.When I finish my turn isMyTurn will be false and I send it to the other player .But it doesn't show me "Its my turn" and streaming.
  • Tobias
    Options
    You should read the Marco Polo Tutorial and make sure your script is on a GO together with a PhotonView. Drag and drop the script on said GO to the "Observed" field of the PV and try again.
    http://doc.exitgames.com/photon-cloud/M ... o_Tutorial
  • Thanks Tobias it worked :)