python - 如何使用诅咒检测特定坐标中的字符?
问题描述
我目前正在开发一款 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)
解决方案
推荐阅读
- nginx - Nginx的配置文件nginx.conf是静态加载还是动态加载?
- vba - 将不同的工作表合并到一个中但是当任何文件丢失时循环失败
- junit - When/thenReturn 未映射
- python - PyMySQL:我在 python 中导入 PyMySQL 模块时出错
- excel - 如何在 VBA 中使用多个 If Then 语句
- android - 如何注入相同类型的对象
- ruby-on-rails - 一段时间后,Rails HTTP 请求引发“EOFError:文件结尾”
- reactjs - 什么是 Chrome 上的 BetterJsPop 错误?
- javascript - 图案成数组
- reactjs - 反应服务器渲染