Beispiel #1
0
 static bool AreStateUpdatesEqual(StateUpdateServer a, StateUpdateServer b) =>
 a.PlayerId.Equals(b.PlayerId) &&
 a.Playfield.SequenceEqual(b.Playfield) &&
 a.FloatingPiece == b.FloatingPiece &&
 b.XPosition == b.XPosition &&
 b.YPosition == b.YPosition &&
 b.Rotation == b.Rotation;
Beispiel #2
0
        public void SerializeAndDeSerializeStateUpdateServerMessages()
        {
            Game game = new Game();

            game.AddCommingPiece(Piece.I);
            game.Tick();
            game.AddCommingPiece(Piece.J);
            game.MoveDown();
            game.Tick();
            game.Tick();

            StateUpdateServer stateUpdate = StateUpdateServer.CreateState(0, game);

            byte[]            bytes   = Serializer.Serialize(stateUpdate, playerIntegerSize);
            StateUpdateServer message = (StateUpdateServer)Serializer.DeSerializeClient(bytes, playerIntegerSize);

            Assert.IsTrue(AreStateUpdatesEqual(stateUpdate, message), "Should be able to serialize and deserialize the state update server message.");

            Game messageGame = message.ToGame();

            Assert.AreEqual(game.Floating, messageGame.Floating, "Should produce an exact copy of the floating piece.");
            Assert.IsTrue(game.ClonePlayField().SequenceEqual(messageGame.ClonePlayField()), "Should produce an exact copy of the playfield.");