'===========================================================================
' Subject: BATTLE OF NUMBERS GAME            Date: Unknown Date (00:00:00)
'  Author: Unknown Author(s)                 Code: QB, QBasic             
'    Keys: BATTLE,NUMBER,GAME              Packet: GAMES.ABC
'===========================================================================
FUNCTION TAB(N AS INTEGER) AS STRING
  TAB = SPACE$(N)
END FUNCTION

SUBI Colors(...)
END SUB

5 '----------- PC BATTLE OF NUMBERS GAME ------------
8 '
10 CLS
'20 DEFINT C, I, M, P, T, X
30 RANDOMIZE VAL(RIGHT$(TIME$, 2))
40 M = INT(4 * RND + 5)
50 T = INT(19 * RND + 17)
55 LOCATE 24, 25
60 PRINT  "--- THE BATTLE OF NUMBERS ---";
70 PRINT
75 LOCATE 1, 1
80 PRINT "THIS GAME PITS YOU AGAINST THE PC IN A TEST OF ";
90 PRINT "MATHMATICAL SKILL. TWO NUMBERS,"
100 PRINT "ONE SEVERAL TIMES LARGER THAN THE OTHER,HAVE ";
110 PRINT "BEEN SELECTED AT RANDOM. BY TURNS"
120 PRINT "BOTH YOU AND THE COMPUTER SUBTRACT AN INTERGER ";
130 PRINT "BETWEEN 1 AND ";
140 COLORS 15: PRINT M; : COLORS 7: PRINT " FROM THE TOTAL"
150 PRINT "LISTED BELOW UNTIL ZERO IS LEFT. WHOEVER MUST ";
160 PRINT "MAKE THE FINAL SUBTRACTION IS THE"
170 PRINT "LOSER. UNLESS YOU EMPLOY A RATIONAL STRATEGY,";
180 PRINT " THE COMPUTER WILL TROUNCE YOU"
190 PRINT "EVERY TIME, AND GLOAT ABOUT IT, TOO. ";
200 PRINT "THE FIRST TURN IS YOURS -- GOOD LUCK!"
210 PRINT CHR$(201); STRING$(28, 205); CHR$(203);
220 PRINT STRING$(20, 205); CHR$(203); STRING$(28, 205); CHR$(187);
230 PRINT CHR$(186); TAB(28); CHR$(186); TAB(20); CHR$(186); TAB(11);
240 PRINT "TOTAL"; TAB(12); CHR$(186);
250 PRINT CHR$(186); TAB(28); CHR$(199);
260 PRINT STRING$(20, 196); CHR$(182); TAB(28); CHR$(186);
270 FOR I = 10 TO 22
280    LOCATE I, 1
290    PRINT CHR$(186); TAB(28); CHR$(186); TAB(20);
300    PRINT CHR$(186); TAB(28); CHR$(186);
310 NEXT I
315 PRINT CHR$(200); STRING$(28, 205); CHR$(202);
317 PRINT STRING$(20, 205); CHR$(202); STRING$(28, 205); CHR$(188);
320 PC$ = CHR$(19) + " PC WINS " + CHR$(19)
330 PLAYER$ = CHR$(19) + " YOU WIN " + CHR$(19)
340 LOCATE 10, 40: PRINT T
350 '
355 '----------- MAIN STRATEGY LOOP ------------
356 '
360 FOR I = 10 TO 100 STEP 2
370    GOSUB 600'PICK UP PLAYER INPUT
380    T = T - P: LOCATE I + 1, 40: PRINT T;
390    IF T = 0 THEN: WIN$ = PC$: GOTO 480: END IF
400    C = T - ((M + 1) * INT((T - 1) / (M + 1)) + 1)
410    IF C = 0 THEN: C = INT(1 + M * RND): END IF
420    IF T = 1 THEN: C = 1: END IF
430    T = T - C
440    LOCATE I + 1, 58: PRINT "PC SUBTRACTS "; C;
450    LOCATE I + 2, 40: PRINT T;
460    IF T = 0 THEN: WIN$ = PLAYER$: GOTO 480: END IF
470 NEXT I
475 '
476 '--- ANNOUNCE WINNER, SOUND OFF, DISPLAY OPTIONS ---
477 '
480 COLORS 0, 7: LOCATE 8, 31: PRINT STRING$(4, 32); WIN$; STRING$(5, 32)
482 FOR K = 1 TO 2
484    FOR J = 3000 TO 400 STEP -300
486    'SOUND J, .5
487    NEXT J
488 NEXT K
490 COLORS 7, 0: LOCATE 24, 17
500 PRINT "PRESS R TO RUN PROGRAM AGAIN, Q TO QUIT GAME";
520 WHILE (X$ <> "q" AND X$ <> "Q")
530    X$ = INPUT$(1)
540    IF (X$ = "R" OR X$ = "r") THEN: CLS: GOTO 10: END IF
570 WEND
580 CLS:END
585 '
586 '------------ PLAYER-INPUT SUBROUTINE -------------
590 '
600 X = 100
610 WHILE 1
620    LOCATE I, 7: PRINT "YOU SUBTRACT? ";
625    P = VAL(INPUT$(1))
630    IF P >= 1 AND P <= M AND P <= T THEN: GOTO 690: END IF
640    IF M < T THEN: X = M: ELSE: X = T: END IF
650    LOCATE 24, 11: COLORS 15, 0
660    PRINT "IMPROPER INPUT. PLEASE ENTER AN INTERGER IN THE RANGE 1 -"; X;
670    COLORS 7, 0: LOCATE I, 7: PRINT STRING$(18, 32)
680 WEND
690 'IF X < 100 THEN KEY ON: KEY OFF
700 RETURN

