home *** CD-ROM | disk | FTP | other *** search
/ PC & Mediji 1997 February / PCM_9702.iso / bralci / mitja / igre / qbasic / nibbles.bas
BASIC Source File  |  1996-05-10  |  24KB  |  727 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. '
  7. '                         Q B a s i c   N i b b l e s
  8. '
  9. '                   Copyright (C) Microsoft Corporation 1990
  10. '
  11. ' Nibbles is a game for one or two players.  Navigate your snakes
  12. ' around the game board trying to eat up numbers while avoiding
  13. ' running into walls or other snakes.  The more numbers you eat up,
  14. ' the more points you gain and the longer your snake becomes.
  15. '
  16. ' To run this game, press Shift+F5.
  17. '
  18. ' To exit QBasic, press Alt, F, X.
  19. '
  20. ' To get help on a BASIC keyword, move the cursor to the keyword and press
  21. ' F1 or click the right mouse button.
  22. '
  23.  
  24. 'Set default data type to integer for faster game play
  25. DEFINT A-Z
  26.  
  27. 'User-defined TYPEs
  28. TYPE snakeBody
  29.     row AS INTEGER
  30.     col AS INTEGER
  31. END TYPE
  32.  
  33. 'This type defines the player's snake
  34. TYPE snaketype
  35.     head      AS INTEGER
  36.     length    AS INTEGER
  37.     row       AS INTEGER
  38.     col       AS INTEGER
  39.     direction AS INTEGER
  40.     lives     AS INTEGER
  41.     score     AS INTEGER
  42.     scolor    AS INTEGER
  43.     alive     AS INTEGER
  44. END TYPE
  45.  
  46. 'This type is used to represent the playing screen in memory
  47. 'It is used to simulate graphics in text mode, and has some interesting,
  48. 'and slightly advanced methods to increasing the speed of operation.
  49. 'Instead of the normal 80x25 text graphics using chr$(219) "█", we will be
  50. 'using chr$(220)"▄" and chr$(223) "▀" and chr$(219) "█" to mimic an 80x50
  51. 'pixel screen.
  52. 'Check out sub-programs SET and POINTISTHERE to see how this is implemented
  53. 'feel free to copy these (as well as arenaType and the DIM ARENA stmt and the
  54. 'initialization code in the DrawScreen subprogram) and use them in your own
  55. 'programs
  56. TYPE arenaType
  57.     realRow     AS INTEGER        'Maps the 80x50 point into the real 80x25
  58.     acolor      AS INTEGER        'Stores the current color of the point
  59.     sister      AS INTEGER        'Each char has 2 points in it.  .SISTER is
  60. END TYPE                          '-1 if sister point is above, +1 if below
  61.  
  62. 'Sub Declarations
  63. DECLARE SUB SpacePause (text$)
  64. DECLARE SUB PrintScore (NumPlayers%, score1%, score2%, lives1%, lives2%)
  65. DECLARE SUB Intro ()
  66. DECLARE SUB GetInputs (NumPlayers, speed, diff$, monitor$)
  67. DECLARE SUB DrawScreen ()
  68. DECLARE SUB PlayNibbles (NumPlayers, speed, diff$)
  69. DECLARE SUB Set (row, col, acolor)
  70. DECLARE SUB Center (row, text$)
  71. DECLARE SUB DoIntro ()
  72. DECLARE SUB Initialize ()
  73. DECLARE SUB SparklePause ()
  74. DECLARE SUB Level (WhatToDO, sammy() AS snaketype)
  75. DECLARE SUB InitColors ()
  76. DECLARE SUB EraseSnake (snake() AS ANY, snakeBod() AS ANY, snakeNum%)
  77. DECLARE FUNCTION StillWantsToPlay ()
  78. DECLARE FUNCTION PointIsThere (row, col, backColor)
  79.  
  80. 'Constants
  81. CONST TRUE = -1
  82. CONST FALSE = NOT TRUE
  83. CONST MAXSNAKELENGTH = 1000
  84. CONST STARTOVER = 1             ' Parameters to 'Level' SUB
  85. CONST SAMELEVEL = 2
  86. CONST NEXTLEVEL = 3
  87.  
  88. 'Global Variables
  89. DIM SHARED arena(1 TO 50, 1 TO 80) AS arenaType
  90. DIM SHARED curLevel, colorTable(10)
  91.  
  92.     RANDOMIZE TIMER
  93.     GOSUB ClearKeyLocks
  94.     Intro
  95.     GetInputs NumPlayers, speed, diff$, monitor$
  96.     GOSUB SetColors
  97.     DrawScreen
  98.  
  99.     DO
  100.       PlayNibbles NumPlayers, speed, diff$
  101.     LOOP WHILE StillWantsToPlay
  102.  
  103.     GOSUB RestoreKeyLocks
  104.     COLOR 15, 0
  105.     CLS
  106. END
  107.  
  108. ClearKeyLocks:
  109.     DEF SEG = 0                     ' Turn off CapLock, NumLock and ScrollLock
  110.     KeyFlags = PEEK(1047)
  111.     POKE 1047, &H0
  112.     DEF SEG
  113.     RETURN
  114.  
  115. RestoreKeyLocks:
  116.     DEF SEG = 0                     ' Restore CapLock, NumLock and ScrollLock states
  117.     POKE 1047, KeyFlags
  118.     DEF SEG
  119.     RETURN
  120.  
  121. SetColors:
  122.     IF monitor$ = "M" THEN
  123.         RESTORE mono
  124.     ELSE
  125.         RESTORE normal
  126.     END IF
  127.  
  128.     FOR a = 1 TO 6
  129.         READ colorTable(a)
  130.     NEXT a
  131.     RETURN
  132.  
  133.            'snake1     snake2   Walls  Background  Dialogs-Fore  Back
  134. mono:   DATA 15,         7,       7,     0,          15,            0
  135. normal: DATA 14,         13,      12,    1,          15,            4
  136. END
  137.  
  138. 'Center:
  139. '  Centers text on given row
  140. SUB Center (row, text$)
  141.     LOCATE row, 41 - LEN(text$) / 2
  142.     PRINT text$;
  143. END SUB
  144.  
  145. 'DrawScreen:
  146. '  Draws playing field
  147. SUB DrawScreen
  148.  
  149.     'initialize screen
  150.     VIEW PRINT
  151.     COLOR colorTable(1), colorTable(4)
  152.     CLS
  153.  
  154.     'Print title & message
  155.     Center 1, "Nibbles!"
  156.     Center 11, "Initializing Playing Field..."
  157.     
  158.     'Initialize arena array
  159.     FOR row = 1 TO 50
  160.         FOR col = 1 TO 80
  161.             arena(row, col).realRow = INT((row + 1) / 2)
  162.             arena(row, col).sister = (row MOD 2) * 2 - 1
  163.         NEXT col
  164.     NEXT row
  165. END SUB
  166.  
  167. 'EraseSnake:
  168. '  Erases snake to facilitate moving through playing field
  169. SUB EraseSnake (snake() AS snaketype, snakeBod() AS snakeBody, snakeNum)
  170.  
  171.     FOR c = 0 TO 9
  172.         FOR b = snake(snakeNum).length - c TO 0 STEP -10
  173.             tail = (snake(snakeNum).head + MAXSNAKELENGTH - b) MOD MAXSNAKELENGTH
  174.             Set snakeBod(tail, snakeNum).row, snakeBod(tail, snakeNum).col, colorTable(4)
  175.         NEXT b
  176.     NEXT c
  177.     
  178. END SUB
  179.  
  180. 'GetInputs:
  181. '  Gets player inputs
  182. SUB GetInputs (NumPlayers, speed, diff$, monitor$)
  183.  
  184.     COLOR 7, 0
  185.     CLS
  186.  
  187.     DO
  188.         LOCATE 5, 47: PRINT SPACE$(34);
  189.         LOCATE 5, 20
  190.         INPUT "How many players (1 or 2)"; num$
  191.     LOOP UNTIL VAL(num$) = 1 OR VAL(num$) = 2
  192.     NumPlayers = VAL(num$)
  193.  
  194.     LOCATE 8, 21: PRINT "Skill level (1 to 100)"
  195.     LOCATE 9, 22: PRINT "1   = Novice"
  196.     LOCATE 10, 22: PRINT "90  = Expert"
  197.     LOCATE 11, 22: PRINT "100 = Twiddle Fingers"
  198.     LOCATE 12, 15: PRINT "(Computer speed may affect your skill level)"
  199.     DO
  200.         LOCATE 8, 44: PRINT SPACE$(35);
  201.         LOCATE 8, 43
  202.         INPUT gamespeed$
  203.     LOOP UNTIL VAL(gamespeed$) >= 1 AND VAL(gamespeed$) <= 100
  204.     speed = VAL(gamespeed$)
  205.   
  206.     speed = (100 - speed) * 2 + 1
  207.  
  208.     DO
  209.         LOCATE 15, 56: PRINT SPACE$(25);
  210.         LOCATE 15, 15
  211.         INPUT "Increase game speed during play (Y or N)"; diff$
  212.         diff$ = UCASE$(diff$)
  213.     LOOP UNTIL diff$ = "Y" OR diff$ = "N"
  214.  
  215.     DO
  216.         LOCATE 17, 46: PRINT SPACE$(34);
  217.         LOCATE 17, 17
  218.         INPUT "Monochrome or color monitor (M or C)"; monitor$
  219.         monitor$ = UCASE$(monitor$)
  220.     LOOP UNTIL monitor$ = "M" OR monitor$ = "C"
  221.  
  222.     startTime# = TIMER                          ' Calculate speed of system
  223.     FOR i# = 1 TO 1000: NEXT i#                 ' and do some compensation
  224.     stopTime# = TIMER
  225.     speed = speed * .5 / (stopTime# - startTime#)
  226.  
  227. END SUB
  228.  
  229. 'InitColors:
  230. 'Initializes playing field colors
  231. SUB InitColors
  232.     
  233.     FOR row = 1 TO 50
  234.         FOR col = 1 TO 80
  235.             arena(row, col).acolor = colorTable(4)
  236.         NEXT col
  237.     NEXT row
  238.  
  239.     CLS
  240.    
  241.     'Set (turn on) pixels for screen border
  242.     FOR col = 1 TO 80
  243.         Set 3, col, colorTable(3)
  244.         Set 50, col, colorTable(3)
  245.     NEXT col
  246.  
  247.     FOR row = 4 TO 49
  248.         Set row, 1, colorTable(3)
  249.         Set row, 80, colorTable(3)
  250.     NEXT row
  251.  
  252. END SUB
  253.  
  254. 'Intro:
  255. '  Displays game introduction
  256. SUB Intro
  257.     SCREEN 0
  258.     WIDTH 80, 25
  259.     COLOR 15, 0
  260.     CLS
  261.  
  262.     Center 4, "Q B a s i c   N i b b l e s"
  263.     COLOR 7
  264.     Center 6, "Copyright (C) Microsoft Corporation 1990"
  265.     Center 8, "Nibbles is a game for one or two players.  Navigate your snakes"
  266.     Center 9, "around the game board trying to eat up numbers while avoiding"
  267.     Center 10, "running into walls or other snakes.  The more numbers you eat up,"
  268.     Center 11, "the more points you gain and the longer your snake becomes."
  269.     Center 13, " Game Controls "
  270.     Center 15, "  General             Player 1               Player 2    "
  271.     Center 16, "                        (Up)                   (Up)      "
  272.     Center 17, "P - Pause                " + CHR$(24) + "                      W       "
  273.     Center 18, "                     (Left) " + CHR$(27) + "   " + CHR$(26) + " (Right)   (Left) A   D (Right)  "
  274.     Center 19, "                         " + CHR$(25) + "                      S       "
  275.     Center 20, "                       (Down)                 (Down)     "
  276.     Center 24, "Press any key to continue"
  277.  
  278.     PLAY "MBT160O1L8CDEDCDL4ECC"
  279.     SparklePause
  280.  
  281. END SUB
  282.  
  283. 'Level:
  284. 'Sets game level
  285. SUB Level (WhatToDO, sammy() AS snaketype) STATIC
  286.     
  287.     SELECT CASE (WhatToDO)
  288.  
  289.     CASE STARTOVER
  290.         curLevel = 1
  291.     CASE NEXTLEVEL
  292.         curLevel = curLevel + 1
  293.     END SELECT
  294.  
  295.     sammy(1).head = 1                       'Initialize Snakes
  296.     sammy(1).length = 2
  297.     sammy(1).alive = TRUE
  298.     sammy(2).head = 1
  299.     sammy(2).length = 2
  300.     sammy(2).alive = TRUE
  301.  
  302.     InitColors
  303.     
  304.     SELECT CASE curLevel
  305.     CASE 1
  306.         sammy(1).row = 25: sammy(2).row = 25
  307.         sammy(1).col = 50: sammy(2).col = 30
  308.         sammy(1).direction = 4: sammy(2).direction = 3
  309.  
  310.  
  311.     CASE 2
  312.         FOR i = 20 TO 60
  313.             Set 25, i, colorTable(3)
  314.         NEXT i
  315.         sammy(1).row = 7: sammy(2).row = 43
  316.         sammy(1).col = 60: sammy(2).col = 20
  317.         sammy(1).direction = 3: sammy(2).direction = 4
  318.  
  319.     CASE 3
  320.         FOR i = 10 TO 40
  321.             Set i, 20, colorTable(3)
  322.             Set i, 60, colorTable(3)
  323.         NEXT i
  324.         sammy(1).row = 25: sammy(2).row = 25
  325.         sammy(1).col = 50: sammy(2).col = 30
  326.         sammy(1).direction = 1: sammy(2).direction = 2
  327.  
  328.     CASE 4
  329.         FOR i = 4 TO 30
  330.             Set i, 20, colorTable(3)
  331.             Set 53 - i, 60, colorTable(3)
  332.         NEXT i
  333.         FOR i = 2 TO 40
  334.             Set 38, i, colorTable(3)
  335.             Set 15, 81 - i, colorTable(3)
  336.         NEXT i
  337.         sammy(1).row = 7: sammy(2).row = 43
  338.         sammy(1).col = 60: sammy(2).col = 20
  339.         sammy(1).direction = 3: sammy(2).direction = 4
  340.    
  341.     CASE 5
  342.         FOR i = 13 TO 39
  343.             Set i, 21, colorTable(3)
  344.             Set i, 59, colorTable(3)
  345.         NEXT i
  346.         FOR i = 23 TO 57
  347.             Set 11, i, colorTable(3)
  348.             Set 41, i, colorTable(3)
  349.         NEXT i
  350.         sammy(1).row = 25: sammy(2).row = 25
  351.         sammy(1).col = 50: sammy(2).col = 30
  352.         sammy(1).direction = 1: sammy(2).direction = 2
  353.  
  354.     CASE 6
  355.         FOR i = 4 TO 49
  356.             IF i > 30 OR i < 23 THEN
  357.                 Set i, 10, colorTable(3)
  358.                 Set i, 20, colorTable(3)
  359.                 Set i, 30, colorTable(3)
  360.                 Set i, 40, colorTable(3)
  361.                 Set i, 50, colorTable(3)
  362.                 Set i, 60, colorTable(3)
  363.                 Set i, 70, colorTable(3)
  364.             END IF
  365.         NEXT i
  366.         sammy(1).row = 7: sammy(2).row = 43
  367.         sammy(1).col = 65: sammy(2).col = 15
  368.         sammy(1).direction = 2: sammy(2).direction = 1
  369.  
  370.     CASE 7
  371.         FOR i = 4 TO 49 STEP 2
  372.             Set i, 40, colorTable(3)
  373.         NEXT i
  374.         sammy(1).row = 7: sammy(2).row = 43
  375.         sammy(1).col = 65: sammy(2).col = 15
  376.         sammy(1).direction = 2: sammy(2).direction = 1
  377.  
  378.     CASE 8
  379.         FOR i = 4 TO 40
  380.             Set i, 10, colorTable(3)
  381.             Set 53 - i, 20, colorTable(3)
  382.             Set i, 30, colorTable(3)
  383.             Set 53 - i, 40, colorTable(3)
  384.             Set i, 50, colorTable(3)
  385.             Set 53 - i, 60, colorTable(3)
  386.             Set i, 70, colorTable(3)
  387.         NEXT i
  388.         sammy(1).row = 7: sammy(2).row = 43
  389.         sammy(1).col = 65: sammy(2).col = 15
  390.         sammy(1).direction = 2: sammy(2).direction = 1
  391.  
  392.     CASE 9
  393.         FOR i = 6 TO 47
  394.             Set i, i, colorTable(3)
  395.             Set i, i + 28, colorTable(3)
  396.         NEXT i
  397.         sammy(1).row = 40: sammy(2).row = 15
  398.         sammy(1).col = 75: sammy(2).col = 5
  399.         sammy(1).direction = 1: sammy(2).direction = 2
  400.    
  401.     CASE ELSE
  402.         FOR i = 4 TO 49 STEP 2
  403.             Set i, 10, colorTable(3)
  404.             Set i + 1, 20, colorTable(3)
  405.             Set i, 30, colorTable(3)
  406.             Set i + 1, 40, colorTable(3)
  407.             Set i, 50, colorTable(3)
  408.             Set i + 1, 60, colorTable(3)
  409.             Set i, 70, colorTable(3)
  410.         NEXT i
  411.         sammy(1).row = 7: sammy(2).row = 43
  412.         sammy(1).col = 65: sammy(2).col = 15
  413.         sammy(1).direction = 2: sammy(2).direction = 1
  414.  
  415.     END SELECT
  416. END SUB
  417.  
  418. 'PlayNibbles:
  419. '  Main routine that controls game play
  420. SUB PlayNibbles (NumPlayers, speed, diff$)
  421.  
  422.     'Initialize Snakes
  423.     DIM sammyBody(MAXSNAKELENGTH - 1, 1 TO 2) AS snakeBody
  424.     DIM sammy(1 TO 2) AS snaketype
  425.     sammy(1).lives = 5
  426.     sammy(1).score = 0
  427.     sammy(1).scolor = colorTable(1)
  428.     sammy(2).lives = 5
  429.     sammy(2).score = 0
  430.     sammy(2).scolor = colorTable(2)
  431.                  
  432.     Level STARTOVER, sammy()
  433.     startRow1 = sammy(1).row: startCol1 = sammy(1).col
  434.     startRow2 = sammy(2).row: startCol2 = sammy(2).col
  435.  
  436.     curSpeed = speed
  437.  
  438.     'play Nibbles until finished
  439.  
  440.     SpacePause "     Level" + STR$(curLevel) + ",  Push Space"
  441.     gameOver = FALSE
  442.     DO
  443.         IF NumPlayers = 1 THEN
  444.             sammy(2).row = 0
  445.         END IF
  446.  
  447.         number = 1          'Current number that snakes are trying to run into
  448.         nonum = TRUE        'nonum = TRUE if a number is not on the screen
  449.  
  450.         playerDied = FALSE
  451.         PrintScore NumPlayers, sammy(1).score, sammy(2).score, sammy(1).lives, sammy(2).lives
  452.         PLAY "T160O1>L20CDEDCDL10ECC"
  453.  
  454.         DO
  455.             'Print number if no number exists
  456.             IF nonum = TRUE THEN
  457.                 DO
  458.                     numberRow = INT(RND(1) * 47 + 3)
  459.                     NumberCol = INT(RND(1) * 78 + 2)
  460.                     sisterRow = numberRow + arena(numberRow, NumberCol).sister
  461.                 LOOP UNTIL NOT PointIsThere(numberRow, NumberCol, colorTable(4)) AND NOT PointIsThere(sisterRow, NumberCol, colorTable(4))
  462.                 numberRow = arena(numberRow, NumberCol).realRow
  463.                 nonum = FALSE
  464.                 COLOR colorTable(1), colorTable(4)
  465.                 LOCATE numberRow, NumberCol
  466.                 PRINT RIGHT$(STR$(number), 1);
  467.                 count = 0
  468.             END IF
  469.  
  470.             'Delay game
  471.             FOR a# = 1 TO curSpeed:  NEXT a#
  472.  
  473.             'Get keyboard input & Change direction accordingly
  474.             kbd$ = INKEY$
  475.             SELECT CASE kbd$
  476.                 CASE "w", "W": IF sammy(2).direction <> 2 THEN sammy(2).direction = 1
  477.                 CASE "s", "S": IF sammy(2).direction <> 1 THEN sammy(2).direction = 2
  478.                 CASE "a", "A": IF sammy(2).direction <> 4 THEN sammy(2).direction = 3
  479.                 CASE "d", "D": IF sammy(2).direction <> 3 THEN sammy(2).direction = 4
  480.                 CASE CHR$(0) + "H": IF sammy(1).direction <> 2 THEN sammy(1).direction = 1
  481.                 CASE CHR$(0) + "P": IF sammy(1).direction <> 1 THEN sammy(1).direction = 2
  482.                 CASE CHR$(0) + "K": IF sammy(1).direction <> 4 THEN sammy(1).direction = 3
  483.                 CASE CHR$(0) + "M": IF sammy(1).direction <> 3 THEN sammy(1).direction = 4
  484.                 CASE "p", "P": SpacePause " Game Paused ... Push Space  "
  485.                 CASE ELSE
  486.             END SELECT
  487.  
  488.             FOR a = 1 TO NumPlayers
  489.                 'Move Snake
  490.                 SELECT CASE sammy(a).direction
  491.                     CASE 1: sammy(a).row = sammy(a).row - 1
  492.                     CASE 2: sammy(a).row = sammy(a).row + 1
  493.                     CASE 3: sammy(a).col = sammy(a).col - 1
  494.                     CASE 4: sammy(a).col = sammy(a).col + 1
  495.                 END SELECT
  496.  
  497.                 'If snake hits number, respond accordingly
  498.                 IF numberRow = INT((sammy(a).row + 1) / 2) AND NumberCol = sammy(a).col THEN
  499.                     PLAY "MBO0L16>CCCE"
  500.                     IF sammy(a).length < (MAXSNAKELENGTH - 30) THEN
  501.                         sammy(a).length = sammy(a).length + number * 4
  502.                     END IF
  503.                     sammy(a).score = sammy(a).score + number
  504.                     PrintScore NumPlayers, sammy(1).score, sammy(2).score, sammy(1).lives, sammy(2).lives
  505.                     number = number + 1
  506.                     IF number = 10 THEN
  507.                         EraseSnake sammy(), sammyBody(), 1
  508.                         EraseSnake sammy(), sammyBody(), 2
  509.                         LOCATE numberRow, NumberCol: PRINT " "
  510.                         Level NEXTLEVEL, sammy()
  511.                         PrintScore NumPlayers, sammy(1).score, sammy(2).score, sammy(1).lives, sammy(2).lives
  512.                         SpacePause "     Level" + STR$(curLevel) + ",  Push Space"
  513.                         IF NumPlayers = 1 THEN sammy(2).row = 0
  514.                         number = 1
  515.                         IF diff$ = "P" THEN speed = speed - 10: curSpeed = speed
  516.                     END IF
  517.                     nonum = TRUE
  518.                     IF curSpeed < 1 THEN curSpeed = 1
  519.                 END IF
  520.             NEXT a
  521.  
  522.             FOR a = 1 TO NumPlayers
  523.                 'If player runs into any point, or the head of the other snake, it dies.
  524.                 IF PointIsThere(sammy(a).row, sammy(a).col, colorTable(4)) OR (sammy(1).row = sammy(2).row AND sammy(1).col = sammy(2).col) THEN
  525.                     PLAY "MBO0L32EFGEFDC"
  526.                     COLOR , colorTable(4)
  527.                     LOCATE numberRow, NumberCol
  528.                     PRINT " "
  529.                    
  530.                     playerDied = TRUE
  531.                     sammy(a).alive = FALSE
  532.                     sammy(a).lives = sammy(a).lives - 1
  533.  
  534.                 'Otherwise, move the snake, and erase the tail
  535.                 ELSE
  536.                     sammy(a).head = (sammy(a).head + 1) MOD MAXSNAKELENGTH
  537.                     sammyBody(sammy(a).head, a).row = sammy(a).row
  538.                     sammyBody(sammy(a).head, a).col = sammy(a).col
  539.                     tail = (sammy(a).head + MAXSNAKELENGTH - sammy(a).length) MOD MAXSNAKELENGTH
  540.                     Set sammyBody(tail, a).row, sammyBody(tail, a).col, colorTable(4)
  541.                     sammyBody(tail, a).row = 0
  542.                     Set sammy(a).row, sammy(a).col, sammy(a).scolor
  543.                 END IF
  544.             NEXT a
  545.  
  546.         LOOP UNTIL playerDied
  547.  
  548.         curSpeed = speed                ' reset speed to initial value
  549.        
  550.         FOR a = 1 TO NumPlayers
  551.             EraseSnake sammy(), sammyBody(), a
  552.  
  553.             'If dead, then erase snake in really cool way
  554.             IF sammy(a).alive = FALSE THEN
  555.                 'Update score
  556.                 sammy(a).score = sammy(a).score - 10
  557.                 PrintScore NumPlayers, sammy(1).score, sammy(2).score, sammy(1).lives, sammy(2).lives
  558.                 
  559.                 IF a = 1 THEN
  560.                     SpacePause " Sammy Dies! Push Space! --->"
  561.                 ELSE
  562.                     SpacePause " <---- Jake Dies! Push Space "
  563.                 END IF
  564.             END IF
  565.         NEXT a
  566.  
  567.         Level SAMELEVEL, sammy()
  568.         PrintScore NumPlayers, sammy(1).score, sammy(2).score, sammy(1).lives, sammy(2).lives
  569.      
  570.     'Play next round, until either of snake's lives have run out.
  571.     LOOP UNTIL sammy(1).lives = 0 OR sammy(2).lives = 0
  572.  
  573. END SUB
  574.  
  575. 'PointIsThere:
  576. '  Checks the global  arena array to see if the boolean flag is set
  577. FUNCTION PointIsThere (row, col, acolor)
  578.     IF row <> 0 THEN
  579.         IF arena(row, col).acolor <> acolor THEN
  580.             PointIsThere = TRUE
  581.         ELSE
  582.             PointIsThere = FALSE
  583.         END IF
  584.     END IF
  585. END FUNCTION
  586.  
  587. 'PrintScore:
  588. '  Prints players scores and number of lives remaining
  589. SUB PrintScore (NumPlayers, score1, score2, lives1, lives2)
  590.     COLOR 15, colorTable(4)
  591.  
  592.     IF NumPlayers = 2 THEN
  593.         LOCATE 1, 1
  594.         PRINT USING "#,###,#00  Lives: #  <--JAKE"; score2; lives2
  595.     END IF
  596.  
  597.     LOCATE 1, 49
  598.     PRINT USING "SAMMY-->  Lives: #     #,###,#00"; lives1; score1
  599. END SUB
  600.  
  601. 'Set:
  602. '  Sets row and column on playing field to given color to facilitate moving
  603. '  of snakes around the field.
  604. SUB Set (row, col, acolor)
  605.     IF row <> 0 THEN
  606.         arena(row, col).acolor = acolor             'assign color to arena
  607.         realRow = arena(row, col).realRow           'Get real row of pixel
  608.         topFlag = arena(row, col).sister + 1 / 2    'Deduce whether pixel
  609.                                                     'is on top▀, or bottom▄
  610.         sisterRow = row + arena(row, col).sister    'Get arena row of sister
  611.         sisterColor = arena(sisterRow, col).acolor  'Determine sister's color
  612.  
  613.         LOCATE realRow, col
  614.  
  615.         IF acolor = sisterColor THEN                'If both points are same
  616.             COLOR acolor, acolor                           'Print chr$(219) "█"
  617.             PRINT CHR$(219);
  618.         ELSE
  619.             IF topFlag THEN                         'Since you cannot have
  620.                 IF acolor > 7 THEN                  'bright backgrounds
  621.                     COLOR acolor, sisterColor       'determine best combo
  622.                     PRINT CHR$(223);                'to use.
  623.                 ELSE
  624.                     COLOR sisterColor, acolor
  625.                     PRINT CHR$(220);
  626.                 END IF
  627.             ELSE
  628.                 IF acolor > 7 THEN
  629.                     COLOR acolor, sisterColor
  630.                     PRINT CHR$(220);
  631.                 ELSE
  632.                     COLOR sisterColor, acolor
  633.                     PRINT CHR$(223);
  634.                 END IF
  635.             END IF
  636.         END IF
  637.     END IF
  638. END SUB
  639.  
  640. 'SpacePause:
  641. '  Pauses game play and waits for space bar to be pressed before continuing
  642. SUB SpacePause (text$)
  643.  
  644.     COLOR colorTable(5), colorTable(6)
  645.     Center 11, "█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█"
  646.     Center 12, "█ " + LEFT$(text$ + SPACE$(29), 29) + " █"
  647.     Center 13, "█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█"
  648.     WHILE INKEY$ <> "": WEND
  649.     WHILE INKEY$ <> " ": WEND
  650.     COLOR 15, colorTable(4)
  651.  
  652.     FOR i = 21 TO 26            ' Restore the screen background
  653.         FOR j = 24 TO 56
  654.             Set i, j, arena(i, j).acolor
  655.         NEXT j
  656.     NEXT i
  657.  
  658. END SUB
  659.  
  660. 'SparklePause:
  661. '  Creates flashing border for intro screen
  662. SUB SparklePause
  663.  
  664.     COLOR 4, 0
  665.     a$ = "*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    "
  666.     WHILE INKEY$ <> "": WEND 'Clear keyboard buffer
  667.  
  668.     WHILE INKEY$ = ""
  669.         FOR a = 1 TO 5
  670.             LOCATE 1, 1                             'print horizontal sparkles
  671.             PRINT MID$(a$, a, 80);
  672.             LOCATE 22, 1
  673.             PRINT MID$(a$, 6 - a, 80);
  674.  
  675.             FOR b = 2 TO 21                         'Print Vertical sparkles
  676.                 c = (a + b) MOD 5
  677.                 IF c = 1 THEN
  678.                     LOCATE b, 80
  679.                     PRINT "*";
  680.                     LOCATE 23 - b, 1
  681.                     PRINT "*";
  682.                 ELSE
  683.                     LOCATE b, 80
  684.                     PRINT " ";
  685.                     LOCATE 23 - b, 1
  686.                     PRINT " ";
  687.                 END IF
  688.             NEXT b
  689.         NEXT a
  690.     WEND
  691.  
  692. END SUB
  693.  
  694. 'StillWantsToPlay:
  695. '  Determines if users want to play game again.
  696. FUNCTION StillWantsToPlay
  697.  
  698.     COLOR colorTable(5), colorTable(6)
  699.     Center 10, "█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█"
  700.     Center 11, "█       G A M E   O V E R       █"
  701.     Center 12, "█                               █"
  702.     Center 13, "█      Play Again?   (Y/N)      █"
  703.     Center 14, "█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█"
  704.  
  705.     WHILE INKEY$ <> "": WEND
  706.     DO
  707.         kbd$ = UCASE$(INKEY$)
  708.     LOOP UNTIL kbd$ = "Y" OR kbd$ = "N"
  709.  
  710.     COLOR 15, colorTable(4)
  711.     Center 10, "                                 "
  712.     Center 11, "                                 "
  713.     Center 12, "                                 "
  714.     Center 13, "                                 "
  715.     Center 14, "                                 "
  716.  
  717.     IF kbd$ = "Y" THEN
  718.         StillWantsToPlay = TRUE
  719.     ELSE
  720.         StillWantsToPlay = FALSE
  721.         COLOR 7, 0
  722.         CLS
  723.     END IF
  724.  
  725. END FUNCTION
  726.  
  727.