我想检测鼠标是否在文本上方(或文本打印区域) 当您单击文本时。它会将您发送到指定区域。
ive试图检测鼠标是否在单个点上。但我不知道如何在某个区域进行探测。
_MOUSESHOW
a = _MOUSEINPUT
b = _MOUSEBUTTON(1)
IF _MOUSEX = 5 THEN GOTO damage
PRINT "[attack]"
damage:
PRINT u$; "takes", playerDamage%
我想要的结果是,每当用户将鼠标悬停并单击文本[attack]
时,它将发送到damage
答案 0 :(得分: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
答案 1 :(得分: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
答案 2 :(得分: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