Exemplo n.º 1
0
 public FoosPlayerListItem(IFoosPlayer player)
 {
     Email = player.Email;
     DisplayName = player.DisplayName;
     Status = player.Status;
     Priority = 50;
 }
Exemplo n.º 2
0
 public void Challenge(IFoosPlayer playerToChallenge)
 {
     Task.Factory.StartNew(() =>
     {
         Thread.Sleep(2000);
         var repsonse = new ChallengeResponse(playerToChallenge, m_Random.Next(2) == 0);
         if (ChallengeResponse != null) ChallengeResponse(repsonse);
     });
 }
Exemplo n.º 3
0
 public void ShowChallengeAlert(IFoosPlayer challenger)
 {
     m_AlertBubble = new AlertBubble(challenger, 30)
     {
         Top = Screen.PrimaryScreen.WorkingArea.Height - 200,
         Left = Screen.PrimaryScreen.WorkingArea.Width - 300
     };
     m_AlertBubble.ChallengeResponseReceived += AlertBubbleOnChallengeResponseReceived;
     m_AlertBubble.Show();
 }
Exemplo n.º 4
0
        /// <param name="alertColorSequence">
        /// List of (backgroundColor, foregroundColor) tuples to cycle through
        /// when alerting
        /// </param>
        /// 
        /// 
        /// <param name="alertTextSequence">
        /// List of strings to cycle the alert text through when alerting
        /// </param>
        /// 
        /// <param name="cancelledColors">
        /// (backgroundColor, foregroundColor) tuple, used if the challenge is
        /// cancelled
        /// </param>
        /// 
        /// <param name="discTrayAnnoyanceChance">
        /// Chance (number between 0 and 1) that the disc tray will open
        /// </param>
        public AlertWindow(Tuple<SolidColorBrush, SolidColorBrush> [] alertColorSequence,
                           String [] alertTextSequence,
                           Tuple<SolidColorBrush, SolidColorBrush> cancelledColors,
                           IFoosPlayer challenger,
                           double discTrayAnnoyanceChance)
        {
            InitializeComponent();

            m_AlertColorSequence = alertColorSequence;
            m_AlertTextSequence = alertTextSequence;
            m_CancelledColors = cancelledColors;

            m_Challenger = challenger;

            var random = new Random();

            m_StrobeTimer = new Timer {Interval = 1000 + random.Next(10)};

            DescriptionText.Text = "You have been challenged by " 
                                    + m_Challenger.DisplayName + "!";

            var currentFrame = 0;
            
            SetStrobeFrame(currentFrame);

            m_StrobeTimer.Elapsed += (sender, elapsedEventArgs) => Dispatcher.Invoke(() =>
            {
                currentFrame++;
                Dispatcher.Invoke(() => SetStrobeFrame(currentFrame));
            });

            m_StrobeTimer.Start();

            if (random.NextDouble() < discTrayAnnoyanceChance) { 
                // ReSharper disable once EmptyGeneralCatchClause
                try { 
                    OpenDiscDrive();
                    if (random.NextDouble() < 0.5) { 
                        CloseDiscDrive();
                    }
                }
                catch (Exception e)
                {
                    // what's the harm in a little more evil when we're already 
                    // opening the disc tray for a notification?
                }
            }
        }
Exemplo n.º 5
0
 public IFoosPlayer Process(IFoosPlayer player)
 {
     var emailParts = player.Email.Split(new[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
     if (emailParts.Length > 0)
     {
         var nameParts = emailParts[0].Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
         var sb = new StringBuilder();
         for (int i = 0; i < nameParts.Length; i++)
         {
             if (i != 0) sb.Append(" ");
             sb.Append(char.ToUpper(nameParts[i][0]));
             if (nameParts[i].Length > 1) sb.Append(nameParts[i].Substring(1));
         }
         if (emailParts.Length > 1 && !emailParts[1].Equals("red-gate.com", StringComparison.OrdinalIgnoreCase)) sb.Append(String.Format(" ({0})", emailParts[1].Replace(".com", String.Empty)));
         player.DisplayName = sb.ToString();
     }
     return player;
 }
Exemplo n.º 6
0
        public IFoosPlayer Process(IFoosPlayer inputPlayer)
        {
            var player = m_KnownPlayers.FirstOrDefault(p => p.Email == inputPlayer.Email);
            var known = player != null;
            if (!known) player = inputPlayer;
            try
            {
                player.Status = m_CommunicatorIntegration.StatusOfRedgateEmail(player.Email);
                if (player.Status != Status.Unknown)
                    player.DisplayName = m_CommunicatorIntegration.FriendlyName(player.Email);
            }
            catch
            {
                player.Status = Status.Unknown;
            }

            if(!known) m_CommunicatorIntegration.StatusChangedSubscribeEmail(player.Email);
            return player;
        }
Exemplo n.º 7
0
 public ChallengeRequest(IFoosPlayer challenger)
 {
     m_Challenger = challenger;
 }
Exemplo n.º 8
0
 public PlayerDiscoveryMessage(IFoosPlayer player)
 {
     m_Players = new[] { player };
 }
Exemplo n.º 9
0
 public void Challenge(IFoosPlayer playerToChallenge)
 {
     m_WebSocket.SendAsJson(new { action = "challenge", toChallenge = playerToChallenge.Email });
 }
Exemplo n.º 10
0
 private bool PlayableStatus(IFoosPlayer player)
 {
     return player.Status == Status.Available || player.Status == Status.Unknown;
 }
Exemplo n.º 11
0
 private void ChallengeResponseHandler(IFoosPlayer challenger, bool accepted)
 {
     CloseChallengeAlert();
     if (ChallengeResponseReceived != null) ChallengeResponseReceived(challenger, accepted);
 }
Exemplo n.º 12
0
        public void Reset(bool sendCancel)
        {
            lock (m_PlayerLineUp)
            {
                StatusMessage = c_Idle;
                m_Self.GameState = GameState.None;

                if (m_CurrentAlert != null)
                {
                    m_CurrentAlert.CloseChallengeAlert();
                    m_CurrentAlert = null;
                }
                if (m_HasAcceptedRemoteGame && m_CurrentChallenger != null)
                {
                    if (sendCancel) m_NetworkService.Respond(new ChallengeResponse(m_CurrentChallenger, false));
                    m_CurrentChallenger = null;
                }
                else if (m_IsOrganisingGame && sendCancel)
                {
                    m_NetworkService.CancelGame(m_PlayerLineUp.Where(p => p != m_Self).ToArray());
                }

                m_PlayerLineUp.Clear();
                GameCreationInProgress = false;
                HasAcceptedRemoteGame = false;
                m_Cts.Cancel();

                foreach (var item in m_PlayerList)
                {
                    item.GameState = GameState.None;
                }

                m_Cts.Dispose();
                m_Cts = new CancellationTokenSource();
            }
        }
Exemplo n.º 13
0
        public void RemovePlayer(IFoosPlayer player)
        {
            if (!IsGameReadyToStart && m_IsOrganisingGame) StatusMessage = c_CustomGame;
            if (m_HasAcceptedRemoteGame && player.Email.Equals(m_CurrentChallenger.Email, StringComparison.InvariantCultureIgnoreCase)) Reset(false);

            lock (m_PlayerLineUp)
            {
                m_PlayerLineUp.RemoveAll(p => p.Email.Equals(player.Email, StringComparison.InvariantCultureIgnoreCase));
            }
            OnPropertyChanged("IsGameReadyToStart");
        }
Exemplo n.º 14
0
        public void ShowChallengeAlert(IFoosPlayer challenger)
        {
            // Close any alerts already open before we start
            CloseChallengeAlert();

            SpeakerBeep();

            var alertColors = new[]
            {
                new Tuple<SolidColorBrush, SolidColorBrush> (Brushes.Red, Brushes.White),
                new Tuple<SolidColorBrush, SolidColorBrush> (Brushes.Gold, Brushes.Black)
            };

            var cancelledColors =
                new Tuple<SolidColorBrush, SolidColorBrush>(Brushes.Gray, Brushes.White);

            var textSequence = new[] { "FOOS", "ALERT" };

            double diskTrayChance = 0;

            if(DateTime.Now.Day == 1
               && DateTime.Now.Month == 4)
            {
                diskTrayChance = 0.5;
            }

            m_MainAlertWindow = new AlertWindow(alertColors,
                                                textSequence,
                                                cancelledColors,
                                                challenger,
                                                diskTrayChance)
            {
                Top = Screen.PrimaryScreen.WorkingArea.Top,
                Left = Screen.PrimaryScreen.WorkingArea.Left,
                Width = Screen.PrimaryScreen.WorkingArea.Width,
                Height = Screen.PrimaryScreen.WorkingArea.Height
            };
            m_MainAlertWindow.Show();
            m_MainAlertWindow.Activate();
            m_MainAlertWindow.WindowState = WindowState.Maximized;

            m_MainAlertWindow.ChallengeResponseReceived += ChallengeResponseHandler;
            m_MainAlertWindow.AlertClosed += AlertClosedHandler;

            m_SecondaryAlertWindows = new List<SecondaryAlertWindow>();

            foreach (var screen in Screen.AllScreens)
            {
                if (!Equals(screen, Screen.PrimaryScreen))
                {
                    var window = new SecondaryAlertWindow(alertColors,
                                                          textSequence,
                                                          cancelledColors)
                    {
                        Top = screen.WorkingArea.Top,
                        Left = screen.WorkingArea.Left,
                        Width = screen.WorkingArea.Width,
                        Height = screen.WorkingArea.Height
                    };
                    window.Show();
                    window.Activate();
                    window.WindowState = WindowState.Maximized;

                    m_SecondaryAlertWindows.Add(window);
                }
            }
        }
Exemplo n.º 15
0
 private void AlertBubbleOnChallengeResponseReceived(IFoosPlayer challenger, bool accepted)
 {
     if (ChallengeResponseReceived != null) ChallengeResponseReceived(challenger, accepted);
 }
Exemplo n.º 16
0
 private void AlertOnChallengeResponseReceived(IFoosPlayer challenger, bool accepted)
 {
     try
     {
         if (HasAcceptedRemoteGame || m_IsOrganisingGame) return;
         if (accepted)
         {
             HasAcceptedRemoteGame = true;
             OnPropertyChanged("CanCreateGameAuto");
             OnPropertyChanged("CanAddPlayer");
             StatusMessage = c_Accepted;
             var ch = m_PlayerList.FirstOrDefault(p => p.Email.Equals(m_CurrentChallenger.Email, StringComparison.OrdinalIgnoreCase));
             if (ch != null) ch.GameState = GameState.Challenger;
         }
         m_NetworkService.Respond(new ChallengeResponse(challenger, accepted));
     }
     catch (Exception ex)
     {
         if (OnError != null) OnError(this, new ErrorEventArgs(ex));
     }
     finally
     {
         m_CurrentAlert = null;
     }
 }
Exemplo n.º 17
0
 private string GetPlayerName(int playerIndex, IFoosPlayer[] playerArray)
 {
     if (playerArray.Length -1 < playerIndex) return String.Empty;
     return playerArray[playerIndex].DisplayName;
 }
Exemplo n.º 18
0
 private void NetworkServiceOnChallengeReceived(ChallengeRequest challengeRequest)
 {
     if (m_IsOrganisingGame)
     {
         m_NetworkService.Respond(new ChallengeResponse(challengeRequest.Challenger, false));
     }
     else if (m_HasAcceptedRemoteGame)
     {
         var sameChallenger = m_CurrentChallenger.Email.Equals(challengeRequest.Challenger.Email, StringComparison.InvariantCultureIgnoreCase);
         m_NetworkService.Respond(new ChallengeResponse(challengeRequest.Challenger, sameChallenger));
     }
     else
     {
         var challenger = m_PlayerList.FirstOrDefault(p => p.Email.Equals(challengeRequest.Challenger.Email, StringComparison.OrdinalIgnoreCase));
         if (challenger != null)
         {
             m_CurrentChallenger = challengeRequest.Challenger;
             Application.Current.Dispatcher.BeginInvoke(new Action(() =>
             {
                 m_CurrentAlert = m_Alerter.GetAlerter();
                 m_CurrentAlert.ChallengeResponseReceived += AlertOnChallengeResponseReceived;
                 m_CurrentAlert.ShowChallengeAlert(challenger);
             }));
         }
     }
 }
Exemplo n.º 19
0
 public ChallengeResponse(IFoosPlayer player, bool accepted)
 {
     m_Player = player;
     m_Accepted = accepted;
 }
Exemplo n.º 20
0
 public IFoosPlayer Process(IFoosPlayer player)
 {
     player.Status = Status.Unknown;
     return player;
 }