本文整理汇总了C#中LinkedList.Last方法的典型用法代码示例。如果您正苦于以下问题:C# LinkedList.Last方法的具体用法?C# LinkedList.Last怎么用?C# LinkedList.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList
的用法示例。
在下文中一共展示了LinkedList.Last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PanningBackground
public PanningBackground()
{
m_parallaxEnvironments = new LinkedList<ParallaxEnvironment>();
m_random = new Random(DateTime.Now.Millisecond);
float t_houseDistance = Game.getInstance().getResolution().X / 10;
m_background = Game.getInstance().Content.Load<Texture2D>("Images//Background//starry_sky_01");
for (int i = 0; i < 50; i++)
{
m_parallaxEnvironments.AddLast(new ParallaxEnvironment(
new Vector2(t_houseDistance * i - Game.getInstance().m_camera.getRectangle().Width, -300),
"Images//Background//Parallax//bg_house_0" + randomNumber(1, 7).ToString(),
0.950f
));
m_parallaxEnvironments.Last().setParrScroll(randomNumber(50, 600));
}
for (int i = 0; i < 25; i++)
{
m_parallaxEnvironments.AddLast(new ParallaxEnvironment(
new Vector2(t_houseDistance * i - Game.getInstance().m_camera.getRectangle().Width, randomNumber(-300, 200)),
"Images//Background//Parallax//clouds_0" + randomNumber(1, 4).ToString(),
0.950f
));
m_parallaxEnvironments.Last().setParrScroll(randomNumber(50, 600));
}
m_logo = new Environment(new Vector2(-400, -250), "Images//GUI//logotext", 0.800f);
}
示例2: SetValue
public override void SetValue(LinkedList<Node> childrenToAdd)
{
if (childrenToAdd.Count != 2)
throw new Exception("A two parameter operator must have two parameters");
value = InfixOperators.GetOpInfo[this.op].Compute
(childrenToAdd.Last().GetValue(), childrenToAdd.First().GetValue());
Children = childrenToAdd;
}
示例3: MultipleElementSequenceWithoutPredicate
public void MultipleElementSequenceWithoutPredicate()
{
var source = new LinkedList<int>(new int[] { 5, 10 });
Assert.AreEqual(10, source.Last());
}
示例4: selectEvent
public void selectEvent(Button a_button)
{
foreach (Button t_button in m_events.Keys)
{
t_button.setState(Button.State.Normal);
}
a_button.setState(3);
m_triggerButtons = new LinkedList<Button>();
m_effectButtons = new LinkedList<Button>();
m_selectedEvent = a_button;
m_selectedEvent.setPosition(Vector2.Zero);
foreach (EventTrigger t_trigger in m_events[a_button].getTriggers())
{
m_triggerButtons.AddLast(new Button("btn_asset_list", new Vector2(m_btnAddTrigger.getBox().X, 40 + (m_triggerButtons.Count * 25)),
t_trigger.ToString(), "VerdanaBold", Color.Yellow, new Vector2(10, 2)));
m_triggerButtons.Last().m_clickEvent += new Button.clickDelegate(selectEffectTrigger);
if (t_trigger is PlayerIsWithinRectangle)
{
m_recLines = ((PlayerIsWithinRectangle)t_trigger).getRectangle();
}
}
foreach (EventEffect t_effect in m_events[a_button].getEffects())
{
m_effectButtons.AddLast(new Button("btn_asset_list", new Vector2(m_btnAddTrigger.getBox().X + m_btnAddEffect.getBox().Width + 40, 40 + (m_effectButtons.Count * 25)),
t_effect.ToString(), "VerdanaBold", Color.Yellow, new Vector2(10, 2)));
m_effectButtons.Last().m_clickEvent += new Button.clickDelegate(selectEffectTrigger);
}
if (m_triggerButtons.Count() > 0)
{
m_btnAddTrigger.setPosition(new Vector2(m_triggerButtons.Last().getBox().X, m_triggerButtons.Last().getBox().Y + 25));
}
else
{
m_btnAddTrigger.setPosition(new Vector2(0, 40));
}
if (m_effectButtons.Count() > 0)
{
m_btnAddEffect.setPosition(new Vector2(m_effectButtons.Last().getBox().X, m_effectButtons.Last().getBox().Y + 25));
}
else
{
m_btnAddEffect.setPosition(new Vector2(m_btnAddTrigger.getBox().Width + 25, 40));
}
}
示例5: WriteMeshes
/// <summary>
/// Generate the compShape from profile points from pt to bottom.
/// Note that this list will have extra interpolated points added if the change in radius is high to avoid
/// texture stretching.
/// </summary>
/// <param name="pts"></param>
protected void WriteMeshes(LinkedList<ProfilePoint> pts)
{
if (pts == null || pts.Count < 2)
return;
// update nodes
UpdateNodeSize(pts.First(), bottomNodeName);
UpdateNodeSize(pts.Last(), topNodeName);
// Move attachments first, before subdividing
MoveAttachments(pts);
// Horizontal profile point subdivision
SubdivHorizontal(pts);
// Tank stats
float tankULength = 0;
float tankVLength = 0;
int nVrt = 0;
int nTri = 0;
int nColVrt = 0;
int nColTri = 0;
bool customCollider = false;
ProfilePoint first = pts.First.Value;
ProfilePoint last = pts.Last.Value;
if (!first.inCollider || !last.inCollider)
throw new InvalidOperationException("First and last profile points must be used in the collider");
foreach (ProfilePoint pt in pts)
{
customCollider = customCollider || pt.customCollider;
if (pt.inRender)
{
nVrt += pt.circ.totVertexes + 1;
// one for above, one for below
nTri += 2 * pt.circ.totVertexes;
}
if (pt.inCollider)
{
nColVrt += pt.colliderCirc.totVertexes + 1;
nColTri += 2 * pt.colliderCirc.totVertexes;
}
}
// Have double counted for the first and last circles.
nTri -= first.circ.totVertexes + last.circ.totVertexes;
nColTri -= first.colliderCirc.totVertexes + last.colliderCirc.totVertexes;
UncheckedMesh m = new UncheckedMesh(nVrt, nTri);
float sumDiameters = 0;
//Debug.LogWarning("Display mesh vert=" + nVrt + " tris=" + nTri);
bool odd = false;
{
ProfilePoint prev = null;
int off = 0, prevOff = 0;
int tOff = 0;
foreach (ProfilePoint pt in pts)
{
if (!pt.inRender)
continue;
pt.circ.WriteVertexes(diameter: pt.dia, y: pt.y, v: pt.v, norm: pt.norm, off: off, m: m, odd: odd);
if (prev != null)
{
CirclePoints.WriteTriangles(prev.circ, prevOff, pt.circ, off, m.triangles, tOff * 3, !odd);
tOff += prev.circ.totVertexes + pt.circ.totVertexes;
// Deprecated: Volume has been moved up to callers. This way we can use the idealized rather than aproximate volume
// Work out the area of the truncated cone
// integral_y1^y2 pi R(y)^2 dy where R(y) = ((r2-r1)(y-y1))/(r2-r1) + r1 Integrate circles along a line
// integral_y1^y2 pi ( ((r2-r1)(y-y1))/(r2-r1) + r1) ^2 dy Substituted in formula.
// == -1/3 pi (y1-y2) (r1^2+r1*r2+r2^2) Do the calculus
// == -1/3 pi (y1-y2) (d1^2/4+d1*d2/4+d2^2/4) r = d/2
// == -1/12 pi (y1-y2) (d1^2+d1*d2+d2^2) Take out the factor
//volume += (Mathf.PI * (pt.y - prev.y) * (prev.dia * prev.dia + prev.dia * pt.dia + pt.dia * pt.dia)) / 12f;
float dy = (pt.y - prev.y);
float dr = (prev.dia - pt.dia) * 0.5f;
//print("dy=" + dy + " dr=" + dr + " len=" + Mathf.Sqrt(dy * dy + dr * dr).ToString("F3"));
tankVLength += Mathf.Sqrt(dy * dy + dr * dr);
// average diameter weighted by dy
sumDiameters += (pt.dia + prev.dia) * dy;
}
prev = pt;
//.........这里部分代码省略.........
示例6: SingleElementSequenceWithNonMatchingPredicate
public void SingleElementSequenceWithNonMatchingPredicate()
{
var source = new LinkedList<int>(new int[] { 2 });
Assert.Throws<InvalidOperationException>(() => source.Last(x => x > 3));
}
示例7: MultipleElementSequenceWithSinglePredicateMatch
public void MultipleElementSequenceWithSinglePredicateMatch()
{
var source = new LinkedList<int>(new int[] { 1, 2, 5, 2, 1 });
Assert.AreEqual(5, source.Last(x => x > 3));
}
示例8: ValidateMapping
private void ValidateMapping(Type service, LinkedList<Type> breadcrumbs)
{
if (breadcrumbs.Contains(service))
throw new CircularDependenciesException(
"Found a circular dependency when looking up " + breadcrumbs.First() +
", when inspecting the constructor of " + breadcrumbs.Last() + ", violating service: " + service,
breadcrumbs);
if (service.IsGenericType && service.GetGenericTypeDefinition() == typeof(IEnumerable<>))
return;
var buildPlans = GetBuildPlans(service);
if (buildPlans == null)
throw new DependencyNotRegisteredException(breadcrumbs.Last.Value, service);
var cbp = buildPlans.Last() as ConcreteBuildPlan;
if (cbp == null)
return;
breadcrumbs.AddLast(service);
foreach (var parameter in cbp.Constructor.GetParameters())
{
ValidateMapping(parameter.ParameterType, breadcrumbs);
}
breadcrumbs.RemoveLast();
}
示例9: OptimizePath
public static LinkedList<Tile> OptimizePath(LinkedList<Tile> pathUnoptimized)
{
//if there are only 2 tiles then there is not optimization to take place
if (pathUnoptimized.Count > 2)
{
LinkedList<Tile> optimizedPath = new LinkedList<Tile>();
//add the first piont to the path
optimizedPath.AddFirst(pathUnoptimized.First());
//remove our first tile from the unoptimized list
pathUnoptimized.RemoveFirst();
//start with the first tile and work our way through tiles to
Vector2 lastComparitiveSlope = pathUnoptimized.First.Value.TilePosition - optimizedPath.Last().TilePosition;
Tile lastPath = optimizedPath.Last();
foreach (Tile path in pathUnoptimized)
{
Vector2 comparitiveSlope = path.TilePosition - lastPath.TilePosition;
if (!Vector2.Equals(comparitiveSlope, lastComparitiveSlope))
{
//put our current path on the optimized path
optimizedPath.AddLast(lastPath);
optimizedPath.AddLast(path);
lastPath = path;
}
else if (Vector2.Equals(comparitiveSlope, lastComparitiveSlope) && path == pathUnoptimized.Last())
{
optimizedPath.AddLast(path);
}
else
{
lastPath = path;
}
}
return optimizedPath;
}
else
{
return pathUnoptimized;
}
}
示例10: checkSwipe
private static void checkSwipe(float tolerance, LinkedList<Skeleton> moves)
{
int i = 0;
if (!canGesture)
return;
LinkedList<Skeleton> temp = moves;
Joint prevJoint = new Joint();
Joint firstJoint = moves.First<Skeleton>().Joints[JointType.HandRight];
Joint lastJoint = moves.Last<Skeleton>().Joints[JointType.HandRight];
foreach (Skeleton skeleton in moves)
{
//find better implementation, but moves too long for checking swipes so skip first few
if (i < 3)
{
i++;
continue;
}
Joint joint = skeleton.Joints[JointType.HandRight];
if (prevJoint.Position.Z == 0.0)//not the best but checks if empty joint
{
prevJoint = joint;
continue;
}
if (prevJoint.Position.X > joint.Position.X + tolerance)
{
prevJoint = joint;
continue;
}
return;
}
if ((Math.Abs(lastJoint.Position.X - firstJoint.Position.X) > .30) && Math.Abs(lastJoint.Position.Y - firstJoint.Position.Y) < .20)
{
canGesture = false;
lastGesture = "Swiped";
canGestureTimer.Start();
}
}
示例11: add_new_stage
void add_new_stage(LinkedList<Stage> stages)
{
if (stages.Last().position.X + stages.Last().width <= screenWidth)
{
//Any regular stage.
if (stages.Count() < levelLength - 1)
{
stages.AddLast(random_stage(new Vector2(stages.Last().position.X + stages.Last().width - 20, 0)));
}
//The one before the final stage is always bg1
else if (stages.Count() == levelLength - 1)
{
stages.AddLast(new Stage(bg[1], cm[1], collisionColorArray.ElementAt(1), stages.Last().position.X + stages.Last().width - 20, 0, graphics.GraphicsDevice));
}
//The safehouse
else if (stages.Count() == levelLength)
{
stages.AddLast(new Stage(bgx, cmx, collisionColorArray.ElementAt(collisionColorArray.Count()-2), stages.Last().position.X + stages.Last().width - 20, 0, graphics.GraphicsDevice));
stages.Last().safehouse = true;
stages.AddLast(new Stage(bg[1], cm[1], collisionColorArray.ElementAt(1), stages.Last().position.X + stages.Last().width - 20, 0, graphics.GraphicsDevice));//The one after a safehouse is flat.
}
else if (stages.Count() >= levelLength && stages.ElementAt(stages.Count() - 2).position.X < (screenWidth / 2 - stages.ElementAt(stages.Count() - 2).width/4))
{
//Back up the last 3, clear out the rest of the list, then add the new 0 and 1.
Stage temp0 = stages.ElementAt(levelLength - 1);
Stage tempSafehouse = stages.ElementAt(levelLength);
Stage temp1 = stages.ElementAt(levelLength + 1);
stages.Clear();
//Add the 2 new ones
stages.AddLast(temp0);
stages.AddLast(new Stage(blocker_bg, blocker_cm, collisionColorArray.Last(), tempSafehouse.position.X, 0, graphics.GraphicsDevice));
//Let it keep the same color to look cool.
stages.Last().color_map = tempSafehouse.color_map;
stages.Last().safehouse = true;
//Finally, add a new stage, since this one reached the end.
stages.AddLast(temp1);
//Now you can increase the bps and lives.
bps += 0.1;
//lives++;//You no longer increase your lives when you beat a level.
level++;
waveManager.ChangeSpeed(bps-1);
}
}
}
示例12: checkPush
private static void checkPush(LinkedList<Skeleton> moves)
{
if (!canGesture)
return;
Joint prevJoint = new Joint();
Joint firstJoint = moves.First<Skeleton>().Joints[JointType.HandLeft];
Joint lastJoint = moves.Last<Skeleton>().Joints[JointType.HandLeft];
foreach (Skeleton skeleton in moves)
{
Joint joint = skeleton.Joints[JointType.HandLeft];
//Checking if pushing
if (prevJoint.Position.Z == 0.0)
{
prevJoint = joint;
continue;
}
if (prevJoint.Position.Z > joint.Position.Z)
{
prevJoint = joint;
continue;
}
return;
}
if ((Math.Abs(lastJoint.Position.Z - firstJoint.Position.Z) > .25) &&
Math.Abs(lastJoint.Position.X - firstJoint.Position.X) < .20 &&
Math.Abs(lastJoint.Position.Y - firstJoint.Position.Y) < .20)
{
canGesture = false;
lastGesture = "Pushed";
pushed = true;
canGestureTimer.Start();
}
}
示例13: BorderPath
public BorderPath(Border border, Sector sector, PathUtil.PathType type)
{
float[] edgeX, edgeY;
RenderUtil.HexEdges(type, out edgeX, out edgeY);
int lengthEstimate = border.Path.Count() * 3;
List<PointF> points = new List<PointF>(lengthEstimate);
List<byte> types = new List<byte>(lengthEstimate);
LinkedList<LinkedList<PointF>> segments = new LinkedList<LinkedList<PointF>>();
LinkedList<PointF> currentSegment = new LinkedList<PointF>();
// Based on http://dotclue.org/t20/sec2pdf - J Greely rocks my world.
int checkFirst = 0;
int checkLast = 5;
Hex startHex = Hex.Empty;
bool startHexVisited = false;
foreach (Hex hex in border.Path)
{
checkLast = checkFirst + 5;
if (startHexVisited && hex == startHex)
{
// I'm in the starting hex, and I've been
// there before, so stop testing at neighbor
// 5, no matter what
checkLast = 5;
// degenerate case, entering for third time
if (checkFirst < 3)
break;
}
else if (!startHexVisited)
{
startHex = hex;
startHexVisited = true;
// PERF: This seems costly... analyze it!
PointF newPoint = Astrometrics.HexToCenter(Astrometrics.LocationToCoordinates(new Location(sector.Location, hex)));
newPoint.X += edgeX[0];
newPoint.Y += edgeY[0];
// MOVETO
points.Add(newPoint);
types.Add((byte)PathPointType.Start);
// MOVETO
currentSegment.AddLast(newPoint);
}
PointF pt = Astrometrics.HexToCenter(Astrometrics.LocationToCoordinates(new Location(sector.Location, hex)));
int i = checkFirst;
for (int check = checkFirst; check <= checkLast; check++)
{
i = check;
Hex neighbor = Astrometrics.HexNeighbor(hex, i % 6);
if (border.Path.Contains(neighbor)) // TODO: Consider a hash here
break;
PointF newPoint = new PointF(pt.X + edgeX[(i + 1) % 6], pt.Y + edgeY[(i + 1) % 6]);
// LINETO
points.Add(newPoint);
types.Add((byte)PathPointType.Line);
if (hex.IsValid)
{
// MOVETO
currentSegment.AddLast(newPoint);
}
else
{
// LINETO
if (currentSegment.Count > 1)
segments.AddLast(currentSegment);
currentSegment = new LinkedList<PointF>();
currentSegment.AddLast(newPoint);
}
}
i = i % 6;
// i is the direction to the next border hex,
// and when we get there, we'll have come from
// i + 3, so we start checking with i + 4.
checkFirst = (i + 4) % 6;
}
types[types.Count - 1] |= (byte)PathPointType.CloseSubpath;
if (currentSegment.Count > 1)
segments.AddLast(currentSegment);
this.points = points.ToArray();
this.types = types.ToArray();
//.........这里部分代码省略.........
示例14: AddNodeToSort
/// <summary>
/// End UpdatePassiveSensors
/// </summary>
/// <summary>
/// Helper private function that handles adding a new node to a linked list.
/// </summary>
/// <param name="SortList">LinkedList to add the node to.</param>
/// <param name="Sort">LinkedListNode to be added.</param>
/// <param name="TEA">Thermal,EM,Active.</param>
private void AddNodeToSort(LinkedList<int> SortList, LinkedListNode<int> Sort, int TEA)
{
if (SortList.Count == 0)
{
SortList.AddFirst(Sort);
}
else
{
int value = -1, Last = -1, First = -1, NewValue = -1, LastValue = -1;
switch (TEA)
{
case 0: value = Ships[Sort.Value].CurrentThermalSignature;
Last = Ships[SortList.Last()].CurrentThermalSignature;
First = Ships[SortList.First()].CurrentThermalSignature;
break;
case 1: value = Ships[Sort.Value].CurrentEMSignature;
Last = Ships[SortList.Last()].CurrentEMSignature;
First = Ships[SortList.First()].CurrentEMSignature;
break;
case 2: value = Ships[Sort.Value].TotalCrossSection;
Last = Ships[SortList.Last()].TotalCrossSection;
First = Ships[SortList.First()].TotalCrossSection;
break;
}
if (value >= Last)
{
SortList.AddLast(Sort);
}
else if (value <= First)
{
SortList.AddFirst(Sort);
}
else
{
LinkedListNode<int> NextNode = SortList.First;
LastValue = First;
NextNode = NextNode.Next;
bool done = false;
while (done == false)
{
switch (TEA)
{
case 0: NewValue = Ships[NextNode.Value].CurrentThermalSignature;
break;
case 1: NewValue = Ships[NextNode.Value].CurrentEMSignature;
break;
case 2: NewValue = Ships[NextNode.Value].TotalCrossSection;
break;
}
if (value < LastValue)
{
#if LOG4NET_ENABLED
#warning faction messagelog this?
String MSG = String.Format("Taskgroup {0} Sort messed up between {1} and {2}, current NextNodeValue is {3}\n. Condition One with V < LV", Name, LastValue, NewValue, NextNode.Value);
logger.Debug(MSG);
#endif
}
else if (value == LastValue && value > NewValue)
{
#if LOG4NET_ENABLED
#warning faction messagelog this?
String MSG = String.Format("Taskgroup {0} Sort messed up between {1} and {2}, current NextNodeValue is {3}. Condition Two with V = LV V > NV\n", Name, LastValue, NewValue, NextNode.Value);
logger.Debug(MSG);
#endif
}
if (value <= NewValue && value >= LastValue)
{
SortList.AddBefore(NextNode, Sort);
done = true;
}
NextNode = NextNode.Next;
LastValue = NewValue;
}
}
}
}
示例15: LinkedListExtensions_Last_ReturnsLastItemInLinkedList
public void LinkedListExtensions_Last_ReturnsLastItemInLinkedList()
{
var list = new LinkedList<Int32>();
list.AddLast(1);
list.AddLast(2);
list.AddLast(3);
var result = list.Last();
TheResultingValue(result).ShouldBe(3);
}