Minor improvements all over the place

master
BodgeMaster 2022-11-06 06:22:20 +01:00
parent b8b23249a0
commit c00f788d27
1 changed files with 15 additions and 3 deletions

View File

@ -15,7 +15,7 @@
# version 3 along with this program.
# If not, see https://www.gnu.org/licenses/gpl-3.0.en.html
import re
import re, time
debug_mode = False
@ -51,6 +51,8 @@ goal = '$'
cursor_position = [0, 0]
command_delay = 0.3
def clear_field():
field = [
" _________________ ",
@ -66,6 +68,7 @@ def clear_field():
]
def draw_field():
print("\033[2J\033[H")
for row in range(len(field)):
for column in range(len(field[row])):
if column==cursor_position[0] and row==cursor_position[1]:
@ -85,6 +88,7 @@ def run_code(parsed_code):
if not result=="":
return result
draw_field()
time.sleep(command_delay)
return ""
@ -136,7 +140,7 @@ def condition_on_apple(inverted):
# return value: "" or error message
def command_step():
if condition_in_front_of_wall(False):
return "You walked into a wall."
return "You stepped into a wall."
if condition_facing_north(False):
cursor_position[1] = cursor_position[1]-1
@ -334,7 +338,7 @@ def parse_code(code, allowed_commands, allowed_conditions, unformatted_code=True
elif next_command == "take":
parsed_code[0].append(command_take)
elif next_command == "repeat":
return [[], [], next_space, "Syntax error: Condition missing", code]
return [[], [], next_space, "Syntax error: Number of repetitions missing", code]
elif next_command == "while":
return [[], [], next_space, "Syntax error: Condition missing", code]
elif next_command == "if":
@ -476,5 +480,13 @@ def evaluate_parser_result(parsed_code):
#TODO: check if goal reached
return "Success!"
def debug_setup():
global cursor_position
cursor_position = [1,1]
global cursor_current
cursor_current = cursor_south
draw_field()
if __name__ == "__main__":
pass