The event the will handle substitutions.
Inheritance: Event
Esempio n. 1
0
        /*-----------------------------------------------------------------------------------------------------------*/
        /*-----------------------------------------------TURNOVER END------------------------------------------------*/
        /*-----------------------------------------------------------------------------------------------------------*/
        /************************************************************************************************************/
        /****************************************************FOUL****************************************************/
        /************************************************************************************************************/
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void foul_Click(object sender, EventArgs e)
        {
            string str = this.getQuickPromptResult(sender, false);

            bool ejected = false;
            if (str == null)
            {
                return;
            }
            else if (str.ToLower().Equals("ejection"))
            {
                ejected = true;
                str = this.getQuickPromptResult(sender, true);
                if (str == null)
                {
                    return;
                }
            }
            print(str);
            FoulEvent fe = null;
            SubstitutionEvent se = null;
            if (!str.Equals("Technical"))
            {
                if (firstSelectedPlayer == null)
                {
                    MessageBox.Show("Please select at least one player above", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (secondSelectedPlayer != null && firstSelectedPlayer.TeamId == secondSelectedPlayer.TeamId)
                {
                    MessageBox.Show("Selected players must be on different teams", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (!pointSelected)
                {
                    MessageBox.Show("Please select a location on the court", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    firstSelectedContext.Text = "Commit";
                    if (secondSelectedContext != null)
                        secondSelectedContext.Text = "Drew";
                }
            }
            string drewBy = secondSelectedPlayer == null ? null : secondSelectedPlayer.Id;
            if (str.Equals("Offensive"))
            {
                DataForm dataForm = new DataForm(pac, "foul", DataForm.CHARGING, generateDataFormLocation(foulButton));
                dataForm.ejected = ejected;
                dataForm.committedBy = firstSelectedPlayer;
                dataForm.ShowDialog();
                if (dataForm.cancelled)
                {
                    return;
                }

                if (dataForm.ejected)
                {
                    se = new SubstitutionEvent(pac, dataForm.replacingPlayer.Id, firstSelectedPlayer.Id, firstSelectedPlayer.TeamId);
                }

                fe = new FoulEvent(pac, firstSelectedPlayer.TeamId, firstSelectedPlayer.Id,
                    drewBy, dataForm.foulType, ejected, currPoint);
            }
            else if (str.Equals("Defensive"))
            {
                DataForm dataForm = new DataForm(pac, "foul", DataForm.FOUL_TYPE, generateDataFormLocation(foulButton));
                dataForm.ejected = ejected;
                dataForm.committedBy = firstSelectedPlayer;
                dataForm.ShowDialog();
                if (dataForm.cancelled)
                {
                    return;
                }

                if (dataForm.ejected)
                {
                    se = new SubstitutionEvent(pac, dataForm.replacingPlayer.Id, firstSelectedPlayer.Id, firstSelectedPlayer.TeamId);
                }
                fe = new FoulEvent(pac, firstSelectedPlayer.TeamId, firstSelectedPlayer.Id,
                    drewBy, dataForm.foulType, ejected, currPoint);
            }
            else if (str.Equals("Technical"))
            {
                DataForm dataForm = new DataForm(pac, "tech", DataForm.TECHNICAL, generateDataFormLocation(foulButton));
                dataForm.ejected = ejected;
                dataForm.committedBy = firstSelectedPlayer;
                dataForm.ShowDialog();
                if (dataForm.cancelled)
                {
                    return;
                }

                if (dataForm.cancelled)
                {
                    return;
                }

                if (dataForm.ejected)
                {
                    se = new SubstitutionEvent(pac, dataForm.replacingPlayer.Id, dataForm.committedBy.Id, dataForm.committedBy.TeamId);
                }
                fe = new FoulEvent(pac, dataForm.committedBy.TeamId, dataForm.committedBy.Id,
                    null, "technical", ejected, currPoint);

            }

            confirmAndSendEvent(fe);
            if (se != null)
            {
                confirmAndSendEvent(se);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void subPlayer_click(object sender, EventArgs e)
        {
            if (buttonPanel.Visible)
            {
                buttonPanel.Visible = false;
            }
            ToolStripMenuItem subInItem = (ToolStripMenuItem)sender;
            string subInItemText = subInItem.Text;
            ToolStripMenuItem subOutItem = (ToolStripMenuItem)subContextMenuStrip.Items[0];
            string subOutItemText = subOutItem.Text;

            int inBeg = subInItemText.IndexOf("#") + 1;
            int inLength = subInItemText.IndexOf(" (") - inBeg;
            int outBeg = subOutItemText.IndexOf("#") + 1;
            int outLength = subOutItemText.IndexOf(" (") - outBeg;

            int subInNumber = int.Parse(subInItemText.Substring(inBeg, inLength));
            int subOutNumber = int.Parse(subOutItemText.Substring(outBeg, outLength));

            Player subInPlayer = null;
            Player subOutPlayer = null;

            subInPlayer = pac.getPlayerByNumber(homeRightClicked, subInNumber);
            subOutPlayer = pac.getPlayerByNumber(homeRightClicked, subOutNumber);

            SubstitutionEvent subEvent = new SubstitutionEvent(pac, subInPlayer.Id, subOutPlayer.Id, subInPlayer.TeamId);

            confirmAndSendEvent(subEvent);
        }
Esempio n. 3
0
        private void sub_DoubleClick(object sender, EventArgs e)
        {
            string result = null;
            if (sender == homeNameLabel || sender == awayNameLabel)
            {
                resetFirstSecondSelected();
                result = getQuickPromptResult(sender, sender == homeNameLabel);
                if (result == null)
                {
                    return;
                }
                TimeoutEvent timeoutEvent = null;
                if (result.Equals("Home Timeout"))
                {
                    timeoutEvent = new TimeoutEvent(pac, pac.HomeTeam.Id, "team");
                }
                else if (result.Equals("Away Timeout"))
                {
                    timeoutEvent = new TimeoutEvent(pac, pac.AwayTeam.Id, "team");
                }
                else if (result.Equals("Media Timeout"))
                {
                    timeoutEvent = new TimeoutEvent(pac, null, "media");
                }
                else if (result.Equals("Official Timeout"))
                {
                    timeoutEvent = new TimeoutEvent(pac, null, "official");
                }

                confirmAndSendEvent(timeoutEvent);
                return;
            }

            // lets get the jersey nubmer that was clicked on
            int senderNumber = -1;
            if (sender is Label)
            {
                homeRightClicked = homePlayerLabels.Contains(sender);
                senderNumber = int.Parse(((Label)sender).Text);
            }
            else
            {
                homeRightClicked = homePlayerContexts.Contains(sender);
                senderNumber = homeRightClicked ? int.Parse(homePlayerLabels[homePlayerContexts.IndexOf((GroupBox)sender)].Text)
                                                : int.Parse(awayPlayerLabels[awayPlayerContexts.IndexOf((GroupBox)sender)].Text);
            }
            lastPlayer = pac.getPlayerByNumber(homeRightClicked, senderNumber);

            resetFirstSecondSelected();
            result = getQuickPromptResult(sender, homeRightClicked);
            if (result == null)
            {
                return;
            }

            int outBeg = result.IndexOf("#") + 1;
            int outLength = result.IndexOf(" (") - outBeg;

            int subOutNumber = int.Parse(result.Substring(outBeg, outLength));

            Player subOutPlayer = lastPlayer;
            Player subInPlayer = null;

            subInPlayer = pac.getPlayerByNumber(homeRightClicked, subOutNumber);

            SubstitutionEvent subEvent = new SubstitutionEvent(pac, subInPlayer.Id, subOutPlayer.Id, subInPlayer.TeamId);

            confirmAndSendEvent(subEvent);
        }
Esempio n. 4
0
        public List<Event> getEvents(Alpaca pac)
        {
            List<Event> events = new List<Event>();
            if (gameEvents == null)
                return events;

            foreach(Dictionary<string, object> dict in gameEvents)
            {
                Event e = null;
                string eventType = dict["eventType"].ToString().Split(new char[] { '/' })[1];
                Console.WriteLine("Found eventType: " + eventType);
                Context context = JsonConvert.DeserializeObject<Context>(dict["context"].ToString());
                if (eventType.Equals("gameEnd"))
                {
                    e = new GameEndEvent(pac);
                }
                else if (eventType.Equals("periodStart"))
                {
                    Console.WriteLine("Found a periodStart event");
                    e = new PeriodStartEvent(pac);
                }
                else if (eventType.Equals("periodEnd"))
                {
                    e = new PeriodEndEvent(pac);
                }
                else if (eventType.Equals("madeShot"))
                {

                    string shooter = dict["shooter"].ToString();
                    object assisted;
                    dict.TryGetValue("assistedBy", out assisted);

                    string assistedBy = null;
                    if (assisted != null)
                        assistedBy = assisted.ToString();
                    string shotType = dict["shotType"].ToString();
                    int pointsScored = int.Parse(dict["pointsScored"].ToString());
                    bool fastBreak = bool.Parse(dict["fastBreakOpportunity"].ToString());
                    bool goaltending = bool.Parse(dict["goaltending"].ToString());
                    int[] location = JsonConvert.DeserializeObject<int[]>(dict["location"].ToString());
                    Point locPt = new Point(location[0], location[1]);

                    Console.WriteLine("made shot");
                    Console.WriteLine(shooter);
                    Console.WriteLine(location[0] + " " + location[1]);

                    e = new MadeShotEvent(pac, shooter, pac.getPlayer(shooter).TeamId, assistedBy, shotType, pointsScored, fastBreak,
                        goaltending, locPt);
                }
                else if (eventType.Equals("missedShot"))
                {
                    string shooter = dict["shooter"].ToString();
                    object blocked;
                    dict.TryGetValue("blockedBy", out blocked);

                    string blockedBy = null;
                    if (blocked != null)
                        blockedBy = blocked.ToString();

                    string shotType = dict["shotType"].ToString();
                    int pointsAttempted = int.Parse(dict["pointsAttempted"].ToString());
                    bool fastBreak = bool.Parse(dict["fastBreakOpportunity"].ToString());
                    int[] location = JsonConvert.DeserializeObject<int[]>(dict["location"].ToString());
                    Point locPt = new Point(location[0], location[1]);

                    e = new MissedShotEvent(pac, shooter, pac.getPlayer(shooter).TeamId, blockedBy, shotType, pointsAttempted, fastBreak, locPt);

                }
                else if (eventType.Equals("jumpBall"))
                {
                    string homePlayer = dict["homePlayer"].ToString();
                    string awayPlayer = dict["awayPlayer"].ToString();
                    string winner = dict["winner"].ToString();
                    int[] location = JsonConvert.DeserializeObject<int[]>(dict["location"].ToString());
                    Point locPt = new Point(location[0], location[1]);

                    e = new JumpballEvent(pac, homePlayer, awayPlayer, winner, locPt);

                }
                else if (eventType.Equals("rebound"))
                {
                    object rebound;
                    dict.TryGetValue("rebounder", out rebound);

                    string rebounder = null;
                    if (rebound != null)
                    {
                        rebounder = rebound.ToString();
                    }

                    string reboundType = dict["reboundType"].ToString();

                    int[] location = JsonConvert.DeserializeObject<int[]>(dict["location"].ToString());
                    Point locPt = new Point(location[0], location[1]);

                    e = new ReboundEvent(pac, rebounder, reboundType, locPt);

                }
                else if (eventType.Equals("substitution"))
                {
                    string exitingPlayer = dict["exitingPlayer"].ToString();
                    string enteringPlayer = dict["enteringPlayer"].ToString();

                    e = new SubstitutionEvent(pac, enteringPlayer, exitingPlayer, pac.getPlayer(enteringPlayer).TeamId);
                }
                else if (eventType.Equals("turnover"))
                {
                    string committedBy = dict["committedBy"].ToString();
                    object forced;
                    dict.TryGetValue("forcedBy", out forced);

                    string forcedBy = null;
                    if (forced != null)
                    {
                        forcedBy = forced.ToString();
                    }

                    string turnoverType = dict["turnoverType"].ToString();
                    int[] location = JsonConvert.DeserializeObject<int[]>(dict["location"].ToString());
                    Point locPt = new Point(location[0], location[1]);

                    e = new TurnoverEvent(pac, committedBy, forcedBy, turnoverType, locPt);
                }
                else if (eventType.Equals("timeout"))
                {
                    object team;

                    dict.TryGetValue("timeoutTeam", out team);

                    string timeoutTeam = null;
                    if (team != null)
                    {
                        timeoutTeam = team.ToString();
                    }

                    string timeoutType = dict["timeoutType"].ToString();

                    e = new TimeoutEvent(pac, timeoutTeam, timeoutType);

                }
                else if (eventType.Equals("foul"))
                {
                    string committedBy = dict["committedBy"].ToString();

                    object drew;
                    dict.TryGetValue("drewBy", out drew);

                    string drewBy = null;
                    if (drew != null)
                    {
                        drewBy = drew.ToString();
                    }

                    string foulType = dict["foulType"].ToString();
                    bool ejected = bool.Parse(dict["ejected"].ToString());
                    int[] location = JsonConvert.DeserializeObject<int[]>(dict["location"].ToString());
                    Point locPt = new Point(location[0], location[1]);

                    e = new FoulEvent(pac, pac.getPlayer(committedBy).TeamId, committedBy, drewBy, foulType, ejected, locPt);

                }

                if (e != null)
                {
                    e.EventId = dict["eventId"].ToString();
                    e.setContext(context);
                    e.resolve();
                    events.Add(e);
                }
            }
            return events;
        }