luiscobo

Taller_11_Mundo_02

Nov 4th, 2019
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 6.67 KB | None | 0 0
  1. {
  2.   "description": [
  3.     "<h1>La caminata alrededor del lago</h1>",
  4.     "<p> Ya alguna vez hicimos un ejercicio donde el Robot caminaba al rededor de un lago. ",
  5.     "    solo que en esta ocasión, la forma del lago es compleja y Reeborg lleva una banana ",
  6.     "    dentro de si. El robot debe colocar la banana en el sitio de inicio (que va a cambiar ",
  7.     "    de ejecución en ejecución) y empezar a caminar alrededor del lago hasta que encuentre la ",
  8.     "    banana nuevamente. OJO: <b>Reeborg nunca comienza en el mismo sitio, sin embargo, tampoco ",
  9.     "    iniciará en un sitio que tenga un obstáculo frente a él. </b>.</p>",
  10.     "DIFFICULTY5",
  11.     ""
  12.   ],
  13.   "onload": [
  14.     "var _tiles, i, j, choice, x, y, name, backgrounds, obstacles;",
  15.     "var len, path, pos_0, pos_1, orientation, ",
  16.     "    x0, y0, x1, y1; ",    
  17.     "",
  18.     "backgrounds = ['water', 'gravel'];",
  19.     "obstacles = ['fence_double', 'fence_vertical', 'fence_left', 'fence_right'];",
  20.     "",
  21.     "_tiles = {};",
  22.     "_tiles['path1'] = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1],",
  23.     "        [7, 1], [8, 1], [8, 2], [8, 3], [7, 3], [6, 3], [5, 3], [4, 3],",
  24.     "        [3, 3], [3, 4], [3, 5], [3, 6], [4, 6], [5, 6], [6, 6], [7, 6],",
  25.     "        [8, 6], [9, 6], [10, 6], [10, 5], [10, 4], [10, 3], [11, 3], [12, 3],",
  26.     "        [13, 3], [13, 4], [13, 5], [13, 6], [13, 7], [13, 8], [13, 9], [12, 9],",
  27.     "        [11, 9], [10, 9], [9, 9], [9, 8], [8, 8], [7, 8], [6, 8], [5, 8], [5, 9],",
  28.     "        [5, 10], [4, 10], [3, 10], [2, 10], [1, 10], [1, 9], [1, 8], [1, 7],",
  29.     "        [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [1, 1]];",
  30.     "_tiles['gravel1'] = _tiles['path1'];",
  31.     "",
  32.     "_tiles['water1'] = [[2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [2, 3],",
  33.     "      [2, 4], [11, 4], [12, 4], [2, 5], [11, 5], [12, 5], [2, 6], [11, 6], [12, 6],",
  34.     "      [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [7, 7], [8, 7], [9, 7], [10, 7], [11, 7],",
  35.     "      [12, 7], [2, 8], [3, 8], [4, 8], [10, 8], [11, 8], [12, 8], [2, 9], [3, 9], [4, 9]];",
  36.     "    ",
  37.     "_tiles['fence_vertical1'] = [[4, 5], [6, 10], [6, 11], [8, 10],",
  38.     "      [9, 1], [9, 2], [9, 3], [9, 4], [9, 5], [14, 3], [14, 4],",
  39.     "      [14, 5], [14, 6], [14, 7], [14, 8], [14, 9], [14, 10]];",
  40.     "",
  41.     "_tiles['fence_double1'] = [[10, 2], [11, 2], [12, 2], [13, 2],",
  42.     "        [5, 4], [6, 4], [7, 4], [8, 4], [5, 5], [6, 5], [7, 5], [8, 5],",
  43.     "        [7, 9], [9, 10], [10, 10], [11, 10], [12, 10], [13, 10],",
  44.     "        [2, 11], [3, 11], [4, 11], [5, 11]];",
  45.     "",
  46.     "_tiles['fence_left1'] = [[14, 2], [9, 4], [9, 5], [8, 9], [14, 10], [6, 11]];",
  47.     "_tiles['fence_right1'] = [[9, 2], [4, 4], [4, 5], [6, 9], [8, 10], [1, 11]];",
  48.     "",
  49.     "",
  50.     "_tiles['path2'] = [[1, 1], [2, 1], [3, 1], [4, 1], [4, 2],",
  51.     "        [4, 3], [5, 3], [6, 3], [7, 3], [7, 4], [7, 5], [7, 6],",
  52.     "        [8, 6], [9, 6], [10, 6], [11, 6], [12, 6], [13, 6], [13, 7],",
  53.     "        [13, 8], [13, 9], [13, 10], [12, 10], [11, 10], [10, 10],",
  54.     "        [10, 9], [9, 9], [8, 9], [8, 10], [7, 10], [6, 10], [5, 10],",
  55.     "        [4, 10], [3, 10], [2, 10], [1, 10], [1, 9], [1, 8], [2, 8],",
  56.     "        [3, 8], [4, 8], [4, 7], [4, 6], [3, 6], [2, 6], [1, 6], [1, 5],",
  57.     "        [1, 4], [1, 3], [1, 2], [1, 1]];",
  58.     "_tiles['gravel2'] = _tiles['path2'];",
  59.     "",
  60.     "_tiles['water2'] = [[2, 2], [3, 2], [2, 3], [3, 3],",
  61.     "      [2, 4], [3, 4], [4, 4], [5, 4], [6, 4],",
  62.     "      [2, 5], [3, 5], [4, 5], [5, 5], [6, 5],",
  63.     "      [5, 6], [6, 6],",
  64.     "      [5, 7], [6, 7], [7, 7], [8, 7], [9, 7], [10, 7], [11, 7], [12, 7],",
  65.     "      [5, 8], [6, 8], [7, 8], [8, 8], [9, 8], [10, 8], [11, 8], [12, 8],",
  66.     "      [2, 9], [3, 9], [4, 9], [5, 9], [6, 9], [7, 9], [11, 9], [12, 9]]; ",
  67.     "    ",
  68.     "_tiles['fence_vertical2'] = [[5, 1], [5, 2], [8, 3], [8, 4], [8, 5],",
  69.     "      [14, 6], [14, 7], [14, 8], [14, 9], [14, 10], [14, 11],",
  70.     "      [9, 10], [9, 11]];",
  71.     "",
  72.     "_tiles['fence_double2'] = [[6, 2], [7, 2], ",
  73.     "      [9, 5], [10, 5], [11, 5], [12, 5], [13, 5],",
  74.     "      [2, 7], [2, 11], [3, 11], [4, 11], [5, 11], [6, 11], [7, 11], ",
  75.     "      [8, 11], [9, 11], [10, 11], [11, 11], [12, 11], [13, 11]];",
  76.     "",
  77.     "_tiles['fence_left2'] = [[8, 2], [14, 5], [3, 7], [14, 11]];",
  78.     "_tiles['fence_right2'] = [[5, 2], [8, 5], [1, 7], [1, 11]];",
  79.     "",
  80.     "",
  81.     "RUR.fill_background('grass');",
  82.     "RUR.add_decorative_object('tulip', 14,12);",
  83.     "RUR.add_decorative_object('daisy', 10,1);",
  84.     "RUR.add_decorative_object('dandelion', 14,1);",
  85.     "",
  86.     "choice = RUR.randint(1,2).toString();",
  87.     "",
  88.     "if (choice == '1') {",
  89.     "    RUR.add_decorative_object('tulip', 7,10);",
  90.     "    RUR.add_decorative_object('daisy', 4,5);",
  91.     "    RUR.add_decorative_object('daisy', 2,12);",
  92.     "} else {",
  93.     "    RUR.add_decorative_object('daisy', 2,12);",
  94.     "    RUR.add_decorative_object('tulip', 10,4);",
  95.     "    RUR.add_decorative_object('tulip', 6,1);",
  96.     "}",
  97.     "",
  98.     "for (j=0; j<backgrounds.length; j++){",
  99.     "    name = backgrounds[j];",
  100.     "    for (i=0; i<_tiles[name+choice].length; i++) {",
  101.     "        x = _tiles[name+choice][i][0];",
  102.     "        y = _tiles[name+choice][i][1];",
  103.     "        RUR.add_background_tile(name, x, y);",
  104.     "    } ",
  105.     "}",
  106.     "",
  107.     "for (j=0; j<obstacles.length; j++){",
  108.     "    name = obstacles[j];",
  109.     "    for (i=0; i<_tiles[name+choice].length; i++) {",
  110.     "        x = _tiles[name+choice][i][0];",
  111.     "        y = _tiles[name+choice][i][1];",
  112.     "        RUR.add_obstacle(name, x, y);",
  113.     "    } ",
  114.     "}",
  115.     "",
  116.     "path = _tiles['path'+choice];",    
  117.       "len = path.length;",
  118.     "",
  119.     "i = RUR.randint(0, len-2);",
  120.     "pos_0 = path[i];",
  121.     "x0 = pos_0[0];",
  122.     "y0 = pos_0[1];",
  123.     "pos_1 = path[i+1];",
  124.     "x1 = pos_1[0];",
  125.     "y1 = pos_1[1];",
  126.     "",
  127.     "if (x0 == x1) {",
  128.     "    if (y1 == y0 + 1) {",
  129.     "        orientation= 'n';",
  130.     "    } else {",
  131.     "        orientation = 's';",
  132.     "    }",
  133.     "} else {",
  134.     "    if (x1 == x0 + 1) {",
  135.     "        orientation = 'e';",
  136.     "    } else {",
  137.     "        orientation = 'w';",
  138.     "    }",
  139.     "}",
  140.     "r = new UsedRobot(x0, y0, orientation);",
  141.     "RUR.give_object_to_robot('banana', 1);",
  142.     "",
  143.     "RUR.public.path = path.slice(i, len-1).concat(path.slice(0, i+1));"
  144.   ],
  145.   "post": [
  146.     "RUR.check_path(RUR.public['path'],",
  147.     "     {'failure':\"Reeborg no siguió la ruta dada!.\", ",
  148.     "      'success': 'Muy bien hecho!',",
  149.     "      'show_path': 'true', 'color': 'white'})"
  150.   ],
  151.   "small_tiles": false,
  152.   "rows": 12,
  153.   "cols": 14
  154. }
Advertisement
Add Comment
Please, Sign In to add comment