def run(self, run_until_aced=True): while True: wrong = {} for question in self.questions: # question.set_feedback(lambda their_answer: wrong.update({self.questions.index(question), their_answer})) question.set_feedback( lambda their_answer, correct_answers: wrong.update({ self.questions.index(question): (their_answer, correct_answers) })) was_correct = question.run() for question in wrong.items(): number = question[0] + 1 their_wrong_answer = question[1][0] correct_answer = question[1][1][0] print() print("Question #" + str(number)) print(" Wrong answer: " + their_wrong_answer) print("Correct answer: " + correct_answer) score = len(self.questions) - len(wrong) print() print("You got " + str(score) + " out of " + str(len(self.questions)) + ", " + str(int(score / int(len(self.questions)) * 100)) + "%") if run_until_aced and score != len(self.questions): print() input("Press enter to retry") cls() else: input("Press enter to continue") break
def play(self) -> Player: """ Celý jeden průběh hry. """ cls() print("Povolené akce:\n") self.display_available_actions(self.active) print() while not self.winner: self.play_turn() self.end_turn() return self.winner
def draw(): # Pripravit barevnou verzi. colored = arena.replace('#', bg.lightblack + ' ' + bg.default) colored = colored.replace(direction, fg.lightyellow + direction + fg.default) colored = colored.replace('!', fg.lightred + '!' + fg.default) # Vymazat obrazovku. cls() # Zobrazit nadpis a herni plochu. print(' ' * 11, 'Robot!') print(colored)
def level2(): l2i = MyThread(L2Text) l2i.start() cls() set_title("CLIME - Level 2") if OS == windows: for exercise in WL2Exercises: exercise.run() WQuiz2.run() elif OS == linux: for exercise in LL2Exercises: exercise.run() LQuiz2.run() l2i.stop() level3()
def level1(): l1i = MyThread(L1Text) l1i.start() cls() set_title("CLIME - Level 1") if OS == windows: for exercise in WL1Exercises: exercise.run() WQuiz1.run() elif OS == linux: for exercise in LL1Exercises: exercise.run() LQuiz1.run() l1i.stop() level2()
def main(): set_title("AlphaMancala v1.0"); startingPosition = [0, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4, 4, 4, 4] node = Node(startingPosition, True) while(True): cls() printBoard(node.board) if(node.playerTurn): print("\nTurn: player") getTimedBestMove(node, 2, 5, 20) else: print("\nTurn: computer") move = input("move: ") move = int(move) node.makeMove(move)
def main_menu(): cls() set_title("CLIME - Main Menu") print() print(color_random[0] + climeLogo + fx.end) print(spacer + "Welcome to " + color_random[0] + "Command Line Interface Made Easy" + fx.end) print() print(spacer + fg.yellow + " 1" + fg.white + ") Start" + fx.end) print(spacer + fg.yellow + "99" + fg.white + ") Exit" + fx.end) choice = get_choice(["1", "99", "0"]) if choice == "1": start() elif choice == "99" or choice == "0": exit_clime()
def level3(): l3i = MyThread(L3Text) l3i.start() cls() set_title("CLIME - Level 3") if OS == windows: for exercise in WL3Exercises: exercise.run() WQuiz2.run() elif OS == linux: for exercise in LL3Exercises: exercise.run() LQuiz1.run() l3i.stop() cls() print() print(spacer + color_random[0] + "End of program." + fx.end) time.sleep(1) main_menu()
def select_os(): cls() set_title("CLIME - Select an Operating System") print() print(color_random[0] + spacer + "Select the operating system you would like to learn:\n" + fx.end) print(spacer + fg.yellow + " 1" + fg.white + ") Linux" + fx.end) print(spacer + fg.yellow + " 2" + fg.white + ") Windows" + fx.end) print(spacer + fg.yellow + "99" + fg.white + ") Main Menu" + fx.end) choice = get_choice(["1", "2", "99"]) global OS if choice == "1": OS = linux level_select() elif choice == "2": OS = windows level_select() elif choice == "99": main_menu()
def level_select(): cls() set_title("CLIME - Level Select") print(color_random[0] + "\n" + spacer + "Level Selection:\n" + fx.end) print(spacer + fg.yellow + " 1" + fg.white + ") Level 1: description" + fx.end) print(spacer + fg.yellow + " 2" + fg.white + ") Level 2: description" + fx.end) print(spacer + fg.yellow + " 3" + fg.white + ") Level 3: description" + fx.end) print(spacer + fg.yellow + "99" + fg.white + ") Main Menu" + fx.end) choice = get_choice(["1", "2", "3", "99"]) if choice == "1": level1() elif choice == "2": level2() elif choice == "3": level3() elif choice == "99": main_menu()
def run(self): cls() print() print(spacer + self.prompt) if len(self.choices) > 0: print() for choice in self.choices: option = chr(ord('A') + self.choices.index(choice)) print(spacer + fg.yellow + option + fg.white + ") " + choice + fx.end) print() while True: given = input(climePrompt) answer = None if len(self.choices) > 0: if len(given) != 1: print("You need to give a single letter answer.") continue answer = ord(given.upper()) - ord('A') if answer < 0 or answer >= len(self.choices): print("That is not a valid answer.") continue answer = self.choices[answer] else: answer = given correct = answer in self.answers if not correct: if self.feedback is not None: if self.feedback.__code__.co_argcount == 1: self.feedback(answer) else: self.feedback(answer, self.answers) if self.ask_until_correct: continue print() return correct
def move(): global arena, won pos = arena.index(direction) if direction == '^': newpos = pos - cols elif direction == 'v': newpos = pos + cols elif direction == '<': newpos = pos - 1 elif direction == '>': newpos = pos + 1 assert arena[newpos] != '#', 'cannot walk into a wall' if arena[newpos] == '!': cls() print('Congratulations, you have won!') won = True arena = arena[:pos] + ' ' + arena[pos + 1:] arena = arena[:newpos] + direction + arena[newpos + 1:]
('hvy-metal:', ProgressBar(theme='heavy_metal')), ('segmented:', ProgressBar(icons='segmented')), ('triangles:', ProgressBar(theme='shaded', icons='triangles')), ('solid, expanded:\n', ProgressBar(theme='solid', expand=True)), ('solid mono:', ProgressBar(theme='solid', styles='amber_mono')), ('high-def:', HiDefProgressBar(styles='greyen')), ('dies:', HiDefProgressBar(theme='dies', # clear_left=4, partial_chars='⚀⚁⚂⚃⚄⚅', partial_char_extra_style=None)), ] # print each in progress from console.utils import cls cls() with sc.hidden_cursor(): try: for i in range(100): print() for label, bar in bars: print(f' {label:12}', bar(i), sep='') #, end='', flush=True) sleep(.1) if i < 99: cls() sleep(2) except KeyboardInterrupt: pass
def start(): cls() set_title("CLIME - Start") select_os() level_select()
def exit_clime(): print() print(spacer + color_random[0] + "Thanks for using CLIME!" + fx.end) time.sleep(0.5) cls() sys.exit()