Пример #1
0
    def mainMenu(self):
        self.header("Minesweeper")

        inputTool = InputTool({"2": "Play", "3": "Help", "4": "Settings", "5": "High Scores", "6": "Exit"})
        self.screen = inputTool.getInput()

        # set up and reset the game
        if (self.screen == "2"):
            self.firstTurn = True

            if (self.difficulty == "1"):
                self.num_rows = 9
                self.num_cols = 9
                self.num_mines = 10
                self.mines_remaining = 10
            elif (self.difficulty == "2"):
                self.num_rows = 12
                self.num_cols = 12
                self.num_mines = 24
                self.mines_remaining = 24
            elif (self.difficulty == "3"):
                self.num_rows = 16
                self.num_cols = 16
                self.num_mines = 40
                self.mines_remaining = 40

            self.game_board = GameBoard(self.num_rows, self.num_cols, self.num_mines)
            self.game_board.createBoard()
            self.game_board.placeMines()
            self.game_board.fillBoard()

            self.start_time = time.time()
Пример #2
0
    def loseScreen(self):
        self.header("Game Over!")  
        self.game_board.revealMines()

        print(self.game_board)

        inputTool = InputTool({"1": "Main Menu", "6": "Exit"})
        self.screen = inputTool.getInput()
Пример #3
0
    def highScoreScreen(self):
        self.header("High Scores")

        hs = HighScores().outputData()

        for i, s in enumerate(hs):
            name, score = s
            print(str(i + 1) + ") " + name +  ("." * (25 - len(name))) + str(score)) 

        inputTool = InputTool({"1": "Main Menu", "6": "Exit"})
        self.screen = inputTool.getInput()
Пример #4
0
    def winScreen(self):
        self.header("You Win!")
        print("Score: " + str(self.score))
        print(self.game_board)

        self.name = input("Enter your name: ")

        # add score to JSON file
        HighScores().addData(self.name, self.score)

        inputTool = InputTool({"1": "Main Menu", "6": "Exit"})
        self.screen = inputTool.getInput()
Пример #5
0
    def helpScreen(self):
        self.header("Help")

        instructions = [
            "* To win, open all the cells which do not contain a mine.",
            "* Try to win as quickly as possible.",
            "* If you guess a cell with a mine, you lose.",
            "* Every non-mine cell will tell you the total number of mines in the eight neighboring cells.",
            "* To open a square, point at the square and click on it.",
            "* To mark a square you think is a mine with a flag, point and right-click.",
            "* Right-click twice to mark a cell that you are unsure about.",
            "* The first square you open is never a mine.",
            "* The upper left corner contains the number of mines left to find.",
            "* The upper right corner contains a time counter.",
            "* Good luck sweeping!"
        ]

        for i in instructions:
            print(i)

        inputTool = InputTool({"1": "Main Menu", "6": "Exit"})
        self.screen = inputTool.getInput()
Пример #6
0
    def settingsScreen(self):
        self.header("Settings")

        inputTool = InputTool({"1": "Easy", "2": "Medium", "3": "Hard"})
        self.difficulty = inputTool.getInput()

        inputTool = InputTool({"1": "Main Menu", "6": "Exit"})
        self.screen = inputTool.getInput()
Пример #7
0
    def playGameScreen(self):
        self.header("Play")

        current_time = time.time()
        self.score = int(current_time - self.start_time)

        print("Score - " + str(self.score))
        print("Mines Remaining - " + str(self.mines_remaining))

        # display of the back end 2D array of the game board from the GameBoard class
        print(self.game_board)

        inputTool = InputTool({"1": "Flip", "2": "Flag/Mark"})
        action = inputTool.getInput()
        
        # validate input for column and row 
        while True:
            try:
                icol = int(input("[ENTER] || Column | - ")) - 1
            except:
                continue

            if (0 <= icol < self.num_cols):
                break

        while True:
            try:
                irow = int(input("[ENTER] || Row | - ")) - 1
            except:
                continue

            if (0 <= irow < self.num_rows):
                break
        
        # guarantee that the user guesses an empty space on the first guess
        if (self.firstTurn):
            self.game_board.guaranteeEmptyCell(irow, icol)

        # flipping
        if (action == "1" and not (self.game_board.board[irow][icol].isFlagged or self.game_board.board[irow][icol].isMarked)):
            # flip the tile the user guessed
            self.game_board.board[irow][icol].flip()

            # if the user guesses an empty tile...
            if (self.game_board.board[irow][icol].isEmpty()):
                self.game_board.clearEmptyCells(irow, icol)

            # if the users loses...
            if (self.game_board.hasLost(irow, icol)):
                self.screen = "7"

            # if the user wins...
            if (self.game_board.hasWon()):
                current_time = time.time()
                self.score = int(current_time - self.start_time)
                self.screen = "8"

            self.firstTurn = False
        # flagging
        elif (action == "2" and self.firstTurn == False and self.game_board.board[irow][icol].isFlipped == False):
            self.game_board.board[irow][icol].clicks += 1
        
            if (self.game_board.board[irow][icol].clicks % 3 == 1):
                self.game_board.board[irow][icol].isFlagged = True
                self.mines_remaining -= 1
            elif (self.game_board.board[irow][icol].clicks % 3 == 2):
                self.game_board.board[irow][icol].isMarked = True
                self.game_board.board[irow][icol].isFlagged = False
                self.mines_remaining += 1
            else:
                self.game_board.board[irow][icol].isMarked = False
