主题:[原创]青蛙过河(游戏)
DECLARE SUB Show (row!, col!)
DECLARE SUB Clr (row!, col!)
DECLARE SUB MoveZ (s!)
DECLARE SUB MoveM (md!)
DECLARE SUB Lose ()
DECLARE SUB Win ()
CONST Up = -2, Down = 2, LEFT = -1, RIGHT = 1
CONST Quick = 1, Normal = 2, Slow = 3, ToTurn = Quick * Normal * Slow
CONST R0 = 3, C0 = 30 '左上角位置
KeyUp$ = CHR$(0) + CHR$(72)
KeyDown$ = CHR$(0) + CHR$(80)
KeyLeft$ = CHR$(0) + CHR$(75)
KeyRight$ = CHR$(0) + CHR$(77)
KeySpace$ = CHR$(32)
KeyEnter$ = CHR$(13)
KeyEsc$ = CHR$(27)
DIM SHARED room(4 TO 20, 0 TO 11) AS INTEGER
DIM SHARED mrow, mcol, mc
CLS
RANDOMIZE TIMER
mrow = 18: mcol = INT(10 * RND + 1) '产生一个1-10的列数
COLOR 10
CALL Show(mrow, mcol)
REM 边界标记为1,阻碍物标记为1,目标无标记(0)
FOR row = 4 TO 20
room(row, 0) = 1
room(row, 11) = 1
NEXT row
FOR col = 1 TO 10
room(20, col) = 1
NEXT col
REM 画出边界
COLOR 11
LOCATE R0, C0 + 1: PRINT CHR$(201) + STRING$(20, 205) + CHR$(187)
FOR row = 1 TO 4
LOCATE R0 + row, C0 + 1: PRINT CHR$(186) + STRING$(20, 32) + CHR$(186)
NEXT row
FOR row = 5 TO 17 STEP 2
LOCATE R0 + row, C0 + 1: PRINT CHR$(204) + STRING$(20, 205) + CHR$(185)
LOCATE R0 + row + 1, C0 + 1: PRINT CHR$(186) + STRING$(20, 32) + CHR$(186)
NEXT row
LOCATE R0 + 19, C0 + 1: PRINT CHR$(200) + STRING$(20, 205) + CHR$(188)
REM 画出阻碍物 --移动的方块
COLOR 12
FOR row = 6 TO 16 STEP 2
FOR col = 1 TO 10
READ room(row, col)
IF room(row, col) = 1 THEN CALL Show(row, col) ELSE CALL Clr(row, col)
NEXT col
FOR col = 1 TO 3
READ room(row + 1, col)
NEXT col
NEXT row
DATA 1,1,0,0,0,1,1,0,0,0,3,-1,5
DATA 1,1,0,0,1,1,0,0,1,1,2, 1,4
DATA 1,1,1,0,0,1,1,1,0,0,3,-1,5
DATA 1,1,0,0,0,1,1,0,0,0,2, 1,5
DATA 1,1,0,0,1,1,0,0,1,1,1,-1,4
DATA 1,1,1,0,0,0,1,1,1,0,3, 1,6
REM DATA数据说明前10个1,0为有无阻碍的方块,后三个分别为速度,方向,周期
REM 第1个DATA中1,1,0,0,0为一周期 五个元素
REM 第2个DATA中1,1,0,0 为一周期 四个元素
REM Quick = 1, Normal = 2, Slow = 3, ToTurn = Quick * Normal * Slow
REM ToTurn本应为Quick, Normal, Slow的最小公倍数,这里以乘积代替
REM zc 0 1 2 3 4 5 6 7 8 9 ...
REM Q Q Q Q Q Q Q Q Q Q ...
REM N N N N N ...
REM S S S S ...
REM 以上表示ZC依次取0-9时那种速度的方块应该移动一格,以形成不同的速度的方块
REM 可见ZC是以0-5为一周期(Q, N, S的最小公倍数为6)
REM MoveZ(Quick)就表示移动速度为Quick的那一行方块
zc = 0
DO
IF zc MOD Quick = 0 THEN CALL MoveZ(Quick)
IF zc MOD Normal = 0 THEN CALL MoveZ(Normal)
IF zc MOD Slow = 0 THEN CALL MoveZ(Slow)
zc = zc + 1: IF zc = ToTurn THEN zc = 0
tim = TIMER + .5 '改变.5 就可改变游戏速度
DO
key$ = INKEY$
SELECT CASE key$
CASE KeyUp$, KeySpace$
CALL MoveM(Up)
CASE KeyDown$
CALL MoveM(Down)
CASE KeyLeft$
CALL MoveM(LEFT)
CASE KeyRight$
CALL MoveM(RIGHT)
CASE KeyEnter$
DO WHILE INKEY$ = ""
LOOP
CASE KeyEsc$
END
END SELECT
LOOP WHILE TIMER < tim
LOOP
END
DECLARE SUB Clr (row!, col!)
DECLARE SUB MoveZ (s!)
DECLARE SUB MoveM (md!)
DECLARE SUB Lose ()
DECLARE SUB Win ()
CONST Up = -2, Down = 2, LEFT = -1, RIGHT = 1
CONST Quick = 1, Normal = 2, Slow = 3, ToTurn = Quick * Normal * Slow
CONST R0 = 3, C0 = 30 '左上角位置
KeyUp$ = CHR$(0) + CHR$(72)
KeyDown$ = CHR$(0) + CHR$(80)
KeyLeft$ = CHR$(0) + CHR$(75)
KeyRight$ = CHR$(0) + CHR$(77)
KeySpace$ = CHR$(32)
KeyEnter$ = CHR$(13)
KeyEsc$ = CHR$(27)
DIM SHARED room(4 TO 20, 0 TO 11) AS INTEGER
DIM SHARED mrow, mcol, mc
CLS
RANDOMIZE TIMER
mrow = 18: mcol = INT(10 * RND + 1) '产生一个1-10的列数
COLOR 10
CALL Show(mrow, mcol)
REM 边界标记为1,阻碍物标记为1,目标无标记(0)
FOR row = 4 TO 20
room(row, 0) = 1
room(row, 11) = 1
NEXT row
FOR col = 1 TO 10
room(20, col) = 1
NEXT col
REM 画出边界
COLOR 11
LOCATE R0, C0 + 1: PRINT CHR$(201) + STRING$(20, 205) + CHR$(187)
FOR row = 1 TO 4
LOCATE R0 + row, C0 + 1: PRINT CHR$(186) + STRING$(20, 32) + CHR$(186)
NEXT row
FOR row = 5 TO 17 STEP 2
LOCATE R0 + row, C0 + 1: PRINT CHR$(204) + STRING$(20, 205) + CHR$(185)
LOCATE R0 + row + 1, C0 + 1: PRINT CHR$(186) + STRING$(20, 32) + CHR$(186)
NEXT row
LOCATE R0 + 19, C0 + 1: PRINT CHR$(200) + STRING$(20, 205) + CHR$(188)
REM 画出阻碍物 --移动的方块
COLOR 12
FOR row = 6 TO 16 STEP 2
FOR col = 1 TO 10
READ room(row, col)
IF room(row, col) = 1 THEN CALL Show(row, col) ELSE CALL Clr(row, col)
NEXT col
FOR col = 1 TO 3
READ room(row + 1, col)
NEXT col
NEXT row
DATA 1,1,0,0,0,1,1,0,0,0,3,-1,5
DATA 1,1,0,0,1,1,0,0,1,1,2, 1,4
DATA 1,1,1,0,0,1,1,1,0,0,3,-1,5
DATA 1,1,0,0,0,1,1,0,0,0,2, 1,5
DATA 1,1,0,0,1,1,0,0,1,1,1,-1,4
DATA 1,1,1,0,0,0,1,1,1,0,3, 1,6
REM DATA数据说明前10个1,0为有无阻碍的方块,后三个分别为速度,方向,周期
REM 第1个DATA中1,1,0,0,0为一周期 五个元素
REM 第2个DATA中1,1,0,0 为一周期 四个元素
REM Quick = 1, Normal = 2, Slow = 3, ToTurn = Quick * Normal * Slow
REM ToTurn本应为Quick, Normal, Slow的最小公倍数,这里以乘积代替
REM zc 0 1 2 3 4 5 6 7 8 9 ...
REM Q Q Q Q Q Q Q Q Q Q ...
REM N N N N N ...
REM S S S S ...
REM 以上表示ZC依次取0-9时那种速度的方块应该移动一格,以形成不同的速度的方块
REM 可见ZC是以0-5为一周期(Q, N, S的最小公倍数为6)
REM MoveZ(Quick)就表示移动速度为Quick的那一行方块
zc = 0
DO
IF zc MOD Quick = 0 THEN CALL MoveZ(Quick)
IF zc MOD Normal = 0 THEN CALL MoveZ(Normal)
IF zc MOD Slow = 0 THEN CALL MoveZ(Slow)
zc = zc + 1: IF zc = ToTurn THEN zc = 0
tim = TIMER + .5 '改变.5 就可改变游戏速度
DO
key$ = INKEY$
SELECT CASE key$
CASE KeyUp$, KeySpace$
CALL MoveM(Up)
CASE KeyDown$
CALL MoveM(Down)
CASE KeyLeft$
CALL MoveM(LEFT)
CASE KeyRight$
CALL MoveM(RIGHT)
CASE KeyEnter$
DO WHILE INKEY$ = ""
LOOP
CASE KeyEsc$
END
END SELECT
LOOP WHILE TIMER < tim
LOOP
END