回 帖 发 新 帖 刷新版面

主题:[原创]赛车(游戏)  初级版

全屏运行

DECLARE SUB showcar (row!, col!, c!)
DECLARE SUB Win ()
DECLARE SUB MoveZ ()
DECLARE SUB MoveM (md!)
DECLARE SUB Lose ()

CONST R0 = 3, C0 = 30, S0 = 12
CONST Left = -1, Right = 1
CONST KeyUp = 72, KeyDown = 80, KeyLeft = 75, KeyRight = 77
CONST KeySpace = 57, KeyEnter = 28, KeyEsc = 1

TYPE cartype
  row AS INTEGER
  col AS INTEGER
END TYPE

DIM SHARED car(0 TO 3) AS cartype       '存放赛车位置
DIM SHARED state(127) AS INTEGER
DIM SHARED BasePtr(0 TO 18) AS INTEGER  '存放基址
DIM SHARED shape(0 TO 4, 0 TO 2) AS INTEGER
DIM SHARED mrow, mcol, count

CLS
RANDOMIZE TIMER
REM 画边框
fk$ = "[][][][][][][][][][]"
COLOR 11
LOCATE R0 - 1, C0 + 1: PRINT CHR$(201) + STRING$(20, 205) + CHR$(187)
LOCATE R0, C0 + 1: PRINT CHR$(186); SPC(20); CHR$(186)
FOR row = 1 TO 18
  LOCATE R0 + row, C0 + 1: PRINT CHR$(186); SPC(20); CHR$(186)
  COLOR 0: LOCATE R0 + row, C0 + 2: PRINT fk$; : COLOR 11
NEXT row
LOCATE R0 + 19, C0 + 1: PRINT CHR$(200) + STRING$(20, 205) + CHR$(188)

ptr = 160 * (R0 - 1) + 2 * (C0 - 1) + 1
FOR row = 0 TO 18
  BasePtr(row) = ptr
  ptr = ptr + 160
NEXT row
DEF SEG = &HB800
FOR row = 1 TO 18 STEP 4
  FOR dr = 0 TO 1
    ptr = BasePtr(row + dr)
    POKE ptr + 4, 10
    POKE ptr + 6, 10
    POKE ptr + 40, 10
    POKE ptr + 42, 10
  NEXT dr
NEXT row
DEF SEG

REM 赛车形状
FOR i = 0 TO 4
  FOR j = 0 TO 2
    READ x$
    shape(i, j) = VAL(x$)
  NEXT j
NEXT i
DATA 0,0,0                            '赛车向下移动时 擦除最上一行
DATA 0,1,0
DATA 1,1,1
DATA 0,1,0
DATA 1,0,1

mrow = 14: mcol = 3
CALL showcar(mrow, mcol, 12)
count = 0
score = 0
delaytime = .06
DO
  IF count = 0 THEN score = score + 1
  LOCATE 1, 1: PRINT score
  IF score = 50 THEN Win

  count = count + 1
  IF count = S0 THEN                     '两辆赛车间相隔S0行
    count = 0
    car(0).col = INT(2 * RND) * 3 + 3      '产生3,6
    car(0).row = 0
    FOR i = 3 TO 1 STEP -1
      car(i).row = car(i - 1).row
      car(i).col = car(i - 1).col
    NEXT i
  END IF

  CALL MoveZ

  tim = TIMER + delaytime
  DO
    k = INP(&H60)
    IF k < 128 THEN
      state(k) = 1
    ELSE
      state(k - 128) = 0
    END IF
    IF state(KeyLeft) THEN
      CALL MoveM(Left)
      state(KeyLeft) = 0
    END IF
    IF state(KeyRight) THEN
      CALL MoveM(Right)
      state(KeyRight) = 0
    END IF
    IF state(KeySpace) THEN
      delaytime = .01
    END IF
    IF state(KeySpace) = 0 THEN
      delaytime = .06
    END IF
    IF state(KeyEnter) THEN
       DO WHILE INKEY$ = ""
       LOOP
       state(KeyEnter) = 0
    END IF
    IF state(KeyEsc) THEN
       END
    END IF
  LOOP WHILE TIMER < tim
LOOP
END

SUB MoveM (md)
  canmove = 1
  IF mcol = 3 AND md = Left THEN EXIT SUB
  IF mcol = 6 AND md = Right THEN EXIT SUB
  FOR i = 3 TO 1
    IF ABS(car(i).row - mrow) < 4 AND car(i).col <> mcol THEN
      canmove = 0
      EXIT FOR
    END IF
   NEXT i
  IF canmove THEN
    CALL showcar(mrow, mcol, 0)
    mcol = mcol + 3 * md
    CALL showcar(mrow, mcol, 12)
  END IF
END SUB

SUB MoveZ
  FOR i = 1 TO 3
    car(i).row = count + S0 * (i - 1)           '两辆赛车间相隔S0行
    zrow = car(i).row: zcol = car(i).col
    CALL showcar(zrow, zcol, 10)
    IF ABS(car(i).row - mrow) < 4 AND car(i).col = mcol THEN Lose
  NEXT i
  
  REM 画赛道边
  DEF SEG = &HB800
  ptr = BasePtr(4): x = PEEK(ptr + 4)
  ptr = BasePtr(0): POKE ptr + 4, x
  FOR row = 18 TO 1 STEP -1
    ptr = BasePtr(row - 1)
    x = PEEK(ptr + 4)
    ptr = BasePtr(row)
    POKE ptr + 4, x
    POKE ptr + 6, x
    POKE ptr + 40, x
    POKE ptr + 42, x
  NEXT row
  DEF SEG
END SUB

SUB showcar (row, col, c)
  st = 0: en = 4
  IF col <> 3 AND col <> 6 THEN EXIT SUB
  IF row = mrow AND col = mcol THEN
    st = 1
  ELSE
    IF row < 1 THEN st = 1 - row
    IF row > 14 THEN en = 18 - row
    IF st > en THEN EXIT SUB
  END IF
  DEF SEG = &HB800
  FOR i = st TO en
    ptr = BasePtr(row + i) + 4 * col
    FOR j = 0 TO 2
      POKE ptr + 4 * j, c * shape(i, j)
      POKE ptr + 4 * j + 2, c * shape(i, j)
    NEXT j
  NEXT i
  DEF SEG
END SUB

SUB Win
  LOCATE 23, 1: PRINT "Win"
  END
END SUB

SUB Lose
  LOCATE 23, 1: PRINT "Lose"
  END
END SUB

回复列表 (共7个回复)

沙发

程序还不完善,但也只好匆匆发表,等几天再修改

   (程序暂时没办法打印下来仔细查漏补缺,基本框架还是 测试版的)

板凳

有错误,一开始就挂了!

3 楼

再按 F5运行,大概是可以了的

4 楼

好了 经过再三修改
基本上 是可以正常运行了!

5 楼

好强啊!

6 楼

呵呵!好玩,要编这样的游戏,要会那方面的知识呀??我看看了代码有些都不知道是什么意思.哎[em10][em10][em10]

7 楼

可以玩了,不错!!!

我来回复

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