(key)
| 168 | |
| 169 | # 处理用户输入 |
| 170 | def process_input(key): |
| 171 | global current_input, command_history |
| 172 | |
| 173 | if not game_active: |
| 174 | return |
| 175 | |
| 176 | if key == "Return": |
| 177 | if current_input in ["上", "下", "左", "右"]: |
| 178 | # 添加到历史记录 |
| 179 | command_history.append(current_input) |
| 180 | # 移动小红帽 |
| 181 | move_red_hood(current_input) |
| 182 | # 清空输入 |
| 183 | current_input = "" |
| 184 | else: |
| 185 | current_input = "" # 清空无效输入 |
| 186 | elif key == "BackSpace": |
| 187 | if current_input: |
| 188 | current_input = current_input[:-1] |
| 189 | elif key == "Escape": |
| 190 | current_input = "" # 清空输入 |
| 191 | elif key in ["上", "下", "左", "右"]: |
| 192 | current_input = key |
| 193 | elif key in ["w", "a", "s", "d"]: |
| 194 | # 支持WASD按键 |
| 195 | key_map = {"w": "上", "s": "下", "a": "左", "d": "右"} |
| 196 | current_input = key_map[key] |
| 197 | |
| 198 | display_input_box() |
| 199 | display_history() |
| 200 | |
| 201 | # 更新光标闪烁 |
| 202 | def update_cursor(): |
no test coverage detected