本文整理汇总了C#中Ball.Count方法的典型用法代码示例。如果您正苦于以下问题:C# Ball.Count方法的具体用法?C# Ball.Count怎么用?C# Ball.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ball
的用法示例。
在下文中一共展示了Ball.Count方法的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
//.........这里部分代码省略.........