⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameform.cs

📁 c#编写的连连看 功能和单机版的差不多 自己看吧 呵呵
💻 CS
📖 第 1 页 / 共 2 页
字号:
                                if (picKey[k, j] > 0)
                                {
                                    break;
                                }
                            }
                            for (m = i; m > i - k - 1; m--)
                            {
                                picKey[m, j] = picKey[m - i + k, j];
                                picKey[m - i + k, j] = -1;
                            }
                        }
                    }
                }
            }
            else
                return;
            return;
        }
        private bool canline(int px, int py, int px2, int py2)//判断两图是否可消
        {
            int i, j;
            bool flag = false;
            int[] row = new int[YL];//存储每行的key值 
            int[] col = new int[XL];//存储每列的key值 bool flag=false; 
            pathPointArray.Clear();
            if (px2 == px && py2 == py) return false;//两副图为同一张图,不能消 
            if (picKey[px, py] != picKey[px2, py2]) return false;//两副图不一样,不能消 
            if (picKey[px, py] <= 0 || picKey[px2, py2] <= 0) return false;//有一张图为空图,不能消 
            if ((px2 == px && py2 == py - 1) || (px2 == px && py2 == py + 1) ||
                (py2 == py && px2 == px + 1) || (py2 == py && px2 == px - 1))
                return true;
            //两张图相临,能消 
            //有一张图四周被其他图片包围,不能消 
            if ((picKey[px - 1, py] >= 0 && picKey[px + 1, py] >= 0 && picKey[px, py - 1] >= 0 &&
                picKey[px, py + 1] >= 0) || (picKey[px2 - 1, py2] >= 0 && picKey[px2 + 1, py2] >= 0 &&
                picKey[px2, py2 - 1] >= 0 && picKey[px2, py2 + 1] >= 0))
                return false;
            //key数组初始为0 
            for (i = 0; i < XL; i++)
            {
                for (j = 0; j < YL; j++)
                {
                    key[i, j] = 0;
                }
            }
            key[px, py] = 1;
            key[px2, py2] = 1;
            //(px,py)点对应图左边为空,则key值+1 
            for (i = px - 1; i >= 0; i--)
            {
                if (picKey[i, py] > 0)
                    break;
                key[i, py]++;
            }
            //(px,py)点对应图右边为空,则key值+1 
            for (i = px + 1; i < XL; i++)
            {
                if (picKey[i, py] > 0)
                    break;
                key[i, py]++;
            }
            //(px,py)点对应图上边为空,则key值+1 
            for (j = py - 1; j >= 0; j--)
            {
                if (picKey[px, j] > 0)
                    break;
                key[px, j]++;
            }
            //(px,py)点对应图下边为空,则key值+1 
            for (j = py + 1; j < YL; j++)
            {
                if (picKey[px, j] > 0)
                    break;
                key[px, j]++;
            }
            //(px2,py2)点对应图左边为空,则key值+1 
            for (i = px2 - 1; i >= 0; i--)
            {
                if (picKey[i, py2] > 0)
                    break;
                key[i, py2]++;
            }
            //(px2,py2)点对应图右边为空,则key值+1 
            for (i = px2 + 1; i < XL; i++)
            {
                if (picKey[i, py2] > 0)
                    break;
                key[i, py2]++;
            }
            //(px2,py2)点对应图上边为空,则key值+1 
            for (j = py2 - 1; j >= 0; j--)
            {
                if (picKey[px2, j] > 0)
                    break;
                key[px2, j]++;
            }
            //(px2,py2)点对应图下边为空,则key值+1 
            for (j = py2 + 1; j < YL; j++)
            {
                if (picKey[px2, j] >= 0)
                    break;
                key[px2, j]++;
            }

            for (i = 0; i < XL; i++)
            {
                for (j = 0; j < YL; j++)
                {
                    if (key[i, j] == 2)
                    {
                        return true;//key值为2,表示有交叉,可以消
                    }
                    col[i] += key[i, j];
                    //累计每一列的总值 
                    row[j] += key[i, j];
                    //累计每一行的总值 
                }
            }
            //图所在的两列值>=1,且此两列中间存在一条无其他图的可达通路,并且此两图
            //皆可达所在列的并且行值为可达通路行值的区域,可以消 
            if (col[px] >= 1 && col[px2] >= 1)
            {
                for (j = 0; j < YL; j++)
                {
                    if (key[px, j] > 0 && key[px2, j] > 0)
                    {
                        //  flag = true;
                        if (px2 > px)
                        {
                            flag = true;
                            for (i = px; i <= px2; i++)
                            {
                                if (picKey[i, j] > 0)
                                {
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        else if (px > px2)
                        {
                            flag = true;
                            for (i = px; i >= px2; i--)
                            {
                                if (picKey[i, j] > 0)
                                {
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        if (flag)
                        {
                            return true;
                        }
                    }
                }
            }
            //图所在的两行值>=1,且此两行中间存在一条无其他图的可达通路,并且此两图
            //皆可达所在行的并且列值为可达通路列值的区域,可以消
            if (row[py] >= 1 && row[py2] >= 1)
            {
                for (i = 0; i < XL; i++)
                {
                    if (key[i, py] > 0 && key[i, py2] > 0)
                    {
                        //  flag = true;
                        if (py2 > py)
                        {
                            flag = true;
                            for (j = py; j <= py2; j++)
                            {
                                if (picKey[i, j] > 0)
                                {
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        else if (py > py2)
                        {
                            flag = true;
                            for (j = py; j >= py2; j--)
                            {
                                if (picKey[i, j] > 0)
                                {
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        if (flag)
                            return true;
                    }
                }
            }
            return false;
        }


        private void GameForm_Load(object sender, EventArgs e)
        {
            initPicBox();
        }


        private void BtPlaying_Click(object sender, EventArgs e)
        {
            this.label3.Visible = false;
            this.ReDrawTimer.Enabled = true;
            this.progressTimer.Enabled = true;
            //this.btnTip.Enabled = true;
            //this.BtAnew.Enabled = true;
            pBar.Value = GameTimeSec;
            hintTimes = 30;
            this.lbHintTimes.Text = hintTimes.ToString() + "次";
            //PlaySoundInThread("bg-0" + rdImage.Next(1, 4).ToString() + ".mid", SoundType.BGSound, 1);
            this.pictureBox1.Enabled = true;
            this.progressTimer.Enabled = true;
            //ReDrawTimer.Enabled = true;
            InitpicKey();
            initPicBox();
        }

        private void PBMouseUp(object sender, MouseEventArgs e)
        {
            int i = e.X / PicSize;
            int j = e.Y / PicSize;
            /*if (picKey[i, j] > 0)
            {
                PlaySoundInThread("select.wav", SoundType.WAV,1);
            }*/
            if (picKey[i, j] > 0)
            {
                clickedPointArray.Add(new Point(i, j));
                isClicked[i, j] = true;
            }
            if (clickedPointArray.Count == 2)
            {
                if (canline(clickedPointArray[0].X, clickedPointArray[0].Y,
                    clickedPointArray[1].X, clickedPointArray[1].Y))
                {
                    picKey[clickedPointArray[0].X, clickedPointArray[0].Y] = -1;
                    picKey[i, j] = -1;
                    //PlaySoundInThread("bomb.wav", SoundType.BGSound, 2);
                    DrawInThread(clickedPointArray[0].X * PicSize, clickedPointArray[0].Y * PicSize, i * PicSize, j * PicSize, EffectType.Bomb);
                    if (pBar.Value > 55)
                    {
                        pBar.Value = 60;
                    }
                    else
                    {
                        pBar.Value += 5;
                    }
                }
                isClicked[clickedPointArray[0].X, clickedPointArray[0].Y] = false;
                isClicked[i, j] = false;
                clickedPointArray.Clear();
            }
            retractPictureBox(dirs);
            initPicBox();
        }

        private void ReDrawTimer_Tick(object sender, EventArgs e)
        {
            if (!findline(false))
            {
                Reset();
            }
            initPicBox();
            if (win())
            {
                ReDrawTimer.Enabled = false;
                progressTimer.Enabled = false;
                MessageBox.Show("这猪都能过了!");
                pBar.Value = GameTimeSec;
                InitpicKey();
                this.pictureBox1.Enabled = false;
            }
        }

        private void progressTimer_Tick(object sender, EventArgs e)
        {
            pBar.Value--;
            pBar.Update();
            label1.Text = "剩余时间" + pBar.Value.ToString() + "秒:";
            if (pBar.Value <= 0)
            {
                progressTimer.Enabled = false;
                ReDrawTimer.Enabled = false;
                MessageBox.Show("这么简单,都过不了,买块豆腐吧!");
                //this.MyMediaPlayer.Ctlcontrols.stop();
                pBar.Value = GameTimeSec;
                hintTimes = 6;
                InitpicKey();
                this.pictureBox1.Enabled = false;
                this.label3.Visible = true;
            }
        }

        private void rbLR_CheckedChanged(object sender, EventArgs e)
        {
            dirs = directions.LeftToRight;
            retractPictureBox(dirs);
        }

        private void rbRL_CheckedChanged(object sender, EventArgs e)
        {
            dirs = directions.RightToLeft;
            retractPictureBox(dirs);
        }

        private void rbUD_CheckedChanged(object sender, EventArgs e)
        {
            dirs = directions.UpToDown;
            retractPictureBox(dirs);
        }

        private void rbDU_CheckedChanged(object sender, EventArgs e)
        {
            dirs = directions.DownToUp;
            retractPictureBox(dirs);
        }

        private void rbNone_CheckedChanged(object sender, EventArgs e)
        {
            dirs = directions.None;
        }

        private void BTClue_Click(object sender, EventArgs e)
        {
            hintTimes--;
            if (hintTimes < 0)
            {
                MessageBox.Show("提示次数已达三十次!你用到三十次,也够蠢的!");
                return;
            }
            lbHintTimes.Text = hintTimes.ToString() + "次";
            findline(true);
            retractPictureBox(dirs);
            if (Tx1 >= 0)
            {
                //PlaySoundInThread("bomb.wav", SoundType.BGSound, 2);
                DrawInThread(Tx1 * PicSize, Ty1 * PicSize, Tx2 * PicSize, Ty2 * PicSize, EffectType.Bomb);
            }
        }

        private void BtAnew_Click(object sender, EventArgs e)
        {
            //PlaySoundInThread("refresh.wav", SoundType.BGSound, 2);
            Reset(); 
        }

        private void btExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -