Example #1
0
        public override void UserJoined(NonobaGameUser <MyPlayer> user)
        {
            var FromPlayer =
                new SharedClass1.RemoteEvents
            {
                BroadcastRouter = new SharedClass1.RemoteEvents.WithUserArgumentsRouter_Broadcast
                {
                    user = user.UserId,
                },
                SinglecastRouter = new SharedClass1.RemoteEvents.WithUserArgumentsRouter_Singlecast
                {
                    user = user.UserId,
                }
            };

            user.Virtual = new MyPlayer
            {
                ToOthers =
                    new SharedClass1.RemoteMessages
                {
                    Send = q => this.SendOthers(user.UserId, q.i, q.args)
                },
                ToPlayer =
                    new SharedClass1.RemoteMessages
                {
                    Send = e => this.Send(user, e.i, e.args)
                },
                FromPlayer         = FromPlayer,
                FromPlayerDispatch = FromPlayer,
                UserId             = user.UserId,
                Username           = user.Username,

                AddScore         = user.SubmitRankingDelta,
                AwardAchievement = user.AwardAchievement,
            };

            FromPlayer.BroadcastRouter.Target = user.Virtual.ToOthers;

            Virtual.Users.Add(user.Virtual);

            Virtual.UserJoined(user.Virtual);
        }
Example #2
0
        /// <summary>When a user enters this game instance</summary>
        public override void UserJoined(Player player)
        {
            var FromPlayer =
                new SharedClass1.RemoteEvents
            {
                Router = new SharedClass1.RemoteEvents.WithUserArgumentsRouter
                {
                    user = player.UserId,
                }
            };

            player.Virtual = new FlashTowerDefense.Shared.Player
            {
                ToOthers =
                    new SharedClass1.RemoteMessages
                {
                    Send = q => this.SendOthers(player.UserId, q.i, q.args)
                },
                ToPlayer =
                    new SharedClass1.RemoteMessages
                {
                    Send = e => this.Send(player, e.i, e.args)
                },
                FromPlayer         = FromPlayer,
                FromPlayerDispatch = FromPlayer,
                UserId             = player.UserId,
                Username           = player.Username,
                AddScore           = player.SubmitRankingDelta
            };

            FromPlayer.Router.Target = player.Virtual.ToOthers;

            Virtual.Users.Add(player.Virtual);

            Virtual.UserJoined(player.Virtual);
        }
Example #3
0
        private void Initialize()
        {
            var c = NonobaAPI.MakeMultiplayer(stage
                                              //, "192.168.3.102"
                                              //, "192.168.1.119"
                                              );


            var MyEvents   = new SharedClass1.RemoteEvents();
            var MyMessages = new SharedClass1.RemoteMessages
            {
                Send = e => SendMessage(c, e.i, e.args)
            };



            Events   = MyEvents;
            Messages = MyMessages;

            this.InitializeEvents();

            #region Dispatch
            Func <Message, bool> Dispatch =
                e =>
            {
                var type = (SharedClass1.Messages) int.Parse(e.Type);

                if (MyEvents.Dispatch(type,
                                      new SharedClass1.RemoteEvents.DispatchHelper
                {
                    GetLength = i => e.length,
                    GetInt32 = e.GetInt,
                    GetDouble = e.GetNumber,
                    GetString = e.GetString,
                }
                                      ))
                {
                    return(true);
                }

                return(false);
            };
            #endregion


            #region message
            c.Message +=
                e =>
            {
                InitializeMap();


                var Dispatched = false;

                try
                {
                    Dispatched = Dispatch(e.message);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("error at dispatch " + e.message.Type);

                    throw ex;
                }

                if (Dispatched)
                {
                    return;
                }

                System.Console.WriteLine("not on dispatch: " + e.message.Type);
            };
            #endregion

            c.Disconnect +=
                delegate
            {
            };

            c.Init +=
                delegate
            {
                InitializeMap();
            };
        }
