我正在制作游戏" Connect Four"。
玩家必须输入1-4之间的数字,以便光盘落入其中一列。我目前正在编写第一列。问题是你可以输入任何字符并且它会起作用(只有当你按下' 1时才需要工作)我无法弄清楚如何修复它。
此外,该号码显示在屏幕左侧。 当我输入它在屏幕上显示的数字时,我该怎么做呢?
PlayerOneTurn:
cmp [Player1Turn], 255
je Player1Pressed1
Player1Pressed1:
mov ah, 1
int 21h
cmp al, 31h
je Player1Check1
Player1Check1:
cmp [FirstColumnArray], 0
inc [FirstColumnArray]
je DrawPlayer1Disc
cmp [FirstColumnArray + 1], 0
inc [FirstColumnArray]
je DrawPlayer1Disc
cmp [FirstColumnArray + 2], 0
inc [FirstColumnArray]
je DrawPlayer1Disc
cmp [FirstColumnArray + 3], 0
inc [FirstColumnArray]
je DrawPlayer1Loop
DrawPlayer1Loop:
mov bh,0h
mov cx,[Player1Draw1x]
mov dx,[Player1Draw1y]
mov al,[player1disccolor]
mov ah,0ch
int 10h
inc [Player1Draw1x]
cmp cx, 38h
jl DrawPlayer1Loop
DrawPlayer1Disc:
mov bh, 0h
inc [Player1Draw1y]
mov [Player1Draw1x], 25h
cmp dx, 09Bh
jl DrawPlayer1Loop
运行时,我的项目如下所示:
答案 0 :(得分:3)
mov ah, 1 int 21h cmp ah, 31h
您使用的DOS函数会在AL寄存器中生成结果!
使用cmp al, 31h
来比较" 1"按键。
要不让屏幕上回显的输入使用DOS功能7而不是1。
mov ah, 7
int 21h
cmp al, 31h
Player1Pressed1: mov ah, 1 int 21h cmp al, 31h je Player1Check1 Player1Check1:
使用此代码,您始终可以在 Player1Check1 处执行代码。当输入不是" 1"时,你需要跳远它。添加jmp
Player1Pressed1:
mov ah, 1
int 21h
cmp al, 31h
je Player1Check1
jmp ELSEWHERE_YOU_KNOW_WHERE_THIS_IS
Player1Check1: