def draw(self): print(self.term.clear) self._fill_screen() outline_color = self.term.white_on_black title = "INFO PAGE " + str(self.current_screen + 1) + " OF " + str( self.num_screens) outline_editor(self.term, self.info_screen, title, outline_color) self.info_screen.draw()
def draw(self): print(self.term.clear) if self.is_editing or self.is_executing: outline_colors = self.term.white_on_black, self.term.black_on_white else: outline_colors = self.term.green_on_black, self.term.black_on_green outline_editor(self.term, self.stack_editor, title="STACK", color=self.term.white_on_black) self.stack_editor.draw() outline_editor(self.term, self.code_editor, title="DEEP ASSEMBLY", color=outline_colors[self.cursor[0] == 0]) self.code_editor.draw() outline_editor(self.term, self.output_editor, title="OUTPUT", color=self.term.white_on_black) self.output_editor.draw() outline_editor(self.term, self.info_editor, title="INFO", color=self.term.white_on_black) self.info_editor.draw() for i, button in enumerate(self.left_buttons): title = ["CUST1", "CUST2", "CUST3", "EXECUTE"][i] outline_editor(self.term, button, title=title, color=outline_colors[self.cursor == [1, i]]) button.draw() # Draw the execution arrow if self.is_executing: arrow_y = self.asm.pc + 1 else: arrow_y = 1 print( self.term.move_xy(self.STACK_WIDTH + 4, arrow_y) + self.term.red_on_black("→")) # Line numbers for y in range(self.CODE_HEIGHT): if y + 1 != arrow_y: print( self.term.move_xy(self.STACK_WIDTH + 3, y + 1) + self.term.white_on_black(str(y)))
def draw(self): print(self.term.clear) is_highlighted = self.cursor[1] == 0 outline_color = self.term.black_on_green if is_highlighted else self.term.green_on_black # outline_color = self.term.white_on_black outline_editor(self.term, self.info_button, "DEEPER BROS. (R) DIGITAL COMPUTER v0.23", outline_color) self.info_button.draw() for i, button in enumerate(self.puzzle_buttons): title = "PROGRAM " + str(i + 1) is_highlighted = (self.cursor[1] * 3) + self.cursor[0] == i + 3 outline_color = self.term.black_on_green if is_highlighted else self.term.green_on_black outline_editor(self.term, button, title, color=outline_color) button.draw()
def draw(self): # Clear the screen # TODO: Remove this for prettiness print(self.term.clear) if self.is_editing: outline_color = self.term.black_on_white if (self.cursor[0] == 0) else self.term.white_on_black else: outline_color = self.term.black_on_green if (self.cursor[0] == 0) else self.term.green_on_black outline_editor(self.term, self.code_editor, title="DEEPER MICROCODE", color=outline_color) self.code_editor.draw() outline_editor(self.term, self.info_editor, title="INFO", color=self.term.white_on_black) self.info_editor.draw() for i, editor, title in zip( range(len(self.reg_editors)), self.reg_editors, ["INPUT1", "INPUT2", "ADDR", "USER", "OUTPUT", "JUMP",], ): if self.is_editing or i in [3, 4, 5]: outline_color = ( self.term.black_on_white if (self.cursor == [1, i]) else self.term.white_on_black ) else: outline_color = ( self.term.black_on_green if (self.cursor == [1, i]) else self.term.green_on_black ) outline_editor(self.term, editor, title=title, color=outline_color) editor.draw()
def _begin_execution(self): if len(self.code_editor.highlighted_lines) != 0: return def output_callback(_, val): self.output.append(val) self.output_editor.contents = [ list(self._num_to_dec_bin(val)) for val in self.output ] ucodes = [editor.ucode for editor in self.ucode_sub_editors] self.asm = Asm(Asm.parse(self.code_editor.contents), ucodes, self.CODE_HEIGHT) self.asm.output_callback = output_callback total_steps = 0 test_case = 0 self.asm.stack = self.puzzle[2][test_case].copy() self.output = [] self.is_executing = True while self.is_executing: with self.term.cbreak(), self.term.hidden_cursor(): inp = self.term.inkey(esc_delay=self.esc_delay, timeout=0.2) if inp.code == self.term.KEY_ESCAPE: self.is_executing = False self.draw() break self.asm.step() self._fill_stack_editor() # Check for success, even when the prog is not in the process of finishing, beucase that way the # machine doesn't have to know when to stop. success = self.output == self.puzzle[3][test_case] if success: if len(self.puzzle[3]) <= test_case + 1: win_editor = NanoEditor(self.term, (30, 8), (32, 4)) win_editor.is_focused = False win_editor.contents = [ "Your code took " + str(total_steps) + " steps, and", "passed all of the test cases.", ] win_editor.contents = [ list(line) for line in win_editor.contents ] outline_editor(self.term, win_editor, title="SUCCESS!", color=self.term.black_on_green) win_editor.draw() with self.term.cbreak(), self.term.hidden_cursor(): _ = self.term.inkey(esc_delay=self.esc_delay) self.is_executing = False self.draw() break else: # Reset and start again! test_case += 1 self.asm.stack = self.puzzle[2][test_case].copy() self.asm.pc = 0 self.output = [] if self.CODE_HEIGHT <= self.asm.pc or all([ "".join(line).strip() == "" for line in self.code_editor.contents[self.asm.pc:] ]): self.is_executing = False self.draw() break total_steps += 1 self.draw()