回 帖 发 新 帖 刷新版面

主题:问个用Qbasic编游戏的问题?

请问用什么方法才能用键盘控制一个东西移动呢?
就像按右键时小人往右跑之类的……
高手们卜另赐教!!

回复列表 (共34个回复)

沙发

DECLARE SUB box1 (xx1!, yy1!, xx2!, yy2!, col!, col1!, col2!, i!)
DECLARE SUB box (xx1!, yy1!, xx2!, yy2!, col!, col1!, col2!, i)
DECLARE SUB ink (x, y, lx, ly, rx, ry)
DIM win(16, 16)
FOR j = 1 TO 15
  FOR i = 1 TO 15
   READ dates
   win(i, j) = dates
  NEXT
NEXT
x = 15: y = 10
lx = 1: ly = 1: rx = 15: ry = 15
DIM pepple(100)
SCREEN 12
LINE (0, 0)-(20, 20), 14, BF
GET (0, 0)-(19, 19), pepple
PAINT (1, 1), 7
FOR i = lx TO rx
FOR j = ly TO ry
  IF win(i, j) = 1 THEN
   box1 i * 20, j * 20, i * 20 + 20, j * 20 + 20, 6, 7, 7, 1
  ELSEIF win(i, j) = 9 THEN
   box i * 20, j * 20, i * 20 + 20, j * 20 + 20, 14, 8, 8, 1
  ELSEIF win(i, j) = 7 THEN
   box i * 20, j * 20, i * 20 + 20, j * 20 + 20, 4, 8, 8, 1
  ELSEIF win(i, j) = 4 THEN
   'box i * 20, j * 20, i * 20 + 20, j * 20 + 20, 9, 7, 8, 1
END IF
NEXT
NEXT
FOR i = lx TO rx
FOR j = ly TO ry
  IF win(i, j) = 4 THEN tempx = i: tempy = j
NEXT
NEXT
x = tempx: y = tempy
LOCATE 1, 1: PRINT win(tempx, tempy)
DO
PUT (tempx * 20, tempy * 20), pepple
ink x, y, lx, ly, rx, ry
  i = x: j = y
  'box i * 20, j * 20, i * 20 + 20, j * 20 + 20, 10, 8, 15, 3
  PUT (i * 20, j * 20), pepple
LOOP WHILE temp$ <> CHR$(27)
END
DATA 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
DATA 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
DATA 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1
DATA 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1
DATA 1, 1, 0, 7, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1
DATA 1, 1, 0, 0, 0, 0, 0, 0, 7, 0, 0, 1, 1, 1, 1
DATA 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1
DATA 1, 1, 1, 1, 1, 1, 1, 0, 7, 1, 0, 1, 1, 1, 1
DATA 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1
DATA 1, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1
DATA 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1
DATA 1, 1, 1, 0, 7, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1
DATA 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 9, 9, 1
DATA 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 9, 9, 1
DATA 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1

SUB box (xx1, yy1, xx2, yy2, col, col1, col2, i)
LINE (xx1, yy1)-(xx2, yy2), col, BF
LINE (xx1 + i, yy1 + i)-(xx2 - i, yy2 - i), col1, B
LINE (xx2 - i, yy2 - i)-(xx1 + i, yy2 - i), col2
LINE (xx2 - i, yy2 - i)-(xx2 - i, yy1 + i), col2
END SUB

SUB box1 (xx1, yy1, xx2, yy2, col, col1, col2, i)
LINE (xx1, yy1)-(xx2, yy2), col, BF
LINE (xx1, yy1)-(xx2, yy1 + (yy2 - yy1) / 2), 0, B
LINE (xx1 + (xx2 - xx1) / 2, yy1 + (yy2 - yy1) / 2)-(xx1 + (xx2 - xx1) / 2, yy1 + 2 * (yy2 - yy1) / 2), 0

LINE (xx1 + 1, yy1 + 1)-(xx2 + 1, yy1 + (yy2 - yy1) / 2 + 1), 7, B
LINE (xx1 + 1, yy1 + 1)-(xx1 + 1, yy1 + (yy2 - yy1) / 2 - 1), 7
LINE (xx1 + 1, yy1 + 1)-(xx2 + 1, yy1 + 1), 7
LINE (xx1 + (xx2 - xx1) / 2 + 1, yy1 + (yy2 - yy1) / 2 + 1)-(xx1 + (xx2 - xx1) / 2 + 1, yy1 + 2 * (yy2 - yy1) / 2 + 1), 7

END SUB

SUB ink (x, y, lx, ly, rx, ry)
SHARED temp$, win(), pepple(), tempx, tempy
tempx = x: tempy = y
xx = x: yy = y
DO
temp$ = INKEY$
LOOP WHILE temp$ = ""
tem$ = RIGHT$(temp$, 1)
SELECT CASE tem$
   CASE "K"
     'pRINT "<--"
     IF win(xx - 1, yy) <> 1 THEN
      SWAP win(xx - 1, yy), win(xx, yy)
      xx = xx - 1: IF xx <= lx THEN xx = lx
     ELSEIF win(xx - 1, yy) = 4 AND win(xx - 2, yy) <> 1 THEN
      xx = xx - 1: IF xx <= lx THEN xx = lx
     END IF
   CASE "M"
     'PRINT "-->"
     IF win(xx + 1, yy) <> 1 THEN xx = xx + 1: IF xx >= rx THEN xx = rx
   CASE "H"
     'print "^"
     IF win(xx, yy - 1) <> 1 THEN yy = yy - 1: IF yy <= ly THEN yy = ly
   CASE "P"
     'print "v"
     IF win(xx, yy + 1) <> 1 THEN yy = yy + 1: IF yy >= ry THEN yy = ry
END SELECT
x = xx: y = yy
END SUB

'ink (x, y, lx, ly, rx, ry)就是编写的光标键过程

板凳

太长了吧,能不能换个短的~
DECLARE SUB box1 (xx1!, yy1!, xx2!, yy2!, col!, col1!, col2!, i!)
DECLARE SUB box (xx1!, yy1!, xx2!, yy2!, col!, col1!, col2!, i)
DECLARE SUB ink (x, y, lx, ly, rx, ry)
这都是什么意思还请明示·
哪有专门介绍这方面的文章啊?
我太菜了原谅我……
[fly]我想编一个游戏!!![/fly]

3 楼

CLS:y = 1:    LOCATE 10, y1 + y: PRINT CHR$(153)
      DO
        DO: k$ = INKEY$: LOOP UNTIL k$ <> ""
        LOCATE 10, 1: PRINT SPACE$(80)
        SELECT CASE k$
                CASE CHR$(27)
                END
                CASE CHR$(0) + "K"  'ZHUO
                y = y - 1:IF y < 1 THEN y = 80
                CASE CHR$(0) + "M"  'XOU
                y = y + 1: IF y > 80 THEN y = 1
        END SELECT
        LOCATE 10, y1 + y: PRINT CHR$(153)
      LOOP

4 楼

i$=inkey$

5 楼

冷石和qb45两位兄长写的太好了!
小弟给冷石打10分,50块钱
   给qb45打20分,100块!
但是程序运行时怎么图象乱闪哪??
还有几个问题,CHR$(0),CHR$(0)+"K"是什么意思?
为什么是y1+y而不是y?

[fly]期待解答……[/fly]

6 楼

CHR$(0)+"K"是因为BIOS用2个字节表示按键不过好像一个也行


7 楼

你是说我的程序闪么??
如果是
你可以在程序的开始关闭光标     用Locate ,,0
chr$(0)+"K"
这个意思是这样
chr$(0)是键盘标志
"K"在这里实际上就是键盘的扫描码,Left建的扫描吗是&H4B
K的Asc吗的值就是4BH,所以你也可以用
CHR$(0)+CHR$(&H4B)这也是一样可以代表左键(Left)
这个在QBasic的书上很难看到的!那些注重的是讲方法和基本的东西!
有兴趣详细知道的看强强在本论坛发的帖子吧!
那个很好!
那些资料都是编程语言本身外的东西,
是所有Dos下的编程语言都能用的上的资料!
下面我给出一些常用的建
cls
locate , ,0
DO
   DO: k$ = INKEY$: LOOP UNTIL k$ <> ""
   LOCATE 10, 1: PRINT SPACE$(80)
   SELECT CASE k$
           CASE CHR$(27)
             LOCATE 10, 1:PRINT "你按了ESC建"  
           CASE CHR$(0) + chr$(75)
             LOCATE 10, 1:PRINT "你按了左建"  
           CASE CHR$(0) + chr$(77)
             LOCATE 10, 1:PRINT "你按了右建"
           CASE CHR$(0) + chr$(72)
             LOCATE 10, 1:PRINT "你按了上建"    
           CASE CHR$(0) + chr$(80)
             LOCATE 10, 1:PRINT "你按了下建"  
           CASE chr$(8)
             LOCATE 10, 1:PRINT "你按了BACK建"  
           CASE CHR$(0) + chr$(83)
             LOCATE 10, 1:PRINT "你按了DEL建"  
        END SELECT
      LOOP



8 楼

quick basic 的键盘控制很简单
下面我给你一个列表:
      Key     Code      Key       Code      Key       Code
      Esc        1         A           30          F1          59
      ! or 1     2         S           31          F2          60
      @ or 2     3         D           32          F3          61
      # or 3     4         F           33          F4          62
      $ or 4     5         G           34          F5          63
      % or 5     6         H           35          F6          64
      ^ or 6     7         J           36          F7          65
      & or 7     8         K           37          F8          66
      * or 8     9         L           38          F9          67
      ( or 9    10         : or ;      39          F10         68
      ) or 0    11         " or '      40          F11        133
      + or =    13         Left Shift  42          NumLock     69
      Bksp      14         | or \      43          Scroll Lock 70
      Tab       15         Z           44          Home or 7   71
      Q         16         X           45          Up or 8     72
      W         17         C           46          PgUp or 9   73
      E         18         V           47          Gray -      74
      R         19         B           48          Left or 4   75
      T         20         N           49          Center or 5 76
      Y         21         M           50          Right or 6  77
      U         22         < or ,      51          Gray +      78
      I         23         > or .      52          End or 1    79
      O         24         ? or /      53          Down or 2   80
      P         25         Right Shift 54          PgDn or 3   81
      { or [    26         Prt Sc or * 55          Ins or 0    82
      } or ]    27         Alt         56          Del or .    83
      Enter     28         Spacebar    57      
      Ctrl      29         Caps Lock   58      
举个例子:
Ctrl 值是 chr$(0)+chr$(29)  del 值是 chr$(0)+chr$(83)
你在前面加上 Chr$(0) 就可以了

9 楼

哈哈哈,太感谢各位了!

10 楼

不懂

我来回复

您尚未登录,请登录后再回复。点此登录或注册