Exemplo n.º 1
0
        /// <summary>
        /// Draws the player's actions' ways to their target on the graphics depending on the current line Settings.
        /// </summary>
        /// <param name="graphics">The directionlinePanel's graphics</param>
        /// <param name="action"></param>
        /// <param name="player">The player who executes the actions</param>
        private void DrawActionWays(Graphics graphics, Player player)
        {
            Pathfinding pathfinding = new Pathfinding();
            AdjustableArrowCap arrow = new AdjustableArrowCap(3, 3);
            Pen myPen = new Pen(Color.Blue, 1);

            PlayerAction[] playerActions = player.PlayerActions.ToArray();
            Point lastAimPoint = pathfinding.GetExactLocation(player.Location);
            bool drawOneCell = informationPanel.LineSetting == DirectionLineSetting.OneCell;

            for (int i = 0; i < playerActions.Length; i++)
            {
                PlayerAction action = playerActions[i];

                myPen.Color = (action.Type == ActionType.Shoot || action.Type == ActionType.Pass) ? Color.Black : (currentGame.FirstTeam.Players.Contains(player)) ? currentGame.FirstTeam.TeamColor : (currentGame.SecondTeam.Players.Contains(player)) ? currentGame.SecondTeam.TeamColor : Color.DarkBlue;

                //set the correct dash pattern for each action type
                if (action.Type == ActionType.Pass || action.Type == ActionType.Shoot)
                {
                    myPen.DashPattern = new float[] { 5f, 7f, 5f, 2f };
                }
                else
                {
                    myPen.DashPattern = new float[] { 1f };
                }

                Point nextPoint = pathfinding.GetExactLocation(action.TargetPoint);

                if (informationPanel.LineSetting != DirectionLineSetting.DirectWay && action.Type == ActionType.Run || action.Type == ActionType.Tackle)
                {
                    lock (action.WayToTarget)
                    {
                        List<Point> waypoints = action.WayToTarget.ToList();
                        foreach (Point waypoint in waypoints)
                        {
                            nextPoint = pathfinding.GetExactLocation(waypoint);

                            if (waypoint.Equals(action.WayToTarget.ElementAt(action.WayToTarget.Count - 1)) || drawOneCell)
                            {
                                myPen.CustomEndCap = arrow;
                            }
                            else
                            {
                                myPen.EndCap = LineCap.NoAnchor;
                            }

                            graphics.DrawLine(myPen, lastAimPoint, nextPoint);
                            lastAimPoint = nextPoint;

                            if (drawOneCell)
                            {
                                lastAimPoint = pathfinding.GetExactLocation(action.TargetPoint);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    myPen.CustomEndCap = arrow;
                    graphics.DrawLine(myPen, lastAimPoint, nextPoint);
                }

                if (action.Type != ActionType.Shoot && action.Type != ActionType.Pass)
                {
                    lastAimPoint = nextPoint;
                    if (drawOneCell)
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the game ball to the parameter's location.
        /// </summary>
        /// <param name="targetPoint"></param>
        private void SetBallToPoint(Point targetPoint)
        {
            Ball currentBall = currentGame.GameBall;
            Pathfinding pathfinding = new Pathfinding();

            currentBall.Location = targetPoint;
            currentBall.ExactLocation = pathfinding.GetExactLocation(currentBall.Location);
            currentBall.Speed = 0;
            currentBall.TargetPoint = null;
            currentBall.HasPlayerContact = false;
            currentBall.IsInShootState = false;
        }
Exemplo n.º 3
0
        /* Sets object's direction towards it's target.
        * If xDirection or yDirection is '0', the object won't move.
        * If xDirection is '-1' or '1' the object will move in left/right direction.
        * If yDirection is '-1' or '1' the object will move in up/down direction. */
        public void SetDirectionToTargetPoint()
        {
            if (TargetPoint.HasValue)
            {
                Pathfinding pathfinding = new Pathfinding();

                double[] exactDirection = pathfinding.GetExactDirection(ExactLocation, pathfinding.GetExactLocation(TargetPoint.Value));
                if (double.IsNaN(exactDirection[0]) || double.IsNaN(exactDirection[1]))
                {
                    ExactXDirection = 0;
                    ExactYDirection = 0;
                }
                else
                {
                    ExactXDirection = exactDirection[0];
                    ExactYDirection = exactDirection[1];
                }
            }
            else
            {
                ExactXDirection = 0;
                ExactYDirection = 0;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the location of the ball to the current location of the target player,
        /// deletes the target point of the ball and informs the player that he controls the ball now.
        /// </summary>
        /// <param name="targetPlayer"></param>
        private void GiveBallToPlayer(Player targetPlayer)
        {
            Ball currentBall = currentGame.GameBall;
            Pathfinding pathfinding = new Pathfinding();

            currentBall.Location = targetPlayer.Location;
            currentBall.ExactLocation = pathfinding.GetExactLocation(targetPlayer.Location);
            currentBall.Speed = 0;
            currentBall.TargetPoint = null;
            currentBall.IsInShootState = false;
            currentBall.HasPlayerContact = true;
            currentBall.LastPlayer = targetPlayer;

            targetPlayer.HasBall = true;
        }