本文整理汇总了C#中System.Line.Where方法的典型用法代码示例。如果您正苦于以下问题:C# Line.Where方法的具体用法?C# Line.Where怎么用?C# Line.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Line
的用法示例。
在下文中一共展示了Line.Where方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindingFreeParametersShouldWork
public void FindingFreeParametersShouldWork()
{
var l = new Line(new Point(0, 0, false), new Point(1, 1, false, true));
var a = l.Where(p => p.free == true).ToArray();
a.Length.Should().Be(1);
a[0].GetHashCode().Should().Be(l.p2.y.GetHashCode());
}
示例2: MainLoop
private static async Task MainLoop( ConsoleColor bgc, ConsoleColor ec, ConsoleColor mc, int delay)
{
var r = new Random();
int w = Console.WindowWidth, h = Console.WindowHeight;
var chars = new Rc[h][];
for ( int i = 0; i < h; i++ ) chars[ i ] = new Rc[w];
for ( int i = 0; i < h; i++ ) {
var c = chars[ i ];
for ( int j = 0; j < w; j++ )
c[ j ] = new Rc { Char = (char) r.Next( 34, 127 ), Color = bgc };
}
//lines
var lines = new Line[w];
for ( int i = 0; i < w; i++ ) {
var l = new Line { Height = r.Next( 4, h ) };
l.Position = -h + r.Next( 0, h - l.Height + 1 );
l.Speed = r.Next( 1, 4 );
lines[ i ] = l;
}
var tid = 0UL;
while ( true ) {
var del = Task.Delay( delay );
if ( Console.WindowHeight!=h || Console.WindowWidth!=w) {
return;
}
++tid;
//move
var tid1 = tid;
foreach (var line in lines.Where(line => tid1 % (ulong) line.Speed == 0UL))
line.Position = line.Position < h ? line.Position + 1 : -line.Height;
//update chars
for (var i = 0; i < lines.Length; i++ ) {
var line = lines[ i ];
var top = line.Position;
var bottom = top + line.Height - 1;
var topU = top < h;
var topD = top >= 0;
var topV = topU && topD;
var bottomU = bottom >= 0;
var bottomD = bottom < h;
var bottomV = bottomU && bottomD;
if ( bottomV || topV ) { //visible
if ( bottomV ) chars[ bottom ][ i ].Color = ec;
if ( topV ) chars[ top ][ i ].Color = ec;
var ms = Math.Max( 0, Math.Min( h, top+1 ) );
var me = Math.Max( 0, Math.Min( h, bottom ) );
for (var j = ms; j < me; j++ ) chars[ j ][ i ].Color = mc;
if ( topV )
for (var j = 0; j < top - 1; j++ )
chars[ j ][ i ].Color = bgc;
if (!bottomV) continue;
{
for ( var j = bottom+1; j < h; j++ )
chars[ j ][ i ].Color = bgc;
}
}
else
for (var j = 0; j < h; j++ )
chars[ j ][ i ].Color = bgc;
}
//render
var cc = Console.ForegroundColor;
int flushes = 0,
cf = 0,
pf = 0,
wf = 0;
for ( var i = 0; i < h; i++ )
{
var c = chars[ i ];
var pc = false;
for ( var j = 0; j < w; j++ ) {
var cur = c[ j ];
if ( cur.Changed && !(j==w-1&&i==h-1))
{
if ( !pc ) {
if ( !SetCursorPosition( j, i ) ) return;
flushes++;
pf++;
}
pc = true;
if (cc != cur.Color)
{
Console.ForegroundColor = cur.Color;
cc = cur.Color;
flushes++;
cf++;
}
{
Console.Write( cur.Char );
flushes++;
wf++;
}
cur.Changed = false;
}
//.........这里部分代码省略.........