Пример #8
0
def main():
    input_file_name: str = 'C:\\Program Files\\Alteryx\\Samples\\en\\SampleData\\Customers.csv'
    output_file_name: str = 'C:\\Temp\\output.csv'

    # Configure and create input tool
    input_tool_cfg: InputToolConfiguration = InputToolConfiguration(
        input_file_name=input_file_name,
        header_row=True
    )
    source: str = 'File: ' + input_file_name
    record_info: List[Field] = [
        Field(name='Customer ID', source=source), 
        Field(name='Store Number', source=source),
        Field(name='Customer Segment', source=source),
        Field(name='Responder', source=source),
        Field(name='First Name', source=source),
        Field(name='Last Name', source=source),
        Field(name='Address', source=source),
        Field(name='City', source=source),
        Field(name='State', source=source),
        Field(name='Zip', source=source),
        Field(name='Lat', source=source),
        Field(name='Lon', source=source)
    ]
    input_tool: InputTool = InputTool('1', input_tool_cfg, record_info)
    input_tool.position = (78, 66)

    # Configure and create autofield tool
    autofield_fields: List[AutofieldField] = [
        AutofieldField(field='Customer ID'), 
        AutofieldField(field='Store Number'),
        AutofieldField(field='Customer Segment'),
        AutofieldField(field='Responder'),
        AutofieldField(field='First Name'),
        AutofieldField(field='Last Name'),
        AutofieldField(field='Address'),
        AutofieldField(field='City'),
        AutofieldField(field='State'),
        AutofieldField(field='Zip'),
        AutofieldField(field='Lat'),
        AutofieldField(field='Lon')
    ]
    autofield_tool: AutofieldTool = AutofieldTool('3', autofield_fields)
    autofield_tool.position = (196, 66)

    # Configure and create select tool
    select_tool_cfg: SelectToolConfiguration = SelectToolConfiguration()
    select_fields: List[SelectField] = [
        SelectField(field='Lat'),
        SelectField(field='Lon'),
        SelectField(field='*Unknown', selected=True)
    ]
    select_tool: SelectTool = SelectTool('2', select_tool_cfg, select_fields)
    select_tool.position = (313, 66)

    # Configure and create filter tool
    filter_tool_configuration: FilterToolConfiguration = FilterToolConfiguration(
        expression='[City] != "DENVER" AND [Responder] == "Yes"',
        filter_mode=FilterMode.CUSTOM
    )
    filter_tool: FilterTool = FilterTool('4', filter_tool_configuration)
    filter_tool.position = (407, 66)

    # Configure and create output tool
    output_tool_cfg: OutputToolConfiguration = OutputToolConfiguration(
        output_file_name=output_file_name
    )
    output_tool: OutputTool = OutputTool('6', output_tool_cfg)
    output_tool.position = (510, 54)

    # Configure, create, and write workflow
    workflow = Workflow('Simple', '2019.1')
    workflow \
        .add_tool(input_tool) \
        .add_tool(autofield_tool) \
        .add_tool(select_tool) \
        .add_tool(filter_tool) \
        .add_tool(output_tool) \
        .add_connection(input_tool, 'Output', autofield_tool, 'Input') \
        .add_connection(autofield_tool, 'Output', select_tool, 'Input') \
        .add_connection(select_tool, 'Output', filter_tool, 'Input') \
        .add_connection(filter_tool, 'True', output_tool, 'Input') \
        .write() \
        .run('"C:\\Program Files\\Alteryx\\bin\\AlteryxEngineCmd.exe"')