123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- event.load("block_place");
- event.load("block_click");
- games_world = world.getGames();
- red_glass_loc = loc.new(games_world, -425, 149, -51);
- yellow_glass_loc = loc.new(games_world, -425, 149, -50);
- green_glass_loc = loc.new(games_world, -425, 149, -49);
- clear_loc = loc.new(games_world, -425, 148, -50);
- tic_tac_toe_blocks = list.new();
- list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 148, -49));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 149, -49));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 150, -49));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 148, -49));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 149, -49));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 150, -49));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 148, -49));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 149, -49));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 150, -49));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 148, -50));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 149, -50));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 150, -50));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 148, -50));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 149, -50));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 150, -50));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 148, -50));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 149, -50));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 150, -50));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 148, -51));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 149, -51));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -430, 150, -51));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 148, -51));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 149, -51));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -431, 150, -51));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 148, -51));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 149, -51));
- list.add(tic_tac_toe_blocks, loc.new(games_world, -432, 150, -51));
- winning_blocks = list.new();
- setFieldToAir();
- msg("dev", "§bTicTacToe §rloaded.");
- @wait
- wait();
- if(event == "block_click") {
- if(block_loc == clear_loc) {
- setFieldToAir();
- }
- elseif(block_loc == red_glass_loc) {
- player.giveItem(player, read.item("minecraft:red_stained_glass", 32));
- }
- elseif(block_loc == yellow_glass_loc) {
- player.giveItem(player, read.item("minecraft:yellow_stained_glass", 32));
- }
- elseif(block_loc == green_glass_loc) {
- player.giveItem(player, read.item("minecraft:green_stained_glass", 32));
- }
- goto("wait");
- }
- if(event == "block_place") {
- if(is.tictactoe_placeable(block_loc)) {
- cancel = false;
- if(is.triplet(block_loc)) {
- goto("tic_tac_toe_win");
- }
- }
- }
- goto("wait");
- @tic_tac_toe_win
- msg.radius("§b3D-TicTacToe", concat(player.getName(player), " won."), entity.getLocation(player), 5);
- list.add(winning_blocks, block_loc);
- for(a = 0; a < list.getSize(winning_blocks); a++) {
- block.set(list.getIndex(winning_blocks, a), "minecraft:red_wool");
- }
- list.clear(winning_blocks);
- waitfor(60);
- setFieldToAir();
- goto("wait");
- function is.tictactoe_placeable(block_loc) {
- if(!list.contains($tic_tac_toe_blocks, block_loc)) {
- return false;
- }
- loc.addY(block_loc, -1);
- if(block.isAir(block_loc)) {
- loc.addY(block_loc, 1);
- return false;
- }
- loc.addY(block_loc, 1);
- return true;
- }
- function is.triplet(block_loc) {
- if(triplet.straight(block_loc)) {
- return true;
- }
- if(triplet.cross(block_loc)) {
- return true;
- }
- return triplet.cross_cross(block_loc);
- }
- function triplet.straight(block_loc){
- list.clear($winning_blocks);
- temp_block_count = 1;
- loc.addX(block_loc, -2);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addX(block_loc, 1);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addX(block_loc, 2);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addX(block_loc, 1);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addX(block_loc, -2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- temp_block_count = 1;
- loc.addY(block_loc, -2);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addY(block_loc, 1);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addY(block_loc, 2);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addY(block_loc, 1);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addY(block_loc, -2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- temp_block_count = 1;
- loc.addZ(block_loc, -2);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addZ(block_loc, 1);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addZ(block_loc, 2);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addZ(block_loc, 1);
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.addZ(block_loc, -2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- return false;
- }
- function triplet.cross(block_loc){
- list.clear($winning_blocks);
- temp_block_count = 1;
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2, 0,-2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 0, 1));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2, 0, 2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 0, 1));
- loc.addX(block_loc, -2);
- loc.addZ(block_loc, -2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- temp_block_count = 1;
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2, 0, 2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 0,-1));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2, 0,-2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 0,-1));
- loc.addX(block_loc, -2);
- loc.addZ(block_loc, 2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- temp_block_count = 1;
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0,-2,-2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 1, 1));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 2, 2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 1, 1));
- loc.addY(block_loc, -2);
- loc.addZ(block_loc, -2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- temp_block_count = 1;
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0,-2, 2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 1,-1));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 2,-2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 0, 1,-1));
- loc.addY(block_loc, -2);
- loc.addZ(block_loc, 2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- temp_block_count = 1;
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2,-2, 0));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1, 0));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2, 2, 0));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1, 0));
- loc.addY(block_loc, -2);
- loc.addX(block_loc, -2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- temp_block_count = 1;
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2,-2, 0));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-1, 1, 0));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2, 2, 0));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-1, 1, 0));
- loc.addY(block_loc, -2);
- loc.addX(block_loc, 2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- return false;
- }
- function triplet.cross_cross(block_loc){
- list.clear($winning_blocks);
- temp_block_count = 1;
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2,-2,-2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1, 1));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2, 2, 2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1, 1));
- loc.addY(block_loc, -2);
- loc.addX(block_loc, -2);
- loc.addZ(block_loc, -2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- temp_block_count = 1;
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2,-2,-2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-1, 1, 1));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2, 2, 2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-1, 1, 1));
- loc.addY(block_loc, -2);
- loc.addX(block_loc, 2);
- loc.addZ(block_loc, -2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- temp_block_count = 1;
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2, 2,-2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1,-1, 1));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2,-2, 2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1,-1, 1));
- loc.addY(block_loc, 2);
- loc.addX(block_loc, -2);
- loc.addZ(block_loc, -2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- temp_block_count = 1;
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc,-2,-2, 2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1,-1));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 2, 2,-2));
- temp_block_count = temp_block_count + is.blockType(t_loc_add(block_loc, 1, 1,-1));
- loc.addY(block_loc, -2);
- loc.addX(block_loc, -2);
- loc.addZ(block_loc, 2);
- if(temp_block_count > 2){
- return true;
- }
- list.clear($winning_blocks);
- return false;
- }
- function t_loc_add(block_loc, x, y, z){
- loc.add(block_loc,x, y ,z);
- return block_loc;
- }
- function is.blockType(block_loc) {
- if(block.getType(block_loc) == $block_type) {
- list.add($winning_blocks, loc.mod(block_loc, 0, 0, 0));
- return 1;
- }
- return 0;
- }
- function setFieldToAir() {
- for(a = 0; a < list.getSize($tic_tac_toe_blocks); a++) {
- block.set(list.getIndex($tic_tac_toe_blocks, a), "minecraft:air");
- }
- }
|