#click #mouse #qb64
#нажмите #мышь #qb64
Вопрос:
я хочу определить, находится ли мышь над текстом (или областью, в которой печатается текст), и когда вы нажимаете на текст. он отправляет вас в указанную область.
я пытался определить, находится ли мышь над одной точкой. но я не знаю, как определить область.
_MOUSESHOW
a = _MOUSEINPUT
b = _MOUSEBUTTON(1)
IF _MOUSEX = 5 THEN GOTO damage
PRINT "[attack]"
damage:
PRINT u$; "takes", playerDamage%
результат, который я хочу, — это всякий раз, когда пользователь наводит курсор мыши и щелкает по тексту [attack]
, на который он их отправит damage
Ответ №1:
Вот пример сегмента кода с использованием мыши в 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. спасибо, я протестирую все три, чтобы увидеть, какой из них работает лучше всего.
2. помогло бы это и с некоторыми переменными значениями?
u1$ = "player" u$ = "Dark Lord" j$ = "Smith" i$ = "Micheal" o$ = "Johnson" 'health DarkLordHP_1% = 999999999 Playerhp% = 10 smithhp% = 15 johnsonhp% = 7 michealhp% = 10 'damage DarkLordDamamge_1% = 9 playerDamage% = INT(RND * 9 1) johnsonsDanamge% = 3 SmithDamage% = 7 MichealDamage% = 5 'Defence DarkLordDefence_1% = 100000 PlayerDefence% = INT(RND * 9 1) JohnsonDef% = 2 smithDefence% = 5 MichealDefence% = 3
Ответ №2:
Другой сегмент кода с использованием мыши в 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
Ответ №3:
Еще один пример кода с использованием мыши в 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