public void FinishCommand()
    {
        // Ignore finish-command keypresses if in tutorial mode.
        if (!TutorialGuide.tutorialMode)
        {
            // Only to be called by the follower.
            currInstrIdx += 1;
            instructionControl.ShowCommands();
            // End turn when there is no more instruction

            // Set the finish command banner as inactive because the person has followed
            // our instructions. Also reset the previous move time, and the number of
            // moves in the current command.
            turnController.finishCommandBanner.SetActive(false);
            turnController.SetPrevMoveTime();
            turnController.movesInThisCommand = 0;

            Dictionary <string, string> strData = new Dictionary <string, string>()
            {
                { "content", currInstrIdx.ToString() }
            };
            webSocketManager.Send("finishedCommand", strData, null);

            if (currInstrIdx >= instrBuffer.Count)
            {
                TurnController turnController = FindObjectOfType <TurnController>();
                turnController.GiveTurn("Finished All Commands");
            }
        }
    }
Exemple #2
0
    void UpdateTime()
    {
        now      = System.DateTime.Now;
        nowSec   = now.Hour * 3600 + now.Minute * 60 + now.Second;
        gameTime = nowSec - initSec;
        turnTime = curentSecondsPerTurn - (nowSec - startThisTurnsTime);
        turnTime = (turnTime < 0) ? 0 : turnTime;

        if (turnTime <= 0)
        {
            if (turnController.myTurn)
            {
                turnController.GiveTurn("Ran Out of Time");
            }
        }
        DisplayTime(turnTime);
    }
Exemple #3
0
    /// <summary>
    /// Processes the request in queue
    /// start, seed
    /// restart,seed
    ///
    /// start information: See GetMapInfo in InformationGetter Script to view all the types and information sent
    /// <bodytocontrol>,<move>
    /// status human
    /// status agent
    ///
    /// image overhead: sends a byte array of the image taken from the overhead camera
    /// image human: sends a byte array of the image taken for the human camera
    /// image agent: sends a byte array of the image taken for the agent camera
    /// </summary>
    /// <param name="msg"></param>
    private IEnumerator ProcessMsgRequest(string msg)
    {
        msg = msg.Trim();
        //TODO make it wait until the processing flag is false
        Debug.Log("Message: " + msg);

        switch (msg)
        {
        case "grammer":

            InstructionControl instructionControl = FindObjectOfType <InstructionControl>();
            var command = myCommands.Dequeue();

            instructionControl.DisplayInstruction(command);
            yield return(null);

            socketStarter.CerealSendMsg("123");
            break;

        case "state":
            var stateJson = myCommands.Dequeue();

            var setState = startup.SetState(stateJson);

            if (!setState)
            {
                socketStarter.CerealSendMsg("Failed - game not started");
            }
            socketStarter.CerealSendMsg("");
            break;

        case "goaldist":
            var goalJson = myCommands.Dequeue();
            propPlacement.SetGoalDist(goalJson);
            socketStarter.CerealSendMsg("");
            break;

        case "trajdist":
            var trajJson = myCommands.Dequeue();
            propPlacement.SetTrajectoryDist(trajJson);
            socketStarter.CerealSendMsg("");
            break;

        case "obsdist":
            var obsJson = myCommands.Dequeue();
            propPlacement.SetObstacleDist(obsJson);
            socketStarter.CerealSendMsg("");
            break;

        case "avoiddist":
            var avoidJson = myCommands.Dequeue();
            propPlacement.SetAvoidDist(avoidJson);
            socketStarter.CerealSendMsg("");
            break;

        case "newcards":
            var cardsJson = myCommands.Dequeue();
            propPlacement.AddCards(JsonUtility.FromJson <CardLists>(cardsJson));
            socketStarter.CerealSendMsg("");

            break;

        case "start":
            // dequeue get seed number;

            var splitM = myCommands.Dequeue().Split(',');
            // splitM is in the format "seed/numcards"
            var seed = 0;

            var parsed = int.TryParse(splitM[0].Trim(), out seed);

            var numCards       = 0;
            var numCardsParsed = int.TryParse(splitM[1].Trim(), out numCards);

            // Now get the number of cards
            if (!parsed || !numCardsParsed)
            {
                socketStarter.CerealSendMsg("Failed - expected integer for map seed start");
            }
            else
            {
                var result = startup.StandaloneStartWithSeed(seed, numCards);

                if (result)
                {
                }
                else
                {
                    socketStarter.CerealSendMsg("Failed - game already started");
                }
                //send start information - need to wait for the proplacement event
            }
            //set the map seed
            // UI start map

            break;

        case "restart":


            //Resources.UnloadUnusedAssets();
            string sss = SceneManager.GetActiveScene().name;
            SceneManager.LoadScene("Game");



            break;

        case "info":
            yield return(null);


            var info = infoGetter.GetStateDelta();
            socketStarter.CerealSendMsg(info);
            break;

        case "score":
            ScoreKeeper scoreKeeper = FindObjectOfType <ScoreKeeper>();
            int         tmpScore    = scoreKeeper.score;
            socketStarter.CerealSendMsg(tmpScore.ToString());

            break;

        case "finishcommand":
            if (commandCommunication == null)
            {
                commandCommunication = FindObjectOfType <CommandCommunication>();
            }
            commandCommunication.ReplayFinishCommand();
            socketStarter.CerealSendMsg("");
            break;

        case "turn":
            turnController.GiveTurn("Switched From Python");
            socketStarter.CerealSendMsg("");
            break;

        case "agent":
            Debug.Log("Agent is moving");
            splitM = myCommands.Dequeue().Split(',');


            var movement = splitM[0].Trim();
            var ret      = MovementHandler(agentHandler, movement);

            info = infoGetter.GetStateDelta();
            socketStarter.CerealSendMsg(info);
            break;

        case "human":
            Debug.Log("Human is moving");


            splitM   = myCommands.Dequeue().Split(',');
            movement = splitM[0].Trim();
            ret      = MovementHandler(humanHandler, movement);

            info = infoGetter.GetStateDelta();
            socketStarter.CerealSendMsg(info);
            break;

        case "image overhead":
            pic = infoGetter.GetScreenShotImageView("overhead");

            socketStarter.CerealSendMsg(pic);
            break;

        case "image human":
            waitingForActionCompletion = true;
            StartCoroutine(infoGetter.GetPOVImg("human"));
            break;

        case "image agent":
            waitingForActionCompletion = true;
            StartCoroutine(infoGetter.GetPOVImg("agent"));
            break;

        case "status agent":

            socketStarter.CerealSendMsg(infoGetter.GetAgentMoveInfo("Agent"));
            break;

        case "status human":

            socketStarter.CerealSendMsg(infoGetter.GetAgentMoveInfo("Human"));
            break;

        case "quit":
        case "exit":
            socketStarter.CloseConnection();
            Application.Quit();
            break;

        default:
            socketStarter.CerealSendMsg("");
            break;
        }
        yield return(null);

        isProcessingInstruction = false;
        yield return(null);

        yield break;
    }