alle2wochen
Neues Mitglied
hallo, schreibe bald eine infoarbeit und muss dafür so ein nimmspiel programmieren können.
Es funktioniert leider aber nicht. hier der quelltext...vlt könnt ihr mir ja helfen...
danke...
und schonmal frohe Wheinachten
Es funktioniert leider aber nicht. hier der quelltext...vlt könnt ihr mir ja helfen...
danke...
und schonmal frohe Wheinachten
Code:
<html><head><title>Nimmspiel gegen den Computer</title></head>
<body bgcolor="lightblue">
<script language="JavaScript">
var anzahl,max,grad,dran,weg
function start()
{
anzahl=Math.floor(50*Math.random()+20);
nimmspiel.anzahl.value=anzahl;
max=Math.floor(8*Math.random()+3);
nimmspiel.max.value=max;
nimmspiel.snimm.value=""
nimspiel.sieger.value=""
dran=1
}
function rechenen()
{if (drann==-1)
{alert("Du bist nicht am Zug!")}
else {var x=nimmspiel.snimm.value
while ( (x !=parseInt(x)) || (x>max || x<1)) {x = promt ("Du kanst nur zwischen 1 und "+max+" Steine ziehen. Wie viele?" ,"")}
nimmspiel.snimm.value=x
if (x>anzahl) {alert("Es ist (sind nur noch "+anzahl+" Stein(e) da.");
x=anzahl;
nimmspiel.snimm.value=x;
anzahl=anzahl*1-1*x;
nuimmspiel.anzahl.value=anzahl;
nimmspiel.pcnimm.value=""
dran=-dran
if (anzahl<=0) {alert("Schade für dich!");
nimmspiel.sieger.value="Computer"}
}
}
function computer_schlau()
{var rest=anzahl%(max*1+1);weg=rest-1
if (rest==1) {weg=Math.floor(Math.random()*max+1)}
if (rest==0) {weg=max}
return(weg)
}
function computerzug()
{var soviel
if (grad==1) {soviel=computer_schlau()} else {soviel=Math.floor(Math.random()*max+1)}
nimmspeil.pcnimm.value=soviel;
dran=-dran;
anzahl=anzahl-soviel*1;
nimmspiel.anzahl.value=anzahl;
nimmspeil.snimm.value=""
if (anzahl<=0) {alert("Herzlichen Glückwunsch!");
nimmspeil.Sieger.value="Spieler"}
}
</script>
<font size="4">[b]Nimmspiel gegen den Computer[/b]</font></p>
</p>
<form name="nimmspiel">
Computer ist dumm: <input type="radio" onclick=grad=1 name="grad" value="1"></p>
Computer ist intelligent: <input type="radio" onclick=grad=2 name="grad" value="2"></p>
<input type="button" value="start" onclick="start"></p>
Anzahl der Steine: <input type="text" name="anzahl" readonly></p>
Maximal zu ziehende Steine: <input type="text" name="max" readonly></p>
Ich nehme: <input type="text" name="snimm"></p>
<input type="button" onclick="rechnen" value="ziehen"></p>
<input type="button" onclick="computerzug" value="Computerzug"></p>
CVomputer nimmt: <input type="text" name="pcnimm" readonly></p>
Sieger ist: <input type="text" name="sieger" readonly></p>
</p>
<input type="reset" value="Neues Spiel"></p>
</form>
</body>
</html>