{
  "format": "tokbit",
  "version": 1,
  "name": "Pomalejší Simon",
  "main": [
    {
      "id": "u58",
      "kind": "call",
      "call": "hriste()"
    },
    {
      "id": "u59",
      "kind": "declare",
      "name": "rada",
      "type": "list[int]",
      "init": "[]",
      "comment": "Řada polí, kterou si hráč musí pamatovat."
    },
    {
      "id": "u60",
      "kind": "declare",
      "name": "skore",
      "type": "int",
      "init": "0"
    },
    {
      "id": "u61",
      "kind": "declare",
      "name": "hraje",
      "type": "bool",
      "init": "True"
    },
    {
      "id": "u62",
      "kind": "while",
      "condition": "hraje",
      "body": [
        {
          "id": "u63",
          "kind": "call",
          "call": "rada.append(choice([1, 2, 3, 4]))"
        },
        {
          "id": "u64",
          "kind": "call",
          "call": "ukaz_stav(\"Poslouchej...\", skore)"
        },
        {
          "id": "u65",
          "kind": "call",
          "call": "sleep(500)"
        },
        {
          "id": "u66",
          "kind": "call",
          "call": "prehraj(rada, max(300, 450 - len(rada) * 25))"
        },
        {
          "id": "u67",
          "kind": "call",
          "call": "ukaz_stav(\"Opakuj!\", skore)"
        },
        {
          "id": "u68",
          "kind": "assign",
          "target": "hraje",
          "value": "zopakuj(rada)"
        },
        {
          "id": "u69",
          "kind": "if",
          "condition": "hraje",
          "then": [
            {
              "id": "u70",
              "kind": "assign",
              "target": "skore",
              "value": "len(rada)"
            },
            {
              "id": "u71",
              "kind": "call",
              "call": "beep(1200, 60)"
            }
          ],
          "else": []
        }
      ],
      "comment": "Herní smyčka: každé kolo přidá do řady jedno pole, přehraje ji a hráč ji zopakuje."
    },
    {
      "id": "u72",
      "kind": "call",
      "call": "konec(skore)"
    }
  ],
  "functions": [
    {
      "name": "kresli_pole",
      "params": [
        {
          "name": "pole",
          "type": "int"
        },
        {
          "name": "sviti",
          "type": "bool"
        }
      ],
      "returnType": null,
      "blocks": [
        {
          "id": "u1",
          "kind": "declare",
          "name": "sloupce",
          "type": "list[int]",
          "init": "[16, 6, 26, 16]"
        },
        {
          "id": "u2",
          "kind": "declare",
          "name": "radky",
          "type": "list[int]",
          "init": "[4, 9, 9, 14]"
        },
        {
          "id": "u3",
          "kind": "declare",
          "name": "tmave",
          "type": "list[int]",
          "init": "[RED, GREEN, BLUE, BROWN]"
        },
        {
          "id": "u4",
          "kind": "declare",
          "name": "svetle",
          "type": "list[int]",
          "init": "[LIGHT_RED, LIGHT_GREEN, LIGHT_BLUE, YELLOW]"
        },
        {
          "id": "u5",
          "kind": "if",
          "condition": "sviti",
          "then": [
            {
              "id": "u6",
              "kind": "call",
              "call": "color(svetle[pole - 1])"
            }
          ],
          "else": [
            {
              "id": "u7",
              "kind": "call",
              "call": "color(tmave[pole - 1])"
            }
          ]
        },
        {
          "id": "u8",
          "kind": "for",
          "variable": "r",
          "range": "4",
          "body": [
            {
              "id": "u9",
              "kind": "call",
              "call": "at(sloupce[pole - 1], radky[pole - 1] + r)"
            },
            {
              "id": "u10",
              "kind": "output",
              "values": "\"########\"",
              "newline": false
            }
          ]
        },
        {
          "id": "u11",
          "kind": "call",
          "call": "color(WHITE)"
        },
        {
          "id": "u12",
          "kind": "call",
          "call": "at(sloupce[pole - 1] + 3, radky[pole - 1] + 1)"
        },
        {
          "id": "u13",
          "kind": "output",
          "values": "\" \" + str(pole) + \" \"",
          "newline": false
        }
      ],
      "comment": "Nakreslí jedno ze čtyř polí ze znaků; rozsvícené světlejší barvou. Pole 1 nahoře, 2 vlevo, 3 vpravo, 4 dole."
    },
    {
      "name": "rozsvit",
      "params": [
        {
          "name": "pole",
          "type": "int"
        },
        {
          "name": "ms",
          "type": "int"
        }
      ],
      "returnType": null,
      "blocks": [
        {
          "id": "u14",
          "kind": "declare",
          "name": "tony",
          "type": "list[str]",
          "init": "[\"C4\", \"E4\", \"G4\", \"C5\"]"
        },
        {
          "id": "u15",
          "kind": "call",
          "call": "kresli_pole(pole, True)"
        },
        {
          "id": "u16",
          "kind": "call",
          "call": "note(tony[pole - 1], ms)",
          "comment": "Každé pole má svůj tón; note počká, než dohraje."
        },
        {
          "id": "u17",
          "kind": "call",
          "call": "kresli_pole(pole, False)"
        }
      ],
      "comment": "Rozsvítí pole a zahraje jeho tón."
    },
    {
      "name": "hriste",
      "params": [],
      "returnType": null,
      "blocks": [
        {
          "id": "u18",
          "kind": "call",
          "call": "background(BLACK)"
        },
        {
          "id": "u19",
          "kind": "call",
          "call": "border(DARK_GREY)"
        },
        {
          "id": "u20",
          "kind": "call",
          "call": "cls()"
        },
        {
          "id": "u21",
          "kind": "call",
          "call": "color(YELLOW)"
        },
        {
          "id": "u22",
          "kind": "call",
          "call": "at(15, 1)"
        },
        {
          "id": "u23",
          "kind": "output",
          "values": "\"S I M O N\"",
          "newline": false
        },
        {
          "id": "u24",
          "kind": "for",
          "variable": "p",
          "range": "4",
          "body": [
            {
              "id": "u25",
              "kind": "call",
              "call": "kresli_pole(p + 1, False)"
            }
          ]
        },
        {
          "id": "u26",
          "kind": "call",
          "call": "color(GREY)"
        },
        {
          "id": "u27",
          "kind": "call",
          "call": "at(1, 21)"
        },
        {
          "id": "u28",
          "kind": "output",
          "values": "\"Zopakuj řadu: klávesy 1 až 4, šipky.\"",
          "newline": false
        }
      ],
      "comment": "Úvodní obrazovka: nadpis, čtyři pole a nápověda."
    },
    {
      "name": "ukaz_stav",
      "params": [
        {
          "name": "text",
          "type": "str"
        },
        {
          "name": "skore",
          "type": "int"
        }
      ],
      "returnType": null,
      "blocks": [
        {
          "id": "u29",
          "kind": "call",
          "call": "color(WHITE)"
        },
        {
          "id": "u30",
          "kind": "call",
          "call": "at(1, 23)"
        },
        {
          "id": "u31",
          "kind": "output",
          "values": "text + \"   \" + \"Skóre: \" + str(skore) + \"      \"",
          "newline": false
        }
      ],
      "comment": "Dole stav hry: co se děje a skóre."
    },
    {
      "name": "prehraj",
      "params": [
        {
          "name": "rada",
          "type": "list[int]"
        },
        {
          "name": "ms",
          "type": "int"
        }
      ],
      "returnType": null,
      "blocks": [
        {
          "id": "u32",
          "kind": "for",
          "variable": "i",
          "range": "len(rada)",
          "body": [
            {
              "id": "u33",
              "kind": "call",
              "call": "rozsvit(rada[i], ms)"
            },
            {
              "id": "u34",
              "kind": "call",
              "call": "sleep(ms // 3)"
            }
          ]
        }
      ],
      "comment": "Přehraje celou řadu; ms je délka jednoho rozsvícení (zkracuje se, hra zrychluje)."
    },
    {
      "name": "pole_z_klavesy",
      "params": [
        {
          "name": "k",
          "type": "str"
        }
      ],
      "returnType": "int",
      "blocks": [
        {
          "id": "u35",
          "kind": "declare",
          "name": "klavesy",
          "type": "list[str]",
          "init": "[\"1\", \"2\", \"3\", \"4\"]"
        },
        {
          "id": "u36",
          "kind": "declare",
          "name": "sipky",
          "type": "list[str]",
          "init": "[\"up\", \"left\", \"right\", \"down\"]"
        },
        {
          "id": "u37",
          "kind": "for",
          "variable": "i",
          "range": "4",
          "body": [
            {
              "id": "u38",
              "kind": "if",
              "condition": "k == klavesy[i] or k == sipky[i]",
              "then": [
                {
                  "id": "u39",
                  "kind": "return",
                  "value": "i + 1"
                }
              ],
              "else": []
            }
          ]
        },
        {
          "id": "u40",
          "kind": "return",
          "value": "0"
        }
      ],
      "comment": "Číslo pole podle klávesy (1–4 nebo šipka), jiná klávesa 0."
    },
    {
      "name": "cekej_na_pole",
      "params": [],
      "returnType": "int",
      "blocks": [
        {
          "id": "u41",
          "kind": "declare",
          "name": "pole",
          "type": "int",
          "init": "0"
        },
        {
          "id": "u42",
          "kind": "while",
          "condition": "pole == 0",
          "body": [
            {
              "id": "u43",
              "kind": "assign",
              "target": "pole",
              "value": "pole_z_klavesy(key())"
            },
            {
              "id": "u44",
              "kind": "call",
              "call": "sleep(20)"
            }
          ],
          "comment": "key() nečeká: ptáme se dokola, dokud hráč nezmáčkne platnou klávesu."
        },
        {
          "id": "u45",
          "kind": "return",
          "value": "pole"
        }
      ],
      "comment": "Počká, až hráč vybere pole."
    },
    {
      "name": "zopakuj",
      "params": [
        {
          "name": "rada",
          "type": "list[int]"
        }
      ],
      "returnType": "bool",
      "blocks": [
        {
          "id": "u46",
          "kind": "for",
          "variable": "i",
          "range": "len(rada)",
          "body": [
            {
              "id": "u47",
              "kind": "declare",
              "name": "pole",
              "type": "int",
              "init": "cekej_na_pole()"
            },
            {
              "id": "u48",
              "kind": "call",
              "call": "rozsvit(pole, 200)"
            },
            {
              "id": "u49",
              "kind": "if",
              "condition": "pole != rada[i]",
              "then": [
                {
                  "id": "u50",
                  "kind": "call",
                  "call": "beep(110, 500)"
                },
                {
                  "id": "u51",
                  "kind": "return",
                  "value": "False"
                }
              ],
              "else": [],
              "comment": "Porovnání vstupu s pamětí: i-tá klávesa musí sedět s i-tým prvkem řady."
            }
          ]
        },
        {
          "id": "u52",
          "kind": "return",
          "value": "True"
        }
      ],
      "comment": "Hráč zopakuje řadu; při první chybě vrátí False."
    },
    {
      "name": "konec",
      "params": [
        {
          "name": "skore",
          "type": "int"
        }
      ],
      "returnType": null,
      "blocks": [
        {
          "id": "u53",
          "kind": "call",
          "call": "color(LIGHT_RED)"
        },
        {
          "id": "u54",
          "kind": "call",
          "call": "at(1, 23)"
        },
        {
          "id": "u55",
          "kind": "output",
          "values": "\"Chyba! Zapamatoval sis řadu dlouhou\" + \" \" + str(skore) + \".\"",
          "newline": false
        },
        {
          "id": "u56",
          "kind": "for",
          "variable": "i",
          "range": "4",
          "body": [
            {
              "id": "u57",
              "kind": "call",
              "call": "beep(440 - i * 80, 120)"
            }
          ]
        }
      ],
      "comment": "Konec hry: skóre a sestupné tóny."
    }
  ],
  "comment": "Řešení úlohy „Pomalejší hra“: Ať se hra nezrychluje pod 300 ms na pole. Najdi místo, kde se délka rozsvícení počítá."
}
