4 楼
ljxh401 [专家分:200] 发布于 2003-12-13 12:13:00
DECLARE SUB mouseTest ()
DECLARE SUB DrawMap (clor AS INTEGER)
DECLARE SUB Ball (x AS INTEGER, y AS INTEGER, i AS INTEGER)
DECLARE SUB ai (x AS INTEGER, y AS INTEGER, index AS INTEGER, ip AS INTEGER)
DECLARE SUB KillTest (x AS INTEGER, y AS INTEGER, ip AS INTEGER)
DECLARE SUB MouseSet (x AS INTEGER, y AS INTEGER, n AS INTEGER)
DECLARE SUB SETmouse (x AS INTEGER, y AS INTEGER)
DECLARE FUNCTION MouseX! ()
DECLARE FUNCTION MouseY! ()
DECLARE SUB MouseOn ()
DECLARE SUB MouseOff ()
DECLARE FUNCTION MouseClick% (flag AS INTEGER)
DECLARE FUNCTION MouseMove% ()
'$INCLUDE: 'qb.bi'
DIM SHARED REGS AS RegType
TYPE fangxiang
x AS INTEGER
y AS INTEGER
END TYPE
TYPE qizi
x AS INTEGER
y AS INTEGER
score AS LONG
END TYPE
DIM SHARED way(7) AS fangxiang
DIM SHARED q(15, 15) AS INTEGER
DIM SHARED mx AS INTEGER
DIM SHARED my AS INTEGER
DIM SHARED unit AS INTEGER
DIM value AS INTEGER
DIM x1 AS INTEGER
DIM y1 AS INTEGER
DIM x2 AS INTEGER
DIM y2 AS INTEGER
DIM i AS INTEGER
DIM SHARED fenshu(1 TO 4) AS INTEGER
fenshu(1) = 20000
fenshu(2) = 64
fenshu(3) = 8
fenshu(4) = 1
OPEN "setting.txt" FOR INPUT AS #1
FOR i = 1 TO 4
INPUT #1, fenshu(i)
NEXT i
CLOSE #1
way(0).x = 1
way(1).x = 1
way(1).y = 1
way(2).y = 1
way(3).x = -1
way(3).y = 1
way(4).x = -1
way(5).x = -1
way(5).y = -1
way(6).y = -1
way(7).x = 1
way(7).y = -1
mx = 20
my = 20
unit = 26
DIM SHARED zi(65) AS qizi
DIM SHARED indexzi AS INTEGER
DIM i1 AS INTEGER
DIM i2 AS INTEGER
DIM score AS INTEGER
DIM SHARED kt AS INTEGER
DIM attack AS qizi
DIM defend AS qizi
DIM SHARED waiting AS INTEGER
DIM SHARED deep AS INTEGER
DIM SHARED clor AS INTEGER
deep = 3
SCREEN 12
DrawMap 2
MouseOn
mouseTest
Ball 8, 8, 1
DIM mx1 AS INTEGER, mx2 AS INTEGER, my1 AS INTEGER, my2 AS INTEGER
mx1 = 7: my1 = 7
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), clor, B
WHILE value = 0
t = TIMER
WHILE TIMER - t < .2 AND ink$ = ""
ink$ = INKEY$
WEND
SELECT CASE ink$
CASE IS = " "
x1 = mx1
y1 = my1
ink$ = ""
GOTO 1
CASE IS = CHR$(0) + CHR$(72)
ink$ = ""
IF my1 > 1 THEN
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), 8, B
my1 = my1 - 1
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), clor, B
END IF
CASE IS = CHR$(0) + CHR$(80)
ink$ = ""
IF my1 < 15 THEN
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), 8, B
my1 = my1 + 1
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), clor, B
END IF
CASE IS = CHR$(0) + CHR$(75)
ink$ = ""
IF mx1 > 1 THEN
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), 8, B
mx1 = mx1 - 1
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), clor, B
END IF
CASE IS = CHR$(0) + CHR$(77)
ink$ = ""
IF mx1 < 15 THEN
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), 8, B
mx1 = mx1 + 1
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), clor, B
END IF
END SELECT
IF MouseClick(0) = 1 THEN
x1 = (MouseX + unit / 2 - mx) \ unit + 1
y1 = (MouseY + unit / 2 - my) \ unit + 1
1
IF x1 > 0 AND x1 < 16 AND y1 > 0 AND y1 < 16 THEN
IF q(x1, y1) = 0 THEN
value = 1
Ball x1, y1, 2
END IF
END IF
END IF
WEND
Ball 16 - y1, x1, 1
'Main Programme
x2 = 8
y2 = 8
ink$ = ""
WHILE ink$ <> CHR$(27)
t = TIMER
WHILE TIMER - t < .2 AND ink$ = ""
ink$ = INKEY$
WEND
SELECT CASE ink$
CASE IS = " "
x1 = mx1
y1 = my1
ink$ = ""
GOTO 2
CASE IS = CHR$(0) + CHR$(72)
ink$ = ""
IF my1 > 1 THEN
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), 8, B
my1 = my1 - 1
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), clor, B
END IF
CASE IS = CHR$(0) + CHR$(80)
ink$ = ""
IF my1 < 15 THEN
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), 8, B
my1 = my1 + 1
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), clor, B
END IF
CASE IS = CHR$(0) + CHR$(75)
ink$ = ""
IF mx1 > 1 THEN
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), 8, B
mx1 = mx1 - 1
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), clor, B
END IF
CASE IS = CHR$(0) + CHR$(77)
ink$ = ""
IF mx1 < 15 THEN
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), 8, B
mx1 = mx1 + 1
LINE (mx + (mx1 - 1) * unit - unit / 2 + 1, my + (my1 - 1) * unit - unit / 2 + 1)-STEP(unit - 2, unit - 2), clor, B
END IF
END SELECT
IF MouseClick(0) = 1 THEN
x1 = (MouseX + unit / 2 - mx) \ unit + 1
y1 = (MouseY + unit / 2 - my) \ unit + 1
2
IF x1 > 0 AND x1 < 16 AND y1 > 0 AND y1 < 16 THEN
IF q(x1, y1) = 0 THEN
MouseOff
CIRCLE (mx + (x2 - 1) * unit, my + (y2 - 1) * unit), unit / 2 - 2, 0
PAINT (mx + (x2 - 1) * unit, my + (y2 - 1) * unit), 0, 0
MouseOn
waiting = waiting + 1
Ball x1, y1, 2
KillTest x1, y1, 2
IF kt = 1 THEN
LOCATE 15, 30
PRINT "You win!!"
SLEEP
END
END IF
IF q(attack.x, attack.y) > 0 THEN
attack.score = -1
ELSE
indexzi = 0
zi(0).score = 0
q(attack.x, attack.y) = 1
ai attack.x, attack.y, 2, 1
attack.score = zi(0).score
q(attack.x, attack.y) = 0
END IF
FOR i = 0 TO 65
zi(i).score = 0
NEXT i
indexzi = 0
ai x2, y2, 1, 1
attack.score = attack.score / 1.1
FOR i = 0 TO indexzi - 1
IF zi(i).score > attack.score THEN
SWAP attack.score, zi(i).score
SWAP attack.x, zi(i).x
SWAP attack.y, zi(i).y
END IF
NEXT i
attack.score = attack.score * 1.1
FOR i = 0 TO indexzi - 1
zi(i).score = 0
NEXT i
indexzi = 0
ai x1, y1, 1, 2
i2 = indexzi - 1
FOR i = 0 TO i2
indexzi = i
score = zi(i).score * .7
zi(i).score = 0
q(zi(i).x, zi(i).y) = 1
ai zi(i).x, zi(i).y, 2, 1
q(zi(i).x, zi(i).y) = 0
zi(i).score = zi(i).score * .3 + score
NEXT i
indexzi = i
IF q(defend.x, defend.y) > 0 THEN
defend.score = -1
END IF
FOR i = 0 TO indexzi - 1
IF zi(i).score > defend.score THEN
SWAP defend.score, zi(i).score
SWAP defend.x, zi(i).x
SWAP defend.y, zi(i).y
END IF
NEXT i
LOCATE 1, 20
PRINT indexzi
i1 = 0
IF defend.score >= attack.score THEN
zi(i1).x = defend.x
zi(i1).y = defend.y
ELSE
zi(i1).x = attack.x
zi(i1).y = attack.y
END IF
LOCATE 1, 1
PRINT attack.x; " "; attack.y; ""; attack.score; " ";
PRINT defend.x; " "; defend.y; ""; defend.score; " "
Ball zi(i1).x, zi(i1).y, 1
x2 = zi(i1).x
y2 = zi(i1).y
KillTest x2, y2, 1
IF kt = 1 THEN
LOCATE 15, 20
PRINT "How foolish you are !!"
SLEEP
END
END IF
END IF
END IF
END IF
IF waiting > 7 THEN
deep = 4
END IF
MouseOff
CIRCLE (mx + (x2 - 1) * unit, my + (y2 - 1) * unit), unit / 2 - 2, 1
PAINT (mx + (x2 - 1) * unit, my + (y2 - 1) * unit), 1, 1
MouseOn
WEND
SUB ai (x AS INTEGER, y AS INTEGER, index AS INTEGER, ip AS INTEGER)
DIM i1 AS INTEGER
DIM i2 AS INTEGER
DIM x1 AS INTEGER
DIM y1 AS INTEGER
FOR i1 = 0 TO 7
FOR i2 = 1 TO 4
x1 = x + i2 * way(i1).x: y1 = y + i2 * way(i1).y
IF x1 > 0 AND x1 < 16 AND y1 > 0 AND y1 < 16 THEN
SELECT CASE q(x1, y1)
CASE IS = 0
q(x1, y1) = ip
KillTest x1, y1, ip
zi(indexzi).score = zi(indexzi).score + fenshu(index) * kt
IF index < deep AND kt = 0 THEN
ai x1, y1, index + 1, ip
END IF
q(x1, y1) = 0
IF index = 1 THEN
zi(indexzi).x = x1
zi(indexzi).y = y1
indexzi = indexzi + 1
END IF
CASE IS = (ip) MOD 2 + 1
EXIT FOR
END SELECT
END IF
NEXT i2, i1
END SUB
SUB Ball (x AS INTEGER, y AS INTEGER, i AS INTEGER)
q(x, y) = i
MouseOff
CIRCLE (mx + (x - 1) * unit, my + (y - 1) * unit), unit / 2 - 2, (i - 1) * 15
PAINT (mx + (x - 1) * unit, my + (y - 1) * unit), (i - 1) * 15, (i - 1) * 15
MouseOn
END SUB
SUB DrawMap (clor AS INTEGER)
DIM i AS INTEGER
PAINT (100, 100), 8, 8
FOR i = 0 TO 14
LINE (mx + i * unit, my)-STEP(0, 14 * unit), clor
NEXT i
FOR i = 0 TO 14
LINE (mx, my + i * unit)-STEP(14 * unit, 0), clor
NEXT i
LOCATE 4, 55
PRINT "hoker.58shop.com\bbs"
LOCATE 5, 55
PRINT "scau.edu.cn"
LOCATE 6, 55
PRINT "ljxh401@sohu.com"
END SUB
SUB KillTest (x AS INTEGER, y AS INTEGER, ip AS INTEGER)
DIM i1 AS INTEGER
DIM i2 AS INTEGER
DIM i3 AS INTEGER
DIM x1 AS INTEGER
DIM y1 AS INTEGER
DIM value AS INTEGER
kt = 0
FOR i1 = 0 TO 7
FOR i2 = 4 TO 0 STEP -1
value = 0
FOR i3 = 0 TO 4
x1 = x + (i2 - i3) * way(i1).x
y1 = y + (i2 - i3) * way(i1).y
IF x1 > 0 AND x1 < 16 AND y1 > 0 AND y1 < 16 THEN
IF q(x1, y1) <> ip THEN
EXIT FOR
END IF
ELSE
EXIT FOR
END IF
NEXT i3
IF i3 = 5 THEN
kt = 1
EXIT SUB
END IF
NEXT i2, i1
END SUB
FUNCTION MouseClick% (flag AS INTEGER)
'鼠标按键判断,参数flag=0表示检测左键,参数flag=1表示检测右键
REGS.ax = 6
REGS.bx = flag
INTERRUPT &H33, REGS, REGS
MouseClick = REGS.bx '返回值不为0即发生事件
END FUNCTION
FUNCTION MouseMove%
'判断鼠标是否移动
'移动返回1否则返回0
REGS.ax = 11
INTERRUPT &H33, REGS, REGS
IF REGS.cx <> 0 OR REGS.dx <> 0 THEN
MouseMove = 1
ELSE
MouseMove = 0
END IF
END FUNCTION
SUB MouseOff
'屏蔽鼠标(使鼠标不可见)
REGS.ax = 2
INTERRUPT &H33, REGS, REGS
END SUB
SUB MouseOn
'打开鼠标(使鼠标可见)
REGS.ax = 1
INTERRUPT &H33, REGS, REGS
END SUB
SUB MouseSet (x AS INTEGER, y AS INTEGER, n AS INTEGER)
IF n = 1 THEN
x = MouseX + x
y = MouseY + y
END IF
REGS.ax = 4
REGS.cx = x 'x表示鼠标的x坐标
REGS.dx = y 'y表示鼠标的y坐标
INTERRUPT &H33, REGS, REGS
END SUB
SUB mouseTest
DIM i1 AS INTEGER
MouseSet 0, 0, 0
i1 = POINT(2, 2)
IF i1 = 0 THEN
clor = 15
ELSE
clor = 8
END IF
END SUB
FUNCTION MouseX
REGS.ax = 3
INTERRUPT &H33, REGS, REGS
MouseX = REGS.cx '返回鼠标的x坐标
END FUNCTION
FUNCTION MouseY
REGS.ax = 3
INTERRUPT &H33, REGS, REGS
MouseY = REGS.dx '返回鼠标的y坐标
END FUNCTION
速度很慢