tictactoe.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. clear_loc = loc.new(games_world, -425, 148, -50);
  8. tic_tac_toe_blocks = list.new();
  9. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 148, -49));
  10. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 149, -49));
  11. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 150, -49));
  12. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 148, -49));
  13. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 149, -49));
  14. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 150, -49));
  15. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 148, -49));
  16. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 149, -49));
  17. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 150, -49));
  18. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 148, -50));
  19. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 149, -50));
  20. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 150, -50));
  21. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 148, -50));
  22. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 149, -50));
  23. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 150, -50));
  24. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 148, -50));
  25. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 149, -50));
  26. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 150, -50));
  27. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 148, -51));
  28. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 149, -51));
  29. list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 150, -51));
  30. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 148, -51));
  31. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 149, -51));
  32. list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 150, -51));
  33. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 148, -51));
  34. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 149, -51));
  35. list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 150, -51));
  36. winning_blocks = list.new();
  37. setFieldToAir();
  38. msg("dev", "§bTicTacToe §rloaded.");
  39. @wait
  40. wait();
  41. if(event == "block_click") {
  42. if(block_loc == clear_loc) {
  43. setFieldToAir();
  44. }
  45. elseif(block_loc == red_glass_loc) {
  46. player.giveItem(player, read.item("minecraft:red_stained_glass", 32));
  47. }
  48. elseif(block_loc == yellow_glass_loc) {
  49. player.giveItem(player, read.item("minecraft:yellow_stained_glass", 32));
  50. }
  51. elseif(block_loc == green_glass_loc) {
  52. player.giveItem(player, read.item("minecraft:green_stained_glass", 32));
  53. }
  54. goto("wait");
  55. }
  56. if(event == "block_place") {
  57. if(is.tictactoe_placeable(block_loc)) {
  58. cancel = false;
  59. if(is.triplet(block_loc)) {
  60. goto("tic_tac_toe_win");
  61. }
  62. }
  63. }
  64. goto("wait");
  65. @tic_tac_toe_win
  66. msg.radius("§b3D-TicTacToe", concat(player.getName(player), " won."), entity.getLocation(player), 5);
  67. list.add(winning_blocks, block_loc);
  68. for(a = 0; a < list.getSize(winning_blocks); a++) {
  69. block.set(list.getIndex(winning_blocks, a), "minecraft:red_wool");
  70. }
  71. list.clear(winning_blocks);
  72. waitfor(60);
  73. setFieldToAir();
  74. goto("wait");
  75. function is.tictactoe_placeable(block_loc) {
  76. if(!list.contains($tic_tac_toe_blocks, block_loc)) {
  77. return false;
  78. }
  79. loc.addY(block_loc, -1);
  80. if(block.isAir(block_loc)) {
  81. loc.addY(block_loc, 1);
  82. return false;
  83. }
  84. loc.addY(block_loc, 1);
  85. return true;
  86. }
  87. function is.triplet(block_loc) {
  88. if(triplet.straight(block_loc)) {
  89. return true;
  90. }
  91. if(triplet.cross(block_loc)) {
  92. return true;
  93. }
  94. return triplet.cross_cross(block_loc);
  95. }
  96. function triplet.straight(block_loc){
  97. list.clear($winning_blocks);
  98. temp_block_count = 1;
  99. loc.addX(block_loc, -2);
  100. temp_block_count = temp_block_count + is.blockType(block_loc);
  101. loc.addX(block_loc, 1);
  102. temp_block_count = temp_block_count + is.blockType(block_loc);
  103. loc.addX(block_loc, 2);
  104. temp_block_count = temp_block_count + is.blockType(block_loc);
  105. loc.addX(block_loc, 1);
  106. temp_block_count = temp_block_count + is.blockType(block_loc);
  107. loc.addX(block_loc, -2);
  108. if(temp_block_count > 2){
  109. return true;
  110. }
  111. list.clear($winning_blocks);
  112. temp_block_count = 1;
  113. loc.addY(block_loc, -2);
  114. temp_block_count = temp_block_count + is.blockType(block_loc);
  115. loc.addY(block_loc, 1);
  116. temp_block_count = temp_block_count + is.blockType(block_loc);
  117. loc.addY(block_loc, 2);
  118. temp_block_count = temp_block_count + is.blockType(block_loc);
  119. loc.addY(block_loc, 1);
  120. temp_block_count = temp_block_count + is.blockType(block_loc);
  121. loc.addY(block_loc, -2);
  122. if(temp_block_count > 2){
  123. return true;
  124. }
  125. list.clear($winning_blocks);
  126. temp_block_count = 1;
  127. loc.addZ(block_loc, -2);
  128. temp_block_count = temp_block_count + is.blockType(block_loc);
  129. loc.addZ(block_loc, 1);
  130. temp_block_count = temp_block_count + is.blockType(block_loc);
  131. loc.addZ(block_loc, 2);
  132. temp_block_count = temp_block_count + is.blockType(block_loc);
  133. loc.addZ(block_loc, 1);
  134. temp_block_count = temp_block_count + is.blockType(block_loc);
  135. loc.addZ(block_loc, -2);
  136. if(temp_block_count > 2){
  137. return true;
  138. }
  139. list.clear($winning_blocks);
  140. return false;
  141. }
  142. function triplet.cross(block_loc){
  143. list.clear($winning_blocks);
  144. temp_block_count = 1;
  145. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2, 0,-2));
  146. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 0, 1));
  147. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2, 0, 2));
  148. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 0, 1));
  149. loc.addX(block_loc, -2);
  150. loc.addZ(block_loc, -2);
  151. if(temp_block_count > 2){
  152. return true;
  153. }
  154. list.clear($winning_blocks);
  155. temp_block_count = 1;
  156. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2, 0, 2));
  157. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 0,-1));
  158. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2, 0,-2));
  159. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 0,-1));
  160. loc.addX(block_loc, -2);
  161. loc.addZ(block_loc, 2);
  162. if(temp_block_count > 2){
  163. return true;
  164. }
  165. list.clear($winning_blocks);
  166. temp_block_count = 1;
  167. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0,-2,-2));
  168. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 1, 1));
  169. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 2, 2));
  170. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 1, 1));
  171. loc.addY(block_loc, -2);
  172. loc.addZ(block_loc, -2);
  173. if(temp_block_count > 2){
  174. return true;
  175. }
  176. list.clear($winning_blocks);
  177. temp_block_count = 1;
  178. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0,-2, 2));
  179. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 1,-1));
  180. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 2,-2));
  181. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 1,-1));
  182. loc.addY(block_loc, -2);
  183. loc.addZ(block_loc, 2);
  184. if(temp_block_count > 2){
  185. return true;
  186. }
  187. list.clear($winning_blocks);
  188. temp_block_count = 1;
  189. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2,-2, 0));
  190. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1, 0));
  191. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2, 2, 0));
  192. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1, 0));
  193. loc.addY(block_loc, -2);
  194. loc.addX(block_loc, -2);
  195. if(temp_block_count > 2){
  196. return true;
  197. }
  198. list.clear($winning_blocks);
  199. temp_block_count = 1;
  200. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2,-2, 0));
  201. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-1, 1, 0));
  202. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2, 2, 0));
  203. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-1, 1, 0));
  204. loc.addY(block_loc, -2);
  205. loc.addX(block_loc, 2);
  206. if(temp_block_count > 2){
  207. return true;
  208. }
  209. list.clear($winning_blocks);
  210. return false;
  211. }
  212. function triplet.cross_cross(block_loc){
  213. list.clear($winning_blocks);
  214. temp_block_count = 1;
  215. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2,-2,-2));
  216. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1, 1));
  217. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2, 2, 2));
  218. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1, 1));
  219. loc.addY(block_loc, -2);
  220. loc.addX(block_loc, -2);
  221. loc.addZ(block_loc, -2);
  222. if(temp_block_count > 2){
  223. return true;
  224. }
  225. list.clear($winning_blocks);
  226. temp_block_count = 1;
  227. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2,-2,-2));
  228. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-1, 1, 1));
  229. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2, 2, 2));
  230. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-1, 1, 1));
  231. loc.addY(block_loc, -2);
  232. loc.addX(block_loc, 2);
  233. loc.addZ(block_loc, -2);
  234. if(temp_block_count > 2){
  235. return true;
  236. }
  237. list.clear($winning_blocks);
  238. temp_block_count = 1;
  239. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2, 2,-2));
  240. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1,-1, 1));
  241. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2,-2, 2));
  242. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1,-1, 1));
  243. loc.addY(block_loc, 2);
  244. loc.addX(block_loc, -2);
  245. loc.addZ(block_loc, -2);
  246. if(temp_block_count > 2){
  247. return true;
  248. }
  249. list.clear($winning_blocks);
  250. temp_block_count = 1;
  251. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2,-2, 2));
  252. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1,-1));
  253. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2, 2,-2));
  254. temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1,-1));
  255. loc.addY(block_loc, -2);
  256. loc.addX(block_loc, -2);
  257. loc.addZ(block_loc, 2);
  258. if(temp_block_count > 2){
  259. return true;
  260. }
  261. list.clear($winning_blocks);
  262. return false;
  263. }
  264. function t_loc_add(block_loc, x, y, z){
  265. loc.add(block_loc,x, y ,z);
  266. return block_loc;
  267. }
  268. function is.blockType(block_loc) {
  269. if(block.getType(block_loc) == $block_type) {
  270. list.add($winning_blocks, loc.mod(block_loc, 0, 0, 0));
  271. return 1;
  272. }
  273. return 0;
  274. }
  275. function setFieldToAir() {
  276. for(a = 0; a < list.getSize($tic_tac_toe_blocks); a++) {
  277. block.set(list.getIndex($tic_tac_toe_blocks, a), "minecraft:air");
  278. }
  279. }