2005/06/05 | 当年的坦克游戏[qbasic源代码]
类别(编程宝典) | 评论(1) | 阅读(993) | 发表于 14:43

下载地址:http://www.hoker.cn/hoker/bbs/viewfile.asp?ID=300

DECLARE SUB drw ()
DECLARE SUB die ()
DECLARE SUB map ()
DECLARE SUB kil ()
DECLARE SUB zd ()
DECLARE SUB dzm ()
DIM SHARED life AS INTEGER
life = 3
TYPE tank
d AS INTEGER
x AS INTEGER
y AS INTEGER
END TYPE
TYPE zhidan
x AS INTEGER
y AS INTEGER
x1 AS INTEGER
y1 AS INTEGER
i AS INTEGER
END TYPE
DIM SHARED t(4) AS tank
DIM SHARED c(4) AS tank
DIM SHARED z(4) AS zhidan
DIM SHARED i, i1 AS INTEGER, a$, f AS LONG
DIM a(1000)
DIM b(1000)
DIM ba(260)
DIM SHARED st(100)
DIM SHARED m(-2 TO 25, -2 TO 25)
DEF SEG = VARSEG(ba(0))
BLOAD "qbasic.x", 0
SCREEN 12
PUT (10, 10), ba
DEF SEG = VARSEG(st(0))
BLOAD "stick-1.x", 0
DEF SEG = VARSEG(a(0))
BLOAD "tank-2.x", 0
DEF SEG = VARSEG(b(0))
BLOAD "tank-1.x", 0
t(1).x = 18: t(1).y = 22
m(t(1).x, t(1).y) = 1
m(t(1).x + 1, t(1).y) = 1
m(t(1).x, t(1).y + 1) = 1
m(t(1).x + 1, t(1).y + 1) = 1
m(22, 23) = 7
m(23, 22) = 7
m(22, 22) = 7
m(23, 23) = 7
SCREEN 12
WINDOW SCREEN (-100, -100)-(539, 379)
PUT (22 * 15, 22 * 15), ba(0)
LINE (2 * 15, 1 * 15)-STEP(15, 15), 2, BF
LINE (-1, -1)-(24 * 15 + 1, 24 * 15 + 1), 13, B
ON TIMER(1) GOSUB TimeUpdate
TIMER ON
PRINT "Time: "; TIME$
map
WHILE a$ <> CHR$(27)
'drw
p = (p + 1) MOD 6
IF p <> 0 THEN
FOR n = 1 TO 4
LINE (c(n).x * 15, c(n).y * 15)-(c(n).x * 15 + 30, c(n).y * 15 + 30), 0, BF
c(n).x = t(n).x
c(n).y = t(n).y
NEXT n
a$ = INKEY$
dzm
SELECT CASE a$
CASE "w"
t(1).d = 0
IF t(1).y > 0 AND m(t(1).x, t(1).y - 1) = 0 AND m(t(1).x + 1, t(1).y - 1) = 0 THEN
m(t(1).x, t(1).y) = 0
m(t(1).x + 1, t(1).y) = 0
m(t(1).x, t(1).y + 1) = 0
m(t(1).x + 1, t(1).y + 1) = 0
t(1).y = t(1).y - 1
m(t(1).x, t(1).y) = 1
m(t(1).x + 1, t(1).y) = 1
m(t(1).x, t(1).y + 1) = 1
m(t(1).x + 1, t(1).y + 1) = 1
END IF
CASE "s"
t(1).d = 2
IF t(1).y < 22 AND m(t(1).x, t(1).y + 2) = 0 AND m(t(1).x + 1, t(1).y + 2) = 0 THEN
m(t(1).x, t(1).y) = 0
m(t(1).x + 1, t(1).y) = 0
m(t(1).x, t(1).y + 1) = 0
m(t(1).x + 1, t(1).y + 1) = 0
t(1).y = t(1).y + 1
m(t(1).x, t(1).y) = 1
m(t(1).x + 1, t(1).y) = 1
m(t(1).x, t(1).y + 1) = 1
m(t(1).x + 1, t(1).y + 1) = 1
END IF
CASE "a"
t(1).d = 3
IF t(1).x > 0 AND m(t(1).x - 1, t(1).y) = 0 AND m(t(1).x - 1, t(1).y + 1) = 0 THEN
m(t(1).x, t(1).y) = 0
m(t(1).x + 1, t(1).y) = 0
m(t(1).x, t(1).y + 1) = 0
m(t(1).x + 1, t(1).y + 1) = 0
t(1).x = t(1).x - 1
m(t(1).x, t(1).y) = 1
m(t(1).x + 1, t(1).y) = 1
m(t(1).x, t(1).y + 1) = 1
m(t(1).x + 1, t(1).y + 1) = 1
END IF
CASE "d"
t(1).d = 1
IF t(1).x < 22 AND m(t(1).x + 2, t(1).y) = 0 AND m(t(1).x + 2, t(1).y + 1) = 0 THEN
m(t(1).x, t(1).y) = 0
m(t(1).x + 1, t(1).y) = 0
m(t(1).x, t(1).y + 1) = 0
m(t(1).x + 1, t(1).y + 1) = 0
t(1).x = t(1).x + 1
m(t(1).x, t(1).y) = 1
m(t(1).x + 1, t(1).y) = 1
m(t(1).x, t(1).y + 1) = 1
m(t(1).x + 1, t(1).y + 1) = 1
END IF
CASE CHR$(13)
IF z(1).i = 0 THEN
z(1).i = 1
SELECT CASE t(1).d
CASE IS = 0
z(1).x1 = 0
z(1).y1 = -1
z(1).x = t(1).x + 1
z(1).y = t(1).y
CASE IS = 2
z(1).x1 = 0
z(1).y1 = 1
z(1).x = t(1).x + 1
z(1).y = t(1).y + 2
CASE IS = 3
z(1).x1 = -1
z(1).y1 = 0
z(1).x = t(1).x
z(1).y = t(1).y + 1
CASE IS = 1
z(1).x1 = 1
z(1).y1 = 0
z(1).x = t(1).x + 2
z(1).y = t(1).y + 1
END SELECT
END IF
END SELECT
PUT (t(1).x * 15, t(1).y * 15), a((t(1).d) * 250)
FOR n = 2 TO 4
PUT (t(n).x * 15, t(n).y * 15), b((t(n).d) * 250)
NEXT n
END IF
zd
kil
tim = TIMER
FOR n1 = 1 TO 14000
NEXT n1
IF life <= 0 THEN die
WEND
END
TimeUpdate:
LOCATE 1, 7: PRINT TIME$
RETURN

