Example #1
0
 /// <summary>
 /// 开始一个拼图游戏。
 /// </summary>
 /// <remarks>开始游戏前,需要保证之前的游戏已结束。</remarks>
 /// <param name="jigsawPieces">拼图碎片集合。</param>
 /// <param name="info">游戏信息。</param>
 /// <param name="ct">取消任务的通知。</param>
 /// <returns>开始拼图游戏的任务。</returns>
 public Task StartGame(JigsawPieceCollection jigsawPieces, JigsawInfo info, CancellationToken ct)
 {
     Debug.Assert(!this.hasGame);
     this.pieces   = jigsawPieces;
     this.gameInfo = info;
     return(new Task(() => this.StartGame(ct), ct));
 }
Example #2
0
        /// <summary>
        /// 开始一个拼图游戏。
        /// </summary>
        /// <param name="pieces">拼图碎片集合。</param>
        /// <param name="info">游戏信息。</param>
        public void StartGame(JigsawPieceCollection pieces, JigsawInfo info)
        {
            this.StopGame(true);
            this.gamePath = null;
            this.ShowLoadingForm();
            Task task = gameManager.StartGame(pieces, info, this.tokenCancelSource.Token);

            task.ContinueWith(t => BeginGame(), TaskContinuationOptions.OnlyOnRanToCompletion);
            task.ContinueWith(t => HideLoadingForm());
            task.Start();
        }
Example #3
0
 /// <summary>
 /// 打开拼图游戏。
 /// </summary>
 /// <param name="fileName">要打开的拼图游戏存档路径。</param>
 /// <param name="ct">取消任务的通知。</param>
 /// <returns>打开拼图游戏的任务。</returns>
 public Task OpenGame(string fileName, CancellationToken ct)
 {
     using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
     {
         JigsawSerializeContext context   = new JigsawSerializeContext(this.devices);
         BinaryFormatter        formatter = new BinaryFormatter(null,
                                                                new StreamingContext(StreamingContextStates.File, context));
         this.gameInfo = (JigsawInfo)formatter.Deserialize(stream);
         this.pieces   = (JigsawPieceCollection)formatter.Deserialize(stream);
     }
     this.gameChanged = false;
     return(this.StartGame(this.pieces, this.gameInfo, ct));
 }
		/// <summary>
		/// 打开拼图游戏。
		/// </summary>
		/// <param name="fileName">要打开的拼图游戏存档路径。</param>
		/// <param name="ct">取消任务的通知。</param>
		/// <returns>打开拼图游戏的任务。</returns>
		public Task OpenGame(string fileName, CancellationToken ct)
		{
			using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
			{
				JigsawSerializeContext context = new JigsawSerializeContext(this.devices);
				BinaryFormatter formatter = new BinaryFormatter(null,
					new StreamingContext(StreamingContextStates.File, context));
				this.gameInfo = (JigsawInfo)formatter.Deserialize(stream);
				this.pieces = (JigsawPieceCollection)formatter.Deserialize(stream);
			}
			this.gameChanged = false;
			return this.StartGame(this.pieces, this.gameInfo, ct);
		}
		/// <summary>
		/// 开始一个拼图游戏。
		/// </summary>
		/// <remarks>开始游戏前,需要保证之前的游戏已结束。</remarks>
		/// <param name="jigsawPieces">拼图碎片集合。</param>
		/// <param name="info">游戏信息。</param>
		/// <param name="ct">取消任务的通知。</param>
		/// <returns>开始拼图游戏的任务。</returns>
		public Task StartGame(JigsawPieceCollection jigsawPieces, JigsawInfo info, CancellationToken ct)
		{
			Debug.Assert(!this.hasGame);
			this.pieces = jigsawPieces;
			this.gameInfo = info;
			return new Task(() => this.StartGame(ct), ct);
		}
		/// <summary>
		/// 开始一个拼图游戏。
		/// </summary>
		/// <param name="pieces">拼图碎片集合。</param>
		/// <param name="info">游戏信息。</param>
		public void StartGame(JigsawPieceCollection pieces, JigsawInfo info)
		{
			this.StopGame(true);
			this.gamePath = null;
			this.ShowLoadingForm();
			Task task = gameManager.StartGame(pieces, info, this.tokenCancelSource.Token);
			task.ContinueWith(t => BeginGame(), TaskContinuationOptions.OnlyOnRanToCompletion);
			task.ContinueWith(t => HideLoadingForm());
			task.Start();
		}