php 数字小游戏
<html>
<head>
<title>Simple Game</title>
<script LANGUAGE="javascript">
<!--
function rdoclick(t)
{
    window.document.form1.tmptran.value=t;
}
function submit1_onclick()
{
    var flag;
    var i;
    flag=true;


    if (window.document.form1.szInput.value.length !=4 )
        {
            alert('请提交4位数字');
            return false;
        }


    for ( i = 0 ; i < window.document.form1.szInput.value.length ; i++ )
    {
//    alert(i + "===" + window.document.form1.szInput.value.substr (i , 1) );
    if (!(window.document.form1.szInput.value.substr (i , 1) >=0 && window.document.form1.szInput.value.substr (i , 1) < 10))
        {
            alert('提交不全是数字');
            return false;
        }
    for ( j = i+1 ; j < window.document.form1.szInput.value.length ; j++ )
        {
        if (window.document.form1.szInput.value.substr (i , 1) == window.document.form1.szInput.value.substr (j , 1) )
        {    alert('提交不能有重复数字');
            return false;
        }
        }

    }

        return true;
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF">
<div align="center"> 
  <h2>数字分析(测试版V3)</h2>

 <form Method="POST"> 
  <?    
    
print "<center><INPUT TYPE=hidden name="szBootcard" Value="">n";
     print 
"<INPUT TYPE=hidden name="nTimes" Value="0">n";
    print 
"<INPUT TYPE=SUBMIT Value="重新开始!"></center>n";
  
?>
  </form>
 
<form name=form1 Method="POST">     
<table border="0%" cellspaccing="2" cellpadding="2" width="80%" bordercolor="#808000">
  <tr>
  <td width="100%">
    <table width="100%" bordercolor="#336600" border="1" cellspacing="3" cellpadding="0">
          <tr>
        <th width="10%" align="center" bgcolor="#1F4D00"><font color="#FFFFFF">次数</font></td>
        <th width="20%" align="center" bgcolor="#1F4D00"><font color="#FFFFFF">回答</font></td>
        <th width="35%" align="center" bgcolor="#1F4D00"><font color="#FFFFFF">数字和位置都正确A</font></td>
        <th width="35%" align="center" bgcolor="#1F4D00"><font color="#FFFFFF">数字正确但位置不正确B</font></td>
          </tr>
    <?
    $nMaxTimes
20;

    if ( 
$nTimes == )
    {
    
srand((double)microtime()*10000);

    for ( 
$i$i $i++ )
        {
        
        
$chBootNum[$i] = rand(09);
            for ( 
$j$i $j >= $j-- )
            {
            if ( 
$chBootNum[$i] == $chBootNum[$j] )
            break;
            }
        if ( 
$j != -1  )
        
$i --;
    
        }

    
$szBootcard $chBootNum[0].$chBootNum[1].$chBootNum[2].$chBootNum[3]; 

    
$EncodeIndex rand(1080);

    
$szEncode $szBootcard $EncodeIndex ;
    
$szEncodecard $EncodeIndex.$szEncode;
//    print "Bootcard=$szBootcard;EncodeIndex=$EncodeIndex;Encodecard=$szEncodecard<br>" ;
    
    
}
    else
    {
    
$szUncodecardTemp substr ($szEncodecard );
    
$EncodeIndex substr ($szEncodecard );
    
$szUncodecardTemp $szUncodecardTemp $EncodeIndex ;
    if ( 
strlen($szUncodecardTemp ) == )
        
$szBootcard '0'.$szUncodecardTemp;
    else     
$szBootcard $szUncodecardTemp;
//    print "$nTimes:UncodecardTemp=$szUncodecardTemp :$EncodeIndex :szBootcard=$szBootcard<br>";
    
}
    
    
//    if ( $nTimes < 20 )
//    {

        
$nHistoryTimes $nTimes;
        
$szHistory[$nTimes]=$szInput ;

    
$nBothDnpOK 0;
    for ( 
$i$i $i++ )
        {
    
$chInput substr($szInput$i 1); 
    
    
$chBoot substr($szBootcard $i 1) ;
//    print "chInput: $chInput--$chBoot<br>";
    
if ( $chInput == substr($szBootcard $i 1) )
        
$nBothDnpOK ++ ;
        }

    
$nOnlyDigit 0;
    for ( 
$i$i $i++ )
        {
    
$chInput substr($szInput$i 1); 
    
        for ( 
$j$j $j++ )
            {
            
$chBoot substr($szBootcard $j 1);
                if ( 
$chInput == substr($szBootcard $j 1) )
                {
                
$nOnlyDigit ++ ;
                }
//                print "chInput$i: $chInput ----chBoot$chBoot OK?$nOnlyDigit<br>";
            
}
/*
        print "$i!";

        for ( $j= $i ; $j < 4 ; $j++ )
        {
        $chInputNext= substr($szInput, $j , 1) ;
        if ($chInput == $chInputNext )
        $i = $i;
        print "$j : $chInput ?=? $chInputNext <br>";
        }
        print "$iEnd";
*/        
        
}
    
$nOnlyDigit -=$nBothDnpOK;
        

        
$szHistoryBoth[$nTimes] =$nBothDnpOK ;
        
$szHistoryOnly[$nTimes] =$nOnlyDigit ;
//        print "both -$szHistoryBoth[$nTimes];;;;; Only =$szHistoryOnly[$nTimes] " ;

        
for ( $i $i $nHistoryTimes $i ++ )
            {
            
$szHisVarName "szHistory".$i;
            
$szHistory[$i]= $$szHisVarName ;
            print 
"<INPUT TYPE=hidden name=$szHisVarName Value="$szHistory[$i]">n";

            
$szBothVarName "szBoth".$i;
            
$szHistoryBoth[$i] = $$szBothVarName ;
            print 
"<INPUT TYPE=hidden name=$szBothVarName Value="$szHistoryBoth[$i]">n";
            
$szOnlyVarName "szOnlyDigit".$i;
            
$szHistoryOnly[$i] =$$szOnlyVarName;
            print 
"<INPUT TYPE=hidden name=$szOnlyVarName Value="$szHistoryOnly[$i]">n";

            }

            
$szBothVarName "szBoth".$i;
            print 
"<INPUT TYPE=hidden name=$szBothVarName Value="$szHistoryBoth[$i]">n";
            
$szOnlyVarName "szOnlyDigit".$i;
            print 
"<INPUT TYPE=hidden name=$szOnlyVarName Value="$szHistoryOnly[$i]">n";

            
$szHisVarName "szHistory".$i;
            print 
"<INPUT TYPE=hidden name=$szHisVarName Value="$szHistory[$i]">n";
            print 
"<INPUT TYPE=hidden name="szEncodecard" Value="$szEncodecard">n";

//    }

    
$nHistoryTimes ++ ;
    
    for ( 
$i$i $nHistoryTimes$i ++ )
        {
        if ( 
$szHistoryBoth[$i] >= 4  )
        {
            print 
"<tr bgcolor=#ff9966>n";
        
$szOK "OK";
        }
        else
        {
        print 
"<tr>n";
        
$szOK "";
        }

          print 
"    <td>$i</td><td>$szHistory[$i]</td>n";
          print 
"    <td>$szHistoryBoth[$i]A </td><td>$szHistoryOnly[$i]B </td>n";
          print 
"   </tr>n";
        }

    
$Score 100 - ( $nTimes 100 $nMaxTimes );

    if ( 
$nTimes $nMaxTimes )
    {
    if (
$szOK == "OK" )
        {
        print 
"<tr bgcolor=#cc3366>n";
        print 
"    <td><font color=#cc99cc>完成</font></td><td><font color=#cc99cc>聪明伶俐一百分</font></td>n";

        print 
"    <td>你成功了。你的得分是<font color=Yellow>$Score</font></td><td>请重新开始</td>n";
        }
    else    
        {
        
$nTimesNext $nHistoryTimes  //has been add 1;
        
print "<tr>n";
        print 
"<INPUT TYPE=hidden name="nTimes" Value=$nTimesNext>n";
        print 
"    <td>$nTimesNext</td><td><INPUT TYPE=text name="szInput" SIZE=8></td>n";
        print 
"    <td><INPUT TYPE=SUBMIT value="  提  交  " onclick="return submit1_onclick()"></td><td> </td>n";
        }
    }
    else
    {    print 
"<tr bgcolor=#000000>n";
        print 
"    <td><font color=#FFFFFF>完成</td><td><font color=#cc99cc>答案是:$szBootcard</font></td>n";
        print 
"    <td><font color=#FFFFFF>很遗憾,你没有在规定的次数内完成。你的得分是<font color=Yellow>$Score</font></font></td><td><font color=#FFFFFF>请重新开始</font></td>n";
    }

        print 
"   </tr>n";

  
?>
        </table>
  </td>
  </tr>
</table>
 </div>
 </form>
<p>
说明
<br>
1.开始时系统自动生成一个4位数的底牌,这4位数字从0-9中随机取出,随机排列,并且不重复。<br>
2.输入猜测的底牌(4位不重复的数字),如果正确,系统会提示完成。如果有错误,系统会将比较结果列出。<br>
3.你通过比较结果,分析底牌,再次输入。<br>
4.最多次数为20次,努力吧!<br>
5."数字正确但位置不正确B"数字个数中不包括"数字和位置都正确A"的个数。<br>
如:底牌为2345,当输入2035时,系统提示为1A2B。<br>
<p>
<br>
已知的问题:<br>
1.界面有些难看。
2.没有最高分记录。
<p>
上述问题如果解决,会在页面上消失。谢谢。
<p>
已经解决的问题:<br>
1.底牌可以通过source看到,这个版本已经加密。<br>
2.在IE下问题已经解决,使用IE4.0测试通过。Netscape 4.x下测试正常。<br>
<p>
<a href="http://haio.yeah.net">http://haio.yeah.net<a>
<p>
<a href="mailto:[email protected]">[email protected]<a>

</body>
</html>