如何检测鼠标输入,单击。在印刷文字?

问题描述 投票:1回答:3

我想检测鼠标是否在文本上(或文本打印区域)以及单击文本时。它会将您送到指定区域。

香港专业教育学院试图检测鼠标是否超过一个点。但我不知道如何检测一个区域。

_MOUSESHOW
a = _MOUSEINPUT
b = _MOUSEBUTTON(1)


IF _MOUSEX = 5 THEN GOTO damage
PRINT "[attack]"

damage:
PRINT u$; "takes", playerDamage%

我想要的结果是每当用户鼠标移动并点击文本[attack]时它会将它们发送到damage

click mouse qb64
3个回答
0
投票

以下是QB64中使用鼠标的示例代码段:

u$ = "Player1"
CLS
PRINT "[attack]"
DO
    IF INKEY$ <> "" THEN END ' or gosub your keyboard input routine
    IF _MOUSEINPUT THEN
        IF _MOUSEBUTTON(1) THEN ' left mouse click
            ' X, Y return single
            MouseY = CINT(_MOUSEX): MouseX = CINT(_MOUSEY)
            ' check mouseover text
            IF MouseX = 1 AND (MouseY >= 1 AND MouseY <= 8) THEN
                GOSUB damage
            END IF
        END IF
    END IF
LOOP
END

damage:
playerdamage% = INT(RND * 9 + 1)
LOCATE 3, 1
PRINT u$; "takes", playerdamage%
RETURN

0
投票

在QB64中使用鼠标的另一个代码段:

u$ = "Player1"
CLS
PRINT "[attack] [defend]"
DO
    x$ = INKEY$
    IF x$ = "a" THEN GOSUB damage
    IF x$ = "d" THEN GOSUB defend
    IF x$ = CHR$(27) THEN END
    IF _MOUSEINPUT THEN
        IF _MOUSEBUTTON(1) THEN ' left mouse click
            ' X, Y return single
            MouseY = CINT(_MOUSEX): MouseX = CINT(_MOUSEY)
            ' check mouseover text
            IF MouseX = 1 AND (MouseY >= 1 AND MouseY <= 8) THEN
                GOSUB damage
            END IF
            IF MouseX = 1 AND (MouseY >= 10 AND MouseY <= 17) THEN
                GOSUB defend
            END IF
        END IF
    END IF
LOOP
END

damage:
playerdamage% = INT(RND * 9 + 1)
LOCATE 3, 1
PRINT u$; " takes"; playerdamage%
RETURN

defend:
playerdefense% = INT(RND * 9 + 1)
LOCATE 4, 1
PRINT u$; " restores"; playerdefense%
RETURN

0
投票

在QB64中使用鼠标的另一个示例代码:

DEFINT A-Z
REM $dynamic
u$ = "Player1": playerhits% = 128: playerlevel% = 1
CONST maxhits = 9 ' maximum hits for attack/defend
CONST hitsrequired = 90 ' hits required to level up
CLS
LOCATE 25, 1
COLOR 15, 1
PRINT SPACE$(80);
LOCATE 25, 1
PRINT "Enter [a]ttack, [d]efend, [i]nfo, <esc> to quit";
LOCATE 1, 1
COLOR 15, 0
PRINT "[attack] [defend] [info] [quit]"
GOSUB info
DO
    x$ = LCASE$(INKEY$)
    IF x$ = "a" THEN GOSUB damage: GOSUB info
    IF x$ = "d" THEN GOSUB defend: GOSUB info
    IF x$ = "i" THEN GOSUB info
    IF x$ = CHR$(27) THEN SYSTEM
    IF _MOUSEINPUT THEN
        IF _MOUSEBUTTON(1) THEN ' left mouse click
            ' X, Y return single
            MouseY = CINT(_MOUSEX): MouseX = CINT(_MOUSEY)
            ' check mouseover text
            IF MouseX = 1 AND (MouseY >= 1 AND MouseY <= 8) THEN ' [attack]
                GOSUB damage
            END IF
            IF MouseX = 1 AND (MouseY >= 10 AND MouseY <= 17) THEN ' [defend]
                GOSUB defend
            END IF
            IF MouseX = 1 AND (MouseY >= 19 AND MouseY <= 24) THEN ' [info]
                GOSUB info
            END IF
            IF MouseX = 1 AND (MouseY >= 26 AND MouseY <= 31) THEN ' [quit]
                SYSTEM
            END IF
            ' check mouseover statusline
            REM "Enter [a]ttack, [d]efend, [i]nfo, <esc> to quit";
            IF MouseX = 25 AND (MouseY >= 7 AND MouseY <= 14) THEN ' [attack]
                GOSUB damage
            END IF
            IF MouseX = 25 AND (MouseY >= 17 AND MouseY <= 24) THEN ' [defend]
                GOSUB defend
            END IF
            IF MouseX = 25 AND (MouseY >= 27 AND MouseY <= 32) THEN ' [info]
                GOSUB info
            END IF
            IF MouseX = 25 AND (MouseY >= 35 AND MouseY <= 47) THEN ' <esc>
                SYSTEM
            END IF
        END IF
    END IF
LOOP
END

damage:
playerdamage% = INT(RND * maxhits + 1)
LOCATE 3, 1
PRINT u$; " takes"; playerdamage%; "points."
IF playerhits% - playerdamage% < 0 THEN
    playerlevel% = playerlevel% - 1%
    playerhits% = maxhits
ELSE
    playerhits% = playerhits% - playerdamage%
END IF
LOCATE 2, 1
PRINT "playerhits:"; playerhits%; "    "
RETURN

defend:
playerdefense% = INT(RND * maxhits + 1)
LOCATE 4, 1
PRINT u$; " restores"; playerdefense%; "points."
IF playerhits% + playerdefense% > hitsrequired THEN
    playerlevel% = playerlevel% + 1%
    playerhits% = maxhits
ELSE
    playerhits% = playerhits% + playerdefense%
    IF playerlevel% <= 0 THEN playerlevel% = 1
END IF
LOCATE 2, 1
PRINT "playerhits:"; playerhits%; "    "
RETURN

info:
LOCATE 5, 1
count = count + 1
PRINT "Player: "; u$; ", display:"; count
PRINT "Hits:"; playerhits%; ", level";
IF playerlevel% <= 0 THEN
    PRINT " <dead>    "
ELSE
    PRINT playerlevel%; "    "
END IF
RETURN
© www.soinside.com 2019 - 2024. All rights reserved.