Example #1
0
def __changeflag (evt,b,g,i,j):
    """
    This function is called on right-click on a button.

    :param b: the board of buttons
    :type b: list of list of ``button``
    :param g: the minesweeper game
    :type g: game
    :param i: the x-coordinate of the cell
    :type i: int
    :param j: the y-coordinate of the cell
    :type j: int
    """
    cell = minesweeper.get_cell(g,i,j)
    if not minesweeper.is_hypothetic_bomb(cell):
        minesweeper.set_hypothetic(cell)
    else:
        minesweeper.unset_hypothetic(cell)
    __redraw(b,g,i,j)
    __test_end (b,g)
Example #2
0
def play(game):
    """
    require action to the player and execute it
    :param game: game
    :type game: a minesweeper game
    :return: None
    :rtype: NoneType
    :UC: none
    """
    action = keyboard_input(game)
    x = action[0]
    y = action[1]
    a = action[2]
    if a == 'R':
        ms.reveal_all_cells_from(game,x, y)
    elif a == 'S':
        cell = ms.get_cell(game, x, y)
        ms.set_hypothetic(cell)
    elif a == 'U':
        cell = ms.get_cell(game, x, y)
        ms.unset_hypothetic(cell)
Example #3
0
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.")