public void GameButton_Click(object sender, RoutedEventArgs e) { if (true == wingame) { MessageBox.Show("You have to restart again to play game"); return; } GameButton btn = sender as GameButton; GameButtonState btnState = new GameButtonState(btn.Id, btn); // int digit = Convert.ToInt32(btn.Content.ToString()); int row = ((int)btn.GetValue(Grid.RowProperty)); int col = ((int)btn.GetValue(Grid.ColumnProperty)); int digit = row * nRows + col; btn.Position = digit; btnState.Oldpos = btn.Position; //record into undo/redo stack before moving. btn.Move(); btnState.Newpos = btn.Position; gameUndoStack.Push(btn); gameReplayList.Add(btnState); Title = gameUndoStack.Count.ToString(); }//end GameButton_Click
private void timer_Tick(object sender, EventArgs e) { Title = index.ToString(); if (index < gameReplayList.Count) { GameButtonState btnState = gameReplayList[index]; btnState.gameButton.Position = btnState.Oldpos; btnState.gameButton.Move(); index++; //MessageBox.Show("1"); //button10.Text = index.ToString(); } if (index == gameReplayList.Count) { tr.Stop(); } }