protected override void OnRender(DrawingContext drawingContext) { double halfX = RenderSize.Width / 2; double halfY = RenderSize.Height / 2; switch (stage) { case 0: drawingContext.DrawRectangle(block1Color, null, new Rect(halfX - halfBlockSize - blockSize, halfY - halfBlockSize, blockSize, blockSize)); drawingContext.DrawRectangle(block2Color, null, new Rect(halfX - halfBlockSize, halfY - halfBlockSize - blockSize, blockSize, blockSize)); drawingContext.DrawRectangle(block3Color, null, new Rect(halfX + halfBlockSize, halfY - halfBlockSize, blockSize, blockSize)); drawingContext.DrawRectangle(block4Color, null, new Rect(halfX - halfBlockSize, halfY + halfBlockSize, blockSize, blockSize)); break; case 1: double currentDiff = (DateTime.Now - startTime).TotalMilliseconds; double move = 0; if (currentDiff > patternStay) { currentDiff -= patternStay; if (currentDiff < roundDuration) { move = currentDiff / roundDuration * moveDistance; } else if (currentDiff > roundDuration + patternStay) { move = moveDistance; startTime = DateTime.Now; if (currentRepeat >= repeat) { stage = 2; MoveEnded?.Invoke(this, null); } else { currentRepeat++; } } else { move = moveDistance; } } drawingContext.DrawRectangle(block1Color, null, new Rect(halfX - halfBlockSize - blockSize - move, halfY - halfBlockSize, blockSize, blockSize)); drawingContext.DrawRectangle(block2Color, null, new Rect(halfX - halfBlockSize, halfY - halfBlockSize - blockSize - move, blockSize, blockSize)); drawingContext.DrawRectangle(block3Color, null, new Rect(halfX + halfBlockSize + move, halfY - halfBlockSize, blockSize, blockSize)); drawingContext.DrawRectangle(block4Color, null, new Rect(halfX - halfBlockSize, halfY + halfBlockSize + move, blockSize, blockSize)); break; case 2: default: drawingContext.DrawRectangle(block1Color, null, new Rect(halfX - halfBlockSize - blockSize - moveDistance, halfY - halfBlockSize, blockSize, blockSize)); drawingContext.DrawRectangle(block2Color, null, new Rect(halfX - halfBlockSize, halfY - halfBlockSize - blockSize - moveDistance, blockSize, blockSize)); drawingContext.DrawRectangle(block3Color, null, new Rect(halfX + halfBlockSize + moveDistance, halfY - halfBlockSize, blockSize, blockSize)); drawingContext.DrawRectangle(block4Color, null, new Rect(halfX - halfBlockSize, halfY + halfBlockSize + moveDistance, blockSize, blockSize)); break; } }
public void OnDragEnd(MouseEventArgs e) { if (Moving) { Moving = false; Position += e.DistanceMoved; MoveEnded?.Invoke(this, e); } }
private void Update() { transform.position = Vector3.MoveTowards(transform.position, _targetPosition, _cameraTranslate.Speed * _speedRate * Time.deltaTime); if (transform.position == _targetPosition) { enabled = false; MoveEnded?.Invoke(); } }
private void DrawSlipper(double timeDiff, DrawingContext drawingContext) { int lineCount = lines.Length; int index = 0; int timeCount = dotTime.Length; while (index < timeCount && dotTime[index] <= timeDiff) { index++; } Point[] points = pattern.Points; if (index >= timeCount) { timer.Stop(); timer = null; int lastIndex = points.Length - 1; double slipperX = points[lastIndex].X; double slipperY = points[lastIndex].Y; drawingContext.DrawEllipse(slipperColor, null, new Point(slipperX, slipperY), slipperSize, slipperSize); stage = 2; MoveEnded?.Invoke(this, null); } else { index--; if (index % 2 == 0) { int dotIndex = index / 2; double slipperX = points[dotIndex].X; double slipperY = points[dotIndex].Y; drawingContext.DrawEllipse(slipperColor, null, new Point(slipperX, slipperY), slipperSize, slipperSize); } else { int lineIndex = index / 2; double lineTimeDiff = timeDiff - dotTime[index]; Point point = pattern.Points[lineIndex] + lineVectors[lineIndex] * lineTimeDiff; drawingContext.DrawEllipse(slipperColor, null, point, slipperSize, slipperSize); } } }
public void Move() { int distance = 0; while (true) { distance += 50; Fuel -= 5; if (Fuel <= 0) { MoveEnded?.Invoke(this, new CarEventArgs("Закончилось топливо.", distance)); break; } OilLevel -= 0.1; if (OilLevel <= 0.6) { MoveEnded?.Invoke(this, new CarEventArgs("Низкий уровень масла.", distance)); break; } TemperatureEngine += 15; if (TemperatureEngine > 100) { MoveEnded?.Invoke(this, new CarEventArgs("Перегрев двигателя.", distance)); break; } MoveEnded?.Invoke(this, new CarEventArgs("Едем.", distance)); Console.WriteLine(); } }
private void OnMoveEnded() { MoveEnded?.Invoke(); MoveNext(); }
protected virtual void OnMoveEnded() { MoveEnded?.Invoke(this, EventArgs.Empty); }