zoukankan      html  css  js  c++  java
  • 很久以前写的一个很简单连连看,贴出来给大家看下

    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

  • 相关阅读:
    追星必备神器 -- 爱豆APP
    关于结对编程项目(Sports club 三)
    关于结对编程项目(Sports club 二)
    关于结对编程项目(Sports club)
    关于对当前大学生的痛点分析
    关于wc项目的简单基本前期制作。
    个人项目作品设计——Sports history
    简单四则运算
    关于介绍手机k歌娱乐软件
    结对项目(3)
  • 原文地址:https://www.cnblogs.com/mdy41034264/p/1418111.html
Copyright © 2011-2022 走看看