コード例 #1
0
    private void evaluateGuess(clientEvent message)
    {
        int correctGuesses = 0;

        foreach (var index in new int[] { 0, 1, 2, 3 })
        {
            if (message.nouns[index] == answer.nouns[index] &&
                message.verbs[index] == answer.verbs[index])
            {
                correctGuesses++;
            }

            if (correctGuesses == 4)
            {
                clientEvent winner = new clientEvent();
                winner.role = message.role;
                NetworkMessaging.SendJsonViaPOST(winner, "http://35.209.52.72:80/winnerdemo");
            }

            else
            {
                clientEvent numCorrect = new clientEvent();
                numCorrect.correctGuesses = correctGuesses.ToString();
                NetworkMessaging.SendJsonViaPOST(numCorrect, "http://35.209.52.72:80/sendcorrectguessesdemo");
            }
        }
    }
コード例 #2
0
 // Start is called before the first frame update
 void Start()
 {
     playerState.playerRole = "Receiver";
     Debug.Log("Connecting to web socket");
     if (!NetworkMessaging.socketOpen())
     {
         NetworkMessaging.ConnectWebSocketToServerAsync("ws://localhost:8095/connectdemo");
     }
 }
コード例 #3
0
 // Update is called once per frame
 void Update()
 {
     if (NetworkMessaging.socketOpen())
     {
         Debug.Log("Socket is open");
         if (!checkingForMessages)
         {
             Debug.Log("Checking for messages");
             checkingForMessages = true;
             checkForMessage();
         }
     }
 }
コード例 #4
0
    private void resolveMessage(clientEvent message)
    {
        switch (message.msgEvent)
        {
        case "connected":
            playerState.id = message.id;
            roleRequest roleSend = new roleRequest();
            roleSend.role = "Sender";
            roleSend.id   = message.id;
            NetworkMessaging.SendJsonViaPOST(roleSend, "http://35.209.52.72:80/roledemo");
            break;

        case "updateGuess":
            Component[]   guessComponents;
            OutputMessage guessUpdate = new OutputMessage();
            guessUpdate.nouns = message.nouns;
            guessUpdate.verbs = message.verbs;
            guessUpdate.role  = message.role;
            guessComponents   = GetComponents <OutputManager>();

            foreach (OutputManager manager in guessComponents)
            {
                manager.updateGuessWindow(guessUpdate);
            }

            evaluateGuess(message);
            break;

        case "correctGuesses":
            Component[]   correctGuessComponents;
            OutputMessage correctGuessUpdate = new OutputMessage();
            correctGuessUpdate.correctGuesses = message.correctGuesses;
            correctGuessComponents            = GetComponents <OutputManager>();

            foreach (OutputManager manager in correctGuessComponents)
            {
                manager.updateCorrectGuessWindow(correctGuessUpdate);
            }
            break;

        case "gameOver":
            playerState.gameResult = message.result;
            sceneManager.changeScene("Result");
            break;

        default:
            Debug.Log("No matching event found for scene...");
            break;
        }
    }
コード例 #5
0
        /** <summary> Sets the initial references for this script</summary>
         * */
        private void SetInitialReferences()
        {
            //Scripts
            if (GetComponent <NetworkMessaging>() != null)
            {
                mMessagingScript = GetComponent <NetworkMessaging>();
                mMessagingScript.SetIntialReferences();
            }
            else
            {
                Debug.LogError("Missing essential script");
            }

            if (GetComponent <NetworkMigration>() != null)
            {
                mMigrationScript = GetComponent <NetworkMigration>();
                mMigrationScript.SetInitialReferences();
            }
            else
            {
                Debug.LogError("Missing essential script");
            }

            if (GetComponent <NetworkUpdates>() != null)
            {
                mUpdatesScript = GetComponent <NetworkUpdates>();
                mUpdatesScript.SetInitialReferences();
            }
            else
            {
                Debug.LogError("Missing essential script");
            }

            if (GetComponent <NetworkServerSpawning>() != null)
            {
                mServerSpawningScript = GetComponent <NetworkServerSpawning>();
                mServerSpawningScript.SetInitialReferences();
            }
            else
            {
                Debug.LogError("Missing essential script");
            }

            //Classes
            mAccessToken = new AccessToken();

            serverObjects = new Dictionary <string, NetworkIdentity>();
        }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (NetworkMessaging.socketOpen())
        {
            Debug.Log("Socket is open");
            if (!receiverInitialized)
            {
                receiverInitialized = true;
                NetworkMessaging.SendJsonViaPOST(cypher, "http://35.209.52.72:80/initreceiverdemo");
            }

            if (!checkingForMessages)
            {
                Debug.Log("Checking for messages");
                checkingForMessages = true;
                checkForMessage();
            }
        }
    }
