<br />
<div style="position: absolute; left: 200px;"><!-- Script-Anfang --> <!-- www-java24.net - DIE Javascript - Ressource --> <!-- Diesen Code musst Du in den -head- einbauen --> <style type="text/css">
#pongTable {
position: absolute;
top: 20px;
left: 20px;
width: 400px;
height: 300px;
border: 4px solid #CCC;
background-color: #F3F3F3;
z-index: 1;
}
#playerOne {
position: absolute;
top: 196px;
left: 45px;
width: 10px;
height: 35px;
background-color: #777;
z-index: 2;
}
#playerTwo {
position: absolute;
top: 196px;
left: 390px;
width: 10px;
height: 35px;
background-color: #777;
z-index: 2;
}
#ball {
position: absolute;
top: 160px;
left: 210px;
width: 7px;
height: 7px;
clip: rect(0px 7px 7px 0px);
background-color: #555;
z-index: 2;
display: none;
}
#click {
position: absolute;
top: 160px;
left: 27px;
width: 400px;
text-align: center;
font-family: Tahoma;
font-size: 10px;
z-index: 3;
}
#scores {
position: absolute;
top: 330px;
left: 24px;
width: 400px;
font-family: Tahoma;
font-size: 11px;
z-index: 3;
}
</style> <script type="text/javascript">
/***********************************************
* DHTML Phong script- © nathan (http://www.n-son.com/)
* Permission granted to DynamicDrive.com to feature script
* This notice must stay intact for use
* Visit
http://www.dynamicdrive.com/ for full source code
***********************************************/
var ballAng;
var speed = 25;
var ping = 2;
var pong = 0;
var mouseSpeed;
var tempY;
function init() {
document.getElementById("click").style.display = "none";
document.getElementById("ball").style.display = "inline";
with( document.getElementById("ball").style ) {
top = "160px";
left = "210px";
}
document.onmouseup = null;
document.onmousemove = movePaddle;
ballAng = Math.round( Math.random() * 100 ) + 130;
moveDaBall = setInterval("moveBall()", 10);
}
function movePaddle(e) {
e = (e)?e:event;
if( tempY ) {
mouseSpeed = Math.round((e.clientY - tempY) * 1.5);
if( mouseSpeed == 0 ) mouseSpeed = 1;
}
with( document.getElementById("playerOne").style ) {
top = e.clientY - 18 + "px";
if( parseInt(top) < 24 || parseInt(top) > 289 ) {
if( parseInt(top) < 24 ) {
top = "24px";
} else {
top = "289px";
}
}
}
tempY = e.clientY;
}
function moveBall() {
var ballX = parseInt(document.getElementById("ball").style.left);
var ballY = parseInt(document.getElementById("ball").style.top);
var playOneX = parseInt( document.getElementById("playerOne").style.left );
var playOneY = parseInt( document.getElementById("playerOne").style.top );
var playTwoX = parseInt( document.getElementById("playerTwo").style.left );
var playTwoY = parseInt( document.getElementById("playerTwo").style.top );
if( ballY >= (playOneY - 5) && ballY <= (playOneY + 35 + 5) && ballX >= playOneX && ballX <= (playOneX + 10) ) {
if( pong == 3 ) {
ping++;
pong = 0;
} else {
pong++;
}
document.getElementById("ball").style.left = playOneX + 10 + "px";
ballAng = 180 - ballAng - mouseSpeed;
}
if( ballY >= (playTwoY - 5) && ballY <= (playTwoY + 35 + 5) && ballX >= playTwoX && ballX <= (playTwoX + 10) ) {
if( pong == 3 ) {
ping++;
pong = 0;
} else {
pong++;
}
document.getElementById("ball").style.left = playTwoX + "px";
ballAng = 180 - ballAng;
}
if( ballY < 25 || ballY > 316 ) {
document.getElementById("ball").style.top = (ballY < 25)?25+"px":316+"px";
ballAng = 360 - ballAng;
}
if( ballX <= 24 || ballX >= 417 ) {
document.getElementById("ball").style.left = (ballX <=24)?24+"px":417+"px";
if( ballX<= 24 ) {
endPoint(document.getElementById("twoScore"));
} else {
endPoint(document.getElementById("oneScore"));
}
}
moveAI( ballY );
moveObjAtAngle( document.getElementById("ball"), ballAng, ping);
}
function moveObjAtAngle( obj, ang, dist ) {
with( obj.style ) {
left = parseInt(left) + ( dist * Math.cos( ang * (Math.PI/180) ) ) + "px";
top = parseInt(top) - ( dist * Math.sin( ang * (Math.PI/180) ) ) + "px";
}
}
function moveAI( y ) {
var AI = document.getElementById("playerTwo");
y = y - 10;
y = parseInt(AI.style.top) + ((y - parseInt(AI.style.top)) / speed);
if( y < 24 || y > 289 ) {
if( y < 24 ) {
y = 24;
} else {
y = 289;
}
}
AI.style.top = y +"px";
}
function endPoint(place) {
clearInterval(moveDaBall);
ping = 7;
pong = 0;
document.onmouseup = init;
document.getElementById("click").innerHTML = "Klicke um weiterzuspielen";
place.innerHTML = parseInt(place.innerHTML) + 1;
if( parseInt(place.innerHTML) == 10 ) {
if( place.id == "oneScore" ) {
endGame(1);
} else {
endGame(0);
}
}
document.getElementById("click").style.display = "inline";
}
function endGame(win) {
document.onmouseup = restartGame;
if( win ) {
document.getElementById("click").innerHTML = "<strong>Du bist der GEWINNER!</strong><br /> NEUES Spiel";
} else {
document.getElementById("click").innerHTML = "<strong>Du hast VERLOREN!</strong><br /> NEUES Spiel";
}
}
function restartGame() {
document.getElementById("oneScore").innerHTML = 0;
document.getElementById("twoScore").innerHTML = 0;
init();
}
document.onmouseup = init;
</script> <!-- Diesen Code musst Du in den -body- einbauen -->
<div id="pongTable">
<div style="border-left: 2px dashed rgb(221, 221, 221); float: right; width: 50%; height: 100%;"> </div>
</div>
<div id="playerOne" style="left: 45px; top: 146px;"> </div>
<div id="playerTwo" style="left: 390px; top: 146px;"> </div>
<div id="ball" style="left: 210px; top: 160px;"> </div>
<div id="click">Klicke hier um weiterzuspielen</div>
<div id="scores"><span style="float: left;" id="oneScore">0</span> <span style="float: right;" id="twoScore">0</span></div>
<!-- Script-Ende --> <!-- www-java24.net - DIE Javascript - Ressource --></div>
<!-- präsentiert von kostenlose-javascripts.de --> <script type='text/javascript'>
<!--
var a, b, c, d, e, f, x, i;
var max = 99;
var win = "Glückwunsch, Sie haben gewonnen!";
var lost = "Sorry, Sie haben verloren!";
var fehler = false;
var wi=0, lo=0, ab=0, ges=0;
</br>
<br>
function B_in(Zahl){
if (isNaN(Zahl) || Zahl.length > 2 || Zahl <= 1 || Zahl=="" || Zahl>49) {
alert("Sie müssen eine Ganzzahl zwischen 2 und 49 eingeben!");
document.streichhoelzchen.B.value="";
fehler=true;
return;
}
b=Zahl;
}
function D_in(Zahl){
var z;
z=(2*b)+1;
if (isNaN(Zahl) || Zahl.length > 2 || Zahl < z || Zahl=="" || Zahl>max) {
alert("Sie müssen eine Ganzzahl zwischen " + z + " und " + max + " eingeben!");
document.streichhoelzchen.D.value="";
fehler=true;
return false;
}
d=Zahl;
}
function zufall(){
var ran=0;
var ran2=0;
ran=GetRandom(1,2);
if (ran==1){
document.streichhoelzchen.anfang[0].checked='';
document.streichhoelzchen.anfang[1].checked='checked';
}
else{
document.streichhoelzchen.anfang[0].checked='checked';
document.streichhoelzchen.anfang[1].checked='';
}
ran=GetRandom(1,2);
if (ran==1){
document.streichhoelzchen.wer[0].checked='';
document.streichhoelzchen.wer[1].checked='checked';
}
else{
document.streichhoelzchen.wer[0].checked='checked';
document.streichhoelzchen.wer[1].checked='';
}
ran=GetRandom(2,9);
document.streichhoelzchen.B.value=ran;
var min=(ran*2)+1;
ran2=GetRandom(min,29);
document.streichhoelzchen.D.value=ran2;
}
function startit(){
if (document.streichhoelzchen.anfang[0].checked==1){
a=1;
}
else {
a=0;
}
if (document.streichhoelzchen.wer[0].checked==1){
c=true;
}
else {
c=false;
}
B_in(document.streichhoelzchen.B.value);
D_in(document.streichhoelzchen.D.value);
if (fehler==true){
fehler=false;
return;
}
show();
//<!-- show(1); -->
x=d;
zeigerest();
document.streichhoelzchen.randomer.style.visibility="hidden";
document.streichhoelzchen.starter.style.visibility="hidden";
document.streichhoelzchen.anfang[0].disabled='true';
document.streichhoelzchen.anfang[1].disabled='true';
document.streichhoelzchen.B.readOnly='enabled';
document.streichhoelzchen.wer[0].disabled='true';
document.streichhoelzchen.wer[1].disabled='true';
document.streichhoelzchen.D.readOnly='enabled';
if (c==true){
cnimm();
}
document.streichhoelzchen.N.focus();
}
function show() {
document.streichhoelzchen.N.style.visibility='';
document.streichhoelzchen.abbruch.style.visibility="visible";
document.streichhoelzchen.nimm.style.visibility="visible";
//<!-- elt=document.getElementById(n);
//elt2=elt.nextSibling;
//for Mozilla
//if(elt2.tagName!="TBODY") elt2=elt2.nextSibling
//
//elt2.style.display="" -->
}
function unshow() {
document.streichhoelzchen.N.style.visibility='hidden';
document.streichhoelzchen.abbruch.style.visibility='hidden';
document.streichhoelzchen.nimm.style.visibility='hidden';
//<!-- elt=document.getElementById(n);
//elt2=elt.nextSibling;
//for Mozilla
//if(elt2.tagName!="TBODY") elt2=elt2.nextSibling
//
//elt2.style.display="none"-->
}
function nehmen(Zahl){
if (isNaN(Zahl) || Zahl.length > 2 || Zahl < 1 || Zahl=="" || Zahl > b) {
alert("Sie müssen eine Ganzzahl zwischen 1 und " + b + " eingeben!");
document.streichhoelzchen.N.value="";
return;
}
var n;
n=Zahl*2;
n=n/2;
if (n > x){
alert("Sie können nicht " +n + " Hölzer nehmen, Sie können maximal " + x + " nehmen!");
document.streichhoelzchen.N.value="";
return;
}
x=x-n;
zeigerest();
document.streichhoelzchen.N.value="";
if (x>0){
cnimm();
}
else {
if (a==1){
lo=lo+1;
loeschen();
alert(lost);
}
else {
wi=wi+1;
loeschen();
alert(win);
}
}
//document.streichhoelzchen.N.focus();
return;
}
function cnimm(){
if (x==1){
alert("Ich nehme 1 Streichhölzchen!");
zeigerest();
if (a==1){
wi=wi+1
loeschen();
alert(win);
}
else {
lo=lo+1;
loeschen();
alert(lost);
}
}
else {
var o, n;
a=a*2;
a=a/2;
b=b*2;
b=b/2;
e= a+b;
o=(x-a) % (b+1);
if (o==0){
n=GetRandom(1,b);
}
else{
for (i=1; i<=b;i++){
if ((x-i-a) % (b+1)==0){
n=i;
}
}
}
x=x-n;
alert("Ich nehme " + n + " Streichhölzchen.");
zeigerest();
if (x==0){
if (a==1){
wi=wi+1;
loeschen();
alert(win);
}
else {
lo=lo+1;
loeschen();
alert(lost);
}
}
}
}
function zeigerest(){
for (i=1; i<=max;i++){
document.streichhoelzchen.bild[i-1].height=0;
}
for (i=1; i<=x;i++){
document.streichhoelzchen.bild[i-1].height=38;
}
}
function abbrechen(){
ab=ab+1;
loeschen();
}
function loeschen(){
for (i=1; i<=max;i++){
document.streichhoelzchen.bild[i-1].height=0;
}
document.streichhoelzchen.starter.style.visibility="visible";
unshow();
//<!-- unshow(1); -->
document.streichhoelzchen.randomer.style.visibility="";
document.streichhoelzchen.anfang[0].disabled='';
document.streichhoelzchen.anfang[1].disabled='';
document.streichhoelzchen.B.readOnly='';
document.streichhoelzchen.wer[0].disabled='';
document.streichhoelzchen.wer[1].disabled='';
document.streichhoelzchen.D.readOnly='';
ges=wi+lo+ab;
document.streichhoelzchen.stat.value="Gewonnen: ";
document.streichhoelzchen.stat.value+=wi;
document.streichhoelzchen.stat.value+=" Verloren: ";
document.streichhoelzchen.stat.value+=lo;
document.streichhoelzchen.stat.value+=" Abbruch: ";
document.streichhoelzchen.stat.value+=ab;
document.streichhoelzchen.stat.value+=" Gesamt: ";
document.streichhoelzchen.stat.value+=ges;
}
function GetRandom( mi, ma ) {
/* --
http://www.naden.de/blog/zufallszahlen-in-javascript-mit-mathrandom -- */
if( mi > ma ) {
return( -1 );
}
if( mi == ma ) {
return( mi );
}
return mi + parseInt( Math.random() * ( ma-mi+1 ));
}
//-->
</script>
<form action="" name="streichhoelzchen">
<table border="0">
<tbody>
<tr>
<td valign="top">
<table cellspacing="0" cellpadding="20" border="1">
<tbody>
<tr>
<td>Derjenige, der das/die letzte/n Hölzchen nimmt, ...<br />
<br />
<input type="radio" checked="checked" name="anfang" /> ... verliert.<br />
<input type="radio" name="anfang" /> ... gewinnt.</td>
</tr>
<tr>
<td>Zahl der zu nehmenden Hölzchen:<br />
<br />
mindestens <strong>eines</strong> bis maximal <input type="text" onchange="B_in(document.streichhoelzchen.B.value)" name="B" size="1" value="3" /> Stück</td>
</tr>
<tr>
<td>Wer soll anfangen?<br />
<br />
<input type="radio" checked="checked" name="wer" /> der Computer<br />
<input type="radio" name="wer" /> der Spieler</td>
</tr>
<tr>
<td>Anzahl an Streichhölzchen zu Beginn:<br />
<br />
<input type="text" onchange="D_in(document.streichhoelzchen.D.value)" name="D" size="1" value="10" /> Stück</td>
</tr>
<tr>
<td><input type="button" onclick="zufall()" name="randomer" value="Zufällige Parameter" /> <input type="button" onclick="startit()" name="starter" value="START" /></td>
</tr>
</tbody>
</table>
</td>
<td valign="top">
<table cellspacing="0" cellpadding="20" border="1">
<tbody>
<tr>
<td><script type="text/javascript">
<!--
for ( var i = 0; i < 100; i++ ) {
document.write('<img src="http://www.kostenlose-javascripts.de/_files/images/streichholz.gif" name="bild" height="0" id="bild'+i+'" />');
if ( i % 5 == 0 ) {
document.write(' ');
}
}
//-->
</script></td>
</tr>
<tr>
<td><input type="text" onkeypress="if(event.keyCode==13){nehmen(document.streichhoelzchen.N.value)}" id="N" name="N" size="1" value="" /> Stück <input type="button" onclick="nehmen(document.streichhoelzchen.N.value)" name="nimm" value="NEHMEN" /></td>
</tr>
<tr>
<td><input type="button" onclick="abbrechen()" name="abbruch" value="ABBRUCH" /></td>
</tr>
</tbody>
</table>
</td>
<td align="center" valign="bottom">
<p><strong>Statistik:</strong></p>
<textarea name="stat" readonly="readonly" cols="11" rows="5"></textarea></td>
</tr>
</tbody>
</table>
</form>
<script type="text/javascript">
<!--
loeschen();
zufall();
unshow();
//-->
</script> <br />
<div align="center" id="kostenlosejavascripts"><a target="_blank" title="Südafrika-Reisen" href="http://www.afrikasafaris.de">Südafrika-Reisen</a></div>
<br />
<!-- präsentiert von kostenlose-javascripts.de