home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 198 / 198.d81 / knights / knights.080d / knights.a7ae (.txt)
Encoding:
Commodore BASIC  |  2000-01-01  |  25.4 KB  |  377 lines

  1. 1 rem "knights basic" 2000.09.21
  2. 2 poke55,0:poke56,55:clr
  3. 3 gosub3002
  4. 4 gosub12:onq%goto4002
  5. 5 q%=3:gosub102:onq%goto4002,5,6,6,4
  6. 6 ono%(0,0)gosub12,160:onq%goto4002,5
  7. 7 gosub174:onq%goto4002,5,5,5,4
  8. 10 :
  9. 12 : rem input
  10. 14 :
  11. 16 pokevl+39,1:rem ready
  12. 18 sysml+9:i%=cr%:on1+(i%=0)goto22:sysml+60,"pehq":on1+(i%=0)goto22
  13. 20 ono%(0,0)goto18,26
  14. 22 ifi%<5thenoni%gosub502,522,574,590:onq%goto28,28:ono%(0,0)goto18,26
  15. 24 ifo%(0,0)thengosub144:ifb%=-1then18
  16. 26 ifq%=5then18
  17. 28 pokevl+39,7:rem busy
  18. 30 return
  19. 100 :
  20. 102 : rem next move
  21. 104 :
  22. 106 a%=-1:b%=-1
  23. 108 rem --- color
  24. 110 p%=1-p%:cy%=ys%+6:gosub128:a$=c$(p%):poke646,c%(6+p%):gosub136:poke646,c%(2)
  25. 112 rem --- move #
  26. 114 m%=m%+1:cy%=ys%+8:a$="[205]ove"+right$("  "+str$(m%),4):gosub136
  27. 116 rem --- ? moves
  28. 118 c%=g%(0)org%(1)
  29. 120 n%=0:fori=0to1:forj=0to1:n%=n%-((d%(b%(a%(p%,i),j))andc%)=0):next:next
  30. 122 ifn%=0thenq%=5:a$="[206]o [205]oves":gosub212
  31. 124 return
  32. 126 :
  33. 128 : rem clear status block line
  34. 130 :
  35. 132 l%=17:sysml+30,xs%,xs%+l%-1,cy%,cy%,160,c%(1):return
  36. 134 :
  37. 136 : rem update status block line
  38. 138 :
  39. 140 sysml+12,fnxc(xs%),cy%,a$:return
  40. 142 :
  41. 144 : rem check move
  42. 146 :
  43. 148 c%=i%-5
  44. 150 ifa%=-1thenf%=((g%(p%)andd%(c%))<>0):a%=a%+(a%-c%)*f%:on2+f%gosub204:goto156
  45. 152 ifc%=a%thenf%=0:gosub204:a%=-1:goto156:rem cancel
  46. 154 b%=c%+(c%-b%)*(fnb(c%)<>0or(b%(a%,0)<>c%andb%(a%,1)<>c%))
  47. 156 return
  48. 158 :
  49. 160 : rem a solution
  50. 162 :
  51. 164 c%=z%(m%-1)andz%(m%+1):a%=fnl2(z%(m%-1)-c%):b%=fnl2(z%(m%+1)-c%)
  52. 166 sysml+21,fnx(a%)+1,fny(a%)+1:sysml+24,o%(2,0):f%=-1:gosub204
  53. 168 sysml+21,fnx(b%)+1,fny(b%)+1:sysml+24,o%(2,0)
  54. 170 return
  55. 172 :
  56. 174 : rem display move results
  57. 176 :
  58. 178 n%=1+(a%(p%,0)=a%):gosub190:f%=0:gosub204
  59. 180 a%(p%,n%)=b%:g%(p%)=fng(g%(p%))
  60. 182 ifg%(0)=w%(0)andg%(1)=w%(1)thena$="[211]olved":gosub212:goto186
  61. 184 ifm%=o%(1,0)thena$="[206]ot [211]olved in"+str$(m%):gosub212
  62. 186 return
  63. 188 :
  64. 190 : rem position knight
  65. 192 :
  66. 194 i%=2+p%*2+n%:cx%=fnx(b%):cy%=fny(b%)
  67. 196 py%=cy%*8+52:px%=cx%*8+24:c%=0:ifpx%>255thenpx%=px%-256:c%=b%(i%)
  68. 198 pokevl+i%*2,px%:pokevl+i%*2+1,py%:pokevl+16,c%
  69. 200 return
  70. 202 :
  71. 204 : rem region "a" highlight                on(f%=-1); off(f%=0)
  72. 206 :
  73. 208 c%=c%(8+(a%andd%(0))):c%=c%+(c%-c%(0))*f%:sysml+36,a%+5,255,c%:return
  74. 210 :
  75. 212 : rem game over
  76. 214 :
  77. 216 q%=5:poke646,c%(5):cy%=ys%+10:gosub136:poke646,c%(2)
  78. 218 return
  79. 500 :
  80. 502 : rem play new game
  81. 504 :
  82. 506 q%=2:gosub510:m%=0:p%=1:cy%=ys%+10:gosub128:return
  83. 508 :
  84. 510 : rem new board
  85. 512 :
  86. 514 a%(0,0)=1:a%(0,1)=3:a%(1,0)=5:a%(1,1)=7:g%(0)=w%(1):g%(1)=w%(0)
  87. 516 fori=0to1:p%=i:forj=0to1:n%=j:b%=a%(i,j):gosub190:next:next
  88. 518 return
  89. 520 :
  90. 522 : rem edit setup
  91. 524 :
  92. 526 gosub632
  93. 528 sysml+42,hs%:pokemv,ls%:pokemv+2,9
  94. 530 n%=0
  95. 532 sysml+9:ifcr%=0thensysml+60,"q":oni%+1goto532,564
  96. 534 ifcr%=9then564
  97. 536 ifcr%<7then548
  98. 538 i=cr%-7
  99. 540 w$=n$(i):sysml+156,p%(i,3)+128,p%(i,4),c%(1),c%(1),p%(i,2),0,"[145]",n$(i)
  100. 542 ifn$(i)=w$then532
  101. 544 n%=n%ord%(i+3)
  102. 546 n$(i)=w$:goto532
  103. 548 forj=0to2:i=2-j:f%=(cr%>=o%(i,1)):j=j+(j-2)*f%:next
  104. 550 ifo%(i,2)=cr%then532
  105. 552 n%=n%ord%(i)
  106. 554 i%=o%(i,2):gosub3540:i%=cr%:gosub3552:f%=cr%-o%(i,1):o%(i,2)=cr%
  107. 556 onigoto560,562
  108. 558 o%(i,0)=f%+1:goto532
  109. 560 o%(i,0)=999-983*f%:goto532
  110. 562 o%(i,0)=60+180*f%:goto532
  111. 564 sysml+39,hs%:gosub640
  112. 566 ifn%>0thengosub608
  113. 568 if(n%andd%(0))<>0thenfori=6to8step2:cy%=ys%+i:gosub128:next:gosub502:q%=5
  114. 570 return
  115. 572 :
  116. 574 : rem help
  117. 576 :
  118. 578 gosub632
  119. 580 sysml+42,hh%:pokemv,lh%:pokemv+2,6
  120. 582 sysml+210,1+128,38,3,18,c%(2),0,c%(4),c%(5),0,"",""
  121. 584 gosub640
  122. 586 return
  123. 588 :
  124. 590 : rem quit
  125. 592 :
  126. 594 gosub632
  127. 596 sysml+42,hq%:pokemv,lq%:pokemv+2,2
  128. 598 sysml+9:i%=cr%:ifi%=0thensysml+60,"ny":ifi%=0then598
  129. 600 ifi%=2thenq%=1:goto604
  130. 602 gosub640
  131. 604 return
  132. 606 :
  133. 608 : rem new setup
  134. 610 :
  135. 612 rem --- solution
  136. 614 if(n%andd%(0))=0then620
  137. 616 cy%=ys%+2:a$=n$(o%(0,0)-1):gosub128:gosub136
  138. 618 cy%=ys%+3:a$=t$(o%(0,0)-1):gosub128:gosub136
  139. 620 rem --- name(s)
  140. 622 fori=0to1:if(n%andd%(i+3))=0then626
  141. 624 ifi=o%(0,0)-1thency%=ys%+2:a$=n$(i):gosub128:gosub136
  142. 626 next
  143. 628 return
  144. 630 :
  145. 632 : rem stash game screen
  146. 634 :
  147. 636 pokevl+21,3:sysml+39,hg%:return
  148. 638 :
  149. 640 : rem restore game screen
  150. 642 :
  151. 644 sysml+42,hg%:pokemv,lg%:pokemv+2,14:pokevl+21,63:return
  152. 3000 :
  153. 3002 : rem initialize
  154. 3004 :
  155. 3006 x=0:dv=peek(186)
  156. 3008 rem --- dim
  157. 3010 dim a%,b%,c%,cc%,cr%,cx%,cy%,f%,h%,hg%,hh%,hr%,hs%,hq%
  158. 3012 dim i%,l%,l1%,l2%,lg%,lh%,ls%,lq%,m%,n%,p%,pp%,px%,py%,q%
  159. 3014 dim r1%,r2%,rg%,sc%,sl%,xb%,xs%,yb%,ys%
  160. 3016 dim cl,i,j,ml,mm,mv,vl,a$,f$,w$
  161. 3018 dim a%(1,1),b%(7,1),c%(9),d%(7),g%(1),o%(2,2),p%(1,4),w%(1),z%(17)
  162. 3020 dim c$(1),n$(1),t$(1)
  163. 3022 rem --- deffn
  164. 3024 def fnb(x)=((g%(0)org%(1))andd%(x))
  165. 3026 def fnl2(x)=log(x)/log(2)
  166. 3028 def fng(x)=x-d%(a%)+d%(b%)
  167. 3030 def fnx(x)=peek(hr%*256+(x+4)*4)+1
  168. 3032 def fny(x)=peek(hr%*256+(x+4)*4+2)+1
  169. 3034 def fnxc(x)=x+(l%-len(a$))/2
  170. 3036 rem --- sprites
  171. 3038 readf%,a$,h%,l%
  172. 3040 iff%thengosub3502
  173. 3042 rem --- font
  174. 3044 readf%,a$,h%,l%
  175. 3046 iff%thengosub3502
  176. 3048 rem --- mouse
  177. 3050 readf%,a$,h%,l%
  178. 3052 iff%thengosub3502
  179. 3054 ml=h%*256+l%
  180. 3056 mv=ml+309
  181. 3058 hr%=97:pokemv+1,hr%
  182. 3060 lg%=0:lh%=lg%+12*4:ls%=lh%+6*4:lq%=ls%+9*4:rem region low bytes
  183. 3062 hg%=224:hh%=232:hs%=240:hq%=248:rem stash pages
  184. 3064 n%=98:fori=42to49:n%=n%+1:pokemv+i,n%:next
  185. 3066 rem --- mouse mate
  186. 3068 readf%,a$,h%,l%
  187. 3070 iff%thengosub3502
  188. 3072 mm=h%*256+l%
  189. 3074 pokemm+9,0:rem disable stop
  190. 3076 rem --- curtain
  191. 3078 readf%,a$,h%,l%
  192. 3080 iff%thengosub3502
  193. 3082 cl=h%*256+l%
  194. 3084 rem --- help text
  195. 3086 readf%,a$,h%,l%
  196. 3088 i=h%*256+l%
  197. 3090 iff%thensysml+201,a$,dv,i
  198. 3092 sysml+204,i
  199. 3094 rem --- vic location
  200. 3096 vl=53248
  201. 3098 rem ---
  202. 3100 w%(0)=160:w%(1)=10
  203. 3102 c$(0)="[215]hite [203]night":c$(1)="[194]lack [203]night"
  204. 3104 t$(0)="([200]uman)":t$(1)="([195]omputer)"
  205. 3106 fori=0to7:forj=0to1:readb%(i,j):next:next
  206. 3108 fori=0to7:readd%(i):next
  207. 3110 fori=0to17:readz%(i):next
  208. 3112 fori=0to9:readc%(i):next
  209. 3114 rem --- screen off
  210. 3116 pokevl+17,11
  211. 3118 rem --- font
  212. 3120 pokevl+24,31
  213. 3122 rem --- setup screen
  214. 3124 pokemv,ls%:pokevl+32,c%(2):pokevl+33,c%(4)
  215. 3126 sysml+126,0,39,0,24,92,94,c%(2),c%(0):sysml+30,5,34,2,19,160,c%(0)
  216. 3128 poke646,c%(0):poke199,1
  217. 3130 readcy%,a$:sysml+27,cy%,a$
  218. 3132 fori=1to3:readcx%,cy%,a$:sysml+12,cx%,cy%,a$:next
  219. 3134 fori=1to6:i%=i:readcx%,cy%,l%,a$:gosub3524:next
  220. 3136 l%=16:fori=0to1:i%=7+i:readcx%,cy%,a$:gosub3524
  221. 3138 p%(i,2)=l%-1:p%(i,3)=cx%:p%(i,4)=cy%:n$(i)=a$:next
  222. 3140 l%=8:i%=9:readcx%,cy%,a$:gosub3510:gosub3540
  223. 3142 fori=0to2:reado%(i,0),o%(i,1),o%(i,2):i%=o%(i,2):gosub3548:next
  224. 3144 poke199,0
  225. 3146 sysml+39,hs%
  226. 3148 rem --- quit screen
  227. 3150 pokemv,lq%:pokevl+32,c%(2):pokevl+33,c%(4)                         
  228. 3152 sysml+126,0,39,0,24,92,94,c%(2),c%(0):sysml+30,10,29,6,15,160,c%(0)
  229. 3154 poke646,c%(0):poke199,1
  230. 3156 readcy%,a$:sysml+27,cy%,a$
  231. 3158 l%=7:fori=1to2:i%=i:readcx%,cy%,a$:gosub3510:gosub3540:next
  232. 3160 poke199,0
  233. 3162 sysml+39,hq%
  234. 3164 rem --- help screen
  235. 3166 pokemv,lh%:pokevl+32,c%(0):pokevl+33,c%(1)
  236. 3168 sysml+30,0,39,0,24,160,c%(0):sysml+30,0,39,2,19,160,c%(4)+16
  237. 3170 poke646,c%(0):poke199,1:readcy%,a$:sysml+27,cy%,a$:poke199,0
  238. 3172 sysml+228,1024+40*cy%+19,1024+40*cy%+27,0
  239. 3174 poke646,c%(3):l%=8:fori=1to4:i%=i:readcx%,cy%,a$:gosub3510:next
  240. 3176 sysml+39,hh%
  241. 3178 rem --- game screen
  242. 3180 pokemv,lg%:pokevl+32,c%(0):pokevl+33,c%(1)
  243. 3182 sysml+30,0,39,0,24,160,c%(0)
  244. 3184 xs%=23:ys%=1:sysml+30,xs%,xs%+16,ys%,ys%+11,160,c%(1)
  245. 3186 poke646,c%(2)
  246. 3188 sysml+12,4,23," [171][172][173][174][175][176][175][176][177][178][165][166][163][164][167][168][146]  [161][162][163][164][165][166][167][168][169][170][171][172][173][174][146] "
  247. 3190 sysml+12,4,24," [179][180][181][182][183][184][183][184][185][186][179][180][177][178][181][182][146]  [175][176][177][178][179][180][181][182][183][184][185][186][187][188][146] "
  248. 3192 poke646,c%(3):l%=8:fori=1to4:i%=i:readcx%,cy%,a$:gosub3510:next
  249. 3194 xb%=3:yb%=4:sysml+126,xb%-3,xb%+17,yb%-3,yb%+17,92,94,c%(2),c%(0)
  250. 3196 fori=0to7:readcx%,cy%:sysml+15,5+i,cx%,cx%+4,cy%,cy%+4:next
  251. 3198 fori=0to7:sysml+36,5+i,160,c%(8+(iandd%(0))):next
  252. 3200 poke646,c%(2):gosub502:q%=5:n%=31:gosub608
  253. 3202 sysml+39,hg%
  254. 3204 rem --- title screen
  255. 3206 pokevl+32,c%(0)
  256. 3208 pokevl+33,c%(1)
  257. 3210 sysml+126,0,39,0,24,92,94,c%(0),c%(2)
  258. 3212 sysml+30,3,36,5,13,160,c%(4)+16
  259. 3214 poke646,c%(3)
  260. 3216 sysml+12,4,6,"[171][172][173][174][175][176][175][176][177][178][165][166][163][164][167][168][146]  [161][162][163][164][165][166][167][168][169][170][171][172][173][174][146]"
  261. 3218 sysml+12,4,7,"[179][180][181][182][183][184][183][184][185][186][179][180][177][178][181][182][146]  [175][176][177][178][179][180][181][182][183][184][185][186][187][188][146]"
  262. 3220 poke646,c%(4)
  263. 3222 sysml+27,9,"by [204]ance [195]. [212]homas"
  264. 3224 sysml+27,11,"(c) 2000 [202][160]& [198] [208]ublishing, [201]nc."
  265. 3226 rem --- game
  266. 3228 syscl
  267. 3230 pokevl+17,27
  268. 3232 gosub3556
  269. 3234 syscl+6
  270. 3236 poke198,0:wait198,15:poke198,0
  271. 3238 syscl+9
  272. 3240 pokevl+17,11:sysml+42,hg%:pokevl+17,27
  273. 3242 gosub3556
  274. 3244 syscl+6
  275. 3246 syscl+3
  276. 3248 sysmm
  277. 3250 sysml
  278. 3252 sysml+6,55*256
  279. 3254 sysml+18,1,37,1,22
  280. 3256 gosub510
  281. 3258 poke2042,223:pokevl+41,c%(7)
  282. 3260 poke2043,223:pokevl+42,c%(7)
  283. 3262 poke2044,222:pokevl+43,c%(7)
  284. 3264 poke2045,222:pokevl+44,c%(7)
  285. 3266 pokevl+28,60:pokevl+37,c%(6):pokevl+38,4:pokevl+21,63
  286. 3268 poke646,c%(2)
  287. 3270 return
  288. 3272 :
  289. 3502 : rem bload file
  290. 3504 :
  291. 3506 sys57812a$,dv,0:poke780,0:poke781,l%:poke782,h%:sys65493:return
  292. 3508 :
  293. 3510 : rem command button
  294. 3512 :
  295. 3514 sysml+15,i%,cx%,cx%+l%-1,cy%,cy%+2
  296. 3516 sysml+30,cx%,cx%+l%-1,cy%,cy%+2,160,c%(1)
  297. 3518 sysml+12,fnxc(cx%),cy%+1,a$
  298. 3520 return
  299. 3522 :
  300. 3524 : rem setup region
  301. 3526 :
  302. 3528 sysml+15,i%,cx%,cx%+l%-1,cy%,cy%
  303. 3530 ifi%<7thensysml+12,fnxc(cx%),cy%,a$:goto3534
  304. 3532 sysml+12,cx%,cy%,a$
  305. 3534 gosub3540
  306. 3536 return
  307. 3538 :
  308. 3540 : rem region highlight off
  309. 3542 :
  310. 3544 sysml+36,i%,255,c%(1):return
  311. 3546 :
  312. 3548 : rem region highlight on
  313. 3550 :
  314. 3552 sysml+36,i%,255,c%(5):return
  315. 3554 :
  316. 3556 : rem pause
  317. 3558 :
  318. 3560 i=ti
  319. 3562 ifti>ithenifti-i<20then3562
  320. 3564 return
  321. 4000 :
  322. 4002 : rem *** exit
  323. 4004 :
  324. 4006 sysml+3
  325. 4008 pokevl+21,0
  326. 4010 sysmm+3
  327. 4012 poke646,11
  328. 4014 goto40000
  329. 9000 :
  330. 9002 : *** data
  331. 9004 :
  332. 9006 data 00,"spr.knights",55,128
  333. 9008 data 00,"f.knights",56,0
  334. 9010 data 00,"mouse2.1 7k 4000",64,0
  335. 9012 data 00,"mouse mate 6000",96,0
  336. 9014 data 00,"curtain 5c00",92,0
  337. 9016 data 00,"t.knights hlp",98,0
  338. 9018 rem ---
  339. 9020 data 3,5, 4,6, 5,7, 6,0, 7,1, 0,2, 1,3, 2,4
  340. 9022 data 1,2,4,8,16,32,64,128
  341. 9024 data 10,160,66,36,80,5,192,12,130,40,6,96,20,65,48,72,160,10
  342. 9026 rem --- colors
  343. 9028 data 12,15,11,6,0,2,1,0,2,10
  344. 9030 rem --- setup
  345. 9032 data 4,"[211]etup"
  346. 9034 data 8,7,"[211]olution    [205]oves   [208]ause"
  347. 9036 data 7,13,"[206]ame     ([200]uman)"
  348. 9038 data 7,16,"[206]ame  ([195]omputer)"
  349. 9040 data 7,8,10,"[200]uman",7,9,10,"[195]omputer"
  350. 9042 data 20,8,5,"999",20,9,5," 16"
  351. 9044 data 28,8,5,"2",28,9,5,"8"
  352. 9046 data 7,14,"[211]ir [216]",7,17,"[203]nees [195]alhoon"
  353. 9048 data 25,15,"[[209]]uit"
  354. 9050 data 1,1,1, 999,3,3, 60,5,5
  355. 9052 rem --- quit
  356. 9054 data 8,"[209]uit?"
  357. 9056 data 12,11,"[[206]]o ",21,11,"[[217]]es"
  358. 9058 rem --- help
  359. 9060 data 0,"[200]elp [204]ine #### of ####"
  360. 9062 data 1,21,"[[200][207][205][197]]",11,21,"[[213][208]]",21,21,"[[196][207][215][206]]",31,21,"[[209]]uit"
  361. 9064 rem --- game
  362. 9066 data 23,15,"[[208]]lay",23,19,"[[197]]dit",32,15,"[[200]]elp",32,19,"[[209]]uit"
  363. 9068 data 8,4, 13,4, 13,9, 13,14, 8,14, 3,14, 3,9, 3,4
  364. 9999 :
  365. 10000 a$="knights basic"
  366. 10010 dv=peek(186):open15,dv,15,"s0:"+a$:close15:savea$,dv:end
  367. 40000 fori=8to29:poke820+i,i:next:ifdv>8anddv<30thenpoke828,dv:poke820+dv,8
  368. 40010 a$="presenter":gosub40030:a$="hello connect":gosub40030
  369. 40020 print"[147]":poke53272,23:poke186,8:poke2048,0:poke44,8:poke43,1:end
  370. 40030 forj=8to29:i=peek(820+j):ifi=14thennext
  371. 40040 close2:open2,i,2:close2:ifstthen40060
  372. 40050 close15:open15,i,15,"r0:"+a$+"="+a$:input#15,er:close15:ifer=63then40070
  373. 40060 next:return
  374. 40070 a$="hello connect":q$=chr$(34):poke646,peek(53281):print"[147]":poke53272,23
  375. 40080 print"[147]p[207]2048,0:p[207]44,8:p[207]43,1:p[207]56,160:p[207]55,0:clr:l[207]"q$a$q$","i
  376. 40090 print"run:":poke631,13:poke632,13:poke198,2:end
  377.