private void RepositionEntity(XEntity xe) { int newX = -1; int newY = -1; do { var direction = HelperMethods.GetRandomDirection(xe); switch (direction) { case MovementDirection.UP: case MovementDirection.DOWN: newY = GetValidVertical(xe.Y, direction); newX = xe.X; break; case MovementDirection.RIGHT: case MovementDirection.LEFT: newX = GetValidHorisental(xe.X, direction); newY = xe.Y; break; } } // If new point equals prev point.. need to get new posision while (newX == xe.PrevPoint.X && newY == xe.PrevPoint.Y); // Save current to prev point xe.PrevPoint = new Point(xe.X, xe.Y); // reposition entity with the new point xe.X = newX; xe.Y = newY; }
internal static MovementDirection GetRandomDirection(XEntity xe) { int r = rnd.Next(1, 5); var dir = (MovementDirection)r; return(dir); }
/// <summary> /// // Update the history track list and remove the last extra step if the list exceeded the number of his steps the user selected /// </summary> /// <param name="xe"></param> private void SaveTrackHistory(XEntity xe) { // Insert new point at index zero. xe.HistoryTrack.Insert(0, new Point(xe.X, xe.Y)); // if the length of the list is greater the intended, go ahead and remove extras. if (xe.HistoryTrack.Count > _board.HisNumberOfSteps) { // Start index to remove at is the HisNumberOfSteps. The list is zero based, so the HisNumberOfSteps indecates the extra start index. int startInx = _board.HisNumberOfSteps; // The raeng count of extras to remove. int range = xe.HistoryTrack.Count - _board.HisNumberOfSteps; // remove range xe.HistoryTrack.RemoveRange(startInx, range); } }