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


C# Ball.All方法代码示例

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


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

示例1: runForSquares

        private bool runForSquares(int startx, int starty, int x, int y)
        {
            int timer = 0;
            Ball[] balls = (Ball[])Balls.Clone();

            List<Point> peremeter = new List<Point>();
            peremeter.Add(new Point(startx, starty));
            foos:
            peremeter.Add(new Point(x, y));

            Ball[] b = new Ball[4];

            #if DONTDRAW
            #else
            current[(y + SIDEPAD) * W + (x + SIDEPAD)] = 'M';
            //            WriteChar(current, x + SIDEPAD, y + SIDEPAD, 'M');
            Thread.Sleep(timer);
            #endif
            for (Direction d = Direction.Up; d <= Direction.Right; d++) {

                var moved = GetMovedXY(d, new Point(x, y));

                b[(int)d] = balls[moved.Y * W + moved.X];
            }
            if (b.All(a => a == Ball.Blue)) {
                return false;
            }
            if (b.Count(a => a == Ball.Blue) == b.Length - 1) {
                return false;
            }
            int m = b.ToList().IndexOf(Ball.Red);
            if (m == -1) {
                return false;
            }
            var o = getOpposite((Direction)m);
            if (b[(int)o] == Ball.Blue) {
                balls[y * W + x] = Ball.Red;

                var l = GetMovedXY(o, new Point(x, y));

                x = l.X;
                y = l.Y;
                goto foos;
            }

            var perp = GetPerp((Direction)m);
            if (b[(int)perp] == Ball.Blue) {
                balls[y * W + x] = Ball.Red;

                var l = GetMovedXY(o, new Point(x, y));
                x = l.X;
                y = l.Y;
                goto foos;
            }

            for (int index = 0; index < b.Length; index++) {
                var ball = b[index];
                if (ball != Ball.Red) {
                    continue;
                }
                var l3 = GetMovedXY(o, new Point(x, y));

                if (l3.X == startx && l3.Y == starty) {
                    var vm = peremeter;//.OrderBy(a => a.Y).OrderBy(a => a.X);

                    bool run = true;
                    foreach (var point in vm.GroupBy(a => a.Y).OrderBy(a => a.Key)) {
                        var f = point.OrderBy(a => a.X).First().X;
                        var l = point.OrderBy(a => a.X).Last().X;
                        foreach (var g in peremeter.Where(a => a.X >= f && a.X <= l).GroupBy(a => a.X).OrderBy(a => a.Key)) {
                            if (!(Balls[point.Key * W + g.Key] == Ball.Blue || Balls[point.Key * W + g.Key] == Ball.Red)) {
                                run = false;
                            }

                        }
                    }
                    if (run) {

                        foreach (var point in vm.GroupBy(a => a.Y).OrderBy(a => a.Key)) {
                            var f = point.OrderBy(a => a.X).First().X;
                            var l = point.OrderBy(a => a.X).Last().X;
                            foreach (var g in peremeter.Where(a => a.X >= f && a.X <= l).GroupBy(a => a.X).OrderBy(a => a.Key)) {
                                Balls[point.Key * W + g.Key] = Ball.Empty;

                                //Draw(startx, starty);
            #if DONTDRAW
            #else
                                Thread.Sleep(timer);
            #endif
                            }
                        }
                    }
                    else {
                        foreach (var point in peremeter) {
                            Balls[point.Y * W + point.X] = Ball.Red;
                            //   Draw(startx, starty);
            #if DONTDRAW
            #else
                            Thread.Sleep(timer);
            #endif
//.........这里部分代码省略.........
开发者ID:dested,项目名称:Sonic-AStar-Pathfinding,代码行数:101,代码来源:Program.cs


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