SUB die
SCREEN 1
COLOR 1, 2
FOR u = 1 TO 5
PRINT
NEXT u
PRINT " You Die!"
tr = TIMER
WHILE TIMER - tr < 1 OR INKEY$ = ""
WEND
END
END SUB

SUB drw
FOR n = 0 TO 360 STEP 15
LINE (n, 0)-(n, 360), 2
NEXT n
FOR n = 0 TO 360 STEP 15
LINE (0, n)-(360, n), 2
NEXT n
END SUB

SUB dzm
i1 = i1 + 1
IF i1 MOD 3 = 0 THEN
FOR n = 2 TO 4
i = INT(26 * RND)
1 SELECT CASE i
CASE IS > 14
i = t(n).d: GOTO 1
CASE IS > 10
IF z(n).i = 0 THEN
z(n).i = 1
SELECT CASE t(n).d
CASE IS = 0
z(n).x1 = 0
z(n).y1 = -1
z(n).x = t(n).x + 1
z(n).y = t(n).y
CASE IS = 2
z(n).x1 = 0
z(n).y1 = 1
z(n).x = t(n).x + 1
z(n).y = t(n).y + 2
CASE IS = 3
z(n).x1 = -1
z(n).y1 = 0
z(n).x = t(n).x
z(n).y = t(n).y + 1
CASE IS = 1
z(n).x1 = 1
z(n).y1 = 0
z(n).x = t(n).x + 2
z(n).y = t(n).y + 1
END SELECT
END IF
CASE IS = 6
IF t(n).x < 12 THEN
i = 1
ELSE
i = 3
END IF
CASE IS = 5
i = 2: GOTO 1
CASE IS = 0
t(n).d = 0
IF t(n).y > 0 AND m(t(n).x, t(n).y - 1) = 0 AND m(t(n).x + 1, t(n).y - 1) = 0 THEN
m(t(n).x, t(n).y) = 0
m(t(n).x + 1, t(n).y) = 0
m(t(n).x, t(n).y + 1) = 0
m(t(n).x + 1, t(n).y + 1) = 0
t(n).y = t(n).y - 1
m(t(n).x, t(n).y) = n
m(t(n).x + 1, t(n).y) = n
m(t(n).x, t(n).y + 1) = n
m(t(n).x + 1, t(n).y + 1) = n
END IF
CASE IS = 2
t(n).d = 2
IF t(n).y < 22 AND m(t(n).x, t(n).y + 2) = 0 AND m(t(n).x + 1, t(n).y + 2) = 0 THEN
m(t(n).x, t(n).y) = 0
m(t(n).x + 1, t(n).y) = 0
m(t(n).x, t(n).y + 1) = 0
m(t(n).x + 1, t(n).y + 1) = 0
t(n).y = t(n).y + 1
m(t(n).x, t(n).y) = n
m(t(n).x + 1, t(n).y) = n
m(t(n).x, t(n).y + 1) = n
m(t(n).x + 1, t(n).y + 1) = n
END IF
CASE IS = 3
t(n).d = 3
IF t(n).x > 0 AND m(t(n).x - 1, t(n).y) = 0 AND m(t(n).x - 1, t(n).y + 1) = 0 THEN
m(t(n).x, t(n).y) = 0
m(t(n).x + 1, t(n).y) = 0
m(t(n).x, t(n).y + 1) = 0
m(t(n).x + 1, t(n).y + 1) = 0
t(n).x = t(n).x - 1
m(t(n).x, t(n).y) = n
m(t(n).x + 1, t(n).y) = n
m(t(n).x, t(n).y + 1) = n
m(t(n).x + 1, t(n).y + 1) = n
END IF
CASE IS = 1
t(n).d = 1
IF t(n).x < 22 AND m(t(n).x + 2, t(n).y) = 0 AND m(t(n).x + 2, t(n).y + 1) = 0 THEN
m(t(n).x, t(n).y) = 0
m(t(n).x + 1, t(n).y) = 0
m(t(n).x, t(n).y + 1) = 0
m(t(n).x + 1, t(n).y + 1) = 0
t(n).x = t(n).x + 1
m(t(n).x, t(n).y) = n
m(t(n).x + 1, t(n).y) = n
m(t(n).x, t(n).y + 1) = n
m(t(n).x + 1, t(n).y + 1) = n
END IF
END SELECT
NEXT n
i1 = 1
END IF
END SUB

