コード例 #1
0
        /// <summary>method:PerformMove
        /// Perform every step during replaying
        /// </summary>
        /// <param name="currentMN"></param>
        /// <param name="mainform"></param>
        private static void PerformMove(MoveNode currentMN, MainForm mainform)
        {
            int currentTopCard = currentMN.cards[currentMN.cards.Length - 1];

            Card  card      = Tools.ParseToCardFromNumber(currentTopCard, currentMN.source);
            Panel sourcePnl = (Panel)mainform.Controls.Find(Tools.ReverseParseArea(currentMN.source), true)[0];
            Panel targetPnl = (Panel)mainform.Controls.Find(Tools.ReverseParseArea(currentMN.target), true)[0];

            if ("undeal".Equals(Tools.ReverseParseArea(currentMN.source)) && "unuse".Equals(Tools.ReverseParseArea(currentMN.target)))
            {
                int fromX = mainform.Location.X + mainform.panel1.Location.X + sourcePnl.Location.X + card.Width / 2;
                int fromY = mainform.Location.Y + mainform.panel1.Location.Y + sourcePnl.Location.Y + card.Height / 2;

                Cursor.Position = new System.Drawing.Point(fromX, fromY);
                mouse_event((int)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
                mouse_event((int)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
            }
            else if ("unuse".Equals(Tools.ReverseParseArea(currentMN.source)) && "undeal".Equals(Tools.ReverseParseArea(currentMN.target)))
            {
                int fromX = mainform.Location.X + mainform.panel1.Location.X + targetPnl.Location.X + targetPnl.Width / 2;
                int fromY = mainform.Location.Y + mainform.panel1.Location.Y + targetPnl.Location.Y + targetPnl.Height / 2;

                Cursor.Position = new System.Drawing.Point(fromX, fromY);
                mouse_event((int)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
                mouse_event((int)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
            }
            else
            {
                // Get the position of the card within the corresponding panel
                int cardPointYInSource;
                if ("unuse".Equals(Tools.ReverseParseArea(currentMN.source)))
                {
                    cardPointYInSource = 0;
                }
                else
                {
                    Card topCard = (Card)sourcePnl.Controls.Find(card.Name, true)[0];
                    cardPointYInSource = (sourcePnl.Controls.Count - 1 - sourcePnl.Controls.GetChildIndex(topCard)) * 30;
                }

                Point cardPointInSource = new Point(0, cardPointYInSource);

                //去掉form的标题栏
                //定位form在屏幕左上角
                int fromX = mainform.Location.X + mainform.panel1.Location.X + sourcePnl.Location.X + cardPointInSource.X + card.Width / 2;
                int fromY = mainform.Location.Y + mainform.panel1.Location.Y + sourcePnl.Location.Y + cardPointInSource.Y + 15;

                int toX = mainform.Location.X + mainform.panel1.Location.X + targetPnl.Location.X + 15;
                int toY = mainform.Location.Y + mainform.panel1.Location.Y + targetPnl.Location.Y + 15;

                Cursor.Position = new System.Drawing.Point(fromX, fromY);
                mouse_event((int)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
                Cursor.Position = new System.Drawing.Point(toX, toY);
                mouse_event((int)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
            }
            lblCurrentStep.Text = currentMN.step.ToString();
        }
コード例 #2
0
        /// <summary>method:StartReplay
        /// Perform replay by using timer
        /// </summary>
        /// <param name="mnList"></param>
        /// <param name="mainform"></param>
        private static void StartReplay(List <MoveNode> mnList, MainForm mainform)
        {
            AutoReplay.isAutoReplaying = true;

            int movestep = 0;

            System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
            timer.Interval = AUTOPLAY_INTERVAL;
            timer.Tick    += (object obj, EventArgs e) => {
                if (movestep == mnList.Count)
                {
                    timer.Enabled = false; AutoReplay.isAutoReplaying = false; return;
                }
                MoveNode currentMN = mnList[movestep];
                PerformMove(currentMN, mainform);

                movestep++;
            };

            timer.Enabled = true;
        }
コード例 #3
0
ファイル: UndoForm.cs プロジェクト: stanleyQi/pokergame
        /// <summary>method:lstUndo_SelectedIndexChanged
        /// event handler: for selecting the step number, so that it can be restored to
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstUndo_SelectedIndexChanged(object sender, EventArgs e)
        {
            int stepSelected = (lstUndo.SelectedItem as MoveNodeDisplay).Step;

            undoSeletedMoveNode = this.mnList.Find((mn) => { return(mn.step == stepSelected); });
        }