Example #1
0
 public void AddSubWorld(YuanWorld world)
 {
     SubWorlds.Add(world);
 }
        /// <summary>
        /// After the SubWorld has been updated.
        /// </summary>
        /// <param name="world">World to process after updating.</param>
        protected override void PostUpdate(BreakoutWorld world)
        {
            base.PostUpdate(world);

            if (((BreakoutWorld)world.Opponent).Dead) // If opponent World is dead...
            {
                // Create Message stating World is dead and send it to player.
                Message message = new Message((short)SuperOps.Utility, (short)UtilityOps.Dead);
                ClientAcceptor.SendMessage(world.Opponent.Client, message);

                // Remove this World.
                SubWorlds.Remove(world);

                if (world.Opponent.Opponent == world) // If there'll be one player left after this player is removed...
                {
                    // Set World opponent to won.
                    message = new Message(0, 2);
                    ClientAcceptor.SendMessage(world.Client, message);

                    // End the match and destroy this SuperWorld.
                    HasEnded = true;
                    Destroy  = true;
                }
                else
                {
                    // Set World's opponent to the opponent's opponent.
                    world.Opponent = world.Opponent.Opponent;

                    // Clear all Balls and Bricks.
                    message = new Message((int)SuperOps.Ball, (int)BallOps.Clear);
                    ClientAcceptor.SendMessage(world.Client, message);

                    message        = new Message((int)SuperOps.Brick, (int)BrickOps.Clear);
                    message.Player = 0;

                    ClientAcceptor.SendMessage(world.Client, message);

                    // Get all new opponent's alive bricks and spawn them.
                    var bricks = world.Opponent.GetSystem <BrickSystem>().GetAliveBricks();
                    foreach (KeyValuePair <Vector2, int> b in bricks)
                    {
                        byte x = (byte)b.Key.x;
                        byte y = (byte)b.Key.y;
                        byte h = (byte)b.Value;

                        message        = new Message((int)SuperOps.Brick, (int)BrickOps.Spawn, new byte[] { x, y, h });
                        message.Player = 0;
                        ClientAcceptor.SendMessage(world.Client, message);
                    }

                    // Get all world's alive bricks and spawn them.
                    bricks = world.GetSystem <BrickSystem>().GetAliveBricks();
                    foreach (KeyValuePair <Vector2, int> b in bricks)
                    {
                        byte x = (byte)b.Key.x;
                        byte y = (byte)b.Key.y;
                        byte h = (byte)b.Value;

                        message = new Message((int)SuperOps.Brick, (int)BrickOps.Spawn, new byte[] { x, y, h });
                        ClientAcceptor.SendMessage(world.Client, message);
                    }
                }
            }
        }