def launch(width, height, bombs): """ launch the game :param width: width of the game :type width: int :param height: height of the game :type height: int :param bombs: number of bombs :type bombs: int """ game = ms.make_game(width, height, bombs) state = ms.get_state(game) while state == ms.GameState.unfinished: try: display_game(game) play(game) state = ms.get_state(game) except KeyboardInterrupt: sys.exit() display_game(game) if state == ms.GameState.losing: print("You lose!") elif state == ms.GameState.unfinished: print("You win!") else: print("an unexpected error has occured, please contact the developpers")
def __test_end (b,g): """ This function tests if the game is finished or not. In the first case, depending on the state of the game, all graphical cells are diabled or events are unbinded. :param b: the board of buttons :type b: list of list of ``button`` :param g: the minesweeper game :type g: game """ state = minesweeper.get_state(g) if state == minesweeper.GameState.losing: __disable_game (b,g) elif state == minesweeper.GameState.winning: __block_game(b,g)
import sys import minesweeper as msp if __name__ == "__main__": assert len(sys.argv)==4, "Give me more arguments, please." assert (int(sys.argv[1])>0 and int(sys.argv[2])>0 and int(sys.argv[3])>0), "All these arguments should be positive." g = msp.make_game(int(sys.argv[1]),int(sys.argv[2]),int(sys.argv[2])) while(msp.get_state(g)==msp.GameState(3)): msp.draw(g) tmp = input("Your play x,y,C (C=(R)eval,(S)et,(U)nset):") str = tmp.split(" ") print(str) if(str[2]=="R"): msp.reveal(msp.get_cell(g,int(str[0]),int(str[1]))) continue if(str[2]=="S"): msp.set_hypothetic(msp.get_cell(g,int(str[0]),int(str[1]))) if(get_state(g)==msp.GameState(1)): print("You won.") else: print("You lost.")
:author: `DECOTTIGNIES Cyril et MORLET Kevin` :date: 2015, october """ import minesweeper as m import sys 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() game=m.make_game(5,5,3) show_grid(game) while (m.get_state(game) == m.GameState.unfinished): val = input("Your play x,y,C (C=(R)eval,(S)et,(U)nset :") show_grid(game)