SUB kil
IF z(1).i = 1 THEN
FOR n = 2 TO 4
IF m(z(1).x, z(1).y) = n OR m(z(1).x - 1, z(1).y) = n OR m(z(1).x, z(1).y - 1) = n OR m(z(1).x - 1, z(1).y - 1) = n THEN
z(1).i = 3
m(t(n).x, t(n).y) = 0
m(t(n).x + 1, t(n).y) = 0
m(t(n).x, t(n).y + 1) = 0
m(t(n).x + 1, t(n).y + 1) = 0
f = f + 1
t(n).x = (f MOD 3) * 11
t(n).y = 0
END IF
NEXT n
SELECT CASE 5
CASE IS = m(z(1).x, z(1).y)
LINE (z(1).x * 15, z(1).y * 15)-STEP(15, 15), 0, BF
m(z(1).x, z(1).y) = 0
z(1).i = 3
CASE IS = m(z(1).x - 1, z(1).y)
LINE ((z(1).x - 1) * 15, z(1).y * 15)-STEP(15, 15), 0, BF
m(z(1).x - 1, z(1).y) = 0
z(1).i = 3
CASE IS = m(z(1).x, z(1).y - 1)
LINE (z(1).x * 15, (z(1).y - 1) * 15)-STEP(15, 15), 0, BF
m(z(1).x, z(1).y - 1) = 0
z(1).i = 3
CASE IS = m(z(1).x - 1, z(1).y - 1)
LINE ((z(1).x - 1) * 15, (z(1).y - 1) * 15)-STEP(15, 15), 0, BF
m(z(1).x - 1, z(1).y - 1) = 0
z(1).i = 3
END SELECT
SELECT CASE 6
CASE IS = m(z(1).x, z(1).y)
z(1).i = 3
CASE IS = m(z(1).x - 1, z(1).y)
z(1).i = 3
CASE IS = m(z(1).x, z(1).y - 1)
z(1).i = 3
CASE IS = m(z(1).x - 1, z(1).y - 1)
z(1).i = 3
END SELECT
SELECT CASE 7
CASE IS = m(z(1).x, z(1).y)
die
CASE IS = m(z(1).x - 1, z(1).y)
die
CASE IS = m(z(1).x, z(1).y - 1)
die
CASE IS = m(z(1).x - 1, z(1).y - 1)
die
END SELECT

