예제 #1
0
        private bool HandleScreenDisconnected(DisconnectedMessage msg)
        {
            Screen s = msg.Sender as Screen;
            if(s == null)
            {
                return true;
            }
            Trace.WriteLine(String.Format("Screen disconnected: {0}", s.ID));

            // Gets screen's balloons
            var balloons = BallonsOnScreen(s.ID);
            // Gets left and right screens
            Screen left = GetPreviousScreen(s);
            Screen right = GetNextScreen(s);
            if(left == s || right == s) {
                // if next or previous screen are equal to current screen
                // it means that this was the last screen left
                m_bubbles.Clear();
                m_planes.Clear();
            } else {
                foreach(ServerBalloon balloon in balloons)
                {
                    // Choose randomly between left or right screen
                    int random = m_random.Next(2);
                    Screen newScreen = null;
                    NewBalloonMessage nbm = null;
                    if(random == 0) {
                        newScreen = left;
                        nbm = new NewBalloonMessage(balloon.ID, Direction.Right,
                                                    0.1f, Configuration.BalloonVelocityLeft);
                    } else {
                        newScreen = right;
                        nbm = new NewBalloonMessage(balloon.ID, Direction.Left,
                                                    0.1f, Configuration.BalloonVelocityRight);
                    }
                    balloon.Screen = newScreen;
                    if(newScreen != null)
                    {
                        newScreen.Connection.SendMessage(nbm);
                    }
                }

                // Remove any plane present in the screen
                foreach (ServerPlane plane in m_planes.Values)
                {
                    // Use enqueue so that the map isn't changed during iteration
                    EnqueueMessage(new PopObjectMessage(plane.ID));
                }
            }
            m_screens.Remove(s);
            return true;
        }
예제 #2
0
파일: Server.cs 프로젝트: PyrO70/hwkinect
        private bool HandleScreenDisconnected(DisconnectedMessage msg)
        {
            Console.WriteLine("Screen disconnected");
            Screen s = GetScreen(msg.ScreenID);

            // Gets screen's balloons
            var balloons = s.GetBalloons();
            // Gets left and right screens
            Screen left = GetPreviousScreen(s);
            Screen right = GetNextScreen(s);
            if(left == s || right == s) {
                // if next or previous screen are equal to current screen
                // it means that this is the only screen left
                // set the balloons' screen to null,
                // they will be reacffected when a new screen connects
                foreach(KeyValuePair<int, ServerBalloon> i in balloons)
                {
                    i.Value.Screen = null;
                }
            } else {
                foreach(KeyValuePair<int, ServerBalloon> i in balloons)
                {
                    // Choose randomly between left or right screen
                    int random = m_random.Next(1);
                    if(random == 0) {
                        left.EnqueueMessage(new NewBalloonMessage(i.Value.ID, Direction.Right, 0.1f, ServerBalloon.VelocityLeft), this);
                    } else {
                        right.EnqueueMessage(new NewBalloonMessage(i.Value.ID, Direction.Left, 0.1f, ServerBalloon.VelocityRight), this);
                    }
                }
            }
            m_screens.Remove(s);
            return true;
        }
예제 #3
0
        private bool HandleScreenDisconnected(DisconnectedMessage msg)
        {
            Screen s = msg.Sender as Screen;
            if(s == null)
            {
                return true;
            }
            Trace.WriteLine(String.Format("Screen disconnected: {0}", s.ID));

            // Gets screen's balloons
            var balloons = s.Balloons;
            // Gets left and right screens
            Screen left = GetPreviousScreen(s);
            Screen right = GetNextScreen(s);
            if(left == s || right == s) {
                // if next or previous screen are equal to current screen
                // it means that this was the last screen left
                m_bubbles.Clear();
            } else {
                foreach(ServerBalloon balloon in balloons.Values)
                {
                    // Choose randomly between left or right screen
                    int random = m_random.Next(1);
                    Screen newScreen = null;
                    NewBalloonMessage nbm = null;
                    if(random == 0) {
                        newScreen = left;
                        nbm = new NewBalloonMessage(balloon.ID, Direction.Right,
                                                    0.1f, Configuration.VelocityLeft);
                    } else {
                        newScreen = right;
                        nbm = new NewBalloonMessage(balloon.ID, Direction.Left,
                                                    0.1f, Configuration.VelocityRight);
                    }
                    balloon.Screen = newScreen;
                    if(newScreen != null)
                    {
                        newScreen.Balloons.Add(nbm.BalloonID, balloon);
                        newScreen.Connection.SendMessage(nbm);
                    }
                }
            }
            m_screens.Remove(s);
            return true;
        }