Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (state == ServerState.OFF && Input.GetKeyDown(KeyCode.L))
        {
            state = ServerState.WAITING_TO_START;
            cl.StartListening();
        }

        if (state == ServerState.SETUP_GAME)
        {
            StartGame();
        }

        if (state == ServerState.PROCESSING)
        {
            bool finished = false;

            while (!finished)
            {
                finished = gr.StepThroughSim();
            }

            if (finished)
            {
                // Send gamestate to players

                SendGameState();

                if (gr.IsGameFinished())
                {
                    // GAME OVER.
                    state = ServerState.FINISHING;
                }
                else
                {
                    gr.NewTurn();
                }
            }
        }

        if (state == ServerState.FINISHING)
        {
            // WAIT 60 seconds then disconnect clients
            //DISCONNECT FROM CLIENTS. RESET SERVER

            if (endOfGameDisconnectWaitTimer > endOfGameDisconnectWait)
            {
                SendDisconnectToAllClients();
                endOfGameDisconnectWaitTimer = 0.0f;

                // TODO
                // RESET SERVER
                state = ServerState.RESETTING;
            }
            else
            {
                endOfGameDisconnectWaitTimer += Time.deltaTime;
            }
        }

        if (state == ServerState.RESETTING)
        {
            ResetServer();
        }
    }