Ejemplo n.º 1
0
        public void Handle(ResponseMessage message)
        {
            switch (message.Id)
            {
            case MessageId.Bitfield:
                OnBitfieldReceived?.Invoke(
                    new BitfieldEventArgs {
                    Bitfield = new Bitfield(message.Payload)
                }
                    );
                break;

            case MessageId.Piece:
                OnPieceReceived?.Invoke(new PieceEventArgs
                {
                    Payload = message.Payload
                }
                                        );
                break;

            case MessageId.Choke:
                OnChokeReceived?.Invoke();
                break;

            case MessageId.Unchoke:
                OnUnchokeReceived?.Invoke();
                break;

            case MessageId.Have:
                OnHaveReceived?.Invoke(new HaveEventArgs {
                    Index = BigEndian.ToUint32(message.Payload)
                });
                break;
            }
        }
Ejemplo n.º 2
0
    private void GeneratePiece()
    {
        Vector2         direction;
        float           velocity;
        PieceParameters parameters;

        direction = new Vector2(UnityEngine.Random.Range(-0.5f, 0.5f), 1.0f);
        direction = direction.normalized;

        velocity = UnityEngine.Random.Range(5.0f, 20.0f) * 100.0f;

        parameters = new PieceParameters
        {
            Direction  = direction,
            Velocity   = velocity,
            Properties = new PieceProperties
            {
                Brand = (PieceBrand)UnityEngine.Random.Range(1, 4),
                Color = (PieceColor)UnityEngine.Random.Range(1, 4),
                Shape = (PieceShape)UnityEngine.Random.Range(1, 4),
                Size  = (PieceSize)UnityEngine.Random.Range(1, 4)
            }
        };

        OnPieceReceived?.Invoke(parameters);
    }
Ejemplo n.º 3
0
    private void HandlePiece(string body)
    {
        PieceParameters parameters;

        try
        {
            parameters = JsonConvert.DeserializeObject<PieceParameters>(body);
            OnPieceReceived?.Invoke(parameters);
        }
        catch
        {
            Debug.LogError("Erreur lors de la déserialisation de la pièce.");
        }
    }