主题:[原创]射击(游戏)
DECLARE SUB zidan ()
DECLARE SUB mubiao ()
DECLARE SUB lose ()
DECLARE SUB win ()
DIM SHARED room(0 TO 24, 0 TO 15)
COMMON SHARED x0
gun = 7: x0 = 20
RANDOMIZE TIMER
VIEW PRINT 1 TO 25: CLS '初始化边界
LOCATE 1, x0 + 1: PRINT CHR$(201); STRING$(30, 205); CHR$(187)
FOR i = 2 TO 24
LOCATE i, x0 + 1: PRINT CHR$(186); SPC(30); CHR$(186)
NEXT i
DEF SEG = &HB800
POKE 24 * 160 + 2 * x0, 200
FOR j = 2 TO 60 STEP 2
POKE 24 * 160 + 2 * x0 + j, 205
NEXT j
POKE 24 * 160 + 2 * x0 + 62, 188
COLOR 9
LOCATE 24, x0 + 2 * gun: PRINT "[]"
DO
CALL mubiao '目标下移
FOR j = 1 TO 15
IF room(0, j) = 24 THEN
CALL lose
END IF
NEXT j
mubiaotime = TIMER + 1.5
DO
zidantime = TIMER + .01
DO
key$ = INKEY$
LOOP UNTIL TIMER > zidantime OR key$ <> ""
COLOR 9
SELECT CASE key$
CASE CHR$(0) + CHR$(75) '按键 左
LOCATE 24, x0 + 2 * gun: PRINT " "
gun = gun - 1: IF gun = 0 THEN gun = 1
LOCATE 24, x0 + 2 * gun: PRINT "[]"
CASE CHR$(0) + CHR$(77) '按键 右
LOCATE 24, x0 + 2 * gun: PRINT " "
gun = gun + 1: IF gun = 16 THEN gun = 15
LOCATE 24, x0 + 2 * gun: PRINT "[]"
CASE " " '按键 空格
room(24, 0) = gun
CASE CHR$(13) '按键 回车:暂停
DO WHILE INKEY$ = ""
LOOP
CASE CHR$(27) '按键 ESCape :退出
COLOR 7
END
END SELECT
COLOR 7
CALL zidan
LOOP UNTIL TIMER > mubiaotime
LOOP
SUB lose
END
END SUB
SUB mubiao
COLOR 10
FOR j = 1 TO 15
room(1, j) = 1: room(0, j) = room(0, j) + 1
'LOCATE 24, 1: PRINT "room(0,"; j; ")="; room(0, j)
NEXT j
FOR k = 1 TO 5
r = INT(RND * 15 + 1)
room(1, r) = 0
NEXT k
FOR i = 23 TO 2 STEP -1
FOR j = 1 TO 15
room(i, j) = room(i - 1, j)
IF room(i, j) = 1 THEN cc$ = "[]" ELSE cc$ = " "
LOCATE i, x0 + 2 * j: PRINT cc$
NEXT j
NEXT i
FOR j = 1 TO 15
FOR i = 24 TO 2 STEP -1
IF room(i, j) = 0 THEN
room(0, j) = room(0, j) - 1
ELSE
EXIT FOR
END IF
NEXT i
NEXT j
COLOR 7
DO '清空按键
key$ = INKEY$
LOOP UNTIL key$ = ""
END SUB
SUB zidan
COLOR 12
FOR i = 2 TO 23
IF room(i, 0) <> 0 THEN
LOCATE i, x0 + 2 * room(i, 0): PRINT " "
END IF
room(i, 0) = room(i + 1, 0)
NEXT i
FOR i = 2 TO 23
IF room(i, 0) > 0 THEN
IF room(i, room(i, 0)) = 0 THEN
LOCATE i, x0 + 2 * room(i, 0): PRINT "[]"
ELSE
LOCATE i, x0 + 2 * room(i, 0): PRINT " "
room(i, room(i, 0)) = 0
room(i, 0) = 0
END IF
END IF
NEXT i
room(24, 0) = 0
COLOR 7
DO '清空按键
key$ = INKEY$
LOOP UNTIL key$ = ""
END SUB
DECLARE SUB mubiao ()
DECLARE SUB lose ()
DECLARE SUB win ()
DIM SHARED room(0 TO 24, 0 TO 15)
COMMON SHARED x0
gun = 7: x0 = 20
RANDOMIZE TIMER
VIEW PRINT 1 TO 25: CLS '初始化边界
LOCATE 1, x0 + 1: PRINT CHR$(201); STRING$(30, 205); CHR$(187)
FOR i = 2 TO 24
LOCATE i, x0 + 1: PRINT CHR$(186); SPC(30); CHR$(186)
NEXT i
DEF SEG = &HB800
POKE 24 * 160 + 2 * x0, 200
FOR j = 2 TO 60 STEP 2
POKE 24 * 160 + 2 * x0 + j, 205
NEXT j
POKE 24 * 160 + 2 * x0 + 62, 188
COLOR 9
LOCATE 24, x0 + 2 * gun: PRINT "[]"
DO
CALL mubiao '目标下移
FOR j = 1 TO 15
IF room(0, j) = 24 THEN
CALL lose
END IF
NEXT j
mubiaotime = TIMER + 1.5
DO
zidantime = TIMER + .01
DO
key$ = INKEY$
LOOP UNTIL TIMER > zidantime OR key$ <> ""
COLOR 9
SELECT CASE key$
CASE CHR$(0) + CHR$(75) '按键 左
LOCATE 24, x0 + 2 * gun: PRINT " "
gun = gun - 1: IF gun = 0 THEN gun = 1
LOCATE 24, x0 + 2 * gun: PRINT "[]"
CASE CHR$(0) + CHR$(77) '按键 右
LOCATE 24, x0 + 2 * gun: PRINT " "
gun = gun + 1: IF gun = 16 THEN gun = 15
LOCATE 24, x0 + 2 * gun: PRINT "[]"
CASE " " '按键 空格
room(24, 0) = gun
CASE CHR$(13) '按键 回车:暂停
DO WHILE INKEY$ = ""
LOOP
CASE CHR$(27) '按键 ESCape :退出
COLOR 7
END
END SELECT
COLOR 7
CALL zidan
LOOP UNTIL TIMER > mubiaotime
LOOP
SUB lose
END
END SUB
SUB mubiao
COLOR 10
FOR j = 1 TO 15
room(1, j) = 1: room(0, j) = room(0, j) + 1
'LOCATE 24, 1: PRINT "room(0,"; j; ")="; room(0, j)
NEXT j
FOR k = 1 TO 5
r = INT(RND * 15 + 1)
room(1, r) = 0
NEXT k
FOR i = 23 TO 2 STEP -1
FOR j = 1 TO 15
room(i, j) = room(i - 1, j)
IF room(i, j) = 1 THEN cc$ = "[]" ELSE cc$ = " "
LOCATE i, x0 + 2 * j: PRINT cc$
NEXT j
NEXT i
FOR j = 1 TO 15
FOR i = 24 TO 2 STEP -1
IF room(i, j) = 0 THEN
room(0, j) = room(0, j) - 1
ELSE
EXIT FOR
END IF
NEXT i
NEXT j
COLOR 7
DO '清空按键
key$ = INKEY$
LOOP UNTIL key$ = ""
END SUB
SUB zidan
COLOR 12
FOR i = 2 TO 23
IF room(i, 0) <> 0 THEN
LOCATE i, x0 + 2 * room(i, 0): PRINT " "
END IF
room(i, 0) = room(i + 1, 0)
NEXT i
FOR i = 2 TO 23
IF room(i, 0) > 0 THEN
IF room(i, room(i, 0)) = 0 THEN
LOCATE i, x0 + 2 * room(i, 0): PRINT "[]"
ELSE
LOCATE i, x0 + 2 * room(i, 0): PRINT " "
room(i, room(i, 0)) = 0
room(i, 0) = 0
END IF
END IF
NEXT i
room(24, 0) = 0
COLOR 7
DO '清空按键
key$ = INKEY$
LOOP UNTIL key$ = ""
END SUB