Exemple #1
0
        //开始游戏的时候发四张牌
        private void btnStart_Click(object sender, EventArgs e)
        {
            lblInput.Text = "";
            GetPlayingCareds(); //生成一副牌
            Shuffle();          //洗牌
            topCard = 0;        //显示在窗体四张牌中扑克牌的编号(1-52)
            int    imageNum;    //文件夹中扑克牌图片的编号(文件名)
            string path;

            //画第一张牌
            topCard             = topCard = 1;
            pictureBox1.Visible = true;
            //获得文件中某张牌并且知道是什么花色对应的编号计算公式:
            //牌面花色(1、2、3、4):要获得某张牌的的花色
            //(牌面数字大小-1)*4:要获得的某张牌的前一个牌面大小如:要获得的牌是10,前一个牌面就是9
            //牌面花色(1、2、3、4)+(牌面数字大小-1)*4
            imageNum          = PlayingCards[topCard].suit + (PlayingCards[topCard].face - 1) * 4;//文件图片编号
            path              = Directory.GetCurrentDirectory() + @"\images\" + imageNum.ToString() + ".bmp";
            pictureBox1.Image = Image.FromFile(path);
            NumberA           = Convert.ToInt32(PlayingCards[topCard].face);//牌面大小对应的数字大小
            btnNumber1.Text   = NumberA.ToString();
            //画第二张牌
            topCard             = topCard + 1;
            pictureBox2.Visible = true;
            imageNum            = PlayingCards[topCard].suit + (PlayingCards[topCard].face - 1) * 4;
            path = Directory.GetCurrentDirectory() + @"\images\" + imageNum.ToString() + ".bmp";
            pictureBox2.Image = Image.FromFile(path);
            NumberB           = Convert.ToInt32(PlayingCards[topCard].face);
            btnNumber2.Text   = NumberB.ToString();
            //画第三张牌
            topCard             = topCard + 1;
            pictureBox3.Visible = true;
            imageNum            = PlayingCards[topCard].suit + (PlayingCards[topCard].face - 1) * 4;
            path = Directory.GetCurrentDirectory() + @"\images\" + imageNum.ToString() + ".bmp";
            pictureBox3.Image = Image.FromFile(path);
            NumberC           = Convert.ToInt32(PlayingCards[topCard].face);
            btnNumber3.Text   = NumberC.ToString();
            //画第四张牌
            topCard             = topCard + 1;
            pictureBox4.Visible = true;
            imageNum            = PlayingCards[topCard].suit + (PlayingCards[topCard].face - 1) * 4;
            path = Directory.GetCurrentDirectory() + @"\images\" + imageNum.ToString() + ".bmp";
            pictureBox4.Image = Image.FromFile(path);
            NumberD           = Convert.ToInt32(PlayingCards[topCard].face);
            btnNumber4.Text   = NumberD.ToString();
            //初始化界面控件
            btnStart.Visible    = false; //开始游戏
            groupBox1.Visible   = true;  //计算表达式
            groupBox2.Visible   = true;  //查看答案
            groupBox3.Visible   = true;  //游戏规则
            lblShowTime.Visible = true;  //显示时间
            timer1.Enabled      = true;  //启用时钟
            beginTime           = DateTime.Now;
        }
Exemple #2
0
        //点击下一轮按钮
        private void btnNext_Click(object sender, EventArgs e)
        {
            #region 点击下一轮按钮更新初始化数据
            btnAdd.Enabled     = true;
            btnMinus.Enabled   = true;
            btnDivide.Enabled  = true;
            btnMulti.Enabled   = true;
            btnNumber1.Enabled = true;
            btnNumber2.Enabled = true;
            btnNumber3.Enabled = true;
            btnNumber4.Enabled = true;
            btnDelete.Enabled  = true;
            btnClear.Enabled   = true;
            btnLeft.Enabled    = true;
            btnRight.Enabled   = true;
            btnEnter.Enabled   = true;
            lblInput.Text      = "";
            txtAnswer.Text     = "";
            lblResult.Visible  = false;
            lblShowTime.Text   = "";
            timer1.Enabled     = true;
            beginTime          = DateTime.Now;
            #endregion

            int    imageNum;
            string path;
            //画第一张牌
            if (topCard >= 52)
            {
                MessageBox.Show("恭喜你已算完整副牌,开始新的一副牌。");
                topCard = 0;
                Shuffle();//洗牌
            }
            topCard           = topCard + 1;
            imageNum          = PlayingCards[topCard].suit + (PlayingCards[topCard].face - 1) * 4;
            path              = Directory.GetCurrentDirectory() + @"\images\" + imageNum.ToString() + ".bmp";
            pictureBox1.Image = Image.FromFile(path);
            NumberA           = Convert.ToInt32(PlayingCards[topCard].face);
            btnNumber1.Text   = NumberA.ToString();
            //画第二张牌
            if (topCard >= 52)
            {
                MessageBox.Show("恭喜你已算完整副牌,开始新的一副牌。");
                topCard = 0;
                Shuffle();
            }
            topCard           = topCard + 1;
            imageNum          = PlayingCards[topCard].suit + (PlayingCards[topCard].face - 1) * 4;
            path              = Directory.GetCurrentDirectory() + @"\images\" + imageNum.ToString() + ".bmp";
            pictureBox2.Image = Image.FromFile(path);
            NumberB           = Convert.ToInt32(PlayingCards[topCard].face);
            btnNumber2.Text   = NumberB.ToString();
            //画第三张牌
            if (topCard >= 52)
            {
                MessageBox.Show("恭喜你已算完整副牌,开始新的一副牌。");
                topCard = 0;
                Shuffle();
            }
            topCard           = topCard + 1;
            imageNum          = PlayingCards[topCard].suit + (PlayingCards[topCard].face - 1) * 4;
            path              = Directory.GetCurrentDirectory() + @"\images\" + imageNum.ToString() + ".bmp";
            pictureBox3.Image = Image.FromFile(path);
            NumberC           = Convert.ToInt32(PlayingCards[topCard].face);
            btnNumber3.Text   = NumberC.ToString();
            //画第四张牌
            if (topCard >= 52)
            {
                MessageBox.Show("恭喜你已算完整副牌,开始新的一副牌。");
                topCard = 0;
                Shuffle();
            }
            topCard           = topCard + 1;
            imageNum          = PlayingCards[topCard].suit + (PlayingCards[topCard].face - 1) * 4;
            path              = Directory.GetCurrentDirectory() + @"\images\" + imageNum.ToString() + ".bmp";
            pictureBox4.Image = Image.FromFile(path);
            NumberD           = Convert.ToInt32(PlayingCards[topCard].face);
            btnNumber4.Text   = NumberD.ToString();
        }