Esempio n. 1
0
def c_main(stdscr: "curses._CursesWindow") -> int:
    dims = {"easy": game.EASY, "medium": game.MEDIUM, "hard": game.HARD}
    app = GameApp(stdscr, game.create_game(*game.EASY))
    mv = {
        "b": lambda x, y: game.prev_unswept(app.game.board, x, y),
        "h": lambda x, y: (x - 1, y) if x > 0 else (x, y),
        "j": lambda x, y: (x, y + 1) if y + 1 < app.game.height else (x, y),
        "k": lambda x, y: (x, y - 1) if y - 1 >= 0 else (x, y),
        "l": lambda x, y: (x + 1, y) if x < app.game.width - 1 else (x, y),
        "w": lambda x, y: game.next_unswept(app.game.board, x, y),
        "\n": lambda x, y: (0, y + 1) if y + 1 < app.game.height else (x, y),
        "0": lambda _, y: (0, y),
        "$": lambda _, y: (app.game.width - 1, y),
        "H": lambda _, __: (0, 0),
        "L": lambda _, __: (0, app.game.height - 1),
        "M": lambda _, __: (0, int((app.game.height - 1) / 2)),
    }
    difficulty = ed_choose(app)
    if difficulty != "easy":
        app = GameApp(stdscr, game.create_game(*dims[difficulty]))
    else:
        overwrite_str(app.stdscr, 0, app.game.height + 1, " " * 30)
    for c in async_input(stdscr):
        if c == ":":
            app = GameApp(stdscr, game.create_game(*dims[ed_choose(app)]))
        elif c == "x":
            app.sweep_cell()
            if game.is_loss(app.game.board):
                app.reveal_mines()
                bye(app, "Game Over  ")
                app = GameApp(stdscr, game.create_game(*dims[ed_choose(app)]))
            elif game.is_win(app.game.board):
                bye(app, "You win!   ")
                app = GameApp(stdscr, game.create_game(*dims[ed_choose(app)]))
        elif c == "m":
            app.mark_cell()
        elif c in mv:
            app.move_to(Cursor.from_model(*mv[c](*app.cursor.to_model())))
        else:
            debug(app, f"{c} not implemented")
    return 0
Esempio n. 2
0
def test_prev_unswept_prev_row_skip_1():
    board = game._to_cells([[" ", "1"], [" ", " "]])
    board[0][1].is_swept = True
    assert game.prev_unswept(board, 1, 1) == (0, 0)
Esempio n. 3
0
def test_prev_unswept_beginning_of_row():
    board = game._to_cells([[" ", " ", " "]])
    assert game.prev_unswept(board, 2, 0) == (0, 0)
Esempio n. 4
0
def test_prev_unswept_skip_unswept():
    board = game._to_cells([[" ", " ", "1", " "]])
    board[0][2].is_swept = True
    assert game.prev_unswept(board, 3, 0) == (1, 0)
Esempio n. 5
0
def test_prev_unswept_prev_row():
    board = game._to_cells([[" ", " "], [" ", " "]])
    assert game.prev_unswept(board, 1, 1) == (1, 0)