Example #1
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()
Example #2
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()
Example #3
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()
Example #4
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()
Example #5
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()
Example #6
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()
Example #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