Example #4
0
        internal void Initialize()
        {
            var c = NonobaAPI.MakeMultiplayer(stage
                                              //, "192.168.3.102"
                                              //, "192.168.1.119"
                                              );

            #region Messages
            var ActiveMessages = new List <TextField>();
            var ShowMessageNow = default(Action <string, Action>);

            ShowMessageNow =
                (MessageText, Done) =>
            {
                var p = new TextField
                {
                    textColor       = ColorWhite,
                    background      = true,
                    backgroundColor = ColorBlack,
                    filters         = new[] { new GlowFilter(ColorBlack) },
                    autoSize        = TextFieldAutoSize.LEFT,
                    text            = MessageText,
                    mouseEnabled    = false
                };

                var y = DefaultControlHeight - p.height - 32;

                p.AddTo(ActiveMessages).AttachTo(this).MoveTo((DefaultControlWidth - p.width) / 2, DefaultControlHeight);

                Sounds.snd_message.ToSoundAsset().play();

                var MessagesToBeMoved = (from TheMessage in ActiveMessages select new { TheMessage, y = TheMessage.y - TheMessage.height }).ToArray();



                (1000 / 24).AtInterval(
                    t =>
                {
                    foreach (var i in MessagesToBeMoved)
                    {
                        if (i.TheMessage.y > i.y)
                        {
                            i.TheMessage.y -= 4;
                        }
                    }

                    p.y -= 4;

                    if (p.y < y)
                    {
                        t.stop();

                        if (Done != null)
                        {
                            Done();
                        }

                        500.AtDelayDo(
                            delegate
                        {
                            p.alpha = 0.5;
                        }
                            );
                        9000.AtDelayDo(
                            () => p.RemoveFrom(ActiveMessages).FadeOutAndOrphanize(1000 / 24, 0.21)
                            );
                    }
                }
                    );
            };


            var QueuedMessages = new Queue <string>();

            this.ShowMessage =
                Text =>
            {
                if (QueuedMessages.Count > 0)
                {
                    QueuedMessages.Enqueue(Text);
                    return;
                }

                // not busy
                QueuedMessages.Enqueue(Text);

                var NextQueuedMessages = default(Action);

                NextQueuedMessages =
                    () => ShowMessageNow(QueuedMessages.Peek(),
                                         delegate
                {
                    QueuedMessages.Dequeue();

                    if (QueuedMessages.Count > 0)
                    {
                        NextQueuedMessages();
                    }
                }
                                         );

                NextQueuedMessages();
            };
            #endregion


            var MyEvents = new SharedClass1.RemoteEvents();
            Events   = MyEvents;
            Messages = new SharedClass1.RemoteMessages
            {
                Send = e => SendMessage(c, e.i, e.args)
            };

            this.InitializeEvents();

            #region Dispatch
            Func <Message, bool> Dispatch =
                e =>
            {
                var type = (SharedClass1.Messages) int.Parse(e.Type);

                if (MyEvents.Dispatch(type,
                                      new SharedClass1.RemoteEvents.DispatchHelper
                {
                    GetLength = i => e.length,
                    GetInt32 = e.GetInt,
                    GetDouble = e.GetNumber,
                    GetString = e.GetString,
                }
                                      ))
                {
                    return(true);
                }

                return(false);
            };
            #endregion


            #region message
            c.Message +=
                e =>
            {
                InitializeMap();


                var Dispatched = false;

                try
                {
                    Dispatched = Dispatch(e.message);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("error at dispatch " + e.message.Type);

                    throw ex;
                }

                if (Dispatched)
                {
                    return;
                }

                System.Console.WriteLine("not on dispatch: " + e.message.Type);
            };
            #endregion

            c.Disconnect +=
                delegate
            {
                ShowMessage("Disconnected!");
            };

            c.Init +=
                delegate
            {
                InitializeMap();
            };
        }
        private void Initialize()
        {
            var c = NonobaAPI.MakeMultiplayer(stage
                                              //, "192.168.3.102"
                                              //, "192.168.1.119"
                                              );


            var MyEvents   = new SharedClass1.RemoteEvents();
            var MyMessages = new SharedClass1.RemoteMessages
            {
                Send = e => c.SendMessage(e.i, e.args)
            };



            var MyImplementation = new Implementation
            {
                NetworkEvents   = MyEvents,
                NetworkMessages = MyMessages
            };

            MyImplementation.InitializeEvents();

            Func <Message, bool> Dispatch =
                e =>
            {
                var type = (SharedClass1.Messages) int.Parse(e.Type);

                if (MyEvents.Dispatch(type,
                                      new SharedClass1.RemoteEvents.DispatchHelper
                {
                    GetLength = i => e.length,
                    GetInt32 = e.GetInt,
                    GetDouble = e.GetNumber,
                    GetString = e.GetString,
                }
                                      ))
                {
                    return(true);
                }

                return(false);
            };

            #region message
            c.Message +=
                e =>
            {
                var Dispatched = false;

                try
                {
                    Dispatched = Dispatch(e.message);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("error at dispatch " + e.message.Type);

                    throw ex;
                }

                if (Dispatched)
                {
                    return;
                }

                System.Console.WriteLine("not on dispatch: " + e.message.Type);
            };
            #endregion

            c.Disconnect +=
                delegate
            {
                if (MyImplementation.Map == null)
                {
                    throw new Exception("Cannot connect to server at the moment");
                }

                MyImplementation.Map.ShowMessage("Disconnected!");
                MyImplementation.Map.CanAutoSpawnEnemies = true;

                foreach (var v in MyImplementation.Players.ToArray())
                {
                    v.RemoveFrom(MyImplementation.Players).AddDamage(v.Health);
                }
            };



            c.Init +=
                delegate
            {
                MyImplementation.Map = new FlashTowerDefense();
                MyImplementation.InitializeMap();
                MyImplementation.Map.AttachTo(this);
            };
        }
        private void Initialize()
        {
            var c = NonobaAPI.MakeMultiplayer(Element.stage, ServerEndPoint
                                              //, "192.168.3.102"
                                              //, "192.168.1.119"
                                              );



            var MyEvents   = new SharedClass1.RemoteEvents();
            var MyMessages = new SharedClass1.RemoteMessages
            {
                Send = e => SendMessage(c, e.i, e.args)
            };



            Events   = MyEvents;
            Messages = MyMessages;

            this.InitializeEventsOnce();

            #region Dispatch
            Func <Message, bool> Dispatch =
                e =>
            {
                var type = (SharedClass1.Messages) int.Parse(e.Type);

                //Converter<uint, byte[]> GetMemoryStream =
                //    index =>
                //    {
                //        var a = e.GetByteArray(index);

                //        if (a == null)
                //            throw new Exception("bytearray missing at " + index + " - " + e.ToString());

                //        return a.ToArray();
                //    };

                if (MyEvents.Dispatch(type,
                                      new SharedClass1.RemoteEvents.DispatchHelper
                {
                    GetLength = i => e.length,
                    GetInt32 = e.GetInt,
                    GetDouble = e.GetNumber,
                    GetString = e.GetString,
                    //				 GetMemoryStream = GetMemoryStream
                }
                                      ))
                {
                    return(true);
                }

                return(false);
            };
            #endregion

            //c.MessageDirect +=
            //    e =>
            //    {
            //        throw new Exception("got first message");
            //    };

            #region message
            c.Message +=
                e =>
            {
                InitializeMap();


                var Dispatched = false;

                try
                {
                    Dispatched = Dispatch(e.message);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("error at dispatch " + e.message.Type);

                    throw ex;
                }

                if (Dispatched)
                {
                    return;
                }

                System.Console.WriteLine("not on dispatch: " + e.message.Type);
            };
            #endregion

            c.Disconnect +=
                delegate
            {
                // disconnected...
            };
        }