| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1824 人关注过本帖
标题:魔兽密保卡效果,精通数组的大虾请进!
只看楼主 加入收藏
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
那ABCD这些字母干什么啊,数组中不要保存这些字母,但是在网页中显示重来就可以了嘛……
2008-06-17 18:18
冰彩虹
Rank: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
收藏
得分:0 
遇到什么问题?

Flying without wings
2008-06-17 19:57
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
//问题描述
//有时间正确  有时间取不到随即数 有时间数组索引超出范围   竟然能取到z  我实在看不出来   请高手帮助
//
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;  //动态数组命名空间
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        yanzheng();
        Response.Write("<meta http-equiv='refresh' content='30;URL=Default.aspx' /> ");  //30秒后自动刷新页面        
    }
    protected void tijiao_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.shuru.Text == "")
            {
                Response.Write("<script language=javascript>window.alert('请输入验证码!')</script>");
            }
            else
            {               
                if (this.shuru.Text == Session["yzm"].ToString())
                {
                    this.jieguo.Text = "你终于成功了";
                }
                else
                {
                    this.jieguo.Text = "你失败了";
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
    //通过二维数组产生验证码
    public void yanzheng()
    {
        string[,] myArray;      // 创建数组
        myArray = new string[,] { {"Z","A","B","C","D","E","F","G","H","I"},              //填充数组
                                   {"A","11","32","33","54","55","76","77","98","99"},
                                   {"B","12","31","34","53","56","75","78","97","01"},
                                   {"C","13","30","35","52","57","74","79","96","02"},
                                   {"D","14","29","36","51","58","73","80","95","03"},
                                   {"E","15","28","37","50","59","72","81","94","04"},
                                   {"F","16","27","38","49","60","71","82","93","05"},
                                   {"G","17","26","39","48","61","70","83","92","06"},
                                   {"H","18","25","40","47","62","69","84","91","07"},
                                   {"I","19","24","41","46","63","68","85","90","08"},
                                   {"J","20","23","42","45","64","67","86","89","09"},
                                   {"K","21","22","43","44","65","66","87","88","10"}};
        try
        {
            for (int x = 0; x < 12; x++)       //输出数组  (方便测试)
            {
                for (int y = 0; y < 10; y++)
                {
                    Response.Write(myArray[x, y] + "  ");
                }
                Response.Write("<br>");
            }
            //输出字母索引行
            for (int j = 0; j < 10; j++)
            {
                Response.Write("列:" + myArray[0, j] + "  ");
            }
            //字输出母索引列
            Response.Write("<br>");
            for (int j = 0; j < 12; j++)
            {
                Response.Write("行:" + myArray[j, 0] + "  ");
            }
            Random rdm = new Random();       // 实例化一个生成器
            for (int x = 0; x < 12; x++)
            {
                for (int y = 0; y < 10; y++)
                {
                    if (myArray[x, y] == myArray[rdm.Next(1, 12), rdm.Next(1, 10)])
                    {
                        Response.Write(myArray[x, 0]);    //测试输出用
                        Response.Write(myArray[0, y]);
                        Response.Write("<br>");
                        Response.Write(x);
                        Response.Write(y);
                        Response.Write("<br>");
                        Response.Write(myArray[y, x]);
                        Session["lie"] = myArray[x, 0];  // 产生行字母
                        Session["hang"] = myArray[0, y]; //产生列字母
                        Session["yzm"] = myArray[y, x];  //产生行和列坐标交叉点的数字
                    }
                }
                Response.Write("<br>");
            }
            Response.Write("<br>");
            this.xianshi.Text = Session["lie"].ToString();
            this.xianshi.Text += Session["hang"].ToString();      //给显示验证码的label赋值     
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
}

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-18 08:59
191638141
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2008-1-5
收藏
得分:0 
实例化生成器内错误
为什么把myArray[rdm.Next(1, 12), rdm.Next(1, 10)]这就写在循环内?
每循环一次变化一次 怎么比较啊?
2008-06-18 11:29
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
只要能产生字母可以验证成功
 只是有时会出现取不到值    超出范围

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-18 13:30
191638141
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2008-1-5
收藏
得分:0 
让再说一次吗?

没取到值原因:
你每循环一次 随机产生一次 当循环几次还没取到值,这时随机数随到你前面循环的位置 你能取到值?比如 你循环X-2次 Y-3次 当随机产生为myarry[1,],myarry[1,..] ...或者myarry[2,1],...myarryp[2,2]你能取到相等值吗?
超出范围原因:
当你X循环9次以上,Y循环随便循环几次的时候 你的myarry[y,x]能不超出范围.
行和列的数目又不是相等的..

ps:不要一味的个人主义 好的建议就要先考虑再做判断 不要浪费大家的所谓的无意义的时间.
2008-06-18 16:54
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
谢谢了   问题解决了

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-30 09:07
快速回复:魔兽密保卡效果,精通数组的大虾请进!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017318 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved