示例#1
0
    void OnEnable()
    {
        webSocketManager     = FindObjectOfType <WebSocketManager>();
        commandCommunication = FindObjectOfType <CommandCommunication>();
        //if(Replay.replaying) { commandHistory = GameObject.FindGameObjectWithTag("CommandHistoryData").GetComponent<InputField>(); }

        //TODO: need to adjust replay
        if (Replay.replaying)
        {
            leaderCommandHistory = GameObject.FindGameObjectWithTag("CommandHistoryData").GetComponent <InputField>();
        }

        Restarter.OnRestartEvent += ClearHistory;
    }
示例#2
0
    void OnEnable()
    {
        infoGetter = FindObjectOfType <InformationGetter>();
        // hexgrid = FindObjectOfType<HexGrid>();
        turnController       = FindObjectOfType <TurnController>();
        commandCommunication = FindObjectOfType <CommandCommunication>();
        propPlacement        = FindObjectOfType <PropPlacement>();
        startup = FindObjectOfType <Startup>();

        InformationGetter.OnImageTakenEvent += GetSendImage;
        PropPlacement.OnMapCompleteEvent    += SendMapCompleteMsg;
        PropPlacement.OnMapCompleteEvent    += GetHandlers;

        HexQueuedCntrl.OnFinishedHexActionEvent += SendAgentInfo;
        QueuedControl.OnFinishedActionEvent     += SendAgentInfo;
    }
示例#3
0
    /// <summary>
    /// Functions (* means complete)
    /// for * endfor
    /// while -endwhile
    /// WalkForward *
    /// WalkBackward*
    /// RotateRight*
    /// RotateLeft*
    /// Clear*
    /// near - todo
    /// notnear -todo
    /// edge -todo
    /// notEdge -todo
    /// </summary>
    public void SubmitCode()
    {
        if (inputField.text == "\n" || inputField.text == "") // Check for empty commands.
        {
            inputField.text = "";
            return;
        }
        else if (!IsInputFieldValid(inputField.text))
        {
            return;
        }

        if (inputType == InputType.PLInput)
        {
            inputText = inputField.text;
            var pv = ProcessCommandInput(inputText);
            if (pv > 0)
            {
                //get pv code
                queuedControl.StopClearAll();
                StartCoroutine(RedTintScreen());
                // change screen to red for 2 seconds?
            }
        }
        // language input
        else
        {
            inputText = CommandCommunication.Filter(inputField.text);

            Dictionary <string, string> strData = new Dictionary <string, string>()
            {
                { "content", inputText }
            };
            webSocketManager.Send("instruction", strData, null);
        }


        inputField.text = "";
        turnController.endTurnButton.interactable = true;
        AddCommandToQueue(inputText);
    }
示例#4
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;
    }