Ejemplo n.º 1
0
    private void AskForGame(Schema.LookingForGame playerLookingForGame)
    {
        this.Game = Server.FindGame(this);

        Schema.JoinedGame joinedGame = new Schema.JoinedGame
        {
            Username = this.Username,
        };

        Console.WriteLine("Telling player they got a game");
        this.SendMessage(Any.Pack(joinedGame));

        Console.WriteLine("Telling player initial board state");
        this.SendMessage(Any.Pack(Game.Board.GetBoardState()));
    }
Ejemplo n.º 2
0
    public void Packet_InsertProtobuf()
    {
        Packet packet   = new Packet();
        string username = "******";

        Schema.JoinedGame message = new Schema.JoinedGame()
        {
            Username = username
        };
        Any any = Any.Pack(message);

        byte[] bytes = any.ToByteArray();
        packet.SetContents(bytes, bytes.Length);
        Assert.AreEqual(Constants.DEFAULT_BUFFER_SIZE, packet.Buffer.Length);
        CompareArrayToBuffer(any.ToByteArray(), packet.Buffer);

        Assert.IsTrue(packet.Message.Is(Schema.JoinedGame.Descriptor));
        Assert.AreEqual(username, packet.Message.Unpack <Schema.JoinedGame>().Username);
    }
Ejemplo n.º 3
0
    public void Server_ClientLookingForGame()
    {
        Server server = new Server(8080);
        Client client = TestObjects.BuildClient(server);

        client.ClientSendToServer(Any.Pack(client.BuildLookingForGame()));

        Assert.IsTrue(client.MessageLog.First.Value.Is(Schema.LookingForGame.Descriptor));

        Schema.JoinedGame joinedGameResponse = client.MessageLog.First.Next.Value.Unpack <Schema.JoinedGame>();
        Assert.AreEqual(client.Username, joinedGameResponse.Username);

        Assert.IsTrue(client.MessageLog.Last.Value.Is(Schema.BoardState.Descriptor));
        Schema.BoardState boardState = client.MessageLog.Last.Value.Unpack <Schema.BoardState>();
        byte[]            bytes      = boardState.ToByteArray();
        Assert.IsTrue(bytes.Length < Constants.DEFAULT_BUFFER_SIZE);
        int totalHexagonCount = boardState.HexagonSets[0].Hexagons.Count + boardState.HexagonSets[1].Hexagons.Count;

        Assert.AreEqual(Constants.RowsPerPlayer * Constants.HexagonsPerRow * 2, totalHexagonCount);
    }
Ejemplo n.º 4
0
    public void HandleData(Any any)
    {
        if (any == null)
        {
            return;
        }

        if (any.Is(Schema.JoinedGame.Descriptor))
        {
            Schema.JoinedGame joinedGame = any.Unpack <Schema.JoinedGame>();
            Debug.Log($"User {joinedGame.Username}");
        }
        else if (any.Is(Schema.BoardState.Descriptor))
        {
            Managers.Board.HandleBoardStateChange(any.Unpack <Schema.BoardState>());
        }
        else if (any.Is(Schema.ProjectileCreated.Descriptor))
        {
            Managers.Player.InstantiateProjectile(any.Unpack <Schema.ProjectileCreated>());
        }
    }