Пример #1
0
        /// <summary>
        /// Draws the point, from the clicked location...
        /// 
        /// TODO: Needs to be documented
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void courtBox_MouseDown(object sender, MouseEventArgs e)
        {
            buttonPanel.Location = new Point(this.Width, this.Height);
            buttonPanel.Visible = false;
            courtBox.Refresh();
            historyBox.ClearSelected();
            const int imageBorder = 2;

            MouseButtons currButton = e.Button;
            Point loc = new Point(e.X, e.Y);

            if (!pac.InsidePeriod)
            {
                MessageBox.Show("You must start a period before continuing", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (currButton == System.Windows.Forms.MouseButtons.Right)
            {
                buttonPanel.Visible = false;
                update();
                return;
            }

            /* We need to get the location of the click in "ESPN" coordinates.  That is, the top left corner is (0,0)
             * and the bottom right corner is (940, 500). */

            /* This is close enough for now... later we can make a better rescale of the image and perfect this algorithm */

            loc.X = (int)(loc.X - imageBorder);
            loc.Y = (int)(loc.Y - imageBorder);

            if (loc.X < 0) loc.X = 0;
            if (loc.Y < 0) loc.Y = 0;

            currPoint = loc;
            if (waitingForReboundClick)
            {
                ReboundEvent re = new ReboundEvent(pac, savedPlayer.Id, savedReboundType, currPoint);
                confirmAndSendEvent(savedEvent);
                confirmAndSendEvent(re);
                savedPlayer = null;
                savedEvent = null;
                savedReboundType = null;
                waitingForReboundClick = false;
                postRebound = true;
                return;
            }
            // the form needs to know if we have selected a point yet
            pointSelected = true;

            Graphics g = courtBox.CreateGraphics();
            using (Pen p = new Pen(Color.Red, 4))
            {
                g.DrawEllipse(p, e.X - 5, e.Y - 5, 10, 10);
            }
            Point courtLoc = this.courtBox.Location;
            int bLocX = Math.Max(courtLoc.X + e.X + 8, 8);
            bLocX = Math.Min(bLocX, courtLoc.X + courtBox.Width);
            int bLocY = Math.Max(courtLoc.Y, courtLoc.Y + e.Y - (buttonPanel.Height / 2));
            bLocY = Math.Min(bLocY, courtLoc.Y + courtBox.Height - buttonPanel.Height);
            Point buttonPanelLoc = new Point(bLocX, bLocY);
            buttonPanel.Location = buttonPanelLoc;
        }
Пример #2
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;
        }