Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. // Creating variables
  2.  
  3. var goleminaX = 7, goleminaY = 7;
  4. var pole = [];
  5. var igrachNaHod = 1;
  6.  
  7. for(var i = 0;i < goleminaX;i = i+1){
  8. pole[i] = [];
  9. for(var j = 0;j < goleminaY;j = j+1){
  10. pole[i][j] = 0;
  11. }
  12. }
  13.  
  14. function update() {
  15.  
  16. }
  17.  
  18. var drawGolemina = 55;
  19. function draw() {
  20.  
  21. for(var x = 0;x < goleminaX;x = x+1){
  22. for(var y = 0;y < goleminaY;y = y+1){
  23. if(pole[x][y] == 1) {
  24. context.fillStyle = "red";
  25. context.fillRect(x * drawGolemina, y * drawGolemina, drawGolemina, drawGolemina);
  26. }
  27. if(pole[x][y] == 2) {
  28. context.fillStyle = "blue";
  29. context.fillRect(x * drawGolemina, y * drawGolemina, drawGolemina, drawGolemina);
  30. }
  31. context.strokeRect(x * drawGolemina, y * drawGolemina, drawGolemina, drawGolemina);
  32. }
  33. }
  34.  
  35. };
  36.  
  37. function keyup(key) {
  38. // Show the pressed keycode in the console
  39. console.log("Pressed", key);
  40. };
  41.  
  42. function mouseup() {
  43. // Show coordinates of mouse on click
  44. console.log("Mouse clicked at", mouseX, mouseY);
  45. var idxX=0;
  46. for(var tekustoKv = 0;;tekustoKv ++) {
  47. var tekX = tekustoKv * drawGolemina;
  48. if(tekX > mouseX) {
  49. idxX = tekustoKv-1;
  50. break;
  51. }
  52. }
  53.  
  54. for(var i = goleminaY - 1;i >= 0;i --) {
  55. if(pole[idxX][i] == 0) {
  56. pole[idxX][i] = igrachNaHod;
  57. if(igrachNaHod == 1) {
  58. igrachNaHod = 2;
  59. } else {
  60. igrachNaHod = 1;
  61. }
  62. break;
  63. }
  64. }
  65.  
  66.  
  67. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement