Пример #1
0
        //定时器,用来显示发牌时的动画
        internal void timer_Tick(object sender, EventArgs e)
        {
            if (musicFile.Length > 0 && (!MciSoundPlayer.IsPlaying()) && PlayMusicToolStripMenuItem.Checked)
            {
                MciSoundPlayer.Stop();
                MciSoundPlayer.Close();
                MciSoundPlayer.Play(musicFile, "song");
            }
            else if (musicFile.Length > 0 && (!MciSoundPlayer.IsPlaying()) && RandomPlayToolStripMenuItem.Checked)
            {
                PlayRandomSongs();
            }
            //1.分牌
            if (currentState.CurrentCardCommands == CardCommands.ReadyCards) //分牌
            {
                if (currentCount == 0)
                {
                    //画工具栏
                    if (!gameConfig.IsDebug)
                    {
                        drawingFormHelper.DrawToolbar();
                    }
                }

                if (currentCount < 25)
                {
                    drawingFormHelper.ReadyCards(currentCount);
                    currentCount++;
                }
                else
                {
                    currentState.CurrentCardCommands = CardCommands.DrawCenter8Cards;
                }
            }
            else if (currentState.CurrentCardCommands == CardCommands.WaitingShowBottom) //翻底牌完毕后的清理工作
            {
                drawingFormHelper.DrawCenterImage();
                //画8张牌的背面
                Graphics g = Graphics.FromImage(bmp);

                for (int i = 0; i < 8; i++)
                {
                    g.DrawImage(gameConfig.BackImage, 200 + i * 2, 186, 71, 96);
                }

                SetPauseSet(gameConfig.Get8CardsTime, CardCommands.DrawCenter8Cards);
            }
            else if (currentState.CurrentCardCommands == CardCommands.DrawCenter8Cards) //2.抓底牌
            {
                //如果无人亮主,流局
                if (drawingFormHelper.DoRankNot())
                {
                    if (gameConfig.IsPass) //如果设置为流局
                    {
                        //暂停3秒
                        init();
                        isNew = false;
                        //画图片
                        drawingFormHelper.DrawPassImage();
                        SetPauseSet(gameConfig.NoRankPauseTime, CardCommands.WaitingShowPass);
                        return;
                    }
                    else //如果设置为翻底牌
                    {
                        //将底牌的第三张的花色设置为主
                        ArrayList bottom = new ArrayList();
                        bottom.Add(pokerList[0][0]);
                        bottom.Add(pokerList[0][1]);
                        bottom.Add(pokerList[1][0]);
                        bottom.Add(pokerList[1][1]);
                        bottom.Add(pokerList[2][0]);
                        bottom.Add(pokerList[2][1]);
                        bottom.Add(pokerList[3][0]);
                        bottom.Add(pokerList[3][1]);
                        int suit = CommonMethods.GetSuit((int)bottom[2]);
                        currentState.Suit = suit;

                        Graphics g = Graphics.FromImage(bmp);

                        if (currentState.Master == 1 || currentState.Master == 2)
                        {
                            drawingFormHelper.DrawSuit(g, suit, true, true);
                        }
                        else if (currentState.Master == 3 || currentState.Master == 4)
                        {
                            drawingFormHelper.DrawSuit(g, suit, false, true);
                        }

                        g.Dispose();

                        //在中央画8张底牌,第三张稍微向上
                        drawingFormHelper.DrawCenterImage();
                        drawingFormHelper.DrawBottomCards(bottom);

                        //暂停一段时间,让大家能看到翻的底牌
                        SetPauseSet(gameConfig.NoRankPauseTime, CardCommands.WaitingShowBottom);

                        return;
                    }
                }


                whoseOrder = currentState.Master;//第一次由主家发牌
                firstSend  = whoseOrder;

                SetPauseSet(gameConfig.Get8CardsTime, CardCommands.DrawMySortedCards);

                drawingFormHelper.DrawCenter8Cards();

                initSendedCards();
                drawingFormHelper.DrawMySortedCards(currentPokers[0], currentPokers[0].Count);
                currentState.CurrentCardCommands = CardCommands.WaitingForSending8Cards; //摸牌完毕,排序我的牌

                //初始化得分牌
                drawingFormHelper.DrawScoreImage(0);
            }
            else if (currentState.CurrentCardCommands == CardCommands.WaitingShowPass) //显示流局信息
            {
                //将流局图片清理掉
                drawingFormHelper.DrawCenterImage();
                //drawingFormHelper.DrawScoreImage(0);
                Refresh();
                currentState.CurrentCardCommands = CardCommands.ReadyCards;
            }
            else if (currentState.CurrentCardCommands == CardCommands.WaitingForSending8Cards) //3.扣底牌
            {
                //如果需要
                switch (currentState.Master)
                {
                case 1:
                    if (gameConfig.IsDebug)
                    {
                        Algorithm.Send8Cards(this, 1);
                    }
                    else
                    {
                        drawingFormHelper.DrawMyPlayingCards(currentPokers[0]);
                        Refresh();
                        return;
                    }
                    break;

                case 2:
                    Algorithm.Send8Cards(this, 2);
                    break;

                case 3:
                    Algorithm.Send8Cards(this, 3);
                    break;

                case 4:
                    Algorithm.Send8Cards(this, 4);
                    break;
                }
            }
            else if (currentState.CurrentCardCommands == CardCommands.DrawMySortedCards) //4.画我的牌
            {
                //将最后自己的牌进行排序显示
                SetPauseSet(gameConfig.SortCardsTime, CardCommands.DrawMySortedCards);

                drawingFormHelper.DrawMySortedCards(currentPokers[0], currentPokers[0].Count);
                Refresh();

                currentState.CurrentCardCommands = CardCommands.WaitingForSend;
            }
            else if (currentState.CurrentCardCommands == CardCommands.WaitingForSend) //等待出牌
            {
                //如果是对家
                if (whoseOrder == 2)
                {
                    drawingFormHelper.DrawFrieldUserSendedCards();
                }
                if (whoseOrder == 3)
                {
                    drawingFormHelper.DrawPreviousUserSendedCards();
                }
                if (whoseOrder == 4)
                {
                    drawingFormHelper.DrawNextUserSendedCards();
                }
                if (whoseOrder == 1)
                {
                    if (gameConfig.IsDebug)
                    {
                        if (firstSend == 1)
                        {
                            Algorithm.ShouldSendedCards(this, 1, currentPokers, currentSendCards, currentState.Suit, currentRank);
                        }
                        else
                        {
                            Algorithm.MustSendedCards(this, 1, currentPokers, currentSendCards, currentState.Suit, currentRank, currentSendCards[firstSend - 1].Count);
                        }
                        drawingFormHelper.DrawMyFinishSendedCards();
                        if (currentSendCards[3].Count > 0) //是否完成
                        {
                            currentState.CurrentCardCommands = CardCommands.Pause;
                            SetPauseSet(gameConfig.FinishedOncePauseTime, CardCommands.DrawOnceFinished);
                        }
                        else
                        {
                            whoseOrder = 4;
                            currentState.CurrentCardCommands = CardCommands.WaitingForSend;
                        }
                    }
                    else
                    {
                        currentState.CurrentCardCommands = CardCommands.WaitingForMySending;//等待鼠标事件
                    }
                }
            }
            else if (currentState.CurrentCardCommands == CardCommands.Pause) //如果需要暂停
            {
                //如果是Pause,则只是让程序休息一会()
                long interval = (DateTime.Now.Ticks - sleepTime) / 10000;

                if (interval > sleepMaxTime)
                {
                    currentState.CurrentCardCommands = wakeupCardCommands;
                }
            }
            else if (currentState.CurrentCardCommands == CardCommands.DrawOnceFinished) //如果是大家都出完牌
            {
                drawingFormHelper.DrawFinishedOnceSendedCards();                        //完成清理工作
                if (currentPokers[0].Count > 0)
                {
                    currentState.CurrentCardCommands = CardCommands.WaitingForSend;
                }
            }
            else if (currentState.CurrentCardCommands == CardCommands.DrawOnceRank) //如果本轮大家都出完牌
            {
                currentState.CurrentCardCommands = CardCommands.Undefined;
                init();
            }
        }