This is a php-based word guessing game that uses SESSION and AJAX. For more information, see. Copy the local file and run it.
<? Phpsession_start (); header ("Content-type: text/html; charset = utf-"); $ url = 'HTTP: // '$ _ SERVER ['HTTP _ host'] $ _ SERVER ['php _ SELF']; function get_word () {$ wordtext = "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the foll Owing disclaimer Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclawing in the documentation and/or other materials provided with the distribution Neither the name of Yii Software LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permissio N this software is provided by the copyright holders and contributors as is and any express or implied warranties, INCLUDING, but not limited, the implied warranties of merchantability and fitness for a special purpose are disclaimed in no event shall the copyright owner or contributors be liable for any direct, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, or consequential damages (INCLUDING, B Ut not limited to, procurement of substitute goods or services; loss of use, DATA, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage "; $ words = preg_split ("/[\ s,] +/", $ wordtext); do {$ I = Rand (, count ($ words)-); $ word = strtoupper ($ words [$ I]);} while (strlen ($ word) <|! Ctype_alpha ($ word); return $ word;} function guess ($ word) {return str_repeat ('_', strlen ($ word);} function output ($ word) {$ str = ''; for ($ I =; $ I
Script function Ajax (recvType) {var aj = new Object (); ajrecvType = recvType? 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 ;} ajXMLHttpReques T = ajcreateXMLHttpRequest (); ajprocessHandle = function () {if (ajXMLHttpRequestreadyState =) {if (ajXMLHttpRequeststatus =) {if (ajrecvType = "HTML ") {ajresultHandle (signature);} else if (ajrecvType = "XML") {ajresultHandle (Signature) ;}}} ajget = function (targetUrl, resultHandle) {ajtargetUrl = targetUrl; if (resultHandle! = Null) {response = ajprocessHandle; ajresultHandle = resultHandle;} if (windowXMLHttpRequest) {ajXMLHttpRequestopen ("get", ajtargetUrl); ajXMLHttpRequestsend (null );} else {ajXMLHttpRequestopen ("get", ajtargetUrl, true); ajXMLHttpRequestsend () ;}return aj ;} script var ajax = Ajax (); function select (v) {documentgetElementById (v) styledisplay = 'none'; ajaxget ("guessphp? Op = ajax & k = "+ v, function (r) {var t = rsplit (" | "); documentgetElementById ('word') innerHTML = t []; if (t [] =) {documentgetElementById ('select') styledisplay = 'none'; documentgetElementById ('result') innerHTML = 'success ';} else if (t [] =) {documentgetElementById ('select') styledisplay = 'none'; documentgetElementById ('result') innerHTML = 'failed ';}});} function check (v) {ajaxget ("guessphp? Op = start & k = "+ v, function (r) {windowlocationhref =" <? Php echo $ url;?> ";}) ;}Script <? Phpif (! Isset ($ _ SESSION ['num']) {echo'
Easy: wrong
'; Echo'
Normal: wrong
'; Echo'
Hard: wrong
';} Else {// echo $ word; echo "you can guess at most" $ _ SESSION ['num'] "times"; echo"
"; Echo"
"; Echo output ($ guess_word); echo"
"; Echo'
'; Echo'
'; For ($ I = ord ('A'); $ I <= ord ('Z'); ++ $ I) {echo "\ n "; $ letter = chr ($ I); echo ''' $ letter ''';} echo'
'; Echo'
'; Echo'
'; Echo'
'; Echo'
'; Echo'
'; Echo 'restart';}?>
This is a php-based word-guessing game. I hope you can draw a line from each other to implement other games and be familiar with php programming.