当前位置: 首页>>代码示例>>C#>>正文


C# Ball.GetClosest方法代码示例

本文整理汇总了C#中Ball.GetClosest方法的典型用法代码示例。如果您正苦于以下问题:C# Ball.GetClosest方法的具体用法?C# Ball.GetClosest怎么用?C# Ball.GetClosest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ball的用法示例。


在下文中一共展示了Ball.GetClosest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Action

        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            foreach (Player player in myTeam.Players)
            {
                Player closestEnemy = player.GetClosest(enemyTeam);

                if (ball.Owner == player)  //Allways shoots for the enemy goal.
                    player.ActionShootGoal();
                else if (player.CanPickUpBall(ball))  //Picks up the ball if posible.
                    player.ActionPickUpBall();
                else if (player.CanTackle(closestEnemy))  //Tackles any enemy that is close.
                    player.ActionTackle(closestEnemy);
                else  //If the player cannot do anything urgently usefull, move to a good position.
                {
                    if (player == ball.GetClosest(myTeam))  //If the player is closest to the ball, go for it.
                        player.ActionGo(ball);
                    else if (player.PlayerType == PlayerType.Keeper)  //The keeper protects the goal.
                        player.ActionGo(new Vector(50, Math.Max(Math.Min(ball.Position.Y, Field.MyGoal.Bottom.Y), Field.MyGoal.Top.Y))); //The keeper positions himself 50 units out from the goal                                                                                                            //at the same height as the ball, although never leaving the goal
                    else if (player.PlayerType == PlayerType.LeftDefender)
                        player.ActionGo(new Vector(Field.Borders.Width * 0.2, ball.Position.Y));  //The left defender helps protect the goal
                    else if (player.PlayerType == PlayerType.RightDefender)
                        player.ActionGo(Field.MyGoal.GetClosest(enemyTeam));   //The right defender chases the enemy closest to myGoal
                    else if (player.PlayerType == PlayerType.RightForward)
                        player.ActionGo((Field.Borders.Center + Field.Borders.Bottom + ball.Position) / 3);  //Right forward stays in position on the midline, untill the ball comes close.
                    else if (player.PlayerType == PlayerType.LeftForward)
                        player.ActionGo((Field.Borders.Center + Field.Borders.Top + ball.Position) / 3);   //Left forward stays in position on the midline, untill the ball comes close.
                    else if (player.PlayerType == PlayerType.CenterForward)
                        player.ActionGo((Field.Borders.Center + Field.EnemyGoal.Center + ball.Position) / 3);    //Center forward stays in position on the enemy side of the field.
                }
            }
        }
开发者ID:voidgit,项目名称:CloudBall,代码行数:31,代码来源:TeamTwo.cs

示例2: Action

        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            foreach (Player player in myTeam.Players)
            {
                Player closestEnemy = player.GetClosest(enemyTeam);
                switch (player.PlayerType)
                {
                    case PlayerType.Keeper:
                        if (ball.Owner == player)
                        {
                            var partner = player.GetClosestUncovered(myTeam, enemyTeam);
                            if (partner != null)
                            {
                                var power = player.GetDistanceTo(partner) / 10;
                                player.ActionShoot(partner, power);
                                continue;
                            }
                            else
                            {
                                // todo: shoot just to enemy side
                                player.ActionShootGoal();
                                continue;
                            }
                        }
                        if (player.GetDistanceTo(ball) < 50 
                            && player.CanPickUpBall(ball))
                        {
                            player.ActionPickUpBall();
                            continue;
                        }
                        if (ball.GetClosest(myTeam) == player
                            && ball.GetClosest(enemyTeam).GetDistanceTo(ball) < player.GetDistanceTo(ball)
                            && ball.GetDistanceTo(Field.MyGoal.Center) < 400)
                        {
                            player.ActionGo(ball.Position);
                            continue;
                        }

                        var direction = GoalKeeper.ChooseDirection(player, ball);
                        player.ActionGo(direction);
                        continue;

                    default:
                        if (ball.Owner == player)
                            if (player.GetDistanceTo(Field.EnemyGoal.Center) > 400)
                            {
                                var inters = player.GetClosestInterceptors(enemyTeam, 400);
                                if (!inters.Any())
                                {
                                    player.ActionGo(Field.EnemyGoal.Center);
                                    continue;
                                }
                                else if (inters.Count() >= 3)
                                {
                                    var partner = player.GetClosestUncovered(myTeam, enemyTeam);
                                    if (partner != null) player.ActionShoot(partner, 100);
                                }
                                var goalDirect = (Field.EnemyGoal.Center - player.Position).GetDirection();
                                var direct = (from i in inters
                                              select (i.Velocity) + (player.Position - i.Position).GetDirection() * (1 - i.GetDistanceTo(player) / 500))
                                              .Aggregate(Vector.Zero, (acc, v) => acc + v).GetDirection() + goalDirect;
                                var dest = player.Position + direct;
                                //if (direct.X < -50 && partner != null)
                                //{
                                //    player.ActionShoot(partner, 100);
                                //    continue;
                                //}
                                //else 
                                //    if (dest.Y < Field.Borders.Top.Y + 200
                                //    || dest.Y > Field.Borders.Bottom.Y - 200)
                                //{
                                //    player.ActionGo(dest + goalDirect * 2);
                                //    continue;
                                //}
                                //else 
                                //        if (dest.X > Field.Borders.Right.X - 100)
                                //{
                                //    player.ActionGo(Field.Borders.Center);
                                //    continue;
                                //}
                                //else 
                                //if (Field.Borders.Contains(dest))
                                //{
                                    player.ActionGo(dest);
                                    continue;
                                //}
                                //else
                                //{
                                //    player.ActionGo(Field.EnemyGoal.Center);
                                //    continue;
                                //}
                            }
                            else
                            {
                                //var goalkepers = from ep in enemyTeam.InFrontOf(player)
                                //                 ;

                                player.ActionShootGoal();
                            }
                        break;
//.........这里部分代码省略.........
开发者ID:yojig,项目名称:CloudBall,代码行数:101,代码来源:MadGuys.cs


注:本文中的Ball.GetClosest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。