I got a problem concidering talking to the value of a button. Just for you to maybe understand my target a little bit better, I will post my whole code and the sence of my 'problemcode' right here:
for(i=0;i<144;i++){
if(i%12 <= 10 && i%12 >= 1 && Math.floor(i/12) >= 1 && Math.floor(i/12) <= 10) {
window.alert(change.button+i.value);
if(change.button+i.value==0 && change.button+i.className=='revealed') {
change.button+(i-1).className='revealed';
change.button+(i+1).className='revealed';
change.button+(i-11).className='revealed';
change.button+(i-12).className='revealed';
change.button+(i-13).className='revealed';
change.button+(i+11).className='revealed';
change.button+(i+12).className='revealed';
change.button+(i+13).className='revealed';
alert.writeln("test");
}
}
}
So I wrote a simple Minesweeper code. Works pretty good but I wanted to improve it by revealing the area around one button if it has the value '0'. Additionally I should admit that the array has the size of 144 but I will only show 100 elements, so I have an invisible boarder. Now again coming to the problem. I want to do a scan everytime a button got clicked. So I check the value of every button if it is 'revealed' and it's value is '0'. My problem here though is that the way I try to talk to it is wrong, but you may understand what I am trying to reach. So here is my code, I would appreachead if you might help me :) *note ignore the dbclick, this does not work
<html>
<head>
<title>Einfachsweeper</title>
<style>
.revealed{color:blue;}
.invisible{color:transparent}
.fahne{background-color:blue;color:transparent;}
</style>
<script language="Javascript">
feld3 = [];
minen=12;
feld2 = [];
for(y=0;y<=11;y++){
feld3[y]=[];
for(x=0;x<=11;x++){
feld3[y][x]=0;
}
}
for(y=0;y<=11;y++){
for(x=0;x<=11;x++){
//document.writeln(+feld3[y][x]+" ");
}
}
for(i=1;i<=minen;i++){
randz=Math.random();
randz=Math.floor(randz*100);
randx=randz%10+1;
randy=Math.floor(randz/10)+1;
//document.writeln(randy + " " + randx + ",");
if(feld3[randy][randx]==0){
//document.writeln("test");
feld3[randy][randx]='x';
}
else{
//document.writeln("test");
i--;
}
}
for(y=1;y<=10;y++){
for(x=1;x<=10;x++){
wert=0;
if(feld3[y][x]!='x'){
if(feld3[y-1][x-1]=='x'){
wert++;
}
if(feld3[y-1][x]=='x'){
wert++;
}
if(feld3[y-1][x+1]=='x'){
wert++;
}
if(feld3[y][x+1]=='x'){
wert++;
}
if(feld3[y+1][x+1]=='x'){
wert++;
}
if(feld3[y+1][x]=='x'){
wert++;
}
if(feld3[y+1][x-1]=='x'){
wert++;
}
if(feld3[y][x-1]=='x'){
wert++;
}
feld3[y][x]=wert;
}
}
}
i=0;
while(i<144){
for(y=0;y<=11;y++){
for(x=0;x<=11;x++){
feld2[i]=feld3[y][x];
i++;
}
}
}
document.writeln("<form method='post' name='change' action='bla.html'><table border='1'><tr>");
for(i=0;i<144;i++){
if(i%12<=10 && i%12>=1 && Math.floor(i/12)>=1 && Math.floor(i/12)<=10){
document.writeln("<td><input class='invisible' type='button' name='button"+i+"' value='"+feld2[i]+"' onDblClick='right(this)' onClick='changer(this)'></td>");
}
if(i%12==11){
document.writeln("</tr><tr>");
}
}
document.writeln("</tr></table>");
function right(item){
item.className='fahne';
window.alert('works');
}
function changer(item){
//window.alert(item.name);
i=21;
// window.alert(change.button+i.value);
/*for(i=0;i<144;i++){
if(i%12<=10 && i%12>=1 && Math.floor(i/12)>=1 && Math.floor(i/12)<=10){
window.alert(change.button+i.value);
if(change.button+i.value==0 && change.button+i.className=='revealed'){
change.button+(i-1).className='revealed';
change.button+(i+1).className='revealed';
change.button+(i-11).className='revealed';
change.button+(i-12).className='revealed';
change.button+(i-13).className='revealed';
change.button+(i+11).className='revealed';
change.button+(i+12).className='revealed';
change.button+(i+13).className='revealed';
alert.writeln("test");
}
}
}*/
if(item.which == 3){
window.alert('right');
}
if(item.value=='x'){
window.alert('You lost!');
}
//window.alert(item.value);
item.className="revealed";
//document.writeln(item);
}
</script>
</head>
<body>
<!--<input type='button' name='invisible' value=' ' onClick="changer()">
<input type='button' name='test' value=' '></form>-->
</body>
</html>