{
  "format": "tokbit",
  "version": 1,
  "name": "Hangman with my words",
  "main": [
    {
      "id": "u32",
      "kind": "declare",
      "name": "words",
      "type": "list[str]",
      "init": "[\"PROGRAM\", \"MONITOR\", \"DIAGRAM\", \"LOOP\", \"FUNCTION\", \"ROBOT\", \"SCREEN\", \"INTERNET\", \"TABLET\", \"KEYBOARD\", \"MOUSE\", \"VARIABLE\", \"CONDITION\", \"PIXEL\", \"TOKBIT\"]"
    },
    {
      "id": "u33",
      "kind": "declare",
      "name": "lower",
      "type": "str",
      "init": "\"abcdefghijklmnopqrstuvwxyz\""
    },
    {
      "id": "u34",
      "kind": "declare",
      "name": "upper",
      "type": "str",
      "init": "\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\""
    },
    {
      "id": "u35",
      "kind": "declare",
      "name": "word",
      "type": "str",
      "init": "choice(words)"
    },
    {
      "id": "u36",
      "kind": "declare",
      "name": "tried",
      "type": "str",
      "init": "\"\""
    },
    {
      "id": "u37",
      "kind": "declare",
      "name": "message",
      "type": "str",
      "init": "\"\""
    },
    {
      "id": "u38",
      "kind": "declare",
      "name": "mask",
      "type": "str",
      "init": "\"\""
    },
    {
      "id": "u39",
      "kind": "declare",
      "name": "p",
      "type": "str",
      "init": "\"\""
    },
    {
      "id": "u40",
      "kind": "declare",
      "name": "misses",
      "type": "int",
      "init": "0"
    },
    {
      "id": "u41",
      "kind": "declare",
      "name": "guessed",
      "type": "bool",
      "init": "False"
    },
    {
      "id": "u42",
      "kind": "while",
      "condition": "misses < 7 and not guessed",
      "body": [
        {
          "id": "u43",
          "kind": "call",
          "call": "cls()"
        },
        {
          "id": "u44",
          "kind": "call",
          "call": "color(WHITE)"
        },
        {
          "id": "u45",
          "kind": "call",
          "call": "at(2, 0)"
        },
        {
          "id": "u46",
          "kind": "output",
          "values": "\"HANGMAN\"",
          "newline": false
        },
        {
          "id": "u47",
          "kind": "call",
          "call": "gallows(misses)"
        },
        {
          "id": "u48",
          "kind": "assign",
          "target": "mask",
          "value": "\"\""
        },
        {
          "id": "u49",
          "kind": "for",
          "variable": "i",
          "range": "len(word)",
          "body": [
            {
              "id": "u50",
              "kind": "if",
              "condition": "word[i] in tried",
              "then": [
                {
                  "id": "u51",
                  "kind": "assign",
                  "target": "mask",
                  "value": "mask + word[i] + \" \""
                }
              ],
              "else": [
                {
                  "id": "u52",
                  "kind": "assign",
                  "target": "mask",
                  "value": "mask + \"_ \""
                }
              ]
            }
          ],
          "comment": "The mask shows guessed letters and underscores for the rest."
        },
        {
          "id": "u53",
          "kind": "call",
          "call": "color(YELLOW)"
        },
        {
          "id": "u54",
          "kind": "call",
          "call": "at(2, 12)"
        },
        {
          "id": "u55",
          "kind": "output",
          "values": "mask",
          "newline": false
        },
        {
          "id": "u56",
          "kind": "call",
          "call": "color(WHITE)"
        },
        {
          "id": "u57",
          "kind": "call",
          "call": "at(2, 14)"
        },
        {
          "id": "u58",
          "kind": "output",
          "values": "\"Tried: \" + tried",
          "newline": false
        },
        {
          "id": "u59",
          "kind": "call",
          "call": "color(LIGHT_RED)"
        },
        {
          "id": "u60",
          "kind": "call",
          "call": "at(2, 16)"
        },
        {
          "id": "u61",
          "kind": "output",
          "values": "message",
          "newline": false
        },
        {
          "id": "u62",
          "kind": "call",
          "call": "color(WHITE)"
        },
        {
          "id": "u63",
          "kind": "assign",
          "target": "guessed",
          "value": "\"_\" not in mask"
        },
        {
          "id": "u64",
          "kind": "if",
          "condition": "not guessed",
          "then": [
            {
              "id": "u65",
              "kind": "call",
              "call": "at(2, 18)"
            },
            {
              "id": "u66",
              "kind": "input",
              "target": "p",
              "prompt": "Letter:"
            },
            {
              "id": "u67",
              "kind": "if",
              "condition": "len(p) == 1",
              "then": [
                {
                  "id": "u68",
                  "kind": "for",
                  "variable": "i",
                  "range": "26",
                  "body": [
                    {
                      "id": "u69",
                      "kind": "if",
                      "condition": "lower[i] == p",
                      "then": [
                        {
                          "id": "u70",
                          "kind": "assign",
                          "target": "p",
                          "value": "upper[i]"
                        }
                      ],
                      "else": []
                    }
                  ]
                }
              ],
              "else": [],
              "comment": "Turns a lowercase letter into uppercase; the words are uppercase."
            },
            {
              "id": "u71",
              "kind": "if",
              "condition": "len(p) != 1 or p not in upper",
              "then": [
                {
                  "id": "u72",
                  "kind": "assign",
                  "target": "message",
                  "value": "\"Type one letter A to Z.\""
                }
              ],
              "else": [
                {
                  "id": "u73",
                  "kind": "if",
                  "condition": "p in tried",
                  "then": [
                    {
                      "id": "u74",
                      "kind": "assign",
                      "target": "message",
                      "value": "\"You already tried that letter.\""
                    }
                  ],
                  "else": [
                    {
                      "id": "u75",
                      "kind": "assign",
                      "target": "tried",
                      "value": "tried + p"
                    },
                    {
                      "id": "u76",
                      "kind": "assign",
                      "target": "message",
                      "value": "\"\""
                    },
                    {
                      "id": "u77",
                      "kind": "if",
                      "condition": "p not in word",
                      "then": [
                        {
                          "id": "u78",
                          "kind": "assign",
                          "target": "misses",
                          "value": "misses + 1"
                        },
                        {
                          "id": "u79",
                          "kind": "call",
                          "call": "beep(196, 150)"
                        }
                      ],
                      "else": [
                        {
                          "id": "u80",
                          "kind": "call",
                          "call": "beep(880, 60)"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "else": []
        }
      ]
    },
    {
      "id": "u81",
      "kind": "if",
      "condition": "guessed",
      "then": [
        {
          "id": "u82",
          "kind": "call",
          "call": "color(LIGHT_GREEN)"
        },
        {
          "id": "u83",
          "kind": "call",
          "call": "at(2, 18)"
        },
        {
          "id": "u84",
          "kind": "output",
          "values": "\"You won! The word is complete.\"",
          "newline": false
        }
      ],
      "else": [
        {
          "id": "u85",
          "kind": "call",
          "call": "cls()"
        },
        {
          "id": "u86",
          "kind": "call",
          "call": "gallows(7)"
        },
        {
          "id": "u87",
          "kind": "call",
          "call": "color(LIGHT_RED)"
        },
        {
          "id": "u88",
          "kind": "call",
          "call": "at(2, 18)"
        },
        {
          "id": "u89",
          "kind": "output",
          "values": "\"Hanged! The word was \" + word",
          "newline": false
        }
      ]
    },
    {
      "id": "u90",
      "kind": "call",
      "call": "color(WHITE)"
    },
    {
      "id": "u91",
      "kind": "call",
      "call": "at(0, 20)"
    }
  ],
  "functions": [
    {
      "name": "gallows",
      "params": [
        {
          "name": "misses",
          "type": "int"
        }
      ],
      "returnType": null,
      "blocks": [
        {
          "id": "u1",
          "kind": "call",
          "call": "color(ORANGE)"
        },
        {
          "id": "u2",
          "kind": "if",
          "condition": "misses >= 1",
          "then": [
            {
              "id": "u3",
              "kind": "call",
              "call": "at(2, 9)"
            },
            {
              "id": "u4",
              "kind": "output",
              "values": "\"==========\"",
              "newline": false
            }
          ],
          "else": []
        },
        {
          "id": "u5",
          "kind": "if",
          "condition": "misses >= 2",
          "then": [
            {
              "id": "u6",
              "kind": "for",
              "variable": "y",
              "range": "2, 9",
              "body": [
                {
                  "id": "u7",
                  "kind": "call",
                  "call": "at(4, y)"
                },
                {
                  "id": "u8",
                  "kind": "output",
                  "values": "\"|\"",
                  "newline": false
                }
              ]
            }
          ],
          "else": []
        },
        {
          "id": "u9",
          "kind": "if",
          "condition": "misses >= 3",
          "then": [
            {
              "id": "u10",
              "kind": "call",
              "call": "at(4, 1)"
            },
            {
              "id": "u11",
              "kind": "output",
              "values": "\"+-----+\"",
              "newline": false
            }
          ],
          "else": []
        },
        {
          "id": "u12",
          "kind": "if",
          "condition": "misses >= 4",
          "then": [
            {
              "id": "u13",
              "kind": "call",
              "call": "at(10, 2)"
            },
            {
              "id": "u14",
              "kind": "output",
              "values": "\"|\"",
              "newline": false
            }
          ],
          "else": []
        },
        {
          "id": "u15",
          "kind": "if",
          "condition": "misses >= 5",
          "then": [
            {
              "id": "u16",
              "kind": "call",
              "call": "at(10, 3)"
            },
            {
              "id": "u17",
              "kind": "output",
              "values": "\"O\"",
              "newline": false
            }
          ],
          "else": []
        },
        {
          "id": "u18",
          "kind": "if",
          "condition": "misses >= 6",
          "then": [
            {
              "id": "u19",
              "kind": "call",
              "call": "at(10, 4)"
            },
            {
              "id": "u20",
              "kind": "output",
              "values": "\"|\"",
              "newline": false
            },
            {
              "id": "u21",
              "kind": "call",
              "call": "at(10, 5)"
            },
            {
              "id": "u22",
              "kind": "output",
              "values": "\"|\"",
              "newline": false
            }
          ],
          "else": []
        },
        {
          "id": "u23",
          "kind": "if",
          "condition": "misses >= 7",
          "then": [
            {
              "id": "u24",
              "kind": "call",
              "call": "at(9, 4)"
            },
            {
              "id": "u25",
              "kind": "output",
              "values": "\"/\"",
              "newline": false
            },
            {
              "id": "u26",
              "kind": "call",
              "call": "at(11, 4)"
            },
            {
              "id": "u27",
              "kind": "output",
              "values": "\"\\\\\"",
              "newline": false
            },
            {
              "id": "u28",
              "kind": "call",
              "call": "at(9, 6)"
            },
            {
              "id": "u29",
              "kind": "output",
              "values": "\"/\"",
              "newline": false
            },
            {
              "id": "u30",
              "kind": "call",
              "call": "at(11, 6)"
            },
            {
              "id": "u31",
              "kind": "output",
              "values": "\"\\\\\"",
              "newline": false
            }
          ],
          "else": []
        }
      ],
      "comment": "Draws the gallows by the number of mistakes; each mistake adds a part."
    }
  ],
  "comment": "Solution to the task “Your own words”: Add five words of your own to the list. They must be in capitals – why?"
}
