private bool HandleChangeScreen(ChangeScreenMessage csm) { Screen oldScreen = (Screen)csm.Sender; Screen newScreen = ChooseNewScreen(oldScreen, csm.Direction); if (newScreen == null) { return true; } Direction newDirection = csm.Direction; if (csm.Direction == Direction.Left) { newDirection = Direction.Right; } else if (csm.Direction == Direction.Right) { newDirection = Direction.Left; } if (IsPlane(csm.ObjectID)) { ServerPlane p = GetPlane(csm.ObjectID); if (p == null) { return true; } p.Ttl--; if (p.Ttl > 0) { Trace.WriteLine(String.Format("Plane {0} changed screens and has now TTL={1}.", p.ID, p.Ttl)); p.Screen = newScreen; newScreen.Connection.SendMessage(new NewPlaneMessage( csm.ObjectID, p.Type, newDirection, csm.Y, csm.Velocity, csm.Time)); } else { // the plane has no time left to live Trace.WriteLine(String.Format("Plane {0}'s time has come.", p.ID)); PopObjectMessage pom = new PopObjectMessage(csm.ObjectID); pom.Sender = p.Screen; HandlePopObject(pom); } } else { ServerBalloon b = GetBalloon(csm.ObjectID); if (b == null) { return true; } b.Screen = newScreen; newScreen.Connection.SendMessage(new NewBalloonMessage( csm.ObjectID, newDirection, csm.Y, csm.Velocity)); } return true; }
private bool HandleChangeScreen(ChangeScreenMessage csm) { Screen oldScreen = (Screen)csm.Sender; Screen newScreen = ChooseNewScreen(oldScreen, csm.Direction); ChangeScreen(csm.BalloonID, newScreen); Direction newDirection = csm.Direction; if(csm.Direction == Direction.Left) { newDirection = Direction.Right; } else if(csm.Direction == Direction.Right) { newDirection = Direction.Left; } newScreen.EnqueueMessage(new NewBalloonMessage(csm.BalloonID, newDirection, csm.Y, csm.Velocity), this); return true; }
private bool HandleChangeScreen(ChangeScreenMessage csm) { Screen oldScreen = (Screen)csm.Sender; if(oldScreen != null) { oldScreen.Balloons.Remove(csm.BalloonID); } Screen newScreen = ChooseNewScreen(oldScreen, csm.Direction); ServerBalloon balloon = GetBalloon(csm.BalloonID); if(balloon == null) { // balloon was removed and client wasn't notified yet return true; } balloon.Screen = newScreen; Direction newDirection = csm.Direction; if(csm.Direction == Direction.Left) { newDirection = Direction.Right; } else if(csm.Direction == Direction.Right) { newDirection = Direction.Left; } if(newScreen != null) { newScreen.Balloons.Add(csm.BalloonID, balloon); newScreen.Connection.SendMessage(new NewBalloonMessage( csm.BalloonID, newDirection, csm.Y, csm.Velocity)); } return true; }