Voila, je voulais faire un casse-briques, mais j'ai quelques problemes avec l'affichage des briques, la balle qui n'existe pas, et l'effacage des briques si la balle les touches...
J'ai commencé par faire la table de jeux avec le "paddle" qui lui bouge de droite a gauche.
Voila le code :
CODE
<HTML>
<HEAD>
<script language="javascript">
function départ()
{
créemur()
document.getElementById("15,15").style.backgroundColor = "C80000"
document.getElementById("f15,15").color="C80000"
document.form.positionX.value = 15
document.form.positionY.value = 15
document.getElementById(positionFin).style.backgroundColor = "0AC814"
document.getElementById("f"+positionFin).color = "0AC814"
window.status = "H2ck3r website"
}
function move(e)
{
y = document.form.positionY.value*1
x = document.form.positionX.value*1
if (e == 50 && check(y+1,x))
{
afficher(y+1,x)
}
if (e == 54 && check(y,x+1))
{
afficher(y,x+1)
}
if (e == 56 && check(y-1,x))
{
afficher(y-1,x)
}
if (e == 52 && check(y,x-1))
{
afficher(y,x-1)
}
}
function check(Y,X)
{
if (document.getElementById(Y+","+X)) return true
else return false
}
function afficher(Y,X)
{
effacer(document.form.positionY.value,document.form.positionX.value)
document.getElementById(Y+","+X).style.backgroundColor = "C80000"
document.getElementById("f"+Y+","+X).color="C80000"
document.form.positionX.value = X
document.form.positionY.value = Y
vérifier()
}
function effacer(Y,X)
{
document.getElementById(Y+","+X).style.backgroundColor = "FFFFFF"
document.getElementById("f"+Y+","+X).color = "FFFFFF"
}
function créemur()
{
position = new Array()
pos = position
for (i=0;i<position.length;i++)
{
pos[i] = pos[i].split(",")
if (check(pos[i][0],pos[i][1]))
{
document.getElementById(position[i]).style.backgroundColor = "000000"
document.getElementById("f"+position[i]).color = "000000"
document.getElementById(position[i]).id = ""
}
}
}
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body {
background-color: #F0F1F0;
}
-->
</style></HEAD>
<BODY onload="départ()" onkeypress="move(event.keyCode)">
<FORM name="form">
<INPUT type="hidden" name="hauteur">
<INPUT type="hidden" name="largeur">
<INPUT type="hidden" name="positionX">
<INPUT type="hidden" name="positionY">
</FORM>
<script>
hauteur =20
largeur =30
backgcolor = "FFFFFF"
code ="<TABLE border='0'><TR>"
for (i=0;i<largeur+2;i++)
{
code+="<TD bgcolor='000000'></TD>"
}
code+="</TR>"
for (i=0;i<hauteur;i++)
{
code +="<TR><TD bgcolor='000000'></TD>"
for (x=0;x<largeur;x++)
{
code += "<TD id='"+i+","+x+"' bgcolor='"+backgcolor+"'><FONT color='"+backgcolor+"' id='f"+i+","+x+"'>---</FONT></TD>"
}
code+="<TD bgcolor='000000'></TD></TR>"
}
code+="<TR>"
for (i=0;i<largeur+2;i++)
{
code+="<TD bgcolor='000000'></TD>"
}
code+="</TR>"
code+="</TABLE>"
document.write(code)
document.form.hauteur.value = hauteur
document.form.largeur.value = largeur
</SCRIPT>
</BODY>
</HTML>
<HEAD>
<script language="javascript">
function départ()
{
créemur()
document.getElementById("15,15").style.backgroundColor = "C80000"
document.getElementById("f15,15").color="C80000"
document.form.positionX.value = 15
document.form.positionY.value = 15
document.getElementById(positionFin).style.backgroundColor = "0AC814"
document.getElementById("f"+positionFin).color = "0AC814"
window.status = "H2ck3r website"
}
function move(e)
{
y = document.form.positionY.value*1
x = document.form.positionX.value*1
if (e == 50 && check(y+1,x))
{
afficher(y+1,x)
}
if (e == 54 && check(y,x+1))
{
afficher(y,x+1)
}
if (e == 56 && check(y-1,x))
{
afficher(y-1,x)
}
if (e == 52 && check(y,x-1))
{
afficher(y,x-1)
}
}
function check(Y,X)
{
if (document.getElementById(Y+","+X)) return true
else return false
}
function afficher(Y,X)
{
effacer(document.form.positionY.value,document.form.positionX.value)
document.getElementById(Y+","+X).style.backgroundColor = "C80000"
document.getElementById("f"+Y+","+X).color="C80000"
document.form.positionX.value = X
document.form.positionY.value = Y
vérifier()
}
function effacer(Y,X)
{
document.getElementById(Y+","+X).style.backgroundColor = "FFFFFF"
document.getElementById("f"+Y+","+X).color = "FFFFFF"
}
function créemur()
{
position = new Array()
pos = position
for (i=0;i<position.length;i++)
{
pos[i] = pos[i].split(",")
if (check(pos[i][0],pos[i][1]))
{
document.getElementById(position[i]).style.backgroundColor = "000000"
document.getElementById("f"+position[i]).color = "000000"
document.getElementById(position[i]).id = ""
}
}
}
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body {
background-color: #F0F1F0;
}
-->
</style></HEAD>
<BODY onload="départ()" onkeypress="move(event.keyCode)">
<FORM name="form">
<INPUT type="hidden" name="hauteur">
<INPUT type="hidden" name="largeur">
<INPUT type="hidden" name="positionX">
<INPUT type="hidden" name="positionY">
</FORM>
<script>
hauteur =20
largeur =30
backgcolor = "FFFFFF"
code ="<TABLE border='0'><TR>"
for (i=0;i<largeur+2;i++)
{
code+="<TD bgcolor='000000'></TD>"
}
code+="</TR>"
for (i=0;i<hauteur;i++)
{
code +="<TR><TD bgcolor='000000'></TD>"
for (x=0;x<largeur;x++)
{
code += "<TD id='"+i+","+x+"' bgcolor='"+backgcolor+"'><FONT color='"+backgcolor+"' id='f"+i+","+x+"'>---</FONT></TD>"
}
code+="<TD bgcolor='000000'></TD></TR>"
}
code+="<TR>"
for (i=0;i<largeur+2;i++)
{
code+="<TD bgcolor='000000'></TD>"
}
code+="</TR>"
code+="</TABLE>"
document.write(code)
document.form.hauteur.value = hauteur
document.form.largeur.value = largeur
</SCRIPT>
</BODY>
</HTML>