def run(): """运行游戏""" # load setting first background = func.hex_to_rgb(func.setting["color"]["background"]) level = func.setting["level"] screenSize = (func.size * 50, func.size * 50) # 创建屏幕对象 pygame.init() screen = pygame.display.set_mode(screenSize) pygame.display.set_caption("Minesweeper") board = getBoard(level) print("Initial Board") func.printBoard(board) while True: checkEvents(board, screen) updateScreen(background, screen, board) status = func.isEnd(board, func.size * level) if status[0]: time.sleep(1) print("End Board") func.printBoard(board) displayEndBoard(background, screen, status[1])
def main(): #starts the timer to record length of run start_time = time.time() if len(sys.argv) == 1: print("No arguments passed. Exiting now.") return #this sets the file to the one given in the command line fileName = sys.argv[1] #check for valid file and automatically close file if os.path.exists(fileName): with open(fileName) as f: lines = f.read().split("\n") else: print("Filename does not exist. Exiting now.") return #parses the gameboard input wrigglerInput = lines[0] lineOneList = wrigglerInput.split() #check for invalid input if len(lineOneList) != 3: print( "This file has too many inputs for the length width and num of wrigglers. Exiting now." ) return if lineOneList[0].isdigit() == False: print("Invalid width puzzle") return if lineOneList[1].isdigit() == False: print("Invalid height puzzle") return if lineOneList[2].isdigit() == False: print("Invalid numWrigglers puzzle") return widthPuzzle = int(lineOneList[0]) heightPuzzle = int(lineOneList[1]) numWrigglers = int(lineOneList[2]) #initialize the gameboard gameBoard = [] row = [] for ro in range(heightPuzzle): x = lines[1 + ro] row = x.split() gameBoard.append(row) #check for invalid characters in board for row in gameBoard: for item in range(len(row)): if row[item] not in ("v", "D", ">", "R", "^", "U", "<", "L", "e", "x"): #check if its a number, if not exit if row[item].isdigit() == True: continue else: print("Invalid character in input. Exiting now.") return # for x in gameBoard: # print(*x) #the Problem is the bottom right corner problem = cla.Problem(gameBoard, widthPuzzle, heightPuzzle, numWrigglers, 20) #50 is max depth # perform a*gs on the gameBoard given and returns winning node solution1 = fun.astarSearch(problem) finalSol1 = fun.findPath(solution1) # print out the solution if solution1: for item in finalSol1: print(''.join(item)) fun.printBoard(solution1) print('{} '.format(time.time() - start_time)) print(str(fun.getPathCost(solution1))) else: print('Failure') print('{}'.format(time.time() - start_time))
print("\n\n\n\n") print( "This is the menus.\nEnter the number for the option you would like.\n" ) print("1. Print theater layout.") print("2. Purchase 1 or more seats.") print("3. Display theater statistics.") print("4. Reset theater.") print("5. Quit program.") # try: # collect user's decision on what function to use userChoice = str(input("\n\nWhich option would you like to select? ")) if userChoice == '1': # displays the layout of the theater functions.printBoard(NumberOfRows, NumberOfColumns, theater) continue elif userChoice == '2': # allows users to purchase seats theater = functions.pickMultipleSeats(NumberOfRows, NumberOfColumns, theater) continue elif userChoice == '3': # displays how many seats have been purchased, how many seats left, and theater revenue functions.statistics(NumberOfRows, NumberOfColumns, theater) continue elif userChoice == '4': # resets the layout and seats taken in the theater # makes sure that the user really wants to completely reset the program print( "Do you really want to do this. It will reset the entire theater")
import functions import mark1 import random import time board = functions.createNewBoard() print() turn = True while functions.isGameOver(board) == -1: if turn: functions.printBoard(board) print() row = int(input('Input Row: ')) assert row < functions.numRows assert row >= 0 col = int(input('Input Col: ')) print() assert col < functions.numRows assert col >= 0 assert functions.isEmpty(row, col, board) board[row][col] = True else: functions.printBoard(board) time.sleep(random.randint(0, 2)) print() board = mark1.play(board) turn = not turn functions.printBoard(board)