Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. var torx = true;
  2. var rows, cols;
  3. function BuildBoard() {
  4. // document.getElementById("div").innerHTML = "TURN:";
  5. var btnId = 0;
  6. rows = +prompt("enter border size(rows)");
  7. cols = +prompt("enter border size(cols)");
  8. if (cols != rows) {
  9. alert("ROWS AND COLS MUST BE THE SAME");
  10. BuildBoard();
  11. }
  12. var sh, am;
  13. // document.getElementById("restart").style.marginTop = 300;
  14. //document.getElementById("restart").innerHTML = "<button width='250px' height='250px' onclick='BuildBoard();'> + <img height='100%' width='100%' src='restart.jpg' /> + </button>"
  15. var strBuildTable = "<table border='1'>";
  16. for (sh = 0; sh < rows; sh++) {
  17. strBuildTable += "<tr>";
  18. for (am = 0; am < cols; am++) {
  19. strBuildTable += "<td width='" + 500 / cols + "px' height='" + 500 / rows + "px' id='" + btnId.toString() + "' onclick='ButtonClick(this);' style='background-color:skyblue'>";
  20. strBuildTable += "<img width='100%' height='100%' src='empty.png'>";
  21. strBuildTable += "</td>";
  22. btnId++;
  23. }
  24. strBuildTable += "</tr>";
  25. }
  26. strBuildTable += "</table>";
  27. document.getElementById("board").innerHTML = strBuildTable;
  28. document.getElementById("restart").innerHTML = "<button style='width:250px;height:200px;background-color:lightskyblue;color:whitesmoke;font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;font-size:'100px' onclick='BuildBoard();'>Reset game</button>"
  29. //document.write(strBuildTable);
  30. }
  31. function ButtonClick(BtnThis) {
  32. var idnum = BtnThis.id;
  33. var rowclicked = Math.floor(idnum / cols);
  34. var colclicked = idnum % cols;
  35. var i = 0;
  36. var down = (cols * rows) - (cols-colclicked);
  37. while (i < rows) {
  38. if (document.getElementById(down).style.backgroundColor === "skyblue") {
  39. if (torx === true) {
  40. document.getElementById(down).style.backgroundColor = "dodgerblue";
  41. document.getElementById(down).innerHTML = "<img height='100%' width='100%' src='Yellow.png' />"
  42. document.getElementById("tor").innerHTML = "Turn: O";
  43. torx = false;
  44. //down = down - cols;
  45. break;
  46. }
  47. else {
  48. document.getElementById(down).style.backgroundColor = "blue";
  49. document.getElementById(down).innerHTML = "<img height='100%' width='100%' src='Red.png' />"
  50. document.getElementById("tor").innerHTML = "Turn: X";
  51. torx = true;
  52. // down = down - cols;
  53. break;
  54. }
  55. }
  56. down = down - cols;
  57. i++;
  58. }
  59. // alert(rowclicked, ",", colclicked);
  60.  
  61.  
  62. var bodekcol = 0, counter = 0;
  63. while (bodekcol < rows && document.getElementById(idnum).style.backgroundColor === document.getElementById(colclicked + counter).style.backgroundColor) {
  64. bodekcol++;
  65. counter = counter + cols;
  66. }
  67. if (bodekcol === rows) {
  68. if (torx === true) {
  69. document.getElementById("div").innerHTML = "<img height='350' width='350' src='win.png' />"
  70.  
  71. }
  72. else {
  73. document.getElementById("div").innerHTML = "<img height='350' width='350' src='win.png' />"
  74.  
  75. }
  76. }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement