10LOMEM :29650
20REM  Programmed by Bob Zimmerman, Puget Sound ADAM Network
30IF PEEK(259)<>195 THEN END
40ONERR  GOTO 2520
50DIM u(4, 5), l(4, 5), j(4, 5), rt(30), tr(30), tx(30), ty(30)
60GOSUB 1210:GOTO 540
70IF tu THEN ROT =16
80DRAW 1 AT p, q
90ROT =0
100RETURN
110 x1=37*x+30: y1=30*y
120POKE sa+3, tu*4+2:POKE sa+7, tu*4+2
130POKE sa, y1:POKE sa+1, x1:POKE sa+4, y1:POKE sa+5, x1+7
140CALL sr:RETURN
150 xx=38*x+30: yy=30*y:HCOLOR =4: k=u(y, x)+1
160IF k=6 THEN  k=5
170GOSUB 260:HCOLOR =tu*4+1
180ON k GOTO 190, 200, 210, 220, 240, 240
190RETURN
200 p=xx+22: q=yy+13:GOSUB 70:RETURN
210 p=xx+22: q=yy+13:GOSUB 70: p=xx+10:GOSUB 70:RETURN
220 p=xx+22: q=yy+13:GOSUB 70: p=xx+10:GOSUB 70
230 p=xx+16: q=yy+6:GOSUB 70:RETURN
240 p=xx+22: q=yy+13:GOSUB 70: p=xx+10:GOSUB 70
250 p=xx+16: q=yy+6:GOSUB 70: q=yy+19:GOSUB 70:RETURN
260 p=xx+22: q=yy+13:GOSUB 280: p=xx+10:GOSUB 280
270 p=xx+16: q=yy+6:GOSUB 280: q=yy+19:GOSUB 280:RETURN
280ROT =16:XDRAW 1 AT p, q:ROT =0
290XDRAW 1 AT p, q:RETURN
300 r=0: yy=30*y: xx=38*x+30
310FOR i=1 TO u(y, x):CALL boom:NEXT i
320 u(y, x)=u(y, x)-j(y, x):GOSUB 150
330IF u(y, x)=0 THEN  l(y, x)=0
340 tx=x: ty=y
350IF tx>0 THEN  x=tx-1:GOSUB 410
360IF tx<5 THEN  x=tx+1:GOSUB 410
370 x=tx:IF ty>0 THEN  y=ty-1:GOSUB 410
380IF ty<4 THEN  y=ty+1:GOSUB 410
390IF fs(0)<1 OR fs(1)<1 THEN  e=1
400 y=ty:RETURN
410IF l(y, x)<>tu+1 THEN  fs(tu)=fs(tu)+u(y, x)
420IF l(y, x)<>tu+1 THEN  fs(-tu+1)=fs(-tu+1)-u(y, x)
430 l(y, x)=tu+1: u(y, x)=u(y, x)+1:GOSUB 150
440IF fs(0)<10 THEN VTAB 21:HTAB 22:? " "
450IF fs(1)<10 THEN VTAB 22:HTAB 22:? " "
460VTAB 21:HTAB 22+(fs(0)<10):? fs(0)
470VTAB 22:HTAB 22+(fs(1)<10):? fs(1):RETURN
480 lp=0:IF y>0 THEN IF l(y-1, x)=2 THEN  ay=y-1:GOTO 530
490IF x>0 THEN IF l(y, x-1)=2 THEN  ax=x-1:GOTO 530
500IF x<5 THEN IF l(y, x+1)=2 THEN  ax=x+1:GOTO 530
510IF y<4 THEN IF l(y+1, x)=2 THEN  ay=y+1:GOTO 530
520RETURN
530 lp=1:RETURN
540 tu=-tu+1
550IF fs(0)<10 THEN VTAB 21:HTAB 22:? " "
560IF fs(1)<10 THEN VTAB 22:HTAB 22:? " "
570VTAB 21:HTAB 22+(fs(0)<10):? fs(0)
580VTAB 22:HTAB 22+(fs(1)<10):? fs(1)
590IF np=1 AND tu=0 THEN GOSUB 940:GOTO 620
600GOSUB 790
610IF l(y, x)=-tu+2 THEN CALL screwup:GOTO 600
620 u(y, x)=u(y, x)+1: fs(tu)=fs(tu)+1
630IF l(y, x)=0 THEN  l(y, x)=tu+1
640GOSUB 150
650IF u(y, x)=j(y, x) THEN 670
660GOTO 540
670 e=0: fg=0:FOR a=0 TO 4:FOR b=0 TO 5: y=a: x=b
680IF u(y, x)>=j(y, x) AND e=0 THEN  fg=1:GOSUB 300
690NEXT b, a
700IF e=1 THEN VTAB 24:? "                              "; :GOTO 730
710IF fg=1 THEN 670
720GOTO 540
730POKE 64885, 0: i=0
740 d$=LEFT$(s$, 26):VTAB 24:HTAB 1:? SPC(3); d$; 
750 s$=RIGHT$(s$, 56)+LEFT$(d$, 1)
760IF PEEK(64885)=32 THEN RUN
770IF PEEK(64885)>32 THEN 2520
780CALL zap:POKE zap+10, 145+i: i=i+1:ON i=15 GOTO 730:GOTO 740
790 x=hx(tu+1): y=hy(tu+1):POKE 64885, 0:GOSUB 110
800 dx=0: dy=0: k=PEEK(64885)
810 k$=CHR$(k):POKE 64885, 0
820IF k$=" " THEN  hx(tu+1)=x: hy(tu+1)=y:RETURN
830IF k$=CHR$(160) AND y>0 THEN  dy=-1
840IF k$=CHR$(162) AND y<4 THEN  dy=1
850IF k$=CHR$(163) AND x>0 THEN  dx=-1
860IF k$=CHR$(161) AND x<5 THEN  dx=1
870IF dx=0 AND dy=0 THEN 800
880 x=x+dx: y=y+dy:GOSUB 110:GOTO 800
890HCOLOR =7:FOR i=0 TO 1:FOR y=0 TO 5: yy=30*y+i
900HPLOT 30, yy TO 253, yy:NEXT y, i
910FOR i=0 TO 1:FOR x=0 TO 6: xx=37*x+30+i
920HPLOT xx, 0 TO xx, 150:NEXT x, i
930SCALE =2:RETURN
940 xt=0:FOR y=0 TO 4:FOR x=0 TO 5:IF l(y, x)=2 THEN 960
950 xt=xt+1: ty(xt)=y: tx(xt)=x
960NEXT x, y
970REM  COMPUTERS MOVE
980FOR i=1 TO xt: rt(i)=0: tr(i)=0: y=ty(i): x=tx(i):GOSUB 480
990IF fg=1 AND lp AND u(y, x)>0 THEN 1200
1000IF u(y, x)+1<>j(y, x) THEN 1040
1010IF lp=1 AND u(ay, ax)+1=j(ay, ax) THEN  rt(i)=6:GOTO 1150
1020IF lp=0 AND u(y, x)=0 THEN  rt(i)=4:GOTO 1150
1030IF lp=0 THEN  rt(i)=1:GOTO 1150
1040IF j(y, x)<>2 THEN 1080
1050IF lp=0 AND u(y, x)=1 THEN  rt(i)=1:GOTO 1150
1060IF lp=0 AND u(y, x)=0 THEN  rt(i)=4:GOTO 1150
1070IF lp=1 AND u(y, x)=1 THEN  rt(i)=1:GOTO 1150
1080IF u(ay, ax)+1=j(ay, ax) THEN  rt(i)=1:GOTO 1150
1090IF u(y, x)+2<j(y, x) THEN 1130
1100IF lp=1 AND u(ay, ax)+1<j(ay, ax) THEN  rt(i)=5:GOTO 1150
1110IF lp=0 THEN  rt(i)=3:GOTO 1150
1120 rt(i)=2:GOTO 1150
1130IF lp=0 THEN  rt(i)=2:GOTO 1150
1140 rt(i)=1
1150NEXT: zt=0: ab=6
1160FOR i=1 TO xt:IF rt(i)=ab THEN  zt=zt+1: tr(zt)=i
1170NEXT:IF zt>0 THEN 1190
1180 ab=ab-1:GOTO 1160
1190 dh=INT(zt*RND(1))+1: hd=tr(dh): y=ty(hd): x=tx(hd)
1200 fg=fg+1:CALL zap:RETURN
1210 sr=29600
1220READ a:IF a=256 THEN  sr=29600:GOTO 1270
1230POKE sr, a: sr=sr+1:GOTO 1220
1240DATA  14,227,6,1,205,32,253,58,24,252,253,33,08,00,33,178
1250DATA   112,17,00,00,205,44,253 
1260DATA  58,23,252,253,33,02,00,17,00,00,33,60,115,205,44,253,201,256 
1270 sa=29500
1280FOR i=0 TO 7:READ a:POKE sa+i, a:NEXT
1290DATA  200,200,0,9,200,200,4,9
1300 sd=28850
1310READ a:IF a=256 THEN CALL sr:GOTO 1370
1320POKE sd, a: sd=sd+1:GOTO 1310
1330DATA  255,128,128,128,128,128,128,128,128,128,128,128,128
1340DATA   128,128,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255 
1350DATA  255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,1,1,1,1,1,1
1360DATA   1,1,1,1,1,1,1,1,255,256
1370 boom=28000: i=0
1380READ a:IF a=256 THEN 1420
1390POKE boom+i, a: i=i+1:GOTO 1380
1400DATA  6,240,62,228,211,224,120,211,224,17,00, 5,27,122,179
1410DATA    32,251,4,120,254,255,32,239,62,255,211,224,201,256
1420 zap=28035: i=0
1430READ a:IF a=256 THEN 1470
1440DATA   6,20,62,128,211,224,120,211,224,62,146,211,224,17
1450DATA   0,10,27,122,179,32,251,5,16,234,62,159,211,224,201,256
1460POKE zap+i, a: i=i+1:GOTO 1430
1470 screwup=28070: i=0
1480READ a:IF a=256 THEN 1520
1490DATA  62,226,211,224,62,240,211,224,17,0,175,27,122,179
1500DATA   32,251,62,255,211,224,201,256 
1510POKE screwup+i, a: i=i+1:GOTO 1480
1520POKE 16149, 255:POKE 16150, 255:REM  Allow HImemory POKES
1530POKE 25431, 0:POKE 25471, 0:REM  Set HGR background to transparent
1540 s$="....G-A-M-E  O-V-E-R....press SPACE BAR to play again..."
1550FOR i=1 TO 3:FOR j=1 TO 4: j(i, j)=4:NEXT
1560 j(i, 0)=3: j(i, 5)=3:NEXT
1570DATA  229,42,64,63,35,34,64,63,225,201
1580FOR i=172 TO 181:READ a:POKE i, a:NEXT
1590POKE 171, 0:POKE 11907, 201:REM  INSTALL RANDOM FIX
1600FOR j=1 TO 4: j(0, j)=3: j(4, j)=3:READ a, b: j(a, b)=2:NEXT
1610DATA  0,0,0,5,4,0,4,5
1620POKE 16953, 32:REM  REMOVE CURSOR--restore by POKING 16953,95
1630HGR:VTAB 21:? "   CHAIN REACTION":GOSUB 890
1640IF PEEK(29510)<>201 THEN GOSUB 1770:GOTO 1630
1650VTAB 23:HTAB 1:? "   Number of Players (1,2)? "; 
1660 m$="Player 1"
1670GET k$:IF k$<>"1" AND k$<>"2" THEN 1670
1680 np=VAL(k$):IF np=2 THEN 1720
1690VTAB 23:HTAB 1:? CHR$(24); 
1700? "   Computer First? (Y/N) "; 
1710GET k$:IF k$<>"Y" AND k$<>"y" AND k$<>"N" AND k$<>"n" THEN 1710
1720 tu=ABS(k$="Y" OR k$="y"):VTAB 21:HTAB 1:? CHR$(24)
1730IF np=1 THEN  m$="Computer"
1740VTAB 21:HTAB 9:? m$:VTAB 22:HTAB 9:? "Player 2"
1750VTAB 24:HTAB 1:? CHR$(24); :? "  use ARROW keys and SPACE BAR"; 
1760RETURN
1770VTAB 23:HTAB 1:? "   Need Instructions? (Y/N) "; 
1780POKE 29510, 201:GET a$
1790IF a$<>"Y" AND a$<>"y" AND a$<>"n" AND a$<>"N" THEN 1790
1800IF a$="N" OR a$="n" THEN RETURN
1810TEXT:GOSUB 2480
1820? "   This is a clever strategy    game for one or two players."
1830? " Whether you play against the   computer or another human,"
1840? " the objective is the same:     Eliminate all of your"
1850? " opponent's pieces from the     field of play.":?
1860? " Players take alternate turns,  placing one bomb in a square"
1870? " on each turn.":?
1880? "   The results of a move        depend on how many bombs"
1890? " are already in the chosen      square and adjacent squares."
1900GOSUB 2500
1910? " Whenever any square reaches    CRITICAL MASS, it explodes"
1920? " and sends its bombs into any   neighboring squares."
1930? " If those squares are already   loaded to capacity, they"
1940? " explode too, creating a chain  reaction that can engulf"
1950? " a large area of the board.":?
1960? "   The position of a square in  the grid determines how many"
1970? " bombs it requires to create    an explosion."
1980GOSUB 2500
1990? "   A corner square can hold a   maximum of one bomb.  When"
2000? " you place a second bomb in a   corner square that already"
2010? " holds one, both bombs explode  sending a bomb of your color"
2020? " into two neighboring squares.  After the explosion, the"
2030? " original square is emptied.":?
2040? "   Other squares require more   bombs to create an explosion."
2050? " A border square that isn't on  a corner can hold a maximum"
2060? " of two bombs.  When you place  a third bomb in a border"
2070? " square, its explosion sends    three bombs into the squares"
2080? " that adjoin it."
2090GOSUB 2500
2100? "   Squares in the center of     the game board hold the most"
2110? " bombs and also create the      most devastating explosions."
2120? " When you place a fourth bomb   in a central square, it sends"
2130? " four bombs into squares which  adjoin that position.":?
2140? "   When an explosion sends      bombs into adjacent squares,"
2150? " any bombs in that square       change color to match the"
2160? " color of the exploding bombs."
2170GOSUB 2500
2180? " Should one of the adjoining"
2190? " squares surpass its limit,     that square, too, will"
2200? " explode, creating the          potential for even more"
2210? " explosions.  This process      continues until no more"
2220? " explosions are possible.":?
2230? "   Thus, the situation in Chain Reaction is often volatile."
2240? " The lead often seesaws back    and forth between players,"
2250? " as each creates increasingly   more widespread chain"
2260? " reactions.  Even if defeat     seems almost certain, you"
2270? " can often regain the lead with clever play."
2280GOSUB 2500
2290? " Like other games of strategy   and placement, Chain Reaction"
2300? " rewards the player who can     think ahead.  At first, you"
2310? " may be tempted to start        making explosions as quickly"
2320? " as possible, but that's not    always the best long-term"
2330? " tactic.  By spreading bombs    of your color throughout the"
2340? " board, you may be able to      survive chain reactions that"
2350? " would otherwise wipe you out."
2360GOSUB 2500
2370? "   The mechanics of game play   are simple.":?
2380? " Move the grid-marker by using  the appropriate arrow key."
2390? " When the marker is over the    square in which you wish to"
2400? " place your bomb, simply press  the space bar."
2410? "   Note:  you cannot place one  of your bombs in a square"
2420? " that is already occupied by    a bomb of another color."
2430? "   The computer automatically   rotates turns between players."
2440? "   Good luck, and may all your  explosions create Chain"
2450? " Reactions."
2460VTAB 23:HTAB 1:? "...press any key to return..."
2470GET a$:RETURN
2480HOME:? "  Chain Reaction Instructions":?
2490VTAB 4:HTAB 1:RETURN
2500VTAB 23:HTAB 1:? "...press any key for more..."; 
2510GET a$:GOSUB 2480:RETURN
2520POKE 16953, 95
