📄 moveballworker.cs
字号:
////////////////////////////////////////////////
//
// Project: Lines.NET
// Version: 1.1
// Author: Vladimir L.
//
// homepage: http://www.boomsoft.org
// e-mail: support@boomsoft.org
//
// Copyright (c) 2003-2004, Boomsoft.org
//
using System;
using System.Drawing;
using System.Threading;
namespace Lines.Core
{
/// <summary>
/// Animates a ball movement.
/// </summary>
/// <remarks>
/// Moves the ball step-by-step through defined path and fires <see cref="Game.BallMoved"/> event
/// when this job is done. The delay between steps is defined by <see cref="AppSettings.PauseMoveBall"/>
/// property. This class is supposed to be used in a separate thread as it shown in the example:
/// </remarks>
/// <example>
/// <code>
/// MoveBallWorker worker = new MoveBallWorker(game, ball, path);
/// Thread moveBallThread = new Thread(new ThreadStart(worker.Execute));
/// moveBallThread.Start();
/// </code>
/// </example>
public class MoveBallWorker
{
/// <summary>
/// Refers to a game object the ball is moved at.
/// </summary>
private Game game;
/// <summary>
/// Refers to a ball object that is moving.
/// </summary>
private Ball ball;
/// <summary>
/// Holds the path of ball movement.
/// </summary>
private Point[] path;
/// <summary>
/// The cached value of move ball pause.
/// </summary>
/// <remarks>
/// This value is taken from <see cref="AppSettings.PauseMoveBall"/> property.
/// </remarks>
private int pause = AppSettings.Instance.PauseMoveBall;
/// <summary>
/// Creates an instance of destroy balls worker.
/// </summary>
/// <param name="game">The reference to a game object.</param>
/// <param name="ball">The reference to a ball object to be moved.</param>
/// <param name="path">Defines the path of a ball movement.</param>
public MoveBallWorker(Game game, Ball ball, Point[] path)
{
this.game = game;
this.ball = ball;
this.path = path;
}
/// <summary>
/// Executes the ball movement.
/// </summary>
/// <remarks>
/// This method is supposed to be used as an entry point of a separate thread.
/// </remarks>
public void Execute()
{
for (int i = 0; i < path.Length; i++)
{
Point oldPos = ball.Position;
Point newPos = path[i];
game.MoveBall(oldPos, newPos);
Thread.Sleep(pause);
}
game.FireBallMoved(ball);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -