Exemple #1
0
    private IEnumerator ReplayGame()
    {
        yield return(new WaitForSeconds(5));

        int lastTurn;

        int.TryParse(moveList[moveList.Count - 1][4], out lastTurn);
        string character = "";

        // Each iteration queues all the movements for that turn, then dequeues
        // one at a time so that watching a replay you see the moves one turn
        // at a time.
        for (int turn = 0; turn <= lastTurn; turn++)
        {
            foreach (string[] move in moveList)
            {
                if (move[4] == turn.ToString())
                {
                    Tuple <string, string> moveArg = Tuple.Create(move[1], move[2]);
                    character = move[1];
                    QueueMovement(moveArg);

                    // Check if any instructions exist to display.
                    if (instrList.Any() && Int32.Parse(instrList[0][0]) == -1)
                    {
                        instrControl.DisplayInstruction(instrList[0][1]);
                        instrList.RemoveAt(0);
                    }
                    while (instrList.Any() && instrList[0][0] == move[0])
                    {
                        instrControl.DisplayInstruction(instrList[0][1]);
                        instrList.RemoveAt(0);
                    }
                }
            }
            DequeueMovements(character);
            yield return(new WaitWhile(() => running == true)); // Waits while movements are dequeueing.

            yield return(new WaitForSeconds(3));
        }
        instrControl.DisplayInstruction("*********** REPLAY: END OF GAME ***********");
        yield break;
    }
Exemple #2
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;
    }