翻翻看游戏实现逻辑

    技术2022-05-12  25

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Collections;using System.Windows.Forms;

    namespace WindowsFormsApplication1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();

                //定时器委托,用于在图片消失的时候暂停0.6秒            timer1.Tick += new EventHandler(timer1_Tick);        }

          

            PictureBox pic;        List<PictureBox> list=new List<PictureBox>();//存放图片        static int count = 0;// 存放打开图片的数量        private void Form1_Load(object sender, EventArgs e)        {                              }

            private void handleClick(object sender, EventArgs e)        {

               //将发射的信号强制转换为PictureBox判断是哪个picturebox发射的信号

               //判断完成之后加入一List<>根据图片的地址判断图片是否“相等”

              //时间仓促没时间考虑更好的方法            pic = (PictureBox)sender;                        if (pic == pictureBox1)            {                pictureBox1.Load(Application.StartupPath+@"/1.jpg");                count++;                pictureBox1.Enabled = false;                judge(pictureBox1);                list.Add(pictureBox1);                //stack.Push(pictureBox1);            }            else if (pic == pictureBox2)            {                pictureBox2.Load(Application.StartupPath+@"/2.jpg");                count++;                pictureBox2.Enabled = false;                judge( pictureBox2);                //stack.Push(pictureBox1);                list.Add(pictureBox2);            }            else if (pic == pictureBox3)            {                pictureBox3.Load(Application.StartupPath+@"/3.jpg");                count++;                pictureBox3.Enabled = false;                judge( pictureBox3);                list.Add(pictureBox3);            }            else            {                pictureBox4.Load(Application.StartupPath+@"/1.jpg");                count++;                judge( pictureBox4);                pictureBox4.Enabled = false;                list.Add(pictureBox4);            }

                //打开的图片数量达到两个的时候调用tick()

                if (count == 2)            {                timer1.Start();                            }                   }

           //判断打开的图片是否达到两张,如果超过两张直接切换到背景图片

            private void judge(PictureBox pic)        {            if (count > 2)            {                pic.Load(Application.StartupPath+@"/back.jpg");            }        }

            void timer1_Tick(object sender, EventArgs e)        {            //throw new NotImplementedException();            if (list[0].ImageLocation == list[1].ImageLocation)            {                list[0].Hide();                list[1].Hide();            }            else            {                list[0].Load(Application.StartupPath + @"/back.jpg");                list[1].Load(Application.StartupPath + @"/back.jpg");            }            count = 0;            list[0].Enabled = true;            list[1].Enabled = true;

                list.Clear();

                timer1.Stop();                    }

                }}


    最新回复(0)