if a command is entered, return it; otherwise raise the exception Timeout
(next_fall_time)
| 123 | return result |
| 124 | |
| 125 | def get_command(next_fall_time): |
| 126 | "if a command is entered, return it; otherwise raise the exception Timeout" |
| 127 | while True: # until a timeout occurs or a command is found: |
| 128 | timeout = next_fall_time - time.time() |
| 129 | if timeout > 0.0: |
| 130 | (r, w, e) = select.select([ sys.stdin ], [], [], timeout) |
| 131 | else: |
| 132 | raise Timeout() |
| 133 | if sys.stdin not in r: # not input on stdin? |
| 134 | raise Timeout() |
| 135 | key = os.read(sys.stdin.fileno(), 1) |
| 136 | if key == 'j': |
| 137 | return left |
| 138 | elif key == 'l': |
| 139 | return right |
| 140 | elif key == 'k': |
| 141 | return turn |
| 142 | elif key == ' ': |
| 143 | return down |
| 144 | elif key == 'q': |
| 145 | return quit |
| 146 | else: # any other key: ignore |
| 147 | pass |
| 148 | |
| 149 | def place_block(block, coordinates, color): |
| 150 | "if the given block can be placed in the shaft at the given coordinates"\ |