tictactoe.txt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. event.load("block_place");
  2. event.load("block_click");
  3. games_world = world.getGames();
  4. red_glass_loc = loc.new(games_world, -425, 149, -51);
  5. yellow_glass_loc = loc.new(games_world, -425, 149, -50);
  6. green_glass_loc = loc.new(games_world, -425, 149, -49);
  7. tic_tac_toe_blocks = list.new();
  8. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 148, -49));
  9. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 149, -49));
  10. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 150, -49));
  11. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 148, -49));
  12. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 149, -49));
  13. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 150, -49));
  14. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 148, -49));
  15. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 149, -49));
  16. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 150, -49));
  17. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 148, -50));
  18. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 149, -50));
  19. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 150, -50));
  20. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 148, -50));
  21. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 149, -50));
  22. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 150, -50));
  23. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 148, -50));
  24. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 149, -50));
  25. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 150, -50));
  26. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 148, -51));
  27. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 149, -51));
  28. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 150, -51));
  29. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 148, -51));
  30. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 149, -51));
  31. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 150, -51));
  32. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 148, -51));
  33. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 149, -51));
  34. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 150, -51));
  35. winning_blocks = list.new();
  36. length = 3;
  37. setFieldToAir();
  38. msg("dev", "§bTicTacToe §rloaded.");
  39. @wait
  40. wait();
  41. if(event == "block_click") {
  42. if(block_loc == red_glass_loc) {
  43. player.giveItem(player, read.item("minecraft:red_stained_glass", 32));
  44. }
  45. elseif(block_loc == yellow_glass_loc) {
  46. player.giveItem(player, read.item("minecraft:yellow_stained_glass", 32));
  47. }
  48. elseif(block_loc == green_glass_loc) {
  49. player.giveItem(player, read.item("minecraft:green_stained_glass", 32));
  50. }
  51. goto("wait");
  52. }
  53. if(event == "block_place") {
  54. if(is.tictactoe_placeable(block_loc)) {
  55. cancel = false;
  56. if(is.triplet(block_loc)) {
  57. goto("tic_tac_toe_win");
  58. }
  59. }
  60. }
  61. goto("wait");
  62. @tic_tac_toe_win
  63. msg.radius("§b3D-TicTacToe", concat(player.getName(player), " won."), entity.getLocation(player), 5);
  64. list.add(winning_blocks, block_loc);
  65. for(a = 0; a < list.getSize(winning_blocks); a++) {
  66. block.set(list.getIndex(winning_blocks, a), "minecraft:red_wool");
  67. }
  68. list.clear(winning_blocks);
  69. waitfor(60);
  70. setFieldToAir();
  71. goto("wait");
  72. function is.tictactoe_placeable(block_loc) {
  73. if(!list.contains($tic_tac_toe_blocks, block_loc)) {
  74. return false;
  75. }
  76. loc.addY(block_loc, -1);
  77. if(block.isAir(block_loc)) {
  78. loc.addY(block_loc, 1);
  79. return false;
  80. }
  81. loc.addY(block_loc, 1);
  82. return true;
  83. }
  84. function is.triplet(block_loc) {
  85. if(triplet.straight(block_loc)) {
  86. return true;
  87. }
  88. if(triplet.cross(block_loc)) {
  89. return true;
  90. }
  91. return triplet.cross_cross(block_loc);
  92. }
  93. function triplet.straight(block_loc){
  94. if(triplet.loop(block_loc, 1, 0, 0)){
  95. return true;
  96. }
  97. if(triplet.loop(block_loc, 0, 1, 0)){
  98. return true;
  99. }
  100. if(triplet.loop(block_loc, 0, 0, 1)){
  101. return true;
  102. }
  103. list.clear($winning_blocks);
  104. return false;
  105. }
  106. function triplet.cross(block_loc) {
  107. if(triplet.loop(block_loc, 1, 0, 1)) {
  108. return true;
  109. }
  110. if(triplet.loop(block_loc, 1, 0, -1)) {
  111. return true;
  112. }
  113. if(triplet.loop(block_loc, 0, 1, 1)) {
  114. return true;
  115. }
  116. if(triplet.loop(block_loc, 0, 1, -1)) {
  117. return true;
  118. }
  119. if(triplet.loop(block_loc, 1, 1, 0)) {
  120. return true;
  121. }
  122. if(triplet.loop(block_loc, -1, 1, 0)) {
  123. return true;
  124. }
  125. list.clear($winning_blocks);
  126. return false;
  127. }
  128. function triplet.cross_cross(block_loc) {
  129. if(triplet.loop(block_loc, 1, 1, 1)) {
  130. return true;
  131. }
  132. if(triplet.loop(block_loc, -1, 1, 1)) {
  133. return true;
  134. }
  135. if(triplet.loop(block_loc, 1, -1, 1)) {
  136. return true;
  137. }
  138. if(triplet.loop(block_loc, 1, 1, -1)) {
  139. return true;
  140. }
  141. list.clear($winning_blocks);
  142. return false;
  143. }
  144. function triplet.loop(block_loc, x,y,z) {
  145. list.clear($winning_blocks);
  146. temp_block_count = 1;
  147. loc.add(block_loc, -2 * x, -2 * y, -2 * z);
  148. for(a = 0; a < 2 * $length - 2; a++) {
  149. temp_block_count = temp_block_count + is.blockType(block_loc);
  150. loc.add(block_loc, x, y ,z);
  151. }
  152. loc.add(block_loc, -2 * x, -2 * y, -2 * z);
  153. return temp_block_count > $length;
  154. }
  155. function is.blockType(block_loc) {
  156. if(block.getType(block_loc) == $block_type) {
  157. list.add($winning_blocks, loc.mod(block_loc, 0, 0, 0));
  158. return 1;
  159. }
  160. return 0;
  161. }
  162. function setFieldToAir() {
  163. for(a = 0; a < list.getSize($tic_tac_toe_blocks); a++) {
  164. block.set(list.getIndex($tic_tac_toe_blocks, a), "minecraft:air");
  165. }
  166. }