示例#1
0
 private void leaveMatch_Click(object sender, RoutedEventArgs e)
 {
     leaveMatch.IsEnabled = false;
     joinMatch.IsEnabled  = true;
     selectedMatch        = (Match)matchViewList.SelectedItem;
     MatchHubProxy.Invoke("LeaveMatch", selectedMatch.Name);
     cStatus.Content = "Not Connected";
 }
示例#2
0
        private async void HubConnection()
        {
            Connection    = new HubConnection(ServerURI);
            MatchHubProxy = Connection.CreateHubProxy("MatchHub");

            MatchHubProxy.On <Round>("addRound", (round) =>
                                     this.Dispatcher.Invoke(() => {
                roundList.Items.Add("Round " + round.Number + " started!");
                roundList.Items.Add("");
            })
                                     );
            MatchHubProxy.On <Kill>("addKill", (kill) =>
                                    this.Dispatcher.Invoke(() => {
                roundList.Items.Add(kill.KillerName + " killed " + kill.KilledName);
                roundList.Items.Add("");
                UpdateScrollBar(roundList);
            })
                                    );

            MatchHubProxy.On <Odds>("addOdds", (odds) =>
                                    this.Dispatcher.Invoke(() => {
                decimal d1 = odds.Odds1;
                decimal d2 = odds.Odds2;
                d1         = decimal.Round(d1, 2);
                d2         = decimal.Round(d2, 2);

                Odds1.Text = d1.ToString();
                Odds2.Text = d2.ToString();
            })
                                    );
            try {
                await Connection.Start();

                Console.WriteLine("Connected");
            } catch (HttpRequestException) {
                Console.WriteLine("Unable to connect to server: Start server before connecting clients.");
                return;
            }
        }
示例#3
0
        /// <summary>
        /// Algorithm to calculate odds based on round win. invokes BroadcastRoed(Round round) and BroadcastOdds(List<Odds> odds, Round round) on the matchHub.
        /// </summary>
        /// <param name="round"></param>
        public void CalculateOdds(Round round)
        {
            MatchHubProxy.Invoke("BroadcastRound", round);

            if (round.Number == 1)
            {
                odds.Add(CurrentTeam0Odds = 1.5M);
                odds.Add(CurrentTeam1Odds = 1.5M);
            }

            if (round.Winner == round.Match.Teams[0])
            {
                odds[0] = (CurrentTeam0Odds = CurrentTeam0Odds - ((CurrentTeam0Odds - 1M) * 0.15M));
                odds[1] = (CurrentTeam1Odds = CurrentTeam1Odds + ((CurrentTeam1Odds - 1M) * 0.15M));
            }
            else
            {
                odds[1] = (CurrentTeam1Odds = CurrentTeam1Odds - ((CurrentTeam1Odds - 1M) * 0.15M));
                odds[0] = (CurrentTeam0Odds = CurrentTeam0Odds + ((CurrentTeam0Odds - 1M) * 0.15M));
            }
            MatchHubProxy.Invoke("BroadcastOdds", odds, round);
        }