IF z(1).i = 3 THEN z(1).i = 0
END IF
FOR n = 2 TO 4
IF z(n).i = 1 THEN
IF (m(z(n).x, z(n).y) = 1 OR m(z(n).x - 1, z(n).y) = 1 OR m(z(n).x, z(n).y - 1) = 1 OR m(z(n).x - 1, z(n).y - 1) = 1) THEN
z(n).i = 3
life = life - 1
m(t(1).x, t(1).y) = 0
m(t(1).x + 1, t(1).y) = 0
m(t(1).x, t(1).y + 1) = 0
m(t(1).x + 1, t(1).y + 1) = 0
t(1).x = 12: t(1).y = 22
END IF
SELECT CASE 5
CASE IS = m(z(n).x, z(n).y)
LINE (z(n).x * 15, z(n).y * 15)-STEP(15, 15), 0, BF
m(z(n).x, z(n).y) = 0
z(n).i = 3
CASE IS = m(z(n).x - 1, z(n).y)
LINE ((z(n).x - 1) * 15, z(n).y * 15)-STEP(15, 15), 0, BF
m(z(n).x - 1, z(n).y) = 0
z(n).i = 3
CASE IS = m(z(n).x, z(n).y - 1)
LINE (z(n).x * 15, (z(n).y - 1) * 15)-STEP(15, 15), 0, BF
m(z(n).x, z(n).y - 1) = 0
z(n).i = 3
CASE IS = m(z(n).x - 1, z(n).y - 1)
LINE ((z(n).x - 1) * 15, (z(n).y - 1) * 15)-STEP(15, 15), 0, BF
m(z(n).x - 1, z(n).y - 1) = 0
z(n).i = 3
END SELECT
SELECT CASE 6
CASE IS = m(z(n).x, z(n).y)
z(n).i = 3
CASE IS = m(z(n).x - 1, z(n).y)
z(n).i = 3
CASE IS = m(z(n).x, z(n).y - 1)
z(n).i = 3
CASE IS = m(z(n).x - 1, z(n).y - 1)
z(n).i = 3
END SELECT
SELECT CASE 7
CASE IS = m(z(n).x, z(n).y)
die
CASE IS = m(z(n).x - 1, z(n).y)
die
CASE IS = m(z(n).x, z(n).y - 1)
die
CASE IS = m(z(n).x - 1, z(n).y - 1)
die
END SELECT
IF z(n).i = 3 THEN z(n).i = 0
END IF
NEXT n
END SUB

SUB map
OPEN "2.txt" FOR INPUT AS #1
FOR n = 3 TO 20
FOR n1 = 0 TO 23
INPUT #1, m(n1, n)
IF m(n1, n) = 5 THEN
PUT (n1 * 15, n * 15), st(0)
END IF
IF m(n1, n) = 6 THEN
PUT (n1 * 15, n * 15), st(50)
END IF
NEXT n1, n
CLOSE #1
END SUB

SUB zd
FOR n = 1 TO 4
IF z(n).i = 1 THEN
CIRCLE (z(n).x * 15, z(n).y * 15), 3, 0
z(n).x = z(n).x + z(n).x1
z(n).y = z(n).y + z(n).y1
CIRCLE (z(n).x * 15, z(n).y * 15), 3, 19
IF z(n).x > 23 OR z(n).x < 0 OR z(n).y > 23 OR z(n).y < 0 THEN
z(n).i = 0
END IF
END IF
NEXT n
END SUB

0

评论Comments