zoukankan      html  css  js  c++  java
  • 游戏--疯狂猜字随机混乱正确答案逻辑

    不重复字库:

     public static $wordConfig = array(
            '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','退','','','','',' ','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','耀','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','姿','','','','','','','','','廿','','','','','','','','','','丿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','诿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','涿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','槿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','趿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','鱿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','便','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','齿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','蹿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','殿','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','饿','','','','','','','','',
        );

    数据库存的正确答案为 a,b,c,d  

    $config = self::$wordConfig;
            $configNum = count($config);
            foreach($list as  $key => $row){
    
                $ignorRandAgain = null;//这个其实可以不要
                $recodRand = null;
                $trueRand = null;
                $trueWord = null;
                $randWord = null;
                $theTrue = explode(',',$row['trueAnswer']);
                $ansNum = count($theTrue);
                //确定正确答案在数组中出现的位置
                foreach($theTrue as $tw){
                    $yes_Or_no = true;
                    do {
                        $temp = rand(0,11);
                        //判断是否位置被占用
                        if(!in_array($temp,$randWord)){
                            $trueWord[] = $temp;
                            //占用位置
                            $randWord[] = $temp;
                            $yes_Or_no = false;
                        }
                    } while ($yes_Or_no);
                }
                //确定混乱文字出现的位置
                for($i = 0; $i < 12-$ansNum; $i++){
                    $yes_Or_no = true;
                    do {
                        //在12个字中的位置
                        $temp = rand(0,11);
                        //判断是否位置被占用
                        if(!in_array($temp,$randWord)){
                            $trueRand[] = $temp;
                            //占用位置
                            $randWord[] = $temp;
                            //位置没有被占用后 再确定混乱字符挑选
                            $yes_Or_no_config = true;
                            do{
                                $tempConfig = rand(0,$configNum);
                                if(!in_array($tempConfig,$ignorRandAgain)){
                                    $recodRand[] = $tempConfig;
                                    $ignorRandAgain[] = $tempConfig;//这一步可以不要  直接判断recordRand就可以了
                                    $yes_Or_no_config = false;
                                }
                            }while($yes_Or_no_config);
                            $yes_Or_no = false;
                        }
                    } while ($yes_Or_no);
                }
                $record = null;
                $count = 0;
                for($i = 0; $i < 12; $i++){
                    //判断当前位置属于谁
                    if(in_array($i,$trueRand)){
                        $word = $config[$recodRand[$i-$count]];
                        $record[] = $word;
                    }else{
                        $word = $theTrue[$count];
                        $record[] = $word;
                        $count++;
                    }
                }
                $list[$key]['falseAnswer'] = implode(',',$record);
            }
    积累知识,分享知识,学习知识。
  • 相关阅读:
    Atitit 架构师的技术框架体系图 各种引擎列表 脚本引擎 groovy beanshel php nodejs rhino等 表达式引擎技术 Ognl/MVELl等 通讯, rest 命令解
    Atitit 架构师的分类 架构师都有哪些种类? 1. 应用架构师 应用架构师是行业中数量最多的架构师,主要负责公司产品的技术架构。产品架构师需要对业务有足够的理解,根据产品需求设计架构,在运营团
    Atitit 教育学体系 教育学主要内容多语言,教学论,心理学,体育 高等教育学 职业技术教育学 教育史
    Atitit 微信开发文档总结获取token和菜单管理功能 /bookmarksHtmlEverythingIndexPrj/src/com/attilax/wechatToto/wechatMen
    Atitit 薪酬管理法 工作手册 员:薪酬管理办法 1.薪酬结构 所有员工的薪酬均由岗位工资、级别工资、校龄工资、特别津贴、绩效工资和季度奖金六部分组成。其中岗位工资、级别工资、校龄工资、22
    Atitit springcloud的艺术 attilax总结 目录 1.1. 服务治理:Spring Cloud Eureka 39 注册中心 1 1.2. 第4章 客户端负载均衡:Spring
    ATITIT 后发优势 后发劣势 vs 先发优势的思考 目录 1.1. “后发优势” 1 1.2. “后发劣势”论 1 1.3. 科技、经济界有两种矛盾的说法“后发优势”和“后发劣势” 1 2
    Atitit java项目常用类库表 目录 1. Ati总的常用库 1 1.1. 表达式,语言解析类库 1 1.2. 字符串模板解析库velocity freemark 1 1.3. rest库
    Atitit 命令行dsl传递参数的几种模式对比 cli url模式 键值对NameValuePair urlutil String string = " host 101.13
    Atitit java字符串模板渲染总结 目录 1. 总结:指标 1 1.1. 支持中文变量 提升可读性 1 1.2. 变量placeholder简单性,,velo可以直接¥前导简单。。Free的
  • 原文地址:https://www.cnblogs.com/bin-pureLife/p/4494577.html
Copyright © 2011-2022 走看看