Еще один пример кода с использованием мыши в 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