1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
<head>
<script type="text/javascript">
var couleurs=new Array();
couleurs[1]="#FF0000";
couleurs[2]="#00FF00";
couleurs[3]="#0000FF";
couleurs[4]="#FFFF00";
couleurs[5]="#00FFFF";
couleurs[6]="#FF00FF";
couleurs[7]="#660000";
couleurs[8]="#006600";
couleurs[9]="#000066";
couleurs[10]="#666600";
couleurs[11]="#006666";
couleurs[12]="#660066";
prochaine_piece=0;
var lettre=new Array('','A','B','C','D','E');
var unite = new Array();
function CreerLaCollection(){
var src;
var resH,resG;
//Innitialiser tout le tableau
for (L=1;L<6;L++){
unite[L]=Array();
for (C=1;C<6;C++){
unite[L][C]="#000000";
}
}
for (L=1;L<6;L++){
for (C=1;C<6;C++){
if (SiUn(L,C)){ //Détecter si cette unité est un 1
if(NonTag(L,C)){
prochaine_piece++;
Tag(L,C);
Etendre(L,C);
}
}
}
}
}
function Etendre(L,C){
if(L>1 && SiUn(L-1,C) && NonTag(L-1,C)){
Tag(L-1,C);
Etendre(L-1,C);
}
if(C>1 && SiUn(L,C-1) && NonTag(L,C-1)){
Tag(L,C-1);
Etendre(C-1);
}
if(L<5 && SiUn(L+1,C) && NonTag(L+1,C)){
Tag(L+1,C);
Etendre(L+1,C);
}
if(C<5 && SiUn(L,C+1) && NonTag(L,C+1)){
Tag(L,C+1);
Etendre(L,C+1);
}
}
function NonTag(L,C){
var src=document.getElementById(lettre[L]+""+C);
if (unite[L][C]=="#000000")
return true;
else
return false;
}
function Tag(L,C){
var src=document.getElementById(lettre[L]+""+C);
src.style.color=couleurs[prochaine_piece];
unite[L][C]=couleurs[prochaine_piece];
}
function SiUn(L,C){ //Détecte si une unité est un 1 (true) ou un 0 (false)
var src=document.getElementById(lettre[L]+""+C);
if (src.innerHTML==1)
return true;
else
return false;
}
</script>
</head>
<body>
<div id="A1" style="float:left;margin-left:5px;">0</div>
<div id="A2" style="float:left;margin-left:5px;">1</div>
<div id="A3" style="float:left;margin-left:5px;">0</div>
<div id="A4" style="float:left;margin-left:5px;">0</div>
<div id="A5" style="float:left;margin-left:5px;">0</div><br />
<div id="B1" style="float:left;margin-left:5px;">1</div>
<div id="B2" style="float:left;margin-left:5px;">0</div>
<div id="B3" style="float:left;margin-left:5px;">1</div>
<div id="B4" style="float:left;margin-left:5px;">0</div>
<div id="B5" style="float:left;margin-left:5px;">0</div><br />
<div id="C1" style="float:left;margin-left:5px;">1</div>
<div id="C2" style="float:left;margin-left:5px;">1</div>
<div id="C3" style="float:left;margin-left:5px;">1</div>
<div id="C4" style="float:left;margin-left:5px;">1</div>
<div id="C5" style="float:left;margin-left:5px;">1</div><br />
<div id="D1" style="float:left;margin-left:5px;">1</div>
<div id="D2" style="float:left;margin-left:5px;">0</div>
<div id="D3" style="float:left;margin-left:5px;">0</div>
<div id="D4" style="float:left;margin-left:5px;">1</div>
<div id="D5" style="float:left;margin-left:5px;">1</div><br />
<div id="E1" style="float:left;margin-left:5px;">1</div>
<div id="E2" style="float:left;margin-left:5px;">1</div>
<div id="E3" style="float:left;margin-left:5px;">0</div>
<div id="E4" style="float:left;margin-left:5px;">0</div>
<div id="E5" style="float:left;margin-left:5px;">1</div><br />
<script>CreerLaCollection();</script>
</body>
</html> |
Partager