Esempio n. 1
0
    void Update()
    {
        float action;

        lock (socket_controller_.receive_data_lock_)
        {
            action = action_;
        }
        if (action != -1)
        {
            Time.timeScale          = 1f;
            game_over_text_.enabled = false;
            won_text_.enabled       = false;
        }

        if (brick_manager_.GetActiveBrickCount() == 0)
        {
            Time.timeScale    = 0f;
            action_           = -1;
            game_state_       = 1;
            won_text_.enabled = true;
            lock (socket_controller_.send_data_lock_)
            {
                prize_ = 100;
            }
        }

        switch (action)
        {
        case 0: paddle_.MovePaddle(0.0f); break;

        case 1: paddle_.MovePaddle(-1.0f); break;

        case 2: paddle_.MovePaddle(1.0f); break;

        case 3: Reset(); break;
        }

        lock (socket_controller_.send_data_lock_)
        {
            state_ = GetState();
            socket_controller_.something_to_send.Set();
        }

        var    physics   = state_.Skip(2).Take(5).Select(num => String.Format("{0:0.0}", num));
        string direction = state_.ElementAt(7) == 0 ? "none" : (state_.ElementAt(7) == 1 ? "right" : "left");
        var    bricks    = state_.Skip(8).Select((n, i) => String.Format("{1}{0}", n, i % brick_manager_.cols_ == 0 ? "\n" : ""));

        state_text_.text = "Episode: " + episode_
                           + "\nBall PosX: " + physics.ElementAt(0)
                           + "\nBall PosY: " + physics.ElementAt(1)
                           + "\nBall VelX: " + physics.ElementAt(2)
                           + "\nBall VelY: " + physics.ElementAt(3)
                           + "\nPaddle PosX: " + physics.ElementAt(4)
                           + "\nPaddle direction: " + direction
                           + "\nBrick Status:" + String.Join(" ", bricks);
    }