private void doWhenReachedBottom(CoinAnimationEventArgs e) { timerFall.Stop(); pictureBoxFalingCoin.Visible = false; r_BoardImages[e.CoinArgs.Col][e.CoinArgs.Row].ResetRegion(); // Change the region now, because the picture is not in empty cell. timerFall.Tick -= e.EventHandlerMethod; changeToFullCell(e.CoinArgs); bool isGameFinish = checkStatus(e.State, e.CoinArgs); // TODO:: isGameFinish not needed because adds of m_GameIsFinish member. if (!isGameFinish) { // do this just if the game is not finish. changePlayerCoin(); changeCurrentPlayerName(); if (m_IsComputer && currentPlayerSign() == k_Player2Sign) { int columnToEnter = r_GameLogic.ReturnComputerMove(m_Depth); int rowToEnter = r_GameLogic.EnterCoin(columnToEnter, currentPlayerSign()); EState status = r_GameLogic.CheckBoardStatus(rowToEnter, columnToEnter); onFallingAnimation(columnToEnter, rowToEnter, status); } } }
// This is the falling coin animation method. private void timerFall_Tick(object sender, EventArgs e) { bool Finished = false; CoinAnimationEventArgs coinArgsElement = e as CoinAnimationEventArgs; for (int i = 0; i < k_NumIterrtationForTickMethod && !Finished; ++i) { if (pictureBoxFalingCoin.Bottom >= coinArgsElement.BotoomLimit) { Finished = true; doWhenReachedBottom(coinArgsElement); } else { pictureBoxFalingCoin.Top += 5; } } }
private void onFallingAnimation(int i_Col, int i_Row, EState i_Status) { if (timerFall.Enabled == false) { // if timer is not runing. pictureBoxFalingCoin.Image = getCurrentPlayerCoinImage(); pictureBoxFalingCoin.Visible = true; pictureBoxFalingCoin.Location = new Point(k_CellWidth * i_Col, 0); // Create coin parameter to send for the Tick method. CoinAnimationEventArgs coinArgs = new CoinAnimationEventArgs( pictureBoxFalingCoin.Location, r_BoardImages[i_Col][i_Row].Bottom, new CoinEventArgs(i_Col, i_Row, currentPlayerSign()), i_Status); EventHandler eventHandlerTickMethod = new EventHandler(delegate(object sender, EventArgs e) { timerFall_Tick(this, coinArgs); }); coinArgs.EventHandlerMethod = eventHandlerTickMethod; timerFall.Tick += eventHandlerTickMethod; timerFall.Start(); } }