Advertisement
chowsonice

Untitled

Jan 21st, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. //cái hồ
  2. var fishtank = new Array(12);
  3. endy = 5;
  4. endx = 10;
  5. var nx, ny, x, y;
  6.  
  7. for (i=0;i< fishtank.length;i++){
  8. fishtank[i] = [];
  9. for (j=0;j<=6;j++){
  10. fishtank[i][j] = 0;
  11. }
  12. }
  13. for (y=0;y<=6;++y){
  14. fishtank[0][y]=1;
  15. fishtank[11][y]=1;
  16. }
  17. for (x=0;x<=11;x++){
  18. fishtank[x][0]=1;
  19. fishtank[x][6]=1;
  20. }
  21.  
  22. // //////in ra cai ho
  23. // for (i=0;i<fishtank.length;i++){
  24. // console.log(fishtank[i]);
  25. // }
  26.  
  27. //class cá
  28. class Fish{
  29. constructor(position) {
  30. atk = 10;
  31. hp = 1000;
  32. this.position = position;
  33. }
  34. }
  35.  
  36. //FISH1
  37. var fish1 = new Fish();
  38. x1 = 1;
  39. y1 = 1;
  40.  
  41. //FISH2
  42. var fish2= new Fish();
  43. x2 = 1;
  44. y2 = 1;
  45. a2 = 0;
  46.  
  47. //FISH 3
  48. var fish3 = new Fish();
  49. x3 = 1;
  50. y3 = 1;
  51. a3 = 0;
  52.  
  53. h = 0;
  54.  
  55. while (true) {
  56. //fish 1 changes
  57. if (x1 == 1) nx1 = 1;
  58. if (x1 == 10) nx1 = -1;
  59. if (y1 == 1) ny1 = 1;
  60. if (y1 == 5) ny1 =- 1;
  61.  
  62. //fish 2 changes
  63. if (x2 == 1) nx2 = 1;
  64. if (x2 == 10) nx2 = -1;
  65. if (y2 == 1) ny2 = 1;
  66. if (y2 == 5) ny2 =- 1;
  67.  
  68. //fish3 changes
  69. if (x3 == 1) nx3 = 1;
  70. if (x3 == 10) nx3 = -1;
  71. if (y3 == 1) ny3 = 1;
  72. if (y3 == 5) ny3 = -1;
  73.  
  74. while (h < 20) {
  75. //fish 1 movement
  76. fish1.position = [x1,y1];
  77. fishtank[x1][y1] = 0;
  78. x1 += nx1;
  79. y1 += ny1;
  80. fishtank[x1][y1] = fish1;
  81.  
  82. //fish2 movement
  83. fish2.position = [x2,y2];
  84. fishtank[x2][y2] = 0;
  85. if (a2 == 1) {
  86. x2 += nx2;
  87. a2 = 0;
  88. }
  89. else if (x2 == 10) {
  90. y2 += ny2;
  91. a2 += 1;
  92. }
  93. else if ((x2 == 1) && (y2 > 1)) {
  94. y2 += ny2;
  95. a2 += 1;
  96. }
  97. else x2 += nx2;
  98. fishtank[x2][y2] = fish2;
  99.  
  100. //fish 3 movement
  101. fish3.position = [x3,y3]
  102. if (a3 == 1){
  103. y3 += ny3;
  104. a3 = 0;
  105. }
  106. else if (y3 == 5){
  107. x3 += nx3;
  108. a3 += 1;
  109. }
  110. else if (y3 == 1 && x3 > 1){
  111. x3 += nx3;
  112. a3 += 1;
  113. }
  114. else y3 += ny3;
  115. fishtank[x3][y3] = fish3;
  116.  
  117. h += 1;
  118.  
  119. console.log("fish1", fish1.position, "fish2:", fish2.position,"fish3:",fish3.position);
  120.  
  121.  
  122. if (fishtank[x1+nx1][y1+ny1] == 1) break;
  123. if (fishtank[x2+nx2][y2] == 1) break;
  124. if (fishtank[x3][y3+ny3] == 1) break;
  125. }
  126. }
  127.  
  128. // // FISH 4
  129. // var fish4 = new Fish();
  130. // x4 = 1;
  131. // y4 = 1;
  132. // while (true) {
  133. // if (y4 == 1)
  134. // }
  135.  
  136.  
  137. //attack
  138. if (fish1.position == fish2.position) {
  139. fish1.hp += -fish2.atk;
  140. fish2.hp += -fish1.atk;
  141. }
  142. if (fish1.position == fish3.position) {
  143. fish1.hp += -fish3.atk;
  144. fish3.hp += -fish1.atk;
  145. }
  146. if (fish3.position == fish2.position) {
  147. fish3.hp += -fish2.atk;
  148. fish2.hp += -fish3.atk;
  149. }
  150. //bait
  151. var bait = [];
  152. var N = 5;
  153. for (i;i>=0;++i){
  154. if (h%5 == 0) {
  155. bait[i] = new bait();
  156. bait[i].position = [bx,by]
  157. }
  158. else break;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement