【橙子】C#Winform--翻翻乐

C#Winform–翻翻乐

作者心得
我记得是某个假期没事与俄罗斯方块一起弄的
你别说
还挺好玩的,当是和我爸一起比赛时间,哈哈哈

源代码

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

namespace FFL
{
    public partial class Form1 : Form
    {
        bool q = true;
        int o = 0;
        int l = 0;
        int f;
        int h;
        string n;
        string m;
        int r = 1;
        string[] c = new string[100];
        Button[] b = new Button[100];
        int x = 0, y = 0; int p = 1;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            

            for (int i = 0; i < 100; i++)
            {
                Button button = new Button();
                button.Location = new Point(0, 0);
                button.Size = new Size(40, 40);
                button.Click += new EventHandler(button1_Click);
                if (i % 10 == 0 && i != 0)
                {
                    x = 0;
                    y += 40;
                }
                else if (i % 10 != 0 && i != 0)
                {

                    x += 40;
                }
                button.Location = new Point(x, y);
                b[i] = button;
                Controls.Add(b[i]);

            }
            end(false);
            Random o = new Random();

            for (int i = 0; i < 100; i++)
            {
                if (i == 50)
                    p = 1;
                int g = o.Next(0, 99);
                CheakNull(g);

            }
            for (int i = 0; i < 100; i++)
            {
                c[i] = b[i].Text;
                b[i].Text = "";
            }
            test();
        }

        public void CheakNull(int g)
        {
            if (b[g].Text == "")
            {
                b[g].Text = Convert.ToString(p);
                p++;
            }
            else if (g != 99)
            {
                g += 1;
                CheakNull(g);
            }
            else
            {
                g = 0;
                CheakNull(g);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (r == 3)
            {
                if (n == m)
                {
                    b[f].BackColor = Color.Red;
                    b[h].BackColor = Color.Red;
                    b[f].Enabled = false;
                    b[h].Enabled = false;
                    l += 2;
                    label2.Text = Convert.ToString(l);
                }
                for (int i = 0; i < 100; i++)
                {
                    if (b[h].BackColor != Color.Red && b[f].BackColor != Color.Red)
                    {
                        b[i].Text = "";
                        b[f].Enabled = true;
                        b[f].BackColor = Color.Black;
                        b[h].Enabled = true;
                        b[h].BackColor = Color.Black;
                    }
                }
                r = 1;
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            o++;
            label4.Text = Convert.ToString(o);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            timer2.Enabled = true;
            end(true);
        }

        public void button1_Click(object sender, EventArgs e)
        {
            if (r == 1)
            {
                int a; int d;
                Button button = (Button)sender;
                Point g = new Point();
                g = button.Location;
                a = g.X;
                d = g.Y;
                int u = (a / 40) + (d / 40) * 10;
                button.Text = c[u];
                n = c[u];
                f = u;
                button.Enabled = false;
                button.BackColor = Color.Yellow;
                timer1.Enabled = true;
                cheak_all();
            }
            if (r == 2)
            {
                int a; int d;
                Button button = (Button)sender;
                Point g = new Point();
                g = button.Location;
                a = g.X;
                d = g.Y;
                int u = (a / 40) + (d / 40) * 10;
                button.Text = c[u];
                m = c[u];
                h = u;
                button.Enabled = false;
                button.BackColor = Color.Yellow;
                timer1.Enabled = true;

            }
            if (r == 1 || r == 2)
                r++;

        }

        public void end(bool c)
        {
            for (int i = 0; i < 100; i++)
            {
                b[i].Enabled = c;
            }

        }

        public void cheak_all()
        {
            if (label2.Text == "100")
            {
                end(false);
                timer2.Enabled = false;
                button1.Enabled = false;
                MessageBox.Show("恭喜,总共花费时间:" + Convert.ToString(o));
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {if (q == true)
            {
                textBox1.Visible = true;
                this.Size = new Size(1031, 434);
                q = false;
            }
            else
            {
                textBox1.Visible = false;
                this.Size = new Size(559, 434);
                q = true;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void test()
        {
          
            int i = 0;
            foreach (string k in c)
            {
                if (i % 10 == 0)
                    textBox1.Text = textBox1.Text + "\r\n\r\n\r\n" + k;
                else
                textBox1.Text = textBox1.Text + "\t" + k;
                i++;
            }


        }
    }

}

效果截图
在这里插入图片描述
在这里插入图片描述
作者的话
可以看的出
技术越来越成熟,即将开始走向面相对象时代!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值