123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- event.load("block_place");
- event.load("block_click");
- event.load("function_key");
- games_world = world.getGames();
- winning_blocks = list.new();
- playing_players = list.new();
- start_loc = loc.new(games_world, start_x, start_y, start_z);
- placed_blocks = list.new();
- list.add(placed_blocks, start_loc);
- dimension = 3;
- dem_array = array-new[dimension - 3]
- for(a = 0; a < dimension - 2; a++){
- dem_array[a] = 0;
- }
- length = 3;
- @start
- list.add(placed_blocks, start_loc);
- block.set(start_loc, "minecraft:stone");
- goto("wait");
- @end
- for(a = 0; a < list.getSize(placed_blocks); a++){
- block.set(list.getIndex(placed_blocks, a), "minecraft:air");
- }
- list.clear(placed_blocks);
- goto("start");
- @wait
- wait();
- if(event == "block_click"){
- if(list.contains(ttt_start_loc_list, block_loc)){
- list.add(playing_players, player);
- }
- }
- if(event == "block_place"){
- if(list.contains(playing_players, player)){
- if(is.tictactoe_placeable(block_loc)){
- cancel = false;
- temp_array = array.new[dimension - 2];
- temp_array[0] = block_loc;
-
- list.add(placed_blocks, temp_array)
- if(is.triplet(block_loc)){
- goto("tic_tac_toe_win");
- }
- }
- }
- }
- if(event == "function_key"){
- if(list.contains(playing_players, player)){
-
- }
- }
- goto("wait");
- @tic_tac_toe_win
- msg(player, "You won.");
- for(a = 0; a < list.getSize(tic_tac_toe_blocks); a++){
- block.set(list.getIndex(tic_tac_toe_blocks, a), "minecraft:air");
- }
- 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);
- list.clear(playing_players);
- goto("wait");
- function is.tictactoe_placeable(block_loc){
- if(!ttt.has_neighbours){
- 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 ttt.has_neighbours(block_loc){
- temp_loc = loc.mod(block_loc, 1, 0, 0);
- if(list.contains(placed_blocks, temp_loc)){
- return true;
- }
- temp_loc = loc.mod(block_loc, -1, 0, 0);
- if(list.contains(placed_blocks, temp_loc)){
- return true;
- }
- temp_loc = loc.mod(block_loc, 0, 1, 0);
- if(list.contains(placed_blocks, temp_loc)){
- return true;
- }
- temp_loc = loc.mod(block_loc, 0, -1, 0);
- if(list.contains(placed_blocks, temp_loc)){
- return true;
- }
- temp_loc = loc.mod(block_loc, 0, 0, 1);
- if(list.contains(placed_blocks, temp_loc)){
- return true;
- }
- temp_loc = loc.mod(block_loc, 0, 0, -1);
- if(list.contains(placed_blocks, temp_loc)){
- return true;
- }
- return false;
- }
- function is.triplet(block_loc){
- if(triplet.straight(block_loc)){
- return true;
- }
- if(triplet.cross(block_loc)){
- return true;
- }
- if(triplet.cross_cross(block_loc)){
- return true;
- }
- return false;
- }
- function triplet.straight(block_loc){
- if(triplet.loop(block_loc, 1, 0, 0)){
- return true;
- }
- if(triplet.loop(block_loc, 0, 1, 0)){
- return true;
- }
- if(triplet.loop(block_loc, 0, 0, 1)){
- return true;
- }
- list.clear($winning_blocks);
- return false;
- }
- function triplet.cross(block_loc){
- if(triplet.loop(block_loc, 1, 0, 1)){
- return true;
- }
- if(triplet.loop(block_loc, 1, 0, -1)){
- return true;
- }
- if(triplet.loop(block_loc, 0, 1, 1)){
- return true;
- }
- if(triplet.loop(block_loc, 0, 1, -1)){
- return true;
- }
- if(triplet.loop(block_loc, 1, 1, 0)){
- return true;
- }
- if(triplet.loop(block_loc, -1, 1, 0)){
- return true;
- }
- list.clear($winning_blocks);
- return false;
- }
- function triplet.cross_cross(block_loc){
- if(triplet.loop(block_loc, 1, 1, 1)){
- return true;
- }
- if(triplet.loop(block_loc, -1, 1, 1)){
- return true;
- }
- if(triplet.loop(block_loc, 1, -1, 1)){
- return true;
- }
- if(triplet.loop(block_loc, 1, 1, -1)){
- return true;
- }
- list.clear($winning_blocks);
- return false;
- }
- function triplet.loop(block_loc, x,y,z){
- list.clear($winning_blocks);
- temp_block_count = 1;
- loc.add(block_loc, -($length-1)*x, -($length-1)*y, -($length-1)*z);
- for(a = 0; a < 2 * $length - 1; a++){
- temp_block_count = temp_block_count + is.blockType(block_loc);
- loc.add(block_loc,x, y ,z);
- }
- loc.add(block_loc, -($length-1)*x, -($length-1)*y, -($length-1)*z);
- if(temp_block_count > $length){
- return true;
- }
- return false;
- }
- 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;
- }
|