小编abc*_*556的帖子

NCurses连续更新moveCursor中的x和y坐标

我想用类似蛇的机械手制作某种游戏,在其中您可以使用箭头键更改蛇的坐标。但是由于变量的重新分配并不是haskell的事情,所以我不确定如何执行此操作。这是我的代码:

import Control.Monad
import UI.NCurses

main :: IO ()
main = runCurses $ do
    w <- defaultWindow
    forever $ do
        e <- getEvent w Nothing
        updateWindow w $ do
            moveCursor 0 0
            drawString (show e)
        render

Run Code Online (Sandbox Code Playgroud)

我希望它打印按下的键(drawString (show e)),然后将光标更改为上一个x + 1,上一个y + 1,然后绘制下一个按下的键,然后更改光标,依此类推。

您如何在NCurses中做到这一点?如果可以重新分配,那将很简单,例如

loop forever:
moveCursor x y
print
x = x+1
y = y+1
Run Code Online (Sandbox Code Playgroud)

但是重新分配不起作用,那我该怎么办呢?

haskell ncurses

2
推荐指数
1
解决办法
58
查看次数

do块中的if语句给出错误消息

我正在尝试制作一个非常简单的类似蛇的游戏,如果您尝试使用已经访问过的斧头坐标,则会输掉该游戏。

到目前为止,这是起作用的代码(您可以使用箭头键移动播放器1并使用wasd移动播放器2):

import UI.NCurses

main :: IO ()    
main = runCurses $ do
    w <- defaultWindow
    updateWindow w $ do
        drawBorder Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
    render
    loop w [] 1 1 0 0 10 10 0 0

loop :: Window -> [(Integer, Integer)] -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer ->  Curses ()
loop w list p1x p1y p1oldDx p1oldDy p2x p2y p2oldDx p2oldDy = do
    e …
Run Code Online (Sandbox Code Playgroud)

haskell if-statement ncurses do-notation io-monad

-1
推荐指数
1
解决办法
61
查看次数

标签 统计

haskell ×2

ncurses ×2

do-notation ×1

if-statement ×1

io-monad ×1