def startScreen(): while True: try: clear() print("\n Welcome to Chess: Python Edition!\n\n") n = input(" How many players for this game?\n (0, 1, or 2): ") except ValueError: print("\n Please choose an option.") print("\n Press Enter to continue.") input("") continue if (not n.isdigit()) or (int(n) < 0) or (int(n) > 2): print("\n Please choose an option.") print("\n Press Enter to continue.") input("") continue else: break globVar.numPlayers = int(n) if globVar.numPlayers < 2: random.seed(a=None) if globVar.numPlayers == 0: globVar.noPlayers = True speedMenu() board.populate() return True
def startScreen(): board.populate() if not globVar.show_all_menus: globVar.ready = True return True title = "Welcome to Chess: Python Edition!\n\n" + " How many players for this game?\n (0, 1, or 2)" options = [] n = validOption(0, 2, title, options) if globVar.simulation: clear() print("Running...") return True globVar.numPlayers = int(n) if globVar.numPlayers < 2: random.seed(a=None) # aggressiveMenu() menus_driver("aggressive") if globVar.numPlayers == 0: globVar.noPlayers = True # speedMenu() menus_driver("speed") # formatMenu() menus_driver("format") globVar.ready = True return True
def run(total_num_moves, games_played, W_v, b_v, lock, i, num): if platform.system() == "Windows": lock.acquire() progress(games_played, num) lock.release() board.populate() set_globals() playing = True while playing: if (globVar.playerCount % 2) == 0: globVar.player = "W" else: globVar.player = "b" Player.turn() globVar.playerCount += 1 playing = not utils.checkWin() total_num_moves.value += 1 games_played.value += 1 W_v.value += W_victories b_v.value += b_victories lock.acquire() progress(games_played, num) draw_score(i, W_v, b_v, total_num_moves, games_played, num) lock.release()
def loadSave(): clear() print("\n Save detected. Load previous game? ", end="") if yesNo(): board.populate() read.readSave() else: # board.populate() startScreen()
def choices(choice): if choice.upper() == "Q": quit() elif choice.upper() == "R": board.populate() clear() print("\n The board has been reset.") pressEnter() elif choice.upper() == "L": utils.readSave() clear() print("\n The last save has been loaded.") pressEnter()
def readBoard(save): board.populate() k = 0 sqrArray = save.readline().split(',') for i in range(8): for j in range(8): ps = sqrArray[k] if ps == "True": pieceStatus = True else: pieceStatus = False k += 1 board.Grid(i, j).color = sqrArray[k] k += 1 board.Grid(i, j).row = int(sqrArray[k]) k += 1 board.Grid(i, j).col = int(sqrArray[k]) k += 1 board.Grid(i, j).des = False k += 1 board.Grid(i, j).option = int(sqrArray[k]) k += 1 type = sqrArray[k] k += 1 color = sqrArray[k] k += 1 selected = False k += 1 label = int(sqrArray[k]) k += 1 row = int(sqrArray[k]) k += 1 col = int(sqrArray[k]) k += 1 pc = pieceConstructor(color, type) board.Grid(i, j).piece = pc board.Grid(i, j).piece.selected = selected board.Grid(i, j).piece.label = label board.Grid(i, j).piece.row = row board.Grid(i, j).piece.col = col board.Grid(i, j).pieceStatus = pieceStatus
def choices(choice): if choice.upper() == "Q": quit() return True elif choice.upper() == "R": board.populate() clear() print("\n The board has been reset.") pressEnter() return True elif choice.upper() == "L": utils.readSave() clear() print("\n The last save has been loaded.") pressEnter() return True elif choice.upper() == "S": simulateMenu() return True else: return False
def state(): board.populate() utils.spawn_new() while not utils.check_loss(): # print(utils.elapsed_time()) # thresh = round(utils.elapsed_time() % globs.delay, 2) # print(thresh) # if (utils.elapsed_time() % globs.delay == 0): t = str(utils.elapsed_time()) # print(t) drop_nums = globs.drop_lists[globs.current_level - 1] if (any(x in t for x in drop_nums)): Canvas.draw_board() if (not globs.current_piece.collision()): globs.current_piece.move_down() utils.insert_piece(globs.current_piece) else: # utils.reset_piece(globs.preview_pc) utils.de_select_piece(globs.current_piece) utils.clear_board() # print("DONE CLEARING") # time.sleep(1) utils.spawn_new() # print("SPAWNED") globs.num_placed += 1 utils.check_level() # time.sleep(0.1) # give player 0.2 seconds to make a last-second adjustment if globs.current_piece.collision() and not globs.dropped: Canvas.draw_board() kb.actions(kb.get_dir(0.2)) # give player 0.5 seconds to slide piece once made contact # TODO set timer, only stop accepting input once timer runs out # reset timer when key is pressed else: kb.actions(kb.get_dir(0.05))