예제 #1
0
def play_game():
    board = game.GameBoard()
    r, c = 0, 0

    dir_lookup = {
        'w': (-1, 0),
        'a': (0, -1),
        's': (1, 0),
        'd': (0, 1),
        get_key.UP_ARROW: (-1, 0),
        get_key.LEFT_ARROW: (0, -1),
        get_key.DOWN_ARROW: (1, 0),
        get_key.RIGHT_ARROW: (0, 1),
    }

    key = 0
    while key != '\x03':
        display_tty(board, (r, c))
        key = get_key.getch()
        if key in dir_lookup:
            rd, cd = dir_lookup[key]
            r = sorted([0, r + rd, game.HEIGHT - 1])[1]
            c = sorted([0, c + cd, game.WIDTH - 1])[1]
        elif key in set('e \r'):
            for b in board.advance_tile(r, c):
                display_tty(board, board.last_collapsed)
                time.sleep(SLEEP_TIME)
            if not board.health:
                display_tty(board)
                board.score += sum(map(sum, board.board))
                print("Game Over! Final score: {:,}".format(board.score * 10))
                break
예제 #2
0
def run_cli():
    SIZE = 7
    words = get_original_clues()

    board = HexBoard(words, SIZE)

    x = 0
    y = 0
    ch = None
    while ch != '\x03':
        print("\033c")
        print_board(board, (x, y))
        ch = get_key.getch()
        if ch == get_key.LEFT_ARROW:
            if not board.out_of_bounds(x - 1, y):
                x -= 1
        elif ch == get_key.RIGHT_ARROW:
            if not board.out_of_bounds(x + 1, y):
                x += 1
        elif ch == get_key.UP_ARROW:
            if y % 2 and not board.out_of_bounds(x + 1, y - 1):
                x += 1
            if not board.out_of_bounds(x, y - 1):
                y -= 1
        elif ch == get_key.DOWN_ARROW:
            if not (y % 2) and not board.out_of_bounds(x - 1, y + 1):
                x -= 1
            if not board.out_of_bounds(x, y + 1):
                y += 1
        elif ch in string.ascii_letters:
            board.set_char((x, y), ch.upper())
        elif ch in (' ', '\x7f'):
            board.set_char((x, y), None)
        elif ch == '[':
            board.clues = board.clues[1:] + [board.clues[0]]
        elif ch == ']':
            board.clues = [board.clues[-1]] + board.clues[:-1]
예제 #3
0
파일: rogue.py 프로젝트: orez-/roguelike
        old_pos = (self.x, self.y)
        if key == "w":
            self.y -= 1
        if key == "s":
            self.y += 1
        if key == "a":
            self.x -= 1
        if key == "d":
            self.x += 1
        if board.is_solid(self.x, self.y):
            self.x, self.y = old_pos
        visibility.compute_visibility(self.x, self.y)


visibility = Visibility(board)

def place_dude_free():
    """ Place the dude in the first open space """
    for y in xrange(board.height()):
        for x in xrange(board.width()):
            if not board.is_solid(x, y):
                return Dude(x, y)

dude = place_dude_free()

key = 0
while key != u"\u0003":
    redraw()
    key = getch()
    dude.handle_key(key)