Exemple #1
0
def __redraw (b,g,x,y):
    """
    This function draws the board. Positions x and y are used to test
    which bomb icon has to be drawn.

    :param b: the board of buttons
    :type b: list of list of ``button``
    :param g: the minesweeper game
    :type g: game
    :param x: the x-coordinate of the cell
    :type x: int
    :param y: the y-coordinate of the cell
    :type y: int

    """
    global img
    width,height = (minesweeper.get_width(g),minesweeper.get_height(g))
    for i in range(width):
        for j in range(height):
            cell = minesweeper.get_cell(g,j,i)
            button = b[i][j]
            if minesweeper.is_revealed(cell):
                if minesweeper.is_bomb(cell):
                    new_img = img[10]
                    if x == j and y == i:
                        new_img = img[11]
                else:
                    new_img = img[minesweeper.number_of_bombs_in_neighborhood(cell)]
                button.config(relief=tk.FLAT,image=new_img, command = "")
            elif minesweeper.is_hypothetic_bomb(cell):
                button.config(image=img[12])
            else:
                button.config(image=img[9])
Exemple #2
0
def display_game(game):
    """
    display the game in stdout
    :param game: game
    :type game: a minesweeper game
    :return: None
    :rType: NoneType
    :UC: none
    """
    display_line = "+---"*ms.get_width(game) 
    display_line += "+"
    print(" ", end="")
    for i in range(ms.get_width(game)-1):
        print("  ", i, end="")
    print("  ",ms.get_width(game)-1)
    for h in range(ms.get_height(game)):
        numerotation = ""
        print(" ",display_line)
        print(h ,"",end="")
        for l in range(ms.get_width(game)):
            character = " "
            cell = ms.get_cell(game, h, l)
            if ms.is_revealed(cell):
                if ms.is_bomb(cell):
                    character = "B"
                else:
                    character = ms.number_of_bombs_in_neighborhood(cell)
            elif ms.is_hypothetic_bomb(cell):
                    character = "?"
            print("| ",character, end="")
        print("|")
    print(" ",display_line)
Exemple #3
0
def show_grid (game):
    for x in range(m.get_width(game)):
       print()
       for y in range(m.get_height(game)):
          cell=m.get_cell(game,x,y)
          if m.is_revealed(cell) :
             if m.is_bomb(cell):
                print ("B",end='')
             else : 
                print (m.number_of_bombs_in_neighborhood(cell),end='')
          else :  
             print(" ",end='')   
    print()