/// <summary> /// Raises the GoingBack event. /// </summary> /// <param name="e"></param> protected virtual void OnGoingBack(CancelMoveEventArgs e) { if (GoingBack != null) { GoingBack(this, e); } }
/// <summary> /// Raises the Moving event. /// </summary> /// <param name="e"></param> protected virtual void OnMoving(CancelMoveEventArgs e) { if (Moving != null) { Moving(this, e); } }
/// <summary> /// Raises the GoingForward event. /// </summary> /// <param name="e"></param> protected virtual void OnGoingForward(CancelMoveEventArgs e) { if (GoingForward != null) { GoingForward(this, e); } }
private void model_Moving(object sender, CancelMoveEventArgs e) { // set the index information tempIndex = Utils.GetSANIndex(model); // set the SAN information before the move is made tempSAN = Utils.GetSANBegin(model, e.Move); }
/// <summary> /// Go to the previous board configuration in history. /// </summary> public void Previous() { // if the game is not at the begining if (!IsFirst) { Move move = moveHistory[currentBoardIndex - 1]; // build the event args CancelMoveEventArgs moveEventArgs = new CancelMoveEventArgs(move, currentBoardIndex - 1); // raise the GoingBack event OnGoingBack(moveEventArgs); // if the operation was cancelled if (moveEventArgs.Cancel) { return; } // remove the current board hash from the history RemoveHistoryHash(); // take back the move move.TakeBack(currentBoard); // generate the possible moves GenerateMoves(); // set the status of the game SetStatus(); // decrement the current board index currentBoardIndex--; // raise the GoneBack event OnGoneBack(new MoveEventArgs(move, currentBoardIndex - 1)); } }
/// <summary> /// Go to the next board configuration in history. /// </summary> public void Next() { // if the game is not the at the end if (!IsLast) { Move move = moveHistory[currentBoardIndex]; // build the event args CancelMoveEventArgs moveEventArgs = new CancelMoveEventArgs(move, currentBoardIndex - 1); // raise the GoingForward event OnGoingForward(moveEventArgs); // if the operation was cancelled if (moveEventArgs.Cancel) { return; } // make the move move.Make(currentBoard); // add the current board hash to the history AddHistoryHash(); // generate the possible moves GenerateMoves(); // set the status of the game SetStatus(); // increment the current board index currentBoardIndex++; // raise the GoneForward event OnGoneForward(new MoveEventArgs(move, currentBoardIndex - 1)); } }
/// <summary> /// Makes a move. /// If the move is illegal or it's null, throws an Argument(Null)Exception. /// </summary> /// <param name="move">The move</param> public void Make(Move move) { // check to see if the move it's not null and it's valid if (move == null) { throw new ArgumentNullException("move", Resources.NullMoveMsg); } bool findMove = false; foreach (Move m in PossibleMoves) { if (move.From == m.From && move.To == m.To) { findMove = true; break; } } if (!findMove) { throw new ArgumentException(Resources.IllegalMoveMsg, "move"); } // build the event args CancelMoveEventArgs moveEventArgs = new CancelMoveEventArgs(move, currentBoardIndex - 1); // raise the Moving event OnMoving(moveEventArgs); // if the move was cancelled if (moveEventArgs.Cancel) { return; } // remove the moves after current board index (if any) if (!IsLast) { moveHistory.RemoveRange(currentBoardIndex, moveHistory.Count - currentBoardIndex); } // if this is a promotion, the promotion is not set and the promotion delegate is not null, call the promotion delegate if (move is PromotionMove && (move as PromotionMove).PromotionType == null && Promote != null) { (move as PromotionMove).PromotionType = Promote(); } // make the move move.Make(currentBoard); // add the current hash to the history AddHistoryHash(); // generate the possible moves GenerateMoves(); // set the status of the game SetStatus(); // increment the current board index currentBoardIndex++; // add move to history moveHistory.Add(move); // raise the Moved event OnMoved(new MoveEventArgs(move, currentBoardIndex - 1)); }