• 很久以前写的一个很简单连连看,贴出来给大家看下


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

    namespace 连连看
    {
        
    public partial class Link : Form
        {
            
    private const int COUNT_BUTTONS = 80;//按纽总数
            private const int COLUMNS = 8;//烈数目
            private int count = 0;//鼠标单击按纽次数
            private int firstIndex = 0, secondIndex = 0;//第一次、第二次单击按纽的下标
            Button[] b = new Button[80];
            ArrayList list1 
    = new ArrayList(40);
            ArrayList list2 
    = new ArrayList(40);
            
    public Link()
            {
                InitializeComponent();
            }

            
    private void Link_Load(object sender, EventArgs e)
            {
                generateRandomNums(list1);
                generateRandomNums(list2);

                
    for (int i = 0; i < COUNT_BUTTONS; i++)
                {
                    b[i] 
    = new Button();
                    b[i].FlatStyle 
    = FlatStyle.Flat;

                    
    if (i < 40)
                    {
                        b[i].Image 
    = this.imageList1.Images[Int32.Parse(list1[i].ToString())];
                        b[i].Tag 
    = Int32.Parse(list1[i].ToString());
                    }
                    
    else
                    {
                        b[i].Image 
    = this.imageList1.Images[Int32.Parse(list2[i - 40].ToString())];
                        b[i].Tag 
    = Int32.Parse(list2[i - 40].ToString());
                    }

                    b[i].Width 
    = 30;
                    b[i].Height 
    = 30;
                    b[i].Top 
    = b[i].Height * (i / COLUMNS);
                    b[i].Left 
    = b[i].Width * (i % COLUMNS);

                    b[i].Click 
    += new EventHandler(process_click);
                    
    this.Controls.Add(b[i]);

                }
            }
            
    private void process_click(object sender, EventArgs e)
            {
                count
    ++;
                
    if (count == 1)
                {
                    
    this.firstIndex = GetFocusedButtonIndex();
                }
                
    if (count == 2)
                {
                    
    this.secondIndex = GetFocusedButtonIndex();
                    
    if (b[firstIndex].Tag.Equals(b[secondIndex].Tag) && firstIndex != secondIndex)
                    {
                        b[firstIndex].Dispose();
                        b[secondIndex].Dispose();

                    }
                    count 
    = 0;
                }

            }

            
    /// <summary>
            
    /// 判断哪个按纽被单击 
            
    ///
            
    /// </summary>
            
    /// <returns></returns>
            private int GetFocusedButtonIndex()
            {
                
    for (int i = 0; i < COUNT_BUTTONS; i++)
                    
    if (b[i].Focused == true)
                        
    return i;
                
    return -1;
            }

            
    /// <summary>
            
    /// 产生随机数,存放到数组中
            
    /// </summary>
            
    /// <param name="list"></param>
            private void generateRandomNums(ArrayList list)
            {
                
    int randomNum;
                
    while (true)
                {
                    Random r 
    = new Random();
                    randomNum 
    = r.Next(40);
                    
    if (!list.Contains(randomNum))
                    {
                        list.Add(randomNum);
                    }
                    
    if (list.Count == 40)
                    {
                        
    break;
                    }
                }
            }
        }
    }

    下载地址:

    /Files/mdy41034264/连连看.rar

  • 相关阅读:
    gcc代码反汇编查看内存分布[1]: gcc
    centos5.5 安装git
    裸机代码(uboot) : clear bss
    互联网协议入门
    git从github下载代码
    linux账户管理(centos)
    jz2440: linux/arch/arm/下面的plat-和mach-
    位置无关码
    【漫画】什么是外部排序?【转】
    快速排序 Vs. 归并排序 Vs. 堆排序——谁才是最强的排序算法
  • 原文地址:https://www.cnblogs.com/mdy41034264/p/1418111.html
Copyright © 2020-2023  润新知