题目 -请看,要是有什么不懂得我6pm以后在线msn.A prompt should be answered by player 1 to establish the word.Then player 2 should take over and try and guess the word.At each turn, player 2 should be prompted for an upper case character with a string which contains the number of lives left (initially 7), the letters tried so far (in order) and the partly guessed word e.g. 7[]=======, 5[SA]=A===A=, etc. A life is lost with each incorrect guess.The game should finish with the message "well done" when the word is fully guessed or "bad luck - the word was ......" if the number of lives reaches 0.There should be validation of both players input.Players should be able to type input in upper or lower case letters but the progress of the game should be reported using upper case.
A life is lost with each incorrect guess.The game should finish with the message "well done" when the word is fully guessed or "bad luck - the word was ......" if the number of lives reaches 0.There should be validation of both players input.Players should be able to type input in upper or lower case letters but the progress of the game should be reported using upper case.
<HTML>
<HEAD>
<META http-equiv='Content-Type' content='text/html; charset=gb2312'>
<TITLE> simple IE only</TITLE>
</HEAD>
<BODY >
<script language=javascript>function func(){
var j=0
var a=document.getElementsByName("txt1")[0].value
var b=document.getElementsByName("txt2")[0].value
if(b.length==0 || b.length>7){
if(b.length>7){
document.getElementsByName("txt2")[0].value=document.getElementsByName("txt2")[0].value.substr(0,7)
}
return;
}
var Str="======="
var mm=Str.split("")
var mmm=a.split("")
for(var i=0;i<b.length;i++){
var c=b.substr(i,1)
for(j;j<a.length;j++){
//alert(j)
if(mmm[j]==c){
mm.splice(j,1,c.toUpperCase())
mmm.splice(j,1,"=")
break;
}
}
}
if(mm.join("").indexOf("=")<0){
document.getElementById("div1").innerHTML=(7-b.length)+"["+b+"]"+mm.join("")+"</br></br></br><B>well done</B></br>"
}else{
document.getElementById("div1").innerHTML=(7-b.length)+"["+b+"]"+mm.join("")
}}
function func2(){
document.getElementsByName("txt1")[0].value=""
document.getElementsByName("txt2")[0].value=""
document.getElementById("div1").innerHTML="7[]======="
}
</script>
player 1
<input type="password" name="txt1">input 7 onle</br>
player 2
<input type="text" name="txt2" onpropertychange ="func()"> max 7
<div id="div1">7[]=======</div>
</br>
</br>
<input type="button" name="btn" value="Clear" onclick="func2()">
</BODY>
</HTML>