Beispiel #1
0
        private void InitializeConnection()
        {
            try
            {
                var channelFactory = new ChannelFactory <ISkyShootService>("SkyShootEndpoint");
                _service = channelFactory.CreateChannel();

                _pingTimer.Elapsed += (sender, args) => _service.GetServerGameTime();
                _pingTimer.Start();
            }
            catch (Exception e)
            {
                FatalError(e);
            }
        }
Beispiel #2
0
 public GameManagerForm(ISkyShootService service)
 {
     _service = service;
     InitializeComponent();
 }
Beispiel #3
0
        private void UpdateSt(Object stateInfo)
        {
            while (true)
            {
                if (!GameRuning)
                {
                    AskGame();

                    _level = _games.Level;
                    GameStart(_level);
                }
                else
                {
                    Thread.Sleep(100);
                    DateTime     now = DateTime.Now;
                    SynchroFrame syncObjects;
                    lock (_service)
                    {
                        if (_prevMove != _me.RunVector)
                        {
                            _service.Move(_prevMove = _me.RunVector);
                            // ApplyEvents(_service.Move(_prevMove = _me.RunVector));
                        }
                        if (_shoot != Vector2.Zero)
                        {
                            _service.Shoot(_shoot);
                            // ApplyEvents(_service.Shoot(_shoot));
                            _shoot = Vector2.Zero;
                        }
                        if (_curWeapon != _prevWeapon)
                        {
                            _service.ChangeWeapon(_prevWeapon = _curWeapon);
                            //Thread.Sleep(100);
                        }
                        syncObjects = _service.SynchroFrame();
                        ApplyEvents(_service.GetEvents());
                    }
                    if (syncObjects == null)
                    {
                        GameRuning = false;
                        continue;
                    }
                    lock (_objects)
                    {
                        _objects.Clear();
                        _objects.AddRange(syncObjects);
                    }
                    var tempMe = _objects.Find(m => m.Id == _me.Id);
                    if (tempMe != null)
                    {
                        _me.Copy(tempMe);
                    }
                    //lock (_objects)
                    {
                        try
                        {
                            foreach (var t in _objects)
                            {
                                var m = t;
                                if (float.IsNaN(m.RunVector.X) || float.IsNaN(m.RunVector.Y))
                                {
                                    continue;
                                }
                                m.Coordinates +=
                                    m.RunVector *
                                    (m.Speed * (float)((now - _prev).TotalMilliseconds));
                                if (m.Is(AGameObject.EnumObjectType.Player))
                                {
                                    m.Coordinates = Vector2.Clamp(m.Coordinates, new Vector2(0, 0), new Vector2(_level.Width, _level.Height));                                     /**/
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine("Cli: Update: " + e);
                        }
                    }
                    _prev = now;
                    SetStatus(_me);
                    Redraw();
                }
            }
        }

        private void SetStatus(AGameObject me)
        {
            if (me == null)
            {
                return;
            }
            try
            {
                var sb = new StringBuilder();
                sb.AppendFormat("[pos: {0}; {1}] [dir: {2}; {3}]",
                                _me.Coordinates.X, _me.Coordinates.Y,
                                _me.RunVector.X, _me.RunVector.Y);
                toolStripStatusLabel1.Text = sb.ToString();
                sb.Clear();
                sb.AppendFormat("{0}/{1}", _me.HealthAmount, _me.MaxHealthAmount);
                toolStripStatusLabel2.Text = sb.ToString();
            }
            catch (Exception e)
            {
                Trace.WriteLine("Cli: Status: " + e);
            }
        }

        private void SetStatus(String str)
        {
            toolStripStatusLabel1.Text = str;
            toolStripStatusLabel2.Text = "0/0";
        }

        #endregion

        private readonly WeaponButton[] _buttons;
        private WeaponType _curWeapon, _prevWeapon;

        public MainForm()
        {
            InitializeComponent();

            //WeaponType
            int i = 0;
            /**/
            var weapons = new List <WeaponType>();

            weapons.Add(WeaponType.Pistol);
            weapons.Add(WeaponType.Shotgun);
            weapons.Add(WeaponType.FlamePistol);
            weapons.Add(WeaponType.Heater);
            weapons.Add(WeaponType.RocketPistol);
            weapons.Add(WeaponType.TurretMaker);
            weapons.Add(WeaponType.MobGenerator);
            _buttons = new WeaponButton[weapons.Count];
            foreach (var weapon in weapons)
            {
                var b = new WeaponButton();
                b.WeaponType  = weapon;
                b.Name        = weapon.ToString();
                b.Text        = "(" + (i + 1).ToString() + ") " + weapon.ToString();
                b.Click      += BClick;
                b.BorderStyle = BorderStyle.Fixed3D;
                _buttons[i++] = b;
            }

            /*/
             * int bts = Enum.GetNames(typeof(WeaponType)).Length - 1;
             * _buttons = new WeaponButton[bts];
             * foreach (var s in Enum.GetNames(typeof(WeaponType)))
             * {
             *      if (s == WeaponType.SpiderPistol.ToString())
             *              continue;
             *      var b = new WeaponButton();
             *      WeaponType t;
             *      if (!Enum.TryParse(s, out t))
             *      {
             *              MessageBox.Show(@"Can't load weapons list :(", @"Error");
             *      }
             *      b.WeaponType = t;
             *      b.Name = s;
             *      b.Text = @"(" + (i + 1).ToString() + @") " + s;
             *      b.Click += BClick;
             *      b.BorderStyle = BorderStyle.Fixed3D;
             *      _buttons[i++] = b;
             * }/**/
            Controls.AddRange(_buttons);
            MakeWeaponButtonsLayout();

            var channelFactory = new ChannelFactory <ISkyShootService>("SkyShootEndpoint");

            _service   = channelFactory.CreateChannel();
            GameRuning = false;
            _objects   = new List <AGameObject>();
            _th        = new Thread(UpdateSt);

            _curWeapon = _prevWeapon = WeaponType.Pistol;
        }