Пример #1
0
        public bool Contains(Point point)
        {
            Pathfinding pathfinding = new Pathfinding();
            int back = (Location.X == 1) ? 0 : 52;

            return point.X == back && point.Y >= YCoordinate && point.Y < YCoordinate + Height;
        }
Пример #2
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;
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Draws an arrow line from the start location to the target point of every players' action.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void directionLinesPanel_Paint(object sender, PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            int cellWidth = fieldCell[0, 0].Size.Width;
            int cellHeight = fieldCell[0, 0].Size.Height;

            Pathfinding pathfinding = new Pathfinding();

            AdjustableArrowCap arrow = new AdjustableArrowCap(3, 3);
            Pen myPen = new Pen(Color.Blue, 1);
            myPen.CustomEndCap = arrow;

            Pen dp = new Pen(Brushes.Plum, 1.3f);
            dp.DashPattern = new float[] { 5f, 7f, 5f, 2f };
            dp.Color = Pathfinding.CurrentBlockedRoom.AllowedTeam.TeamColor;

            //draws the blocked room rectangle
            Rectangle drawRoom = new Rectangle(Pathfinding.CurrentBlockedRoom.Room.X * cellWidth, Pathfinding.CurrentBlockedRoom.Room.Y * cellHeight, Pathfinding.CurrentBlockedRoom.Room.Width * cellWidth, Pathfinding.CurrentBlockedRoom.Room.Height * cellHeight);
            graphics.DrawRectangle(dp, drawRoom);

            //draws the throw-room
            if (currentGame.CurrentAction.GameStatus == Status.ThrowIn && currentGame.GameBall.HasPlayerContact)
            {
                dp.DashPattern = new float[] { 20, 5 };
                dp.Color = Color.Black;
                Rectangle throwRoom = currentGame.CurrentAction.ThrowRoom;
                graphics.DrawRectangle(dp, throwRoom.X * cellWidth, throwRoom.Y * cellHeight, throwRoom.Width * cellWidth, throwRoom.Height * cellHeight);
            }

            if (informationPanel.LineSetting != DirectionLineSetting.NoCell)
            {
                //draw the player-directions
                List<Player> allPlayers = new List<Player>();
                allPlayers.AddRange(currentGame.FirstTeam.Players);
                allPlayers.AddRange(currentGame.SecondTeam.Players);
                foreach (Player player in allPlayers)
                {
                    if (player.PlayerActions.Count > 0 && !new Point(player.XCoordinate, player.YCoordinate).Equals(player.PlayerActions.Peek().TargetPoint))
                    {
                        DrawActionWays(graphics, player);
                    }
                }
            }

            //draw the ball direction if the setting "no-direction-lines" is not selected.
            if (informationPanel.LineSetting != DirectionLineSetting.NoCell && currentGame.GameBall.TargetPoint.HasValue && !currentGame.GameBall.HasPlayerContact)
            {
                myPen.Color = Color.Black;
                myPen.DashPattern = new float[] { 5f, 7f, 5f, 2f };
                Point from = currentGame.GameBall.ExactLocation;
                Point targetPoint = currentGame.GameBall.ExactTargetLocation;

                graphics.DrawLine(myPen, from, targetPoint);
            }
        }
Пример #4
0
 /* Returns the last point where the player will go to in the next round.  */
 private Point GetAffectedPoint(Player player)
 {
     Pathfinding pathfinding = new Pathfinding();
     ActionType type;
     return pathfinding.PlayerAtSpecificRound(player, 1, out type);
 }
Пример #5
0
 /* If the player wants to tackle another player, the new target point will be the location the tackled player will
  * have in the amount of rounds which this player needs to get to the current position of the players he wants to tackle. */
 public void UpdateTargetPoint(Point currentLocation, int speed)
 {
     if(Type == ActionType.Tackle && AffectedPlayer != null)
     {
         Pathfinding distanceCalcer = new Pathfinding();
         ActionType type;
         int distance = (int) Pathfinding.DistanceBetweenPoints(currentLocation, AffectedPlayer.Location);
         Point target = distanceCalcer.PlayerAtSpecificRound(AffectedPlayer, distance / speed, out type);
         TargetPointChanged = target != TargetPoint;
         TargetPoint = target;
     }
 }
Пример #6
0
        public new void Move()
        {
            for (int tmpSpeed = Speed; tmpSpeed > 0; tmpSpeed--)
            {
                if (TargetPoint.HasValue || IsInShootState)
                {
                    if (!HasReachedTargetPoint)
                    {
                        SetDirectionToTargetPoint();
                    }

                    Pathfinding pathfinding = new Pathfinding();
                    Point newLocation = ExactLocation;

                    newLocation.X += (int)(ExactXDirection * 20);
                    newLocation.Y += (int)(ExactYDirection * 20);
                    ExactLocation = newLocation;

                    Point gridLocation = pathfinding.GetGridLocation(newLocation);
                    PointReceivedArgs args = new PointReceivedArgs(gridLocation, newLocation);
                    BallWillMove(this, args);
                    if (TargetPoint.HasValue && Location.Equals(TargetPoint.Value))
                    {
                        if (IsInShootState)
                        {
                            HasReachedTargetPoint = true;
                            TargetPoint = null;
                        }
                        else
                        {
                            TargetPoint = null;
                            break;
                        }
                    }
                    if (IsInShootState && HasReachedTargetPoint)
                    {
                        Speed -= 1;
                        if (Speed <= 0)
                        {
                            TargetPoint = null;
                            break;
                        }
                    }
                }
            }
        }
Пример #7
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;
            }
        }
Пример #8
0
        /// <summary>
        /// Checks whether a player stands at the location at the moment and will stand on it in the next round as well. 
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        private Player StandsPlayerOnLocation(Point location)
        {
            Pathfinding pathfinding = new Pathfinding();
            Player foundPlayer = null;
            gameAI.AllPlayers.ToList().ForEach(x =>
            {
                if (x.Location == location)
                {
                    ActionType type;
                    Point nextRoundLocation = pathfinding.PlayerAtSpecificRound(x, 1, out type);
                    if (nextRoundLocation == location)
                    {
                        foundPlayer = x;
                    }
                }
            });

            return foundPlayer;
        }
Пример #9
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;
        }
Пример #10
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;
        }