Пример #1
0
 private void SendMessage(Thickness mar)
 {
     if (remoteProxy == null|| clientUser ==null) return;
     Task.Run(() =>
     {
         try
         {
             //////////////////////////////////////////////////////////////////////////
             BallMessage newMessage = new BallMessage()
             {
                 Date = DateTime.Now,
                 Message = "", //player's coordinates
                 User = clientUser,
                 Margine = mar
             };
             remoteProxy.SendNewMessage(newMessage);
             NetworkError = false;
         }
         catch(Exception ex)
         {
             ex.DebugDesc().Log("SendMargine");
             NetworkError = true;
         }
     });
 }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="newMessage"></param>
        public void AddNewMessage(BallMessage newMessage)
        {
            try
            {
                var ballModel = ballModels[newMessage.User.Key];

                if (newMessage.User.IsFirstUser)
                {
                    ballModel.Player1Margine = newMessage.Margine;
                }
                else
                {
                    var t = ballModel.Player2Margine;
                    t.Left = ballModel.BoardSize.Width - newMessage.Margine.Left - ballModel.PlayerSize.Width;
                    ballModel.Player2Margine = t;
                }
            }
            catch
            { }
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="newMessage"></param>
        public void AddNewMessage(BallMessage newMessage)
        {
            try
            {
                var ballModel = ballModels[newMessage.User.Key];

                if (newMessage.User.IsFirstUser)
                {
                    ballModel.Player1Margine = newMessage.Margine;
                }
                else
                {
                    var t = ballModel.Player2Margine;
                    t.Left = ballModel.BoardSize.Width - newMessage.Margine.Left - ballModel.PlayerSize.Width;
                    ballModel.Player2Margine = t;
                }
            }
            catch
            { }
        }
Пример #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// 
        public List<BallMessage> GetNewMessages(BallUser user)
        {
            try
            {
                var ballModel = ballModels[user.Key];
                switch (ballModel.GameOverPlayer)
                {
                    case PlayerEnum.Player1:
                        massageP1 = "You lose";
                        massageP2 = "You won";
                        break;
                    case PlayerEnum.Player2:
                        massageP2 = "You lose";
                        massageP1 = "You won";
                        break;
                    default:
                        break;
                }
                ballModel.GameOverPlayer = PlayerEnum.None;
                var message = new BallMessage()
                {
                    User = user,
                    Message = "",
                    Date = DateTime.Now,
                    GameSpeed = ballModel.GameSpeed
                };

                try
                {
                    message.User2Name = conectedUsers.First(user2 => user2.Key == user.Key && user.AppAddress != user2.AppAddress).UserName;
                }
                catch{}

                if (user.IsFirstUser)
                {
                    message.BallMargine = ballModel.BallMagine;
                    message.Margine = ballModel.Player2Margine;
                }
                else
                {
                    var w = ballModel.BoardSize.Width - ballModel.BallPosition.X - ballModel.BallSize.Width;
                    var h = ballModel.BoardSize.Height - ballModel.BallPosition.Y - ballModel.BallSize.Height;
                    message.BallMargine = new System.Windows.Thickness(w, h, 0, 0);

                    w = ballModel.BoardSize.Width - ballModel.Player1Margine.Left - ballModel.PlayerSize.Width;
                    message.Margine = new System.Windows.Thickness(w, 0, 0, 0);
                }

                if (message.User.IsFirstUser)
                {
                    message.Message = massageP1;
                    massageP1 = "";
                }
                else
                {
                    message.Message = massageP2;
                    massageP2 = "";
                }

                return new List<BallMessage>() { message };
            }
            catch
            {
                return null;
            }
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        ///

        public List <BallMessage> GetNewMessages(BallUser user)
        {
            try
            {
                var ballModel = ballModels[user.Key];
                switch (ballModel.GameOverPlayer)
                {
                case PlayerEnum.Player1:
                    massageP1 = "You lose";
                    massageP2 = "You won";
                    break;

                case PlayerEnum.Player2:
                    massageP2 = "You lose";
                    massageP1 = "You won";
                    break;

                default:
                    break;
                }
                ballModel.GameOverPlayer = PlayerEnum.None;
                var message = new BallMessage()
                {
                    User      = user,
                    Message   = "",
                    Date      = DateTime.Now,
                    GameSpeed = ballModel.GameSpeed
                };

                try
                {
                    message.User2Name = conectedUsers.First(user2 => user2.Key == user.Key && user.AppAddress != user2.AppAddress).UserName;
                }
                catch {}

                if (user.IsFirstUser)
                {
                    message.BallMargine = ballModel.BallMagine;
                    message.Margine     = ballModel.Player2Margine;
                }
                else
                {
                    var w = ballModel.BoardSize.Width - ballModel.BallPosition.X - ballModel.BallSize.Width;
                    var h = ballModel.BoardSize.Height - ballModel.BallPosition.Y - ballModel.BallSize.Height;
                    message.BallMargine = new System.Windows.Thickness(w, h, 0, 0);

                    w = ballModel.BoardSize.Width - ballModel.Player1Margine.Left - ballModel.PlayerSize.Width;
                    message.Margine = new System.Windows.Thickness(w, 0, 0, 0);
                }

                if (message.User.IsFirstUser)
                {
                    message.Message = massageP1;
                    massageP1       = "";
                }
                else
                {
                    message.Message = massageP2;
                    massageP2       = "";
                }

                return(new List <BallMessage>()
                {
                    message
                });
            }
            catch
            {
                return(null);
            }
        }
Пример #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="newMessage"></param>
 public void SendNewMessage(BallMessage newMessage)
 {
     mainEngine.AddNewMessage(newMessage);
 }
Пример #7
0
 private void StartGame(BallMessage message)
 {
     //BallPosition = new Vector(GameBoard.Width / 2, GameBoard.Height / 2);
     //gameSpeed = 1;
     Player2Label.Content = message.User2Name;
     //ballAngel = (string.Compare(message.User.AppAddress, clientUser.AppAddress) > 0 ? -1 : 1) * Math.PI / 3;
 }
Пример #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="newMessage"></param>
 public void SendNewMessage(BallMessage newMessage)
 {
     mainEngine.AddNewMessage(newMessage);
 }