Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. document.getElementById("submit").addEventListener("click", generate);
  5. var count=0;
  6. var mines;
  7. var width;
  8. var height;
  9. function generate()
  10. {
  11.  
  12.   height=document.getElementById("height").value;
  13.   width=document.getElementById("width").value;
  14.   document.getElementById("test").innerHTML = width+", "+height;
  15.   var outputhtml="<table>";
  16.   mines=new Array(height);
  17.  
  18.   for(i=0;i<height;i++)
  19.   {
  20.     mines[i]=new Array(width);
  21.   }
  22.   count=0;
  23.   for(i=0;i<height; i++)
  24.   {
  25.     outputhtml=outputhtml+"<tr>";
  26.     for(j=0;j<width;j++)
  27.     {
  28.       mines[i][j]=0;
  29.       outputhtml=outputhtml+"<td>";
  30.       outputhtml+=  "<button id=["+makeID(i,j)+"] onclick=clicked("+makeID(i,j)+")>?</button>";
  31.       console.log(makeID(i,j))
  32.       outputhtml=outputhtml+"</td>";
  33.  
  34.     }
  35.     outputhtml=outputhtml+"</tr>";
  36.   }
  37.   outputhtml+="</table>"
  38.   addMines();
  39.  
  40.   document.getElementById("test").innerHTML=outputhtml
  41. }
  42.  
  43. function addMines()
  44. {
  45.  
  46. for(var i=0;i<height;i++)
  47. {
  48.   for(var j=0; j<width; j++)
  49.   {      console.log("currently mining: "+i+", "+j);
  50.  
  51.     mines[i][j]=0;
  52.     if(Math.random<.2)
  53.     {
  54.       mines[i][j]=1;
  55.     }
  56.   }
  57. }
  58.  
  59. }
  60. function makeID(i, j)
  61. {
  62.  
  63.   console.log("i is: "+i+"   j is: "+j);
  64.   return "a"+(width*i+j);
  65. }
  66.  
  67. function makeCoords(id)
  68. {
  69.   id=id.slice(1,end);
  70.   console.log("ID is: "+id);
  71.   i=Math.floor(id/width);
  72.   j=id%width;
  73.  
  74.   console.log("output i is: "+i+" j is:" +j);
  75.   return [i, j];
  76. }
  77.  
  78. function clicked(thisbutton)
  79. {
  80.   console.log("this button is: "+thisbutton);
  81.  
  82.   var coords=makeCoords(thisbutton);
  83.   console.log("it's Coords are: "+coords);
  84.   if(mines[coords[0]][coords[1]]==0)    //empty space
  85.   {
  86.     document.getElementById(thisbutton).innerHTML="O";      //mark as visited and display adjacent mines
  87.   }
  88.  
  89.     //a mine
  90.       //explodes, lose condition, css effects?
  91.  
  92.     //next to mines
  93.       //display number of mines adjacent
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement