Advertisement
Guest User

Untitled

a guest
May 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h2>Szachy</h2>
  6.  
  7. <p id="text"></p>
  8. <p id="cyfry", style="position:absolute; left:0px ; top:88px"></p>
  9. <p id="chess"></p>
  10. <p id="text2"></p>
  11.  
  12. <script>
  13.  
  14. function game()
  15. {
  16. rysujSzachownice();
  17. document.getElementById("chess").innerHTML = " ";
  18. }
  19.  
  20. // var update = setInterval(game,2000);
  21. //var update2 = setInterval(reset,2500);
  22.  
  23.  
  24. var szachownica = [
  25. ["czarnaWie", "czarnySko", "czarnyGon", "czarnyHet", "czarnyKro", "czarnyGon", "czarnySko", "czarnaWie"],
  26. ["czarnyPio", "czarnyPio", "czarnyPio", "czarnyPio", "czarnyPio", "czarnyPio", "czarnyPio", "czarnyPio"],
  27. ["_________", "_________", "_________", "_________", "_________", "_________", "_________", "_________"],
  28. ["_________", "_________", "_________", "_________", "_________", "_________", "_________", "_________"],
  29. ["_________", "_________", "_________", "_________", "_________", "_________", "_________", "_________"],
  30. ["_________", "_________", "_________", "_________", "_________", "_________", "_________", "_________"],
  31. ["bialyPion", "bialyPion", "bialyPion", "bialyPion", "bialyPion", "bialyPion", "bialyPion", "bialyPion"],
  32. ["bialaWiez", "bialySkoc", "bialyGoni", "bialyHetm", "bialyKrol", "bialyGoni", "bialySkoc", "bialaWiez"]];
  33.  
  34. var text = "";
  35.  
  36. //dziala, wszystkie miejsca mozna brac oddzielnie:
  37. //var text3 = szachownica[0][5];
  38. //document.getElementById("text3").innerHTML = text3;
  39.  
  40.  
  41. function rysujSzachownice()
  42. {
  43. for(var i=0; i<szachownica.length; i++)
  44. {
  45. text += szachownica[i] + "<pre>";
  46. }
  47. document.getElementById("chess").innerHTML = text;
  48. }
  49.  
  50. function rysujSzachownice1()
  51. {
  52. for(var i=0; i<szachownica.length; i++)
  53. {
  54. text += szachownica[i] + "<pre>";
  55.  
  56. }
  57. document.getElementById("chess").innerHTML = text;
  58.  
  59. }
  60.  
  61. function reset()
  62. {
  63. //document.getElementById("chess").innerHTML= " ";
  64. }
  65.  
  66. document.getElementById("chess").style.fontFamily = "monospace";
  67. document.getElementById("cyfry").style.fontFamily = "monospace";
  68.  
  69. //rysujSzachownice();
  70.  
  71. var litery = '\xa0\xa0\xa0\xa0\xa0\xa0' + " a " + '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0' + " b " + '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0' + " c " + '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0' + " d " + '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0' + " e " + '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0' + " f " + '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0' + " g " + '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0' + " h ";
  72.  
  73. var liczby = " ";
  74. for(var i=9; i>1; i--)
  75. {
  76. liczby += (i-1) +"<pre>"
  77. }
  78.  
  79. document.getElementById("text").innerHTML = litery ;
  80. document.getElementById("text2").innerHTML = litery;
  81. document.getElementById("cyfry").innerHTML = liczby;
  82.  
  83.  
  84.  
  85.  
  86. function ruszFigure()
  87. {
  88. var a = document.getElementById('ruch1a').value;
  89. var b = document.getElementById('ruch1b').value;
  90. var c = document.getElementById('ruch1c').value;
  91. var d = document.getElementById('ruch1d').value;
  92.  
  93. var temp = szachownica[a][b];
  94.  
  95. //ruch czarnego pionka:
  96. if(szachownica[a][b] == "czarnyPio")
  97. {
  98. if(szachownica[c][d] == "_________" && ( c == ( parseInt(a)+parseInt(1) ) && d == b) )
  99. {
  100. szachownica[c][d] = temp;
  101. szachownica[a][b] = "_________";
  102. } 1
  103. if( szachownica[c][d] != "_________"
  104. && ( c == ( parseInt(a)+parseInt(1) ) && d == ( parseInt(b)-parseInt(1) ) ) )
  105. {
  106. szachownica[c][d] = temp;
  107. szachownica[a][b] = "_________"
  108. }
  109. if( szachownica[c][d] != "_________"
  110. && ( c == ( parseInt(a)+parseInt(1) ) && d == ( parseInt(b)+parseInt(1) ) ) )
  111. {
  112. szachownica[c][d] = temp;
  113. szachownica[a][b] = "_________"
  114. }
  115.  
  116. }
  117.  
  118.  
  119.  
  120.  
  121.  
  122. // {
  123. // document.write("nie wybrales figury");
  124. // }
  125. }
  126.  
  127.  
  128.  
  129. function pomocnicza()
  130. {
  131. var a = document.getElementById('ruch2c').value;
  132. var b = document.getElementById('ruch2d').value;
  133. if(a==0 || b==0)
  134. {
  135. document.write("blad");
  136. }
  137.  
  138. else
  139. {
  140. document.write(a + "<br>");
  141. document.write( parseInt(a) + parseInt(1));
  142. //document.write("na pozycji [a][b]: ");
  143. //document.write(szachownica[a][b] + "<br>");
  144. //document.write("na pozycji [a+1][b]: ");
  145. //document.write(szachownica[a+1][b]);
  146. }
  147. }
  148.  
  149.  
  150. </script>
  151.  
  152.  
  153. <div id = "ruch">
  154. Ruch od:
  155. <input type="text" id="ruch1a" value=""/>
  156. <input type="text" id="ruch1b" value=""/>
  157. Ruch do:
  158. <input type="text" id="ruch1c" value=""/>
  159. <input type="text" id="ruch1d" value=""/>
  160. <button onclick="ruszFigure()">Wykonaj ruch</button>
  161. </div>
  162.  
  163. <br>
  164.  
  165. <div id = "ruch2">
  166. <input type="text" id="ruch2c" value=""/>
  167. <input type="text" id="ruch2d" value=""/>
  168. <button onclick="pomocnicza()">Try it</button>
  169. </div>
  170.  
  171. <br>
  172.  
  173. <div id = "check">
  174. <button onclick="rysujSzachownice1()">Szachownica</button>
  175. </div>
  176.  
  177. </body>
  178. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement