Example #1
0
        public bool IsBallInGoal(Ball ball)
        {
            bool ret = false;

            if (
                ball.Position.X > NWPoint.X &&
                ball.Position.X < NEPoint.X &&
                ball.Position.Y > NWPoint.Y &&
                ball.Position.Y < SWPoint.Y)
            {
                bool wasInFrontOfGoal = false;
                if (this.ID == 1) //left goal
                {
                    wasInFrontOfGoal = (ball.X - ball.TranslateVelocity.X  > SEPoint.X);
                }
                else
                {
                    wasInFrontOfGoal = (ball.X - ball.TranslateVelocity.X < NWPoint.X);
                }

                if (wasInFrontOfGoal)
                {
                    if (!ball.IsBallInGoal)
                    {
                        ball.LastGoalID = ID;
                        ball.IsBallInGoal = true;
                        subscriber.BallEnteredGoal(this, ball);
                    }
                    ret = true;
                }
                else
                {
                    ret = false;
                }
            }
            else
            {
                if (ball.IsBallInGoal && ball.LastGoalID == ID)
                {
                    ball.IsBallInGoal = false;
                    subscriber.BallLeftGoal(this, ball);
                }
            }

            return ret;
        }
 public void BallLeftGoal(Goal goal, Ball ball)
 {
 }
        private List<GhostBall> GetGhostBalls(Team team, Ball ball, bool despair)
        {
            List<GhostBall> ghostBalls = new List<GhostBall>();

            int i = 0;
            foreach (Player player in team.players)
            {
                if (player.IsPlaying)
                {
                    foreach (Goal goal in goals)
                    {
                        List<Point> hotSpots = goal.HotSpots;

                        foreach (Point hotSpot in hotSpots)
                        {
                            //distances between goal hotspot and ball center
                            double dxGoalBallOn = hotSpot.X - ball.Position.X;
                            double dyGoalBallOn = hotSpot.Y - ball.Position.Y;
                            double hGoalBallOn = Math.Sqrt(dxGoalBallOn * dxGoalBallOn + dyGoalBallOn * dyGoalBallOn);
                            double a = dyGoalBallOn / dxGoalBallOn;

                            //distances between ball on center and ghost ball center
                            double hBallOnGhost = (ball.Radius - 1.5) * 2.0;
                            double dxBallOnGhost = hBallOnGhost * (dxGoalBallOn / hGoalBallOn);
                            double dyBallOnGhost = hBallOnGhost * (dyGoalBallOn / hGoalBallOn);

                            //ghost ball coordinates
                            double gX = ball.Position.X - dxBallOnGhost;
                            double gY = ball.Position.Y - dyBallOnGhost;
                            double dxGhostPlayer = player.Position.X - gX;
                            double dyGhostPlayer = player.Position.Y - gY;
                            double hGhostPlayer = Math.Sqrt(dxGhostPlayer * dxGhostPlayer + dyGhostPlayer * dyGhostPlayer);

                            //distances between ball center and player center
                            double dxBallOnPlayer = ball.Position.X - player.Position.X;
                            double dyBallOnPlayer = ball.Position.Y - player.Position.Y;
                            double hBallOnPlayer = Math.Sqrt(dxBallOnPlayer * dxBallOnPlayer + dyBallOnPlayer * dyBallOnPlayer);

                            //if (((Math.Sign(dxGoalBallOn) == Math.Sign(dxBallOnPlayer) || dxGoalBallOn == 0) && (Math.Sign(dyGoalBallOn) == Math.Sign(dyBallOnPlayer) || dyGoalBallOn == 0)))
                            //{
                            //    GhostBall ghostBall = new GhostBall(player, new Point(gX, gY), hBallOnPlayer, a, 0);
                            //    ghostBalls.Add(ghostBall);
                            //    i++;
                            //}

                            int value = 0;
                            if (
                                !(((Math.Sign(dxGoalBallOn) == Math.Sign(dxBallOnPlayer) || dxGoalBallOn == 0) &&
                                (Math.Sign(dyGoalBallOn) == Math.Sign(dyBallOnPlayer) || dyGoalBallOn == 0)))
                                )
                            {
                                value += 10;
                            }

                            GhostBall ghostBall = new GhostBall(player, new Point(gX, gY), hBallOnPlayer, a, value);
                            ghostBalls.Add(ghostBall);
                            i++;
                        }
                    }
                }
            }

            return ghostBalls;
        }
 public void BallEnteredGoal(Goal goal, Ball ball)
 {
     turnEvents.Add(new BallEnteredGoal(currentGame.PlayingTeamID, goal, new Point(ball.Position.X, ball.Position.Y)));
     pottedBalls.Add(ball);
     //if (ball.LastGoalID == 1)
     //{
     //    scoreControl.Team2Score++;
     //}
     //else
     //{
     //    scoreControl.Team1Score++;
     //}
     //letterContainer.Visibility = Visibility.Visible;
     //sbLetters.Begin();
     //hasPendingGoalResolution = true;
 }
        public MainPage(Dictionary<string, object> parameters)
            : base(parameters)
        {
            InitializeComponent();

            GameHelper.Instance.IsMovingDiscoids = false;

            clockTimer.Tick += new EventHandler(clockTimer_Tick);
            clockTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);

            movementTimer.Tick += new EventHandler(movementTimer_Tick);
            movementTimer.Interval = new TimeSpan(0, 0, 0, 0, 10);
            movementTimer.Start();

            clockTimer.Start();

            groups = GameHelper.Instance.Groups;

            teamsDictionary = GameHelper.Instance.TeamsDictionary;

            LoadTeamPlayers(teamPlayers);

            LoadGameTable(gameTable);

            selectedTeamID = Parameters["TeamID1"].ToString();
            DateTime lastGameDate = new DateTime(2010,06,01);

            LoadBall();

            currentGame = GetNextGame(selectedTeamID, lastGameDate);

            strengthPointNW = new Point
            (
                this.colLeftEscapeArea.Width.Value +
                this.colLeftPosts.Width.Value +
                this.colLeftGoalArea.Width.Value +
                this.colLeftPenaltyArea.Width.Value +
                this.colHalfWay.Width.Value +
                this.colRightPenaltyArea.Width.Value +
                this.colRightGoalArea.Width.Value +
                this.colRightPosts.Width.Value,
                this.rowTopEscapeArea.Height.Value +
                this.rowTopFieldLine.Height.Value +
                this.rowTopPenaltyArea.Height.Value +
                this.rowTopGoalArea.Height.Value
            );

            strengthPointSE = new Point
            (
                strengthPointNW.X + colMenu.Width.Value,
                strengthPointNW.Y +
                rowBottomGoalArea.Height.Value +
                rowBottomPenaltyArea.Height.Value
            );

            fieldWidth =
                this.colLeftEscapeArea.Width.Value +
                this.colLeftPosts.Width.Value +
                this.colLeftGoalArea.Width.Value +
                this.colLeftPenaltyArea.Width.Value +
                this.colHalfWay.Width.Value +
                this.colRightPenaltyArea.Width.Value +
                this.colRightGoalArea.Width.Value +
                this.colRightPosts.Width.Value;

            fieldHeight =
                this.rowTopEscapeArea.Height.Value +
                this.rowTopFieldLine.Height.Value +
                this.rowTopPenaltyArea.Height.Value +
                this.rowTopGoalArea.Height.Value +
                this.rowBottomGoalArea.Height.Value +
                this.rowBottomPenaltyArea.Height.Value +
                this.rowBottomFieldLine.Height.Value;

            goalPost00Point = new Point(
                this.colLeftEscapeArea.Width.Value,
                this.rowTopEscapeArea.Height.Value +
                this.rowTopFieldLine.Height.Value +
                this.rowTopPenaltyArea.Height.Value);

            goalPost01Point = new Point(goalPost00Point.X, goalPost00Point.Y + rowTopGoalArea.Height.Value);

            goalPost10Point = new Point(
                this.colLeftEscapeArea.Width.Value +
                this.colLeftPosts.Width.Value +
                this.colLeftGoalArea.Width.Value +
                this.colLeftPenaltyArea.Width.Value +
                this.colHalfWay.Width.Value +
                this.colRightPenaltyArea.Width.Value +
                this.colRightGoalArea.Width.Value,
                goalPost00Point.Y);

            goalPost11Point = new Point(goalPost10Point.X, goalPost10Point.Y + rowTopGoalArea.Height.Value);

            discoids.Add(new GoalPost(new Vector2D(goalPost00Point.X, goalPost00Point.Y), new Vector2D(8, 8), "1001"));
            discoids.Add(new GoalPost(new Vector2D(goalPost01Point.X, goalPost01Point.Y), new Vector2D(8, 8), "1002"));
            discoids.Add(new GoalPost(new Vector2D(goalPost10Point.X, goalPost10Point.Y), new Vector2D(8, 8), "1003"));
            discoids.Add(new GoalPost(new Vector2D(goalPost11Point.X, goalPost11Point.Y), new Vector2D(8, 8), "1004"));

            goals.Add(new Goal(this, 1, new Point(0, goalPost00Point.Y), goalPost00Point, new Point(0, goalPost01Point.Y), goalPost01Point));
            goals.Add(new Goal(this, 2, goalPost10Point, new Point(goalPost10Point.X + colRightGoalArea.Width.Value, goalPost10Point.Y), goalPost11Point, new Point(goalPost11Point.X + colRightGoalArea.Width.Value, goalPost11Point.Y)));

            ball = new Ball(new Vector2D(550, 310), new Vector2D(36, 36), "9");
            ball.X = (goalPost00Point.X + goalPost10Point.X) / 2;
            ball.Y = (rowTopEscapeArea.Height.Value + fieldHeight - rowTopEscapeArea.Height.Value) / 2;

            rootCanvas.Children.Add(bf);

            discoids.Add(ball);

            LoadPlayerFaces();

            ResetPlayerPositions(currentGame.Teams[currentGame.Team1ID], currentGame.Teams[currentGame.Team2ID], rootCanvas, discoids, goalPost00Point.X, goalPost10Point.X, rowTopEscapeArea.Height.Value, fieldHeight - rowTopEscapeArea.Height.Value);

            LayoutRoot.Background = new ImageBrush() { ImageSource = new BitmapImage(new Uri("../Images/Grass.png", UriKind.Relative)) };

            tableBorders.Add(new TableBorder(0, -20, (int)fieldWidth, 20));
            tableBorders.Add(new TableBorder(0, (int)fieldHeight, (int)fieldWidth, 200));
            tableBorders.Add(new TableBorder(-20, 0, 20, (int)fieldHeight));
            tableBorders.Add(new TableBorder((int)fieldWidth, 0, 20, (int)fieldHeight));
            tableBorders.Add(new TableBorder(0, (int)goalPost00Point.Y, (int)colLeftEscapeArea.Width.Value, 10));
            tableBorders.Add(new TableBorder(0, (int)goalPost01Point.Y, (int)colLeftEscapeArea.Width.Value, 10));
            tableBorders.Add(new TableBorder((int)goalPost10Point.X, (int)goalPost10Point.Y, (int)colRightPosts.Width.Value, 10));
            tableBorders.Add(new TableBorder((int)goalPost11Point.X, (int)goalPost11Point.Y, (int)colRightPosts.Width.Value, 10));

            scoreControl.SetValue(Grid.ColumnProperty, 1);
            scoreControl.SetValue(Grid.RowProperty, 0);
            scoreControl.SetValue(Grid.ColumnSpanProperty, 3);
            scoreControl.SetValue(Grid.RowSpanProperty, 1);
            LayoutRoot.Children.Add(scoreControl);

            scoreControl.Team1Name = currentGame.Team1ID;
            scoreControl.Team1Score = currentGame.Scores[currentGame.Team1ID];
            scoreControl.Team2Name = currentGame.Team2ID;
            scoreControl.Team2Score = currentGame.Scores[currentGame.Team2ID];
            scoreControl.PlayingTeamID = currentGame.PlayingTeamID;

            this.Background = new SolidColorBrush(Colors.Black);

            sbStadiumScreen = new Storyboard()
            {
                Duration = new Duration(new TimeSpan(0, 0, 0, 10))
            };

            DoubleAnimation translateAnimation = new DoubleAnimation()
            {
                From = 800,
                To = 0,
                Duration = new Duration(new TimeSpan(0, 0, 0, 3))
            };

            Storyboard.SetTarget(translateAnimation, lettersXTranslate);
            Storyboard.SetTargetProperty(translateAnimation, new PropertyPath("X"));

            DoubleAnimation lettersOpacityAnimation = new DoubleAnimation()
            {
                From = 0.8,
                To = 1.0,
                Duration = new Duration(new TimeSpan(0, 0, 0, 0, 500)),
                AutoReverse = true,
                RepeatBehavior = RepeatBehavior.Forever
            };

            Storyboard.SetTarget(lettersOpacityAnimation, grdBrightness);
            Storyboard.SetTargetProperty(lettersOpacityAnimation, new PropertyPath("Opacity"));

            DoubleAnimation screenOpacityAnimation = new DoubleAnimation()
            {
                From = 1.0,
                To = 0.0,
                BeginTime = new TimeSpan(0, 0, 0, 0),
                Duration = new Duration(new TimeSpan(0, 0, 0, 4))
            };

            sbStadiumScreen.Children.Add(translateAnimation);
            sbStadiumScreen.Children.Add(lettersOpacityAnimation);
            sbStadiumScreen.Children.Add(screenOpacityAnimation);

            Storyboard.SetTarget(screenOpacityAnimation, grdStadiumScreen);
            Storyboard.SetTargetProperty(screenOpacityAnimation, new PropertyPath("Opacity"));

            Storyboard sbBallStrength = new Storyboard()
            {
                RepeatBehavior = RepeatBehavior.Forever
            };

            DoubleAnimation ballStrengthAngle = new DoubleAnimation()
            {
                From = 0.0,
                To = 360,
                Duration = new Duration(new TimeSpan(0, 0, 0, 3, 0)),
                RepeatBehavior = RepeatBehavior.Forever
            };

            sbBallStrength.Children.Add(ballStrengthAngle);
            Storyboard.SetTarget(ballStrengthAngle, rtBallStrength);
            Storyboard.SetTargetProperty(ballStrengthAngle, new PropertyPath("Angle"));
            sbBallStrength.Begin();
        }