123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- event.load("block_break");
- event.load("block_place");
- event.load("block_click");
- event.load("player_join");
- event.load("player_giveup");
- event.load("player_logout");
- rankingtable = "leapfrogranks";
- game_short = "lf";
- sign.started(gamesignloc);
- gamename = "§9Leapfrog";
- points = 0;
- @wait
- wait();
- if(player.hasMinigameId(player, script_id)) {
- ignoreGoto(event);
- }
- goto("wait");
- @player_join
- player_record = ranking.getPoints(rankingtable, player);
- display.reset(player);
- display.add(player, 0, gamename);
- display.add(player, 1, "Points: §e", text.number(points));
- display.add(player, 2, "Your Record: §e", text.number(player_record));
- stacks.setActive(player, false);
- living.setHealth(player, 20);
- player.setHunger(player, 20);
- player.setSaturation(player, 5);
- entity.teleport(player, loc.mod(middleloc, 0.5, 0, 0.5));
- initPlayField();
- resetPlayField();
- msg.prefix(player, gamename, "Click on a torch and jump over another torch to let it disappear. Try to get as many points (jumps) as possible. If the last torch ends up in the middle, you get an extra point.");
- goto("wait");
- @block_break
- @block_place
- cancel = true;
- goto("wait");
- @block_click
- if(hand == "OFF_HAND" || action == "left") {
- goto("wait");
- }
- if(!isInPlayField(block_loc)) {
- goto("wait");
- }
- //Click token
- if(loc.getY(block_loc) == y_bottom + 1) {
- if(pos1 != null) {
- block.set(loc.mod(pos1, 0, -2, 0), torch);
- }
- pos1 = block_loc;
- block.set(loc.mod(pos1, 0, -2, 0), "minecraft:air");
- goto("wait");
- }
- //Jump with token
- if(loc.getY(block_loc) == y_bottom) {
- pos2 = block_loc;
- if(pos1 == null) {
- msg.prefix(player, gamename, "Select a torch first.");
- goto("wait");
- }
- //Are pos1 and pos2 on same line
- x1 = loc.getX(pos1);
- z1 = loc.getZ(pos1);
- x2 = loc.getX(pos2);
- z2 = loc.getZ(pos2);
- if(x1 == x2) {
- if(!distanceCheck(pos1, pos2)) {
- msgUnlegitMove(player);
- goto("wait");
- }
- if(fieldHasToken(pos2)) {
- msgUnlegitMove(player);
- goto("wait");
- }
- if(z2 > z1) {
- middlepos = loc.new(gamesworld, x1, y_bottom + 1, z1 + 1);
- } else {
- middlepos = loc.new(gamesworld, x1, y_bottom + 1, z2 + 1);
- }
- if(!hasToken(middlepos)) {
- msgUnlegitMove(player);
- goto("wait");
- }
- doMove(player, pos1, pos2, middlepos);
- goto("wait");
- }
- if(z1 == z2) {
- if(!distanceCheck(pos1, pos2)) {
- msgUnlegitMove(player);
- goto("wait");
- }
- if(fieldHasToken(pos2)) {
- msgUnlegitMove(player);
- goto("wait");
- }
- if(x2 > x1) {
- middlepos = loc.new(gamesworld, x1 + 1, y_bottom + 1, z1);
- } else {
- middlepos = loc.new(gamesworld, x2 + 1, y_bottom + 1, z1);
- }
- if(!hasToken(middlepos)) {
- msgUnlegitMove(player);
- goto("wait");
- }
- doMove(player, pos1, pos2, middlepos);
- goto("wait");
- }
- msgUnlegitMove(player);
- }
- goto("wait");
- @player_giveup
- @player_logout
- money.addBoost(player, math.round(points / 4));
- script = script.getFromId(script_id);
- minigame.kickPlayer(script, player);
- minigame.term(script, gamesignloc);
- term();
- function msgUnlegitMove(player) {
- msg.prefix(player, $gamename, "Unlegit move. Jump over a torch to a free field.");
- }
- function distanceCheck(pos1, pos2) { //returns true if the distance between the token and the selected field is 2
- return loc.distance(pos1, loc.mod(pos2, 0, 1, 0)) == 2;
- }
- function fieldHasToken(location) { //returns true if above a field is a token
- return !block.isAir(loc.mod(location, 0, 1, 0));
- }
- function hasToken(location) { //returns true if there is a token
- return !block.isAir(location);
- }
- function doMove(player, pos1, pos2, middlepos) {
- block.set(pos1, "minecraft:air");
- block.set(loc.mod(pos2, 0, 1, 0), $torch);
- block.set(middlepos, "minecraft:air");
- block.set(loc.mod(pos2, 0, -1, 0), $torch);
- $points++;
- $pos1 = null;
- if(isGameOver()) {
- msg.prefix(player, $gamename, "Gameover. No more moves possible.");
- msg.prefix(player, $gamename, "Study the field to get better.");
- msg.prefix(player, $gamename, "Use /leave to return to lobby.");
- event.unload("block_click");
- //extra
- if(block.getType($middleloc) == $torch && $points == 43) {
- $points++;
- msg.prefix(player, $gamename, "Extra point for the last torch ending up in the middle.");
- }
- showStats(player, $points);
- }
- display.add(player, 1, "Points: §e", text.number($points));
- player.setHunger(player, 20);
- player.setSaturation(player, 5);
- }
- function isGameOver() {
- //left to right
- for(i = 0; i < list.getSize($left_start_locs); i++) {
- //init a counter and history vars
- counter = 0;
- hist_2 = 1;
- hist_1 = 1;
- loc = list.getIndex($left_start_locs, i);
- loc = loc.mod(loc, 0, 0, 0);
- end_loc = list.getIndex($right_ends_locs, i);
- while(loc != end_loc) {
- //raise counter if current location is torch
- if(block.getType(loc) == $torch) {
- counter++;
- hist_0 = 1;
- } else {
- //if there is no torch and the counter has 2 or more torches the game is not over, else reset counter
- hist_0 = 0;
- if(counter >= 2) {
- return false;
- }
- counter = 0;
- }
- //if counter found 2 torches and the field before these 2 torches is free, game is not over
- if(counter == 2) {
- if(hist_2 == 0) {
- return false;
- }
- }
- hist_2 = hist_1;
- hist_1 = hist_0;
- loc.addX(loc, 1);
- }
- }
- //up to down
- for(i = 0; i < list.getSize($upper_start_locs); i++) {
- counter = 0;
- hist_2 = 1;
- hist_1 = 1;
- loc = list.getIndex($upper_start_locs, i);
- loc = loc.mod(loc, 0, 0, 0);
- end_loc = list.getIndex($down_ends_locs, i);
- while(loc != end_loc) {
- if(block.getType(loc) == $torch) {
- counter++;
- hist_0 = 1;
- } else {
- hist_0 = 0;
- if(counter >= 2) {
- return false;
- }
- counter = 0;
- }
- if(counter == 2) {
- if(hist_2 == 0) {
- return false;
- }
- }
- hist_2 = hist_1;
- hist_1 = hist_0;
- loc.addZ(loc, 1);
- }
- }
- return true;
- }
- function showStats(player, points) {
- minigame.addPlayed(player, $game_short, 1);
- minigame.statsHeader(player, $gamename, "§e");
- minigame.statsLine(player, "§e", "Points", text.number(points));
- if($player_record < points) {
- ranking.setPoints($rankingtable, player, points);
- minigame.statsLine(player, "§e", "Beat own record by", text.number(points - $player_record));
- $player_record = points;
- display.add(player, 2, "Your Record: §e", text.number($player_record));
- }
- minigame.statsLine(player, "§e", "Record", text.number($player_record));
- }
- function isInPlayField(location) {
- if(loc.isBetween(location, $edge1, loc.mod($edge2, 0, -1, 0))) {
- return true;
- }
- if(loc.isBetween(location, $edge3, loc.mod($edge4, 0, -1, 0))) {
- return true;
- }
- return false;
- }
- function initPlayField() {
- $left_start_locs = list.new();
- list.add($left_start_locs, loc.mod($lu_corner, 3, 0, 0));
- list.add($left_start_locs, loc.mod($lu_corner, 3, 0, 1));
- list.add($left_start_locs, loc.mod($lu_corner, 3, 0, 2));
- list.add($left_start_locs, loc.mod($lu_corner, 0, 0, 3));
- list.add($left_start_locs, loc.mod($lu_corner, 0, 0, 4));
- list.add($left_start_locs, loc.mod($lu_corner, 0, 0, 5));
- list.add($left_start_locs, loc.mod($lu_corner, 3, 0, 6));
- list.add($left_start_locs, loc.mod($lu_corner, 3, 0, 7));
- list.add($left_start_locs, loc.mod($lu_corner, 3, 0, 8));
- $right_ends_locs = list.new();
- list.add($right_ends_locs, loc.mod($lu_corner, 6, 0, 0));
- list.add($right_ends_locs, loc.mod($lu_corner, 6, 0, 1));
- list.add($right_ends_locs, loc.mod($lu_corner, 6, 0, 2));
- list.add($right_ends_locs, loc.mod($lu_corner, 9, 0, 3));
- list.add($right_ends_locs, loc.mod($lu_corner, 9, 0, 4));
- list.add($right_ends_locs, loc.mod($lu_corner, 9, 0, 5));
- list.add($right_ends_locs, loc.mod($lu_corner, 6, 0, 6));
- list.add($right_ends_locs, loc.mod($lu_corner, 6, 0, 7));
- list.add($right_ends_locs, loc.mod($lu_corner, 6, 0, 8));
- $upper_start_locs = list.new();
- list.add($upper_start_locs, loc.mod($lu_corner, 0, 0, 3));
- list.add($upper_start_locs, loc.mod($lu_corner, 1, 0, 3));
- list.add($upper_start_locs, loc.mod($lu_corner, 2, 0, 3));
- list.add($upper_start_locs, loc.mod($lu_corner, 3, 0, 0));
- list.add($upper_start_locs, loc.mod($lu_corner, 4, 0, 0));
- list.add($upper_start_locs, loc.mod($lu_corner, 5, 0, 0));
- list.add($upper_start_locs, loc.mod($lu_corner, 6, 0, 3));
- list.add($upper_start_locs, loc.mod($lu_corner, 7, 0, 3));
- list.add($upper_start_locs, loc.mod($lu_corner, 8, 0, 3));
- $down_ends_locs = list.new();
- list.add($down_ends_locs, loc.mod($lu_corner, 0, 0, 6));
- list.add($down_ends_locs, loc.mod($lu_corner, 1, 0, 6));
- list.add($down_ends_locs, loc.mod($lu_corner, 2, 0, 6));
- list.add($down_ends_locs, loc.mod($lu_corner, 3, 0, 9));
- list.add($down_ends_locs, loc.mod($lu_corner, 4, 0, 9));
- list.add($down_ends_locs, loc.mod($lu_corner, 5, 0, 9));
- list.add($down_ends_locs, loc.mod($lu_corner, 6, 0, 6));
- list.add($down_ends_locs, loc.mod($lu_corner, 7, 0, 6));
- list.add($down_ends_locs, loc.mod($lu_corner, 8, 0, 6));
- }
- function resetPlayField() {
- for(i = 0; i < list.getSize($left_start_locs); i++) {
- loc = list.getIndex($left_start_locs, i);
- loc = loc.mod(loc, 0, 0, 0);
- end_loc = list.getIndex($right_ends_locs, i);
- while(loc != end_loc) {
- block.set(loc, $torch);
- block.set(loc.mod(loc, 0, -2, 0), $torch);
- loc.addX(loc, 1);
- }
- }
- block.set($middleloc, "minecraft:air");
- }
|