Home >php教程 >php手册 >php猜单词游戏

php猜单词游戏

WBOY
WBOYOriginal
2016-06-06 19:41:40950browse

这是一款基于php实现的猜单词小游戏,用的SESSION配合AJAX实现的,感兴趣的小伙伴可以参考一下。

直接复制本地运行就可以了

<script> function Ajax(recvType){ var aj=new Object(); ajrecvType=recvType &#63; recvTypetoUpperCase() : 'HTML'; ajtargetUrl=''; ajsendString=''; ajresultHandle=null; ajcreateXMLHttpRequest=function(){ var xmlHttp = false; if(windowXMLHttpRequest){ xmlHttp = new XMLHttpRequest(); }else if(windowActiveXObject){ try{ xmlHttp = new ActiveXObject("MsxmlXMLHTTP"); }catch(error){ try{ xmlHttp = new ActiveXobject("MicrosoftXMLHttp"); }catch(error){ xmlHttp = false; } } } return xmlHttp; } ajXMLHttpRequest=ajcreateXMLHttpRequest(); ajprocessHandle=function(){ if(ajXMLHttpRequestreadyState == ){ if(ajXMLHttpRequeststatus == ){ if(ajrecvType=="HTML"){ ajresultHandle(ajXMLHttpRequestresponseText); }else if(ajrecvType=="XML"){ ajresultHandle(ajXMLHttpRequestresponseXML); } } } } ajget=function(targetUrl, resultHandle){ ajtargetUrl=targetUrl; if(resultHandle!=null){ ajXMLHttpRequestonreadystatechange=ajprocessHandle; ajresultHandle=resultHandle; } if(windowXMLHttpRequest){ ajXMLHttpRequestopen("get", ajtargetUrl); ajXMLHttpRequestsend(null); }else{ ajXMLHttpRequestopen("get", ajtargetUrl, true); ajXMLHttpRequestsend(); } } return aj; } </script> <script> var ajax=Ajax(); function select(v){ documentgetElementById(v)styledisplay='none'; ajaxget("guessphp&#63;op=ajax&k="+v, function(r){ var t=rsplit("|"); documentgetElementById('word')innerHTML=t[]; if(t[] == ){ documentgetElementById('select')styledisplay='none'; documentgetElementById('result')innerHTML='成功'; }else if(t[] == ){ documentgetElementById('select')styledisplay='none'; documentgetElementById('result')innerHTML='失败'; } }); } function check(v){ ajaxget("guessphp&#63;op=start&k="+v, function(r){ windowlocationhref="<&#63;php echo $url;&#63;>"; }); } </script> easy: wrong
'; echo ' normal: wrong
'; echo ' hard: wrong
'; }else{ //echo $word; echo "最多可以猜错 "$_SESSION['num']" 次"; echo "
"; echo "

"; echo output($guess_word); echo "
"; echo '
'; echo '
'; for($i=ord('A');$i'$letter''; } echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '重新开始'; } ?>

这是一款php实现的猜单词游戏,希望大家可以举一反三,实现其他小游戏,,熟练掌握php编程。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP 5.3 新特性Next article:PHP高效率写法及原因