在DOS中获取键盘输入而没有回声 [英] Getting keyboard input without echo in DOS
问题描述
我正在制作四人连线"游戏.
I am making the game "Connect Four".
播放器必须输入1-4之间的数字,这样光盘才能放入列之一.我目前正在第一栏上工作.问题在于您可以输入任何字符,并且该字符将起作用(仅当您按"1"时才需要起作用),而我不知道如何解决该问题.
The players have to enter a number between 1-4 so that the disc will drop into one of the columns. I am currently working on the first column. The problem is that you can enter any character and it will work (it only needs to work when you press '1') and I cant figure out how to fix it.
此外,数字出现在屏幕的左侧. 我如何做到这一点,所以当我输入一个不会在屏幕上显示的数字时?
Moreover, the number appears on the left side of the screen. How do I make it so when I enter the number it won't show on the screen?
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
运行时,我的项目如下:
When run my project looks like this:
推荐答案
mov ah, 1
int 21h
cmp ah, 31h
您使用的DOS函数在AL寄存器中产生结果!
使用cmp al, 31h
比较按键是否为"1".
The DOS function that you used produces a result in the AL register!
Use cmp al, 31h
to compare for a "1" keypress.
要不在屏幕上回显输入,请使用DOS功能7代替1.
To not have the input echoed on the screen use DOS function 7 in stead of 1.
mov ah, 7
int 21h
cmp al, 31h
Player1Pressed1:
mov ah, 1
int 21h
cmp al, 31h
je Player1Check1
Player1Check1:
使用此代码,您始终可以在 Player1Check1 处执行该代码.当输入不为"1"时,您需要跳开它.添加jmp
With this code you always execute the code at Player1Check1. You need to jump away from it when the input is not "1". Add a jmp
Player1Pressed1:
mov ah, 1
int 21h
cmp al, 31h
je Player1Check1
jmp ELSEWHERE_YOU_KNOW_WHERE_THIS_IS
Player1Check1:
这篇关于在DOS中获取键盘输入而没有回声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!