Number Cruncher II Written by mjhayes@cs.buffalo.edu August 28, 1998 This program uses the graphics from "Advanced Dungeons & Dragons: Cloudy Mountain," but you can substitute any other cartridge that has appropriate graphics. In this case they are arrows. I would have used Las Vegas Poker & Blackjack, but after the first three sprites, the other five sprites are displayed incorrectly. I also tried Word Fun, but CALL SHOW makes the whole screen light up! All PRIN outputs also become garbled! I must make a game out of this! Select the number of problems to attempt. For each problem, eight numbers will be generated at random, and a target number is also generated. Solve each problem by finding a combination of numbers whose sum is the target number. Use the left hand controller keypad. Keys 0..7 select/deselect a number, Clear deselects all numbers, and Enter locks your selection. After all problems are finished, the final score appears. Your final score is (the percentage of problems answered correctly * (total number of problems + 1) - points lost for time taken). Try again to beat your highest score. 10 N=30 ; The sprites will be arrows. 20 FOR O=0 TO 7 30 CALL SHOW ; Display the sprite. 40 XS(O)=1 ; Double the sprite width. 50 XP(O)=96 60 YP(O)=O*8+16 ; Put the sprite in place. 70 CO(O)=O*2 80 VS(O)=-1 ; Hide the sprite for now. 90 NEXT O 100 DIM AA(8) ; Create an array of size 8. 110 E=14 ; The background "music" will play in a repeated fade in/fade out envelope. 120 CLR 130 FM(0)=0 ; Two numbers will be displayed on a line, in regular notation, with 0 places to the right of the decimal point. 140 FM(4)=0 ; The first line is black. 150 PRIN"NUMBER CRUNCHER II" 160 FM(4)=1 ; The second line is blue. 170 PRIN"BY MIKE HAYES" 180 FM(4)=2 ; The third line is red. 190 PRIN"DOLM: 8/28/1998 " 200 G=0 ; Reset the score. 210 I=0 ; Reset the total of correct answers. 220 FM(4)=3 ; The fifth line is tan. 230 PRIN"HOW MANY PROBLEMS?" 240 INPU B 250 IF(B<1)GOTO 230 ; Is the input valid? 260 FOR D=1 TO B 270 F=0 ; Reset the target number. 280 CLR 290 PRIN"AVAILABLE NUMBERS:" 300 FM(4)=6 ; Display the numbers in yellow. 310 FOR A=1 TO 8 320 AA(A)=RN(0) ; Generate a random number. 330 PRIN A-1,AA(A) 340 IF(RN(0)<50)F=F+AA(A) ; If this number is chosen to be part of the combination, then add the number to the value of the target number. 350 NEXT A 360 FM(4)=7 ; Display the target number in white. 370 PRIN"TARGET NUMBER IS",F 380 FM(4)=3 390 FOR C=0 TO 5 400 P=(C+RN(C))*D 410 CALL ENVT ; Play that hideous background noise. 420 NEXT C 430 FOR C=0 TO 7 ; The main loop begins here, and hasn't been optimized. As a result, it takes a long time for the game to acknowledge that a key was pressed. Anybody feel like optimizing this section? 440 CALL HAND ; Poll the left hand controller. 450 IF(H=C)VS(C)=0-VS(C) ; Was a keypad key from 0..7 pressed? If so, toggle the visibility of an arrow. 460 CO(C)=CO(C)+1 ; Make the arrows glow. 470 IF(CO(C)=5)CO(C)=6 ; Avoid making the arrows the same color as the background. 480 IF(CO(C)=15)CO(C)=0 ; Cycle back to the first color. 490 IF(CO(C)=0)G=G-1 ; Lose a point for time taken. 500 NEXT C 510 IF(H=10)GOTO 540 ; Was Clear pressed? 520 IF(H=11)GOTO ; Was Enter pressed? 530 GOTO 430 540 FOR A=0 TO 7 550 VS(A)=-1 ; Make all sprites invisible. 560 NEXT A 570 GOTO 430 580 FOR A=0 TO 7 590 C=A+1 600 IF(VS(A)=1)F=F-AA(C) ; If the number was selected, then subtract its value from the target number. 610 VS(A)=-1 ; Make each sprite invisible after it has been checked. 620 NEXT A 630 CLR 640 IF(F=0)GOTO 680 ; If the target number is now 0, then the problem has been answered correctly. 650 IF(F<0)F=0-F ; Calculate the absolute value of the target number. Its new value is the amount that the target was missed by. 660 PRIN"YOU MISSED BY",F 670 GOTO 700 680 PRIN"THAT IS CORRECT." 690 I=I+1 ; Increment the number of problems answered correctly. 700 PRIN"TAP DISC TO CONTINUE" 710 CALL HAND 720 IF(H>-17)GOTO 710 ; Wait for disc to be pressed. 730 CALL HUSH ; Stop that infernal noise! 740 NEXT D 750 CLR 760 A=100/B*I ; Calculate the percentage of problems answered correctly. 770 G=G+(A*D) ; Calculate the final score. See above. 780 PRIN"YOU HAVE ANSWERED",I 790 PRIN"PROBLEMS OUT OF",B 800 PRIN"CORRECTLY. YOUR" 810 PRIN"FINAL SCORE IS",G 820 PRIN"PRESS RETURN TO" 830 PRIN"PLAY ANOTHER GAME." 840 INPU B 850 CLR 860 GOTO 140 ; Play again. You know you want to.