ďťż

[JS] Komentarze do skryptu

       

Podstrony


telcocafe

[Prośba]

Witam, sprawa jest taka że potrzebuje aby ktoś dopisał mi komentarze do skryptu, co i jaka linijka robi. Liczy się każda pomoc. Dziekuje :)

A oto skrypt:

<FORM name="Przewodnik"> <input type="button" value="&lt;&lt;" onclick="parent.location.href='Wisielec.html'"> <input type="button" value="Kółko i krzyżyk" onclick="parent.location.href='Kółko i krzyżyk.html'"> <input type="button" value="&gt;&gt;" onclick="parent.location.href='CheckBox.html'"> </FORM> <script LANGUAGE="LiveScript"> <!-- step = 0; diff=3; // change board when button is clicked function clear_all(form) { step = 0; for (i=0;i<9; ++i) { position="a"+i; form[position].value=""; } } // change board when button is clicked function clickit(field) { if (step == -1) {alert("Naciśnij START"); return;} position=field.name.substring(1,2,1); position = 'a'+position; if (field.form[position].value !="") {alert("Brak ruchu !"); return;} field.form[position].value="X"; if (eval_pos(field.form)) { field.form.output.value="Wygrałeś !"; step = -1; return; } position=get_move(field.form); field.form.output.value='Zaznaczam pole ' + position.substring(1,2,1); if (position=="") { field.form.output.value="Remis"; step = -1; return; } field.form[position].value="O"; if (eval_pos(field.form)) { field.form.output.value="Przegrałeś !"; step = -1; } } // see if there is a winner function eval_pos(form) { if ((form.a0.value!="" && form.a0.value==form.a3.value && form.a0.value==form.a6.value)|| (form.a0.value!="" && form.a0.value==form.a1.value && form.a0.value==form.a2.value) || (form.a0.value!="" && form.a0.value==form.a4.value && form.a0.value==form.a8.value) || (form.a1.value!="" && form.a1.value==form.a4.value && form.a1.value==form.a7.value) || (form.a2.value!="" && form.a2.value==form.a5.value && form.a2.value==form.a8.value) || (form.a2.value!="" && form.a2.value==form.a4.value && form.a2.value==form.a6.value) || (form.a3.value!="" && form.a3.value==form.a4.value && form.a3.value==form.a5.value) || (form.a6.value!="" && form.a6.value==form.a7.value && form.a6.value==form.a8.value)) return true; else return false; } function f(a) { if (a == "") return "."; else return a; } // get position for move. function comp_move(form,player,weight,depth) { var cost; var bestcost=-2; var position; var newplayer; if (player=="X") newplayer="O"; else newplayer="X"; if (depth==diff) return 0; if (eval_pos(form)) return 1; for (var i=0; i<9; ++i) { position='a'+i; if (form[position].value != "") continue; form[position].value=player; cost = comp_move(form,newplayer, -weight, depth+1); if (cost > bestcost) { bestcost=cost; if (cost==1) i=9; } form[position].value=""; } if (bestcost==-2) bestcost=0; return(-bestcost); } // get position for move. function get_move(form) { var cost; var bestcost=-2; bestmove=""; // don't think about first move. if (step++ == 0) if (form.a4.value=="") return "a4"; else if (form.a0.value=="") return "a0"; for (var i=0; i<9; ++i) { localposition='a'+i; if (form[localposition].value != "") continue; form[localposition].value="O"; cost=comp_move(form,"X", -1, 0); if (cost > bestcost) { if (cost==1) i=9; bestmove=localposition; bestcost=cost; } form[localposition].value=""; } return bestmove; } // complain if user attempts to change board function complain(field) { field.form.output.focus(); // put focus eleswhere alert("To pole jest samo uzupełniane podczas gry !"); } // the end --> </SCRIPT> <CENTER><FORM> <INPUT SIZE=1 NAME="a0" onfocus="complain(this)"> <INPUT TYPE="button" NAME="b0" onclick="clickit(this)"> <INPUT SIZE=1 NAME="a1" onfocus="complain(this)"> <INPUT TYPE="button" NAME="b1" onclick="clickit(this)"> <INPUT SIZE=1 NAME="a2" onfocus="complain(this)"> <INPUT TYPE="button" NAME="b2" onclick="clickit(this)"> <BR> <INPUT SIZE=1 NAME="a3" onfocus="complain(this)"> <INPUT TYPE="button" NAME="b3" onclick="clickit(this)"> <INPUT SIZE=1 NAME="a4" onfocus="complain(this)"> <INPUT TYPE="button" NAME="b4" onclick="clickit(this)"> <INPUT SIZE=1 NAME="a5" onfocus="complain(this)"> <INPUT TYPE="button" NAME="b5" onclick="clickit(this)"> <BR> <INPUT SIZE=1 NAME="a6" onfocus="complain(this)"> <INPUT TYPE="button" NAME="b6" onclick="clickit(this)"> <INPUT SIZE=1 NAME="a7" onfocus="complain(this)"> <INPUT TYPE="button" NAME="b7" onclick="clickit(this)"> <INPUT SIZE=1 NAME="a8" onfocus="complain(this)"> <INPUT TYPE="button" NAME="b8" onclick="clickit(this)"> <BR> <BR> <BR> <font size=3 face="Impact" color="Green">Wiadomości:</font> <INPUT NAME="output" TYPE="text"> <BR><BR> <font size=3 face="Impact" color="Blue">Poziom trudności: </font> <SELECT NAME="difficulty" onchange="diff=form.difficulty[form.difficulty.selectedIndex].value;"> <OPTION VALUE=1> Bardzo łatwy <OPTION VALUE=2> Łatwy <OPTION VALUE=3 SELECTED> Średni <OPTION VALUE=4> Trudny </SELECT> <BR><BR> <INPUT TYPE="button" VALUE="Pierwszy ruch komputera" onclick=" if (!step++) this.form.a4.value='O';"> <BR><BR> <INPUT TYPE="reset" VALUE="START" onclick="clear_all(this.form)"> </FORM></CENTER>



To jakiś bardzo stary i kiepski skrypt. Widać niedociągnięcia już od pierwszych linijek.

Ile znasz Javascriptu? Zrób komentarze do tego, co wiesz, a te trudniejsze części ktoś Ci wytłumaczy. Używaj również Google (dostępne pod adresem google.pl), a będziesz wiedział więcej.

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • nvm.keep.pl

  • Sitedesign by AltusUmbrae.