首页 > 解决方案 > 如何使用诅咒检测特定坐标中的字符?

问题描述

我目前正在开发一款 roguelike 游戏,并试图找出墙壁的碰撞检测。我目前在终端中的特定 y、x 坐标处绘制玩家,但我无法弄清楚如何使用它来检测玩家是否撞到墙上,用“#”字符表示。

运动是这样完成的:

def main(root):
    max_h, max_w = root.getmaxyx()

    current_row = 0
    current_col = 0

    while True:
        key = root.getch()

        if key == curses.KEY_UP and current_row > 1:
            current_row -= 1

        elif key == curses.KEY_DOWN and current_row < max_h - 5:
            current_row += 1

        elif key == curses.KEY_LEFT and current_col > 1:
            current_col -= 1

        elif key == curses.KEY_RIGHT and current_col < max_w - 3:
            current_col += 1

        elif key == ord("q"):
            break

        gameWindow(root, current_row, current_col)

'current_row' 和 'current_col' 被发送到另一个函数,它们在其中实际移动玩家角色。为了完整起见,这是该功能:

def player(game_win, current_row, current_col):
    p = "@"

    if current_row > 0:
        game_win.addstr(current_row, current_col, p)

标签: pythonpython-3.xncursespython-curses

解决方案


推荐阅读