public void Resolve(Message message) { switch (message.MessageTarget) { case MessageTarget.Mobile: { var target = _mobiles.WithName(message.Name); if (target != null) switch (message.Type) { case (GameConstants.MOVEMENT): target.MoveTo(message.To.ToPoint()); break; case (GameConstants.ACTIVE): target.IsActive = Convert.ToBoolean(message.To); break; } } break; case MessageTarget.Static: { switch (message.Type) { case (GameConstants.SPLAT): { var tile = _statics[message.From.ToPoint()]; tile.Token = (tile.Token == '.' ? 'b' : '.'); } break; case (GameConstants.CRASH): { var tile = _statics[message.From.ToPoint()]; tile.Token = (tile.Token == '.' ? 'h' : '.'); } break; } } break; case MessageTarget.Game: { switch (message.Type) { case(GameConstants.NEXT_LEVEL): //Load next level; break; } switch (message.Type) { case (GameConstants.LOAD_LEVEL): //Load level X; break; } } break; } }
private void ResolveReaction(Message message, char reationType) { if (message.To != GameConstants.NULL) { var point = message.To.ToPoint(); var stack = _mobiles.GetStack(point.X, point.Y); var offset = new Point(0, 0, stack.Count()); var tile = new Tile { IsTraversible = true, Token = reationType, Location = message.To.ToPoint() + offset }; _mobiles.Tiles.Add(tile); } else { var point = message.From.ToPoint(); var stack = _mobiles.GetStack(point.X, point.Y); _mobiles.Tiles.Remove(stack.Last()); } }
public void Resolve(Message message) { switch (message.MessageTarget) { case MessageTarget.Mobile: { var target = _mobiles.WithName(message.Name); switch (message.Type) { case (GameConstants.MOVEMENT): if (target != null) target.MoveTo(message.To.ToPoint()); break; case (GameConstants.ACTIVE): if (target != null) target.IsActive = Convert.ToBoolean(message.To); break; case (GameConstants.SPLAT): ResolveReaction(message, 'b'); break; case (GameConstants.CRASH): ResolveReaction(message, 'h'); break; } } break; case MessageTarget.Game: { switch (message.Type) { case(GameConstants.NEXT_LEVEL): //Load next level; break; } switch (message.Type) { case (GameConstants.LOAD_LEVEL): //Load level X; break; } } break; } }
private Frame ResolveAction(Message message, Frame frame = null) { if (frame == null) frame = new Frame(); if (frame.IsValid && message != null) { switch (message.Type) { case (GameConstants.MOVEMENT): { var target = Mobiles.WithName(message.Name); var targetLocation = message.To.ToPoint(); var mobileCollisionInfo = Mobiles.CollisionDetection(target, targetLocation); var staticCollisionInfo = Statics.CollisionDetection(target, targetLocation); frame.IsValid = !(mobileCollisionInfo.Collision || staticCollisionInfo.Collision); if (!frame.IsValid) return frame; mobileCollisionInfo.Messages.ForEach(m => ResolveAction(m, frame)); } break; } frame.FrameData.Add(message); frame.FrameData.AddRange(_gameMessageReactor.Select(r=> r(message)).Where(m=> m!= null)); return frame; } return frame; }