コード例 #7
0
    // Start is called before the first frame update
    void Start()
    {
        playerState.playerRole = "Sender";
        step_dropdown          = GameObject.Find("step_dropdown").GetComponent <Dropdown>();
        verb_dropdown          = GameObject.Find("verb_dropdown").GetComponent <Dropdown>();
        noun_dropdown          = GameObject.Find("noun_dropdown").GetComponent <Dropdown>();

        answer.verbs = new string[] { "Push", "Turn", "Turn", "Cut" };
        answer.nouns = new string[] { "Wire", "Dial", "Switch", "Switch" };

        cypher.verbs = new string[] { "Push", "", "Turn", "" };
        cypher.nouns = new string[] { "", "Dial", "", "Switch" };

        Debug.Log("Connecting to web socket");
        if (!NetworkMessaging.socketOpen())
        {
            NetworkMessaging.ConnectWebSocketToServerAsync("ws://localhost:8095/connectdemo");
        }
    }
コード例 #8
0
    public void send_message()
    {
        next_message.step      = (step_dropdown.captionText.text.ToString());
        next_message.noun      = (noun_dropdown.captionText.text.ToString());
        next_message.verb      = (verb_dropdown.captionText.text.ToString());
        next_message.playerId  = playerState.playerId;
        next_message.sessionId = playerState.sessionId;

        message_list.Add(next_message);

        try
        {
            NetworkMessaging.SendJsonViaPOST(next_message, "http://35.209.52.72:80/sendmessagedemo");
        }
        catch (SystemException e)
        {
            Debug.Log(e.Message.ToString());
        }
    }
コード例 #9
0
 // Update is called once per frame
 void Update()
 {
     if (NetworkMessaging.socketOpen())
     {
         Debug.Log("Socket is open");
         if (!joinedSession)
         {
             Debug.Log("Sending join session request");
             var joinSessionReq = new joinSessionRequest();
             joinSessionReq.playerId = playerState.playerId;
             NetworkMessaging.SendSocketMessage(joinSessionReq);
             joinedSession = true;
         }
         else if (!checkingForMessages)
         {
             Debug.Log("Checking for messages");
             checkingForMessages = true;
             checkForMessage();
         }
     }
 }
コード例 #10
0
    public void send_guess()
    {
        for (int i = 0; i < 4; i++)
        {
            guess_message.verbs[i] = verb_Guess[i].captionText.text.ToString();
            guess_message.nouns[i] = noun_Guess[i].captionText.text.ToString();
        }
        guess_message.playerId  = playerState.playerId;
        guess_message.sessionId = playerState.sessionId;

        guess_list.Add(guess_message);

        try
        {
            NetworkMessaging.SendJsonViaPOST(guess_message, "http://35.209.52.72:80/sendguessdemo");
        }
        catch (SystemException e)
        {
            Debug.Log(e.Message.ToString());
        }
    }
コード例 #11
0
    // Start is called before the first frame update
    void Start()
    {
        var    playerRequest = new newPlayerRequest();
        string response      = "";

        playerRequest.playerName = SystemInfo.deviceUniqueIdentifier;
        playerRequest.deviceID   = SystemInfo.deviceUniqueIdentifier;

        try
        {
            Debug.Log("Sending new player");
            response = NetworkMessaging.SendJsonViaPOST(playerRequest, "http://35.209.52.72:80/newPlayer").ToString();
        }
        catch (SystemException e)
        {
            Debug.Log("error was: " + e);
        }

        playerState.playerId = response;
        Debug.Log("Connecting to web socket");
        NetworkMessaging.ConnectWebSocketToServerAsync("ws://localhost:8095/connect");
    }