/// <summary> /// This method is called when the wingame animation is completed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WinAnimation_Completed(object sender, EventArgs e) { BoardCanvas.Children.Remove(_winText); //Resotre the opacity of the board. GameBoard.Opacity = 1; foreach (Ladder ladder in _ladders) { ladder.Opacity = 1; } foreach (Snake snake in _snakes) { snake.Opacity = 1; } //If the number of players left is more than 1, then the game continues. if (_numOfPlayersLeft > 1) { do { CurrentToken = CurrentToken.Next(_enGameType); }while (Tokens[(int)_currentToken].CurrentPosition == 100); DiceCanvas.IsEnabled = true; } //Else we will enable the start game button and we dont enable the dice canvas. else { CurrentToken = enGameToken.Green; _numOfPlayersLeft = (int)_enGameType; foreach (Token token in _tokens) { token.Reset(); } CreateBoardButton.IsEnabled = true; StartGameButton.IsEnabled = true; StopGameButton.IsEnabled = false; PlayerSelectionPanel.IsEnabled = true; DiceCanvas.IsEnabled = false; } }
/// <summary> /// This method is called when the movement of token is completed. So that we can set the final values. Or decide if the token needs another movement. /// </summary> public void OnTokenAnimationComplete() { //If the user wins the game. Start the win animation. if (Tokens[(int)_currentToken].CurrentPosition == 100) { (new System.Media.SoundPlayer(Properties.Resources.WinAudio)).Play(); DoWinAmination(); _numOfPlayersLeft--; return; } //If the user reaches the snake head. Then we will move the user to the tail. if (_snakeNumbers.ContainsKey(Tokens[(int)_currentToken].CurrentPosition)) { Point newDest = GameBoard.GetCenterCoordinates(_snakeNumbers[Tokens[(int)_currentToken].CurrentPosition]); Tokens[(int)_currentToken].MoveToAlongPath(newDest, ref _snakes[_snakeNumbers.GetIndexOfKey(Tokens[(int)_currentToken].CurrentPosition)].SnakePath); Tokens[(int)_currentToken].CurrentPosition = _snakeNumbers[Tokens[(int)_currentToken].CurrentPosition]; return; } //If the user reaches the lower end of ladder, then we will move the user to the upper end of the ladder. else if (_ladderNumbers.ContainsKey(Tokens[(int)_currentToken].CurrentPosition)) { Point newDest = GameBoard.GetCenterCoordinates(_ladderNumbers[Tokens[(int)_currentToken].CurrentPosition]); Tokens[(int)_currentToken].MoveTo(newDest.X, newDest.Y, true); Tokens[(int)_currentToken].CurrentPosition = _ladderNumbers[Tokens[(int)_currentToken].CurrentPosition]; return; } //Conditions to check if the chance should be transferred to the next user. if (currentFace != DiceFace.Six || (bIsTokenMoved == false && currentFace == DiceFace.Six && Tokens[(int)_currentToken].CurrentPosition + (int)currentFace > 100)) { do { CurrentToken = CurrentToken.Next(_enGameType); }while (Tokens[(int)_currentToken].CurrentPosition == 100); } DiceCanvas.IsEnabled = true; //if (RestartGameButton.IsEnabled == false) // RestartGameButton.IsEnabled = true; }