home *** CD-ROM | disk | FTP | other *** search
/ Pacman Top Games Collection / PacmanCollection.iso / KC6 / SRC / KC6.T < prev   
Encoding:
Text File  |  1994-11-04  |  32.6 KB  |  1,533 lines

  1. include "%grafix2.int"
  2. include "%music.int"
  3.  
  4. setscreen ("graphics:e16")
  5. setscreen ("noecho")
  6. const kkk := 41
  7. const kkkover2 := 20
  8.  
  9. const noOfPages := 5
  10.  
  11. const chase := true
  12. const flee := false
  13. const TilesNo := 8 * 13
  14.  
  15. var maxTime : int
  16.  
  17. %.. This boolean makes sure the display message before each page is shown
  18. %   only once.
  19. var messShown : array 1 .. noOfPages - 1 of boolean
  20. for i : 1 .. noOfPages - 1
  21.     messShown (i) := false
  22. end for
  23.  
  24. %.. This variable makes sure there is exactly
  25. var noOfTilesFilled : int
  26.  
  27. var Color : boolean := true
  28. var C : string (1)
  29.  
  30. var smartTheta : int
  31.  
  32. var pageType : int
  33. var newGame := true
  34. var newPage := true
  35.  
  36. var men : int
  37.  
  38. var file, file2 : int
  39. var size : int
  40. open : file, "kc.gfx", read
  41. read : file, size
  42.  
  43. type figure :
  44.     record
  45.     bitmap : array 1 .. 187 of int
  46.     end record
  47.  
  48. const kcright := 1
  49. const kcleft := 2
  50. const kcrightclosed := 3
  51. const kcleftclosed := 4
  52.  
  53. var graphic : array 1 .. 4 of figure
  54. var ghostgraphic : array 1 .. 3, 0 .. 6 of figure
  55. var ghosteye : array 0 .. 5 of figure
  56. var warp : array 0 .. 15 of figure
  57. var blueghost : figure
  58. var Blank : figure
  59.  
  60. var ghostEaten : array 1 .. 3 of boolean
  61. var noOfGhostsEaten : int
  62. for i : 1 .. 4
  63.     read : file, graphic (i).bitmap
  64. end for
  65. read : file, blueghost.bitmap
  66. read : file, Blank.bitmap
  67. for i : 1 .. 3
  68.     for j : 0 .. 5
  69.     read : file, ghostgraphic (i, j).bitmap
  70.     end for
  71. end for
  72. for j : 0 .. 5
  73.     read : file, ghosteye (j).bitmap
  74. end for
  75.  
  76. read : file, size
  77. var dotgraf : array 1 .. size of int
  78. read : file, dotgraf
  79.  
  80. read : file, size
  81. var pillgraf : array 1 .. size of int
  82. read : file, pillgraf
  83. for i : 0 .. 15
  84.     read : file, warp (i).bitmap
  85. end for
  86. close : file
  87.  
  88. %.. This is the wall matrix
  89. var area : array 1 .. 13, 1 .. 8, 1 .. 4 of boolean
  90.  
  91. var movex : array 3 .. 4 of int := init ( - 1, 1)
  92. var movey : array 1 .. 2 of int := init ( - 1, 1)
  93.  
  94. var pillPresent : boolean
  95. var pillTime := 0
  96.  
  97. const up := 1
  98. const down := 2
  99. const left := 3
  100. const right := 4
  101. const wall := 5
  102. const dot := 6
  103. const pill := 7
  104. const KC := 8
  105. const ghost := 9
  106. const zip := 10
  107.  
  108. var pageNo : int := 1
  109.  
  110. var x, y, xx, yy, aa, bb : int
  111.  
  112. var ghostx, ghosty, ghostxx, ghostyy : array 1 .. 3 of int
  113. var pillx, pilly, pillxx, pillyy, pillDir, warpx, warpy : int
  114.  
  115. var dotx, doty, dotxx, dotyy : array 1 .. 10 of int
  116. var eaten : array 1 .. 10 of boolean
  117. for i : 1 .. 10
  118.     eaten (i) := false
  119. end for
  120.  
  121. var object : array 0 .. 14, 0 .. 9 of int
  122. for i : 0 .. 14
  123.     for j : 0 .. 9
  124.     object (i, j) := 0
  125.     end for
  126. end for
  127.  
  128.  
  129. var key : string (1)
  130.  
  131. var frame : int
  132.  
  133. var dir : int
  134.  
  135. var score : int := 0
  136. var hscore : int := 0
  137. open : file, "kc.dat", read
  138. if file not= 0 then
  139.     read : file, hscore
  140.     close : file
  141. else
  142.     open : file, "kc.dat", write
  143.     hscore := 0
  144.     write : file, hscore
  145.     close : file
  146. end if
  147.  
  148.  
  149. var dotsEaten : int := 0
  150. const maxDots := 10
  151.  
  152. %.. These are the bonus variables
  153. var ghostStill, dotStill, kcStill : boolean := false
  154. var ghostTime, dotTime, kcTime : int
  155.  
  156. proc eatGhost
  157.     for i : 1 .. 15
  158.     sound (100 * i, 1)
  159.     end for
  160. end eatGhost
  161.  
  162. proc blueGhost
  163.     for i : 1 .. 10
  164.     sound (100, 1)
  165.     sound (0, 1)
  166.     end for
  167. end blueGhost
  168.  
  169. procedure waka
  170.     for i : 1 .. 3
  171.     sound (100 * i, 1)
  172.     end for
  173.     %     music.sing ("o6 f")
  174. end waka
  175.  
  176. proc eatPill
  177.     for i : 1 .. 3
  178.     for decreasing j : 3 .. 1
  179.         sound (500 * j, 1)
  180.     end for
  181.     end for
  182. end eatPill
  183.  
  184. procedure randsing (l : int)
  185.     var riff := "o6 "
  186.  
  187.     var note : int
  188.     for i : 1 .. l
  189.     randint (note, 97, 103)
  190.     riff := riff + chr (note)
  191.     end for
  192.  
  193.     music.sing (riff)
  194. end randsing
  195.  
  196. procedure pause
  197.     var q : int := 0
  198.     for i : 1 .. 10000
  199.     q += 1
  200.     end for
  201. end pause
  202.  
  203.  
  204. procedure getLastChar (var s : string (1))
  205.     s := ""
  206.     loop
  207.     exit when not grafix.haskey
  208.     grafix.getkey (s)
  209.     end loop
  210. end getLastChar
  211.  
  212. procedure initialize
  213.     pillPresent := false
  214.  
  215.     for i : 1 .. 13
  216.     area (i, 1, up) := true
  217.     area (i, 8, down) := true
  218.  
  219.     for j : 1 .. 8
  220.         if j not= 1 then
  221.         area (i, j, up) := false
  222.         end if
  223.  
  224.         if j not= 8 then
  225.         area (i, j, down) := false
  226.         end if
  227.  
  228.         if i = 1 then
  229.         area (i, j, left) := true
  230.         else
  231.         area (i, j, left) := false
  232.         end if
  233.  
  234.         if i = 13 then
  235.         area (i, j, right) := true
  236.         else
  237.         area (i, j, right) := false
  238.         end if
  239.  
  240.     end for
  241.  
  242.     end for
  243.  
  244.     if newGame or newPage then
  245.     for i : 1 .. 5
  246.         dotx (i) := i
  247.         dotx (i + 5) := i + 8
  248.         doty (i) := 2
  249.         doty (i + 5) := 2
  250.         eaten (i) := false
  251.         eaten (i + 5) := false
  252.     end for
  253.     dotsEaten := 0
  254.     end if
  255.     if newPage and pageNo not= 1 and men < 10 then
  256.     men := men + 1
  257.     newPage := not newPage
  258.     end if
  259.     for i : 1 .. 3
  260.     ghostx (i) := i + 5
  261.     ghosty (i) := 2
  262.     end for
  263.  
  264.     x := 7
  265.     y := 7
  266.  
  267.     for i : 1 .. 13
  268.     for j : 1 .. 8
  269.         object (i, j) := zip
  270.     end for
  271.     end for
  272.  
  273.     for i : 1 .. 13
  274.     object (i, 0) := wall
  275.     object (i, 9) := wall
  276.     end for
  277.  
  278.     for i : 1 .. 8
  279.     object (0, i) := wall
  280.     object (14, i) := wall
  281.     end for
  282.  
  283.     for i : 1 .. 10
  284.     object (dotx (i), doty (i)) := dot
  285.     end for
  286.  
  287.  
  288.  
  289.     key := kleftarrow
  290.     dir := left
  291.  
  292.     if newGame then
  293.     newPage := true
  294.     score := 0
  295.     newGame := false
  296.     end if
  297.  
  298.     if newGame or newPage then
  299.     frame := 0
  300.     end if
  301.  
  302. end initialize
  303.  
  304. procedure ValidateMaze (X : int, Y : int)
  305.     object (X, Y) := KC
  306.     noOfTilesFilled += 1
  307.     if Y > 1 and not area (X, Y, up) and object (X, Y - 1) not= KC then
  308.     ValidateMaze (X, Y - 1)
  309.     end if
  310.     if Y < 8 and not area (X, Y, down) and object (X, Y + 1) not= KC then
  311.     ValidateMaze (X, Y + 1)
  312.     end if
  313.     if X > 1 and not area (X, Y, left) and object (X - 1, Y) not= KC then
  314.     ValidateMaze (X - 1, Y)
  315.     end if
  316.     if X < 13 and not area (X, Y, right) and object (X + 1, Y) not= KC then
  317.     ValidateMaze (X + 1, Y)
  318.     end if
  319. end ValidateMaze
  320.  
  321.  
  322.  
  323. procedure drawMaze
  324.     cls
  325.     for x : 1 .. 13
  326.     for y : 1 .. 8
  327.  
  328.         var a := (x - 1) * kkk
  329.         var b := (y - 1) * kkk
  330.  
  331.         if area (x, y, up) then
  332.         grafix.hlin (a, a + kkk, b, blue + 8)
  333.         end if
  334.  
  335.         if area (x, y, down) then
  336.         grafix.hlin (a, a + kkk, b + kkk, blue + 8)
  337.         end if
  338.  
  339.         if area (x, y, left) then
  340.         grafix.vlin (b, b + kkk, a, blue + 8)
  341.         end if
  342.  
  343.         if area (x, y, right) then
  344.         grafix.vlin (b, b + kkk, a + kkk, blue + 8)
  345.         end if
  346.  
  347.  
  348.     end for
  349.     end for
  350. end drawMaze
  351.  
  352. procedure generateMaze
  353.     loop
  354.     for x : 1 .. 13
  355.         for dummy : 1 .. 4
  356.  
  357.         var y := dummy * 2
  358.  
  359.         var q : int
  360.         randint (q, 1, 4)
  361.         area (x, y, q) := true
  362.  
  363.         if area (x, y, 1) and area (x, y, 2) and area (x, y, 3)
  364.             and area (x, y, 4) then
  365.             area (x, y, q) := false
  366.         else
  367.  
  368.             if q = up and y not= 1 then
  369.             area (x, y - 1, down) := true
  370.             elsif q = down and y not= 8 then
  371.             area (x, y + 1, up) := true
  372.             elsif q = left and x not= 1 then
  373.             area (x - 1, y, right) := true
  374.             elsif q = right and x not= 13 then
  375.             area (x + 1, y, left) := true
  376.             end if
  377.  
  378.         end if
  379.  
  380.  
  381.         end for
  382.     end for
  383.  
  384.     for dummy : 1 .. 4
  385.  
  386.         var y := (dummy * 2) - 1
  387.  
  388.         var x, z : int
  389.  
  390.         randint (x, 3, 11)
  391.         randint (z, 3, 4)
  392.  
  393.         area (x, y, z) := true
  394.  
  395.         if z = left then
  396.         area (x - 1, y, right) := true
  397.         else
  398.         area (x + 1, y, left) := true
  399.         end if
  400.  
  401.     end for
  402.     noOfTilesFilled := 0
  403.     ValidateMaze (4, 6)
  404.     for i : 1 .. 13
  405.         for j : 1 .. 8
  406.         object (i, j) := zip
  407.         end for
  408.     end for
  409.     exit when noOfTilesFilled = TilesNo
  410.     for i : 1 .. 13
  411.         for j : 1 .. 8
  412.         for k : 1 .. 4
  413.             area (i, j, k) := false
  414.         end for
  415.         end for
  416.     end for
  417.     initialize
  418.     end loop
  419. end generateMaze
  420.  
  421. procedure drawEye (a, b, c : int)
  422.     var x := (a - 1) * kkk
  423.     var y := (b - 1) * kkk
  424.  
  425.     if c = 0 then
  426.     drawpic (x + 3, y + 3, Blank.bitmap, 0)
  427.     elsif kcStill and ghostEaten (c) then
  428.     drawpic (x + 3, y + 3, ghosteye (frame mod 6).bitmap, 0)
  429.     end if
  430. end drawEye
  431.  
  432. procedure drawGhost (a, b, c : int)
  433.     var x := (a - 1) * kkk
  434.     var y := (b - 1) * kkk
  435.  
  436.     if c = 0 then
  437.     drawpic (x + 3, y + 3, Blank.bitmap, 0)
  438.     elsif kcStill then
  439.     drawpic (x + 3, y + 3, blueghost.bitmap, 1)
  440.     else
  441.     drawpic (x + 3, y + 3, ghostgraphic (c, frame mod 6).bitmap, 1)
  442.     end if
  443. end drawGhost
  444.  
  445. procedure drawKCHalfway (dir : int)
  446.  
  447.     %drawpic (x + 3, y + 3, Blank.bitmap, 0)
  448.     if frame mod 2 = 0 then
  449.     if dir = left or dir = up then
  450.         drawpic (aa + 2, bb + 2, graphic (kcleft).bitmap, 1)
  451.     else
  452.         drawpic (aa + 2, bb + 2, graphic (kcright).bitmap, 1)
  453.     end if
  454.     else
  455.     if dir = left or dir = up then
  456.         drawpic (aa + 2, bb + 2, graphic (kcleftclosed).bitmap, 1)
  457.     else
  458.         drawpic (aa + 2, bb + 2, graphic (kcrightclosed).bitmap, 1)
  459.     end if
  460.     end if
  461. end drawKCHalfway
  462.  
  463. procedure drawKC (a, b, c, frame, dir : int)
  464.     var x := (a - 1) * kkk
  465.     var y := (b - 1) * kkk
  466.     if c = 0 then
  467.     drawpic (x + 3, y + 3, Blank.bitmap, 0)
  468.     elsif frame mod 2 = 0 then
  469.     if dir = left or dir = up then
  470.         drawpic (x + 3, y + 3, graphic (kcleft).bitmap, 0)
  471.     elsif dir = right or dir = down then
  472.         drawpic (x + 3, y + 3, graphic (kcright).bitmap, 0)
  473.     elsif dir = left + 4 or dir = up + 4 then
  474.         drawpic (x + 3, y + 3, graphic (kcleft).bitmap, 1)
  475.     else
  476.         drawpic (x + 3, y + 3, graphic (kcright).bitmap, 1)
  477.     end if
  478.     else
  479.     if dir = left or dir = up then
  480.         drawpic (x + 3, y + 3, graphic (kcleftclosed).bitmap, 0)
  481.     elsif dir = right or dir = down then
  482.         drawpic (x + 3, y + 3, graphic (kcrightclosed).bitmap, 0)
  483.     elsif dir = left + 4 or dir = up + 4 then
  484.         drawpic (x + 3, y + 3, graphic (kcleftclosed).bitmap, 1)
  485.     else
  486.         drawpic (x + 3, y + 3, graphic (kcrightclosed).bitmap, 1)
  487.     end if
  488.     end if
  489. end drawKC
  490.  
  491. procedure chooseBonus
  492.     var r : int
  493.     randint (r, 1, 8)
  494.     if r = 1 then
  495.     drawKC (x, y, black, 2, up)
  496.     object (x, y) := zip
  497.     randint (x, 1, 13)
  498.     randint (y, 1, 8)
  499.     drawKC (x, y, yellow, frame, dir)
  500.     elsif r = 2 or r = 6 or r = 7 or r = 8 then
  501.     kcStill := true
  502.     ghostStill := false
  503.     ghostTime := 0
  504.     kcTime := 50
  505.     noOfGhostsEaten := 0
  506.     for i : 1 .. 3
  507.         ghostEaten (i) := false
  508.     end for
  509.     blueGhost
  510.     elsif r = 3 then
  511.     dotStill := true
  512.     dotTime := 50
  513.     elsif r = 4 then
  514.     ghostStill := true
  515.     ghostTime := 50
  516.     kcStill := false
  517.     kcTime := 0
  518.     elsif r = 5 then
  519.     if men < 10 then
  520.         men += 1
  521.     end if
  522.     end if
  523. end chooseBonus
  524.  
  525. procedure addscore (x, y : int, var object : int)
  526.     if object = dot then
  527.     object := zip
  528.     score += 10 * pageNo
  529.  
  530.     var found : boolean := false
  531.     for i : 1 .. 10
  532.         if dotx (i) = x and doty (i) = y and not eaten (i) then
  533.         found := true
  534.         eaten (i) := true
  535.         %.. drawDot(dotx(i),doty(i),black)
  536.         waka
  537.         %music.sing ("o6 f")
  538.         drawKC (x, y, yellow, frame, dir)
  539.         end if
  540.         exit when found
  541.     end for
  542.  
  543.  
  544.     if found then
  545.         dotsEaten += 1
  546.     end if
  547.  
  548.     elsif object = pill then
  549.     var points : int
  550.     points := pageNo * 200
  551.     score += points
  552.     var v, w : int
  553.     grafix.text (0, 0, white, "")
  554.     locatexy ( (x - 1) * kkk + (kkk div 2), (y - 1) * kkk + (kkk div
  555.         2))
  556.     put intstr (points)
  557.  
  558.     eatPill
  559.     locatexy ( (x - 1) * kkk + (kkk div 2), (y - 1) * kkk + (kkk div
  560.         2))
  561.     put repeat (" ", length (intstr (points)))
  562.     drawKC (x, y, yellow, frame, dir)
  563.  
  564.     pillPresent := false
  565.     if pageType not= 5 then
  566.         chooseBonus
  567.     end if
  568.     elsif object = ghost then
  569.     var points : int
  570.     points := 100 * (2 ** noOfGhostsEaten) * pageNo
  571.     score += points
  572.     var v, w : int
  573.     grafix.text (0, 0, white, "")
  574.     locatexy ( (x - 1) * kkk + (kkk div 2), (y - 1) * kkk + (kkk div
  575.         2))
  576.     put intstr (points)
  577.  
  578.     eatGhost
  579.     locatexy ( (x - 1) * kkk + (kkk div 2), (y - 1) * kkk + (kkk div
  580.         2))
  581.     put repeat (" ", length (intstr (points)))
  582.     drawKC (x, y, yellow, frame, dir)
  583.     end if
  584.  
  585.     var s : string := "SCORE=" + intstr (score) + "      "
  586.     for i : 1 .. men
  587.     s := s + chr (7)
  588.     end for
  589.  
  590.     grafix.text (0, 0, 15, s)
  591.  
  592.  
  593. end addscore
  594.  
  595. procedure moveKCHalfway
  596.     aa := (x - 1) * kkk
  597.     bb := (y - 1) * kkk
  598.  
  599.     if grafix.haskey then
  600.     grafix.move (79, 25)
  601.     getLastChar (key)
  602.     end if
  603.  
  604.     drawKC (x, y, black, frame, dir)
  605.     object (x, y) := zip
  606.     %frame += 1
  607.  
  608.     if key = kdownarrow then
  609.     dir := up
  610.     if not area (x, y, up) then
  611.         bb -= kkkover2
  612.     elsif pageType = 4 then
  613.         grafix.hlin (aa, aa + kkk - 1, bb, blue)
  614.     end if
  615.     elsif key = kuparrow then
  616.     dir := down
  617.     if not area (x, y, down) then
  618.         bb += kkkover2
  619.     elsif pageType = 4 then
  620.         grafix.hlin (aa, aa + kkk - 1, bb + kkk, blue)
  621.     end if
  622.     elsif key = kleftarrow then
  623.     dir := left
  624.     if not area (x, y, left) then
  625.         aa -= kkkover2
  626.     elsif pageType = 4 then
  627.         grafix.vlin (bb, bb + kkk - 1, aa, blue)
  628.     end if
  629.     elsif key = krightarrow then
  630.     dir := right
  631.     if not area (x, y, right) then
  632.         aa += kkkover2
  633.     elsif pageType = 4 then
  634.         grafix.vlin (bb, bb + kkk - 1, aa + kkk, blue)
  635.     end if
  636.     end if
  637.  
  638.     drawKCHalfway (dir)
  639.  
  640. end moveKCHalfway
  641.  
  642. procedure moveKC (var endMan : boolean)
  643.     var a := (x - 1) * kkk
  644.     var b := (y - 1) * kkk
  645.     %if grafix.haskey then
  646.     %    grafix.move (79, 25)
  647.     %    getLastChar (key)
  648.     %end if
  649.  
  650.     drawKC (x, y, black, frame, dir)
  651.     object (x, y) := zip
  652.     frame += 1
  653.  
  654.     if key = kdownarrow then
  655.     dir := up
  656.     if not area (x, y, up) then
  657.         y -= 1
  658.     elsif pageType = 4 then
  659.         grafix.hlin (a, a + kkk - 1, b, blue)
  660.     end if
  661.     elsif key = kuparrow then
  662.     dir := down
  663.     if not area (x, y, down) then
  664.         y += 1
  665.     elsif pageType = 4 then
  666.         grafix.hlin (a, a + kkk - 1, b + kkk, blue)
  667.     end if
  668.     elsif key = kleftarrow then
  669.     dir := left
  670.     if not area (x, y, left) then
  671.         x -= 1
  672.     elsif pageType = 4 then
  673.         grafix.vlin (b, b + kkk - 1, a, blue)
  674.     end if
  675.     elsif key = krightarrow then
  676.     dir := right
  677.     if not area (x, y, right) then
  678.         x += 1
  679.     elsif pageType = 4 then
  680.         grafix.vlin (b, b + kkk - 1, a + kkk, blue)
  681.     end if
  682.     end if
  683.  
  684.     drawKC (x, y, yellow, frame, dir)
  685.  
  686.     if object (x, y) = ghost then
  687.     endMan := true
  688.     elsif object (x, y) not= zip then
  689.     addscore (x, y, object (x, y))
  690.     end if
  691.  
  692.     if endMan then
  693.     endMan := false
  694.     for i : 1 .. 3
  695.         if ghostx (i) = x and ghosty (i) = y then
  696.         if kcStill and not ghostEaten (i) then
  697.             ghostEaten (i) := true
  698.             noOfGhostsEaten += 1
  699.             addscore (x, y, object (x, y))
  700.         elsif not kcStill then
  701.             endMan := true
  702.         end if
  703.         end if
  704.         exit when endMan
  705.     end for
  706.     end if
  707.  
  708.     if not endMan then
  709.     object (x, y) := KC
  710.     end if
  711.  
  712.     if pillPresent and x = pillx and y = pilly then
  713.     pillPresent := false
  714.     %ghostStop:=true
  715.     var zz := pill
  716.     addscore (pillx, pilly, zz)
  717.     end if
  718. end moveKC
  719.  
  720. function blank (o : int) : boolean
  721.     if o = zip or o = KC then
  722.     result true
  723.     else
  724.     result false
  725.     end if
  726. end blank
  727.  
  728. function surrounded (x, y : int) : boolean
  729.     %.. problem here RIGHT below area(x,y, left)
  730.     if x < 1 or x > 13 or y < 1 or y > 8 then
  731.     grafix.text (0, 0, white, "Problem: " + intstr (x) + "," + intstr
  732.         (y))
  733.     loop
  734.     end loop
  735.     end if
  736.     if (area (x, y, left) or
  737.         not blank (object (x - 1, y)))
  738.         and (area (x, y, right) or
  739.         not blank (object (x + 1, y)))
  740.         and (area (x, y, up) or
  741.         not blank (object (x, y - 1)))
  742.         and (area (x, y, down) or
  743.         not blank (object (x, y + 1))) then
  744.     result true
  745.     else
  746.     result false
  747.     end if
  748. end surrounded
  749.  
  750. procedure moveIfCan (var gx, gy, gd : int, var moved : boolean)
  751.     if gd = up and not area (gx, gy, up) and
  752.         (object (gx, gy - 1) = zip or object (gx, gy - 1) = KC) then
  753.     gy -= 1
  754.     moved := true
  755.     elsif gy not= 8 and gd = down and not area (gx, gy, down) and
  756.         (object (gx, gy + 1) = zip or object (gx, gy + 1) = KC)
  757.     then
  758.     gy += 1
  759.     moved := true
  760.     elsif gd = left and not area (gx, gy, left) and (object (gx - 1,
  761.         gy) = zip or
  762.         object (gx - 1, gy) = KC) then
  763.     gx -= 1
  764.     moved := true
  765.     elsif gd = right and not area (gx, gy, right) and (object (gx +
  766.         1, gy) = zip or
  767.         object (gx + 1, gy) = KC) then
  768.     gx += 1
  769.     moved := true
  770.     else
  771.     moved := false
  772.     end if
  773. end moveIfCan
  774.  
  775. procedure moveSmartGhost (var gx, gy, gc : int, var endMan : boolean,
  776.     chasing : boolean)
  777.  
  778.     var gd : int
  779.     object (gx, gy) := zip
  780.     drawGhost (gx, gy, black)
  781.     if not surrounded (gx, gy) then
  782.  
  783.     randint (gd, 1, 2)
  784.  
  785.     %..Start
  786.     var ranNo : int
  787.  
  788.     var toDir : array 1 .. 2 of int
  789.  
  790.     if x < gx then
  791.         if chasing then
  792.         toDir (1) := left
  793.         else
  794.         toDir (1) := right
  795.         end if
  796.     else
  797.         if chasing then
  798.         toDir (1) := right
  799.         else
  800.         toDir (1) := left
  801.         end if
  802.     end if
  803.  
  804.     if y < gy then
  805.         if chasing then
  806.         toDir (2) := up
  807.         else
  808.         toDir (2) := down
  809.         end if
  810.     else
  811.         if chasing then
  812.         toDir (2) := down
  813.         else
  814.         toDir (2) := up
  815.         end if
  816.     end if
  817.  
  818.     var dd : int
  819.     randint (ranNo, 1, 2)
  820.     dd := toDir (ranNo)
  821.  
  822.     var moved := false
  823.  
  824.     %.. optimal dir
  825.     moveIfCan (gx, gy, dd, moved)
  826.  
  827.     if not moved then
  828.         %.. second optimal dir
  829.         moveIfCan (gx, gy, toDir ( (ranNo mod 2) + 1), moved)
  830.  
  831.         if not moved then
  832.         toDir (1) := (toDir (1) mod 2) + 3
  833.         toDir (2) := (toDir (2) mod 2) + 1
  834.         moveIfCan (gx, gy, toDir (ranNo), moved)
  835.         if not moved then
  836.             moveIfCan (gx, gy, toDir ( (ranNo mod 2) + 1), moved)
  837.         end if
  838.         end if
  839.     end if
  840.  
  841.     object (gx, gy) := ghost
  842.     %..End
  843.     end if
  844.  
  845.     if kcStill and ghostEaten (gc) then
  846.     drawEye (gx, gy, gc)
  847.     else
  848.     drawGhost (gx, gy, gc)
  849.     end if
  850.  
  851.     if gx = x and gy = y then
  852.     if kcStill and not ghostEaten (gc) then
  853.         ghostEaten (gc) := true
  854.         noOfGhostsEaten += 1
  855.         addscore (x, y, object (x, y))
  856.     elsif not kcStill then
  857.         endMan := true
  858.     end if
  859.     end if
  860.  
  861. end moveSmartGhost
  862.  
  863. procedure moveGhost (var gx, gy, gc : int, var endMan : boolean)
  864.  
  865.     var gd : int
  866.  
  867.     object (gx, gy) := zip
  868.     drawGhost (gx, gy, black)
  869.     if not surrounded (gx, gy) then
  870.  
  871.     randint (gd, 1, 4)
  872.  
  873.     var moved : boolean := false
  874.     for i : 1 .. 4
  875.         moveIfCan (gx, gy, gd, moved)
  876.         exit when moved
  877.         gd := (gd mod 4) + 1
  878.     end for
  879.  
  880.     assert moved
  881.     object (gx, gy) := ghost
  882.  
  883.     end if
  884.  
  885.     if kcStill and ghostEaten (gc) then
  886.     drawEye (gx, gy, gc)
  887.     else
  888.     drawGhost (gx, gy, gc)
  889.     end if
  890.  
  891.     if gx = x and gy = y then
  892.     if kcStill and not ghostEaten (gc) then
  893.         ghostEaten (gc) := true
  894.         noOfGhostsEaten += 1
  895.         addscore (x, y, object (x, y))
  896.     elsif not kcStill then
  897.         endMan := true
  898.     end if
  899.     end if
  900. end moveGhost
  901.  
  902.  
  903. %procedure%increase (var dir : int, var dirArray : array 1 .. 2 of int,
  904. %       dirInt : int)
  905. %       dir+=1
  906. %       dirArray (dir) := dirInt
  907. %end%increase
  908.  
  909. function opposite (a : int) : int
  910.     if a = 1 then
  911.     result 2
  912.     else
  913.     result 1
  914.     end if
  915. end opposite
  916.  
  917. procedure drawDot (x, y, c : int)
  918.     var a := ( (x - 1) * kkk) + (kkk div 2)
  919.     var b := ( (y - 1) * kkk) + (kkk div 2)
  920.  
  921.     if c = 0 then
  922.     drawpic (a - (kkk div 2) + 3, b - (kkk div 2) + 3, Blank.bitmap,
  923.         0)
  924.     elsif c = white then
  925.     drawpic (a, b, dotgraf, 1)
  926.     else
  927.     drawpic (a - 3, b - 3, pillgraf, 1)
  928.     end if
  929.     %drawoval (a, b, 5, 5, c)
  930.  
  931. end drawDot
  932.  
  933. procedure moveDot (var dx, dy : int, dc : int)
  934.     if not surrounded (dx, dy) then
  935.  
  936.     drawDot (dx, dy, 0)
  937.     object (dx, dy) := zip
  938.     var ranNo : int
  939.  
  940.     var awayDir : array 1 .. 2 of int
  941.  
  942.     if x > dx then
  943.         awayDir (1) := left
  944.     else
  945.         awayDir (1) := right
  946.     end if
  947.  
  948.     if y > dy then
  949.         awayDir (2) := up
  950.     else
  951.         awayDir (2) := down
  952.     end if
  953.  
  954.     var dd : int
  955.     randint (ranNo, 1, 2)
  956.     dd := awayDir (ranNo)
  957.  
  958.     var moved := false
  959.  
  960.     %.. optimal dir
  961.     moveIfCan (dx, dy, dd, moved)
  962.  
  963.     if not moved then
  964.         %.. second optimal dir
  965.         moveIfCan (dx, dy, awayDir ( (ranNo mod 2) + 1), moved)
  966.  
  967.         if not moved then
  968.         awayDir (1) := (awayDir (1) mod 2) + 3
  969.         awayDir (2) := (awayDir (2) mod 2) + 1
  970.         moveIfCan (dx, dy, awayDir (ranNo), moved)
  971.         if not moved then
  972.             moveIfCan (dx, dy, awayDir ( (ranNo mod 2) + 1),
  973.             moved)
  974.         end if
  975.         end if
  976.     end if
  977.     drawDot (dx, dy, dc)
  978.  
  979.     if object (dx, dy) not= zip then
  980.         var Dot := dot
  981.         addscore (x, y, Dot)
  982.     else
  983.         object (dx, dy) := dot
  984.     end if
  985.  
  986.     end if
  987.  
  988. end moveDot
  989.  
  990. procedure movePill (var s, t, dir : int)
  991.  
  992.     var canMove : boolean := true
  993.     pillTime += 1
  994.     if pillTime = 26 then
  995.     if dir = left then
  996.         dir := right
  997.     else
  998.         dir := left
  999.     end if
  1000.     pillTime := 0
  1001.     end if
  1002.     drawDot (s, t, black)
  1003.     if (s = 1 and dir = left) or (s = 13 and dir = right) then
  1004.     pillPresent := false
  1005.     else
  1006.     if not area (s, t, dir) then
  1007.         s += movex (dir)
  1008.     else
  1009.         var randir : int
  1010.  
  1011.         randint (randir, 1, 2)
  1012.         if area (s, t, randir) then
  1013.         randir := randir mod 2 + 1
  1014.         end if
  1015.         if area (s, t, randir) then
  1016.         if (s = 1 and dir = right) or (s = 13 and dir = left)
  1017.             then
  1018.             canMove := false
  1019.         else
  1020.             randir := dir mod 2 + 3
  1021.         end if
  1022.         end if
  1023.         if area (s, t, randir) then
  1024.         canMove := false
  1025.         end if
  1026.         if canMove then
  1027.         if randir = 3 or randir = 4 then
  1028.             s += movex (randir)
  1029.         else
  1030.             t += movey (randir)
  1031.         end if
  1032.         end if
  1033.     end if
  1034.  
  1035.     if object (s, t) = KC then
  1036.         var dum : int := pill
  1037.         addscore (s, t, dum)
  1038.     else
  1039.         drawDot (s, t, red)
  1040.     end if
  1041.     end if
  1042. end movePill
  1043.  
  1044. procedure startPage
  1045.     ghostTime := 0
  1046.     dotTime := 0
  1047.     kcTime := 0
  1048.     dotStill := false
  1049.     kcStill := false
  1050.  
  1051.     for i : 0 .. 14
  1052.     for j : 0 .. 9
  1053.         object (i, j) := 0
  1054.     end for
  1055.     end for
  1056.     initialize
  1057.     pageType := ((pageNo - 1) mod noOfPages) + 1
  1058.  
  1059.  
  1060.     if pageType = 1 and not messShown (1) then
  1061.     cls
  1062.     grafix.text (30, 10, 15, "THE BEGINNING")
  1063.     grafix.text (20, 12, 15, "Avoid the monsters, eat the dots.")
  1064.     maxTime := 400
  1065.     if pageNo > noOfPages * 3 then
  1066.         grafix.text (11, 18, 15,
  1067.         "BEWARE: All three monsters have the IQ of Einstien.")
  1068.     elsif pageNo > noOfPages * 2 then
  1069.         grafix.text (5, 18, 15,
  1070.         "BEWARE: The red AND the purple monsters have just received Ph.D.'s.")
  1071.  
  1072.     elsif pageNo > noOfPages then
  1073.         grafix.text (13, 18, 15,
  1074.         "BEWARE: The red monster is now very intelligent.")
  1075.     end if
  1076.     elsif pageType = 2 and not messShown (2) then
  1077.     cls
  1078.     grafix.text (31, 10, 15, "MOVING MAZE")
  1079.     grafix.text (17, 12, 15, "Be careful! Walls disappear and reappear.")
  1080.     maxTime := 400
  1081.     elsif pageType = 3 and not messShown (3) then
  1082.     cls
  1083.     grafix.text (33, 10, 15, "NO WALLS")
  1084.     grafix.text (19, 12, 15, "Dots will be extremely hards to eat.")
  1085.     maxTime := 400
  1086.     elsif pageType = 4 and not messShown (4) then
  1087.     cls
  1088.     grafix.text (30, 10, 15, "INVISIBLE MAZE")
  1089.     grafix.text (22, 12, 15, "Walls appear when you hit them.")
  1090.     maxTime := 400
  1091.     elsif pageType = 5 then
  1092.     cls
  1093.     maxTime := 100
  1094.     ghostTime := 200
  1095.     grafix.text (32, 10, 15, "BONUS PAGE")
  1096.     grafix.text (22, 12, 15, "Clear Board as fast as you can")
  1097.     end if
  1098.  
  1099.     if pageType not=5 then
  1100.     messShown(pageType):=true
  1101.     end if
  1102.  
  1103.     delay (2000)
  1104.  
  1105.     ghostStill := (pageType = 5)
  1106.     if pageType not= 3 then
  1107.     generateMaze
  1108.     end if
  1109.  
  1110.     grafix.start
  1111.  
  1112.     if pageType not= 4 then
  1113.     drawMaze
  1114.     end if
  1115.  
  1116.     var s : string := "SCORE=" + intstr (score) + "      "
  1117.     for i : 1 .. men
  1118.     s := s + chr (7)
  1119.     end for
  1120.  
  1121.     grafix.text (0, 0, 15, s)
  1122.     grafix.text (30, 1, cyan, "Time: " + intstr (maxTime - frame) + "  ")
  1123.  
  1124. end startPage
  1125.  
  1126. proc drawBonusBox
  1127.     drawbox (50, 100, 483, 278, red)
  1128.     drawfill (320, 200, red, red)
  1129.     drawbox (55, 105, 478, 273, black)
  1130.     drawfill (320, 200, black, black)
  1131. end drawBonusBox
  1132.  
  1133. %.. The add procedure goes to the next page
  1134. procedure add
  1135.     var s : string
  1136.     var X : int := 259 - ( (kkk * men) div 2)
  1137.     pageNo += 1
  1138.     if pageType not= 5 then
  1139.     music.sing ("O6 ccddccffeeeeeeccddccggffffff")
  1140.     end if
  1141.     grafix.move (79, 49)
  1142.     if pageType = 5 and frame not= maxTime then
  1143.     drawBonusBox
  1144.     grafix.text (20, 19, 14, "BONUS FOR COMPLETING MAZE:")
  1145.     var TIME : int := maxTime - frame
  1146.     for i : 1 .. TIME
  1147.         grafix.text (30, 20, 15, intstr (i * pageNo * 1000))
  1148.         grafix.text (30, 1, cyan, "Time: " + intstr (TIME - i) + "  ")
  1149.         score += pageNo * 1000
  1150.         s := "SCORE=" + intstr (score) + "      "
  1151.         for j : 1 .. men
  1152.         s := s + chr (7)
  1153.         end for
  1154.         grafix.text (0, 0, 15, s)
  1155.         music.sing ("O6 f")
  1156.     end for
  1157.     delay (2000)
  1158.     elsif pageType not= 5 then
  1159.     drawBonusBox
  1160.     grafix.text (21, 19, 14, "BONUS FOR COMPLETING MAZE:")
  1161.     for i : 1 .. men
  1162.         drawpic (X, 140, graphic (kcleft).bitmap, 1)
  1163.         grafix.text (30, 20, 15, intstr (i * pageNo * 1000))
  1164.         waka
  1165.         %         music.sing ("O6 f")
  1166.         score += pageNo * 1000
  1167.         s := "SCORE=" + intstr (score) + "      "
  1168.         for j : 1 .. men
  1169.         s := s + chr (7)
  1170.         end for
  1171.  
  1172.         grafix.text (0, 0, 15, s)
  1173.         delay (100)
  1174.         X += kkk
  1175.     end for
  1176.     delay (400)
  1177.     end if
  1178.  
  1179.     frame := 0
  1180.     newPage := true
  1181.     startPage
  1182.     drawKC (x, y, yellow, 0, 1)
  1183.  
  1184.     for i : 1 .. 10
  1185.     if not eaten (i) then
  1186.         drawDot (dotx (i), doty (i), white)
  1187.     end if
  1188.     end for
  1189.  
  1190.     if pageType not= 5 then
  1191.     for i : 5 .. 7
  1192.         object (i, 2) := ghost
  1193.         drawGhost (ghostx (i - 4), ghosty (i - 4), i - 4)
  1194.     end for
  1195.     end if
  1196.     s := "HIGH SCORE=" + intstr (hscore)
  1197.     grafix.text (50, 0, yellow + 8, s)
  1198.     grafix.text (31, 34, white, "READY")
  1199.     delay (3000)
  1200.     grafix.text (31, 34, black, "     ")
  1201.     smartTheta := ( (pageNo - 1) div 4)
  1202. end add
  1203.  
  1204. function abs2 (z : int) : int
  1205.     if z > 0 then
  1206.     result z
  1207.     else
  1208.     result 1
  1209.     end if
  1210. end abs2
  1211.  
  1212. %.. routine to see if pill appears/moves or not
  1213. procedure xill
  1214.     if not pillPresent then
  1215.     var r : int
  1216.     randint (r, 1, 50 - pageNo * 2)
  1217.     if r = 1 then
  1218.         pillPresent := true
  1219.         pillTime := 0
  1220.         eatPill
  1221.  
  1222.         randint (pillDir, 3, 4)
  1223.         if pillDir = 3 then
  1224.         pillx := 13
  1225.         else
  1226.         pillx := 1
  1227.         end if
  1228.         randint (pilly, 2, 7)
  1229.         drawDot (pillx, pilly, red)
  1230.     end if
  1231.     else
  1232.     movePill (pillx, pilly, pillDir)
  1233.     end if
  1234.     if dotsEaten = 10 then
  1235.     add
  1236.     end if
  1237. end xill
  1238.  
  1239. procedure playTheme
  1240.     music.sing ("O6 L5ab-agafc ")
  1241.     music.sing ("O6 L5cfagab-a ")
  1242.     music.sing ("O6 L5ab-agafc ")
  1243.     music.sing ("O6 L5cfagab-af")
  1244. end playTheme
  1245.  
  1246. procedure changeWalls
  1247.     var wallColour : int
  1248.     var wallx, wally, wallz : int
  1249.  
  1250.     randint (wallx, 2, 12)
  1251.     randint (wally, 2, 7)
  1252.     randint (wallz, 1, 4)
  1253.  
  1254.     if area (wallx, wally, wallz) then
  1255.     wallColour := black
  1256.     else
  1257.     wallColour := cyan
  1258.     end if
  1259.  
  1260.     area (wallx, wally, wallz) := not area (wallx, wally, wallz)
  1261.  
  1262.     var Wallx := (wallx - 1) * kkk
  1263.     var Wally := (wally - 1) * kkk
  1264.  
  1265.     if wallz = up then
  1266.     grafix.hlin (Wallx, Wallx + kkk - 1, Wally, wallColour)
  1267.     area (wallx, wally - 1, down) := not area (wallx, wally - 1,
  1268.         down)
  1269.     elsif wallz = down then
  1270.     grafix.hlin (Wallx, Wallx + kkk - 1, Wally + kkk, wallColour)
  1271.     area (wallx, wally + 1, up) := not area (wallx, wally + 1, up)
  1272.     elsif wallz = left then
  1273.     grafix.vlin (Wally, Wally + kkk - 1, Wallx, wallColour)
  1274.     area (wallx - 1, wally, right) := not area (wallx - 1, wally,
  1275.         right)
  1276.     elsif wallz = right then
  1277.     grafix.vlin (Wally, Wally + kkk - 1, Wallx + kkk, wallColour)
  1278.     area (wallx + 1, wally, left) := not area (wallx + 1, wally,
  1279.         left)
  1280.     end if
  1281.  
  1282. end changeWalls
  1283.  
  1284.  
  1285.  
  1286. procedure MainProgram (men : int)
  1287.     randomize
  1288.     startPage
  1289.     var s : string := "SCORE=" + intstr (score) + "      "
  1290.     for i : 1 .. men
  1291.     s := s + chr (7)
  1292.     end for
  1293.  
  1294.     grafix.text (0, 0, 15, s)
  1295.  
  1296.  
  1297.     object (x, y) := KC
  1298.     aa := (x - 1) * kkk
  1299.     bb := (y - 1) * kkk
  1300.     drawKC (x, y, yellow, 0, 1)
  1301.  
  1302.     for i : 1 .. 10
  1303.     if not eaten (i) then
  1304.         drawDot (dotx (i), doty (i), white)
  1305.         object(dotx(i),doty(i)):=dot
  1306.     end if
  1307.     end for
  1308.  
  1309.     if pageType not= 5 then
  1310.     for i : 5 .. 7
  1311.         object (i, 2) := ghost
  1312.         drawGhost (ghostx (i - 4), ghosty (i - 4), i - 4)
  1313.     end for
  1314.     end if
  1315.     s := "HIGH SCORE=" + intstr (hscore)
  1316.     grafix.text (50, 0, yellow + 8, s)
  1317.     grafix.text (31, 34, 15, "READY")
  1318.     if men = 3 and score = 0 and pageNo = 1 then
  1319.     playTheme
  1320.     else
  1321.     delay (3000)
  1322.     end if
  1323.     grafix.text (31, 34, black, "     ")
  1324.  
  1325.     var endMan : boolean := false
  1326.     var t0, t1, waittime : int := 0
  1327.     smartTheta := ( (pageNo - 1) div 4)
  1328.     loop
  1329.     clock (t0)
  1330.     %.. Test to see if ghost eating pill is eaten
  1331.     if kcStill then
  1332.         kcTime -= 1
  1333.         if kcTime = 0 then
  1334.         blueGhost
  1335.         kcStill := false
  1336.         end if
  1337.     end if
  1338.  
  1339.     moveKCHalfway
  1340.     drawKCHalfway (dir)
  1341.     moveKC (endMan)
  1342.  
  1343.     exit when endMan
  1344.  
  1345.     if pageType = 2 then
  1346.         changeWalls
  1347.     end if
  1348.  
  1349.     if ghostStill then
  1350.         assert ghostTime > 0
  1351.         ghostTime -= 1
  1352.         if pageType not= 5 then
  1353.         for i : 1 .. 3
  1354.             var gc := i
  1355.             drawGhost (ghostx (i), ghosty (i), black)
  1356.             drawGhost (ghostx (i), ghosty (i), gc)
  1357.         end for
  1358.         end if
  1359.         if ghostTime = 0 then
  1360.         ghostStill := false
  1361.         blueGhost
  1362.         end if
  1363.     else
  1364.  
  1365.         if kcStill then
  1366.         for i : 1 .. 3
  1367.             var gc := i
  1368.             moveSmartGhost (ghostx (i), ghosty (i), gc, endMan,
  1369.             flee)
  1370.             exit when endMan
  1371.         end for
  1372.         else
  1373.         for i : 1 .. smartTheta
  1374.             var gc := i
  1375.             moveSmartGhost (ghostx (i), ghosty (i), gc, endMan,
  1376.             chase)
  1377.         end for
  1378.  
  1379.         if frame > 400 and smartTheta < 3 then
  1380.             smartTheta += 1
  1381.         end if
  1382.         for i : smartTheta + 1 .. 3
  1383.             var gc := i
  1384.             moveGhost (ghostx (i), ghosty (i), gc, endMan)
  1385.             exit when endMan
  1386.         end for
  1387.         end if
  1388.     end if
  1389.     exit when endMan
  1390.  
  1391.     if dotStill then
  1392.         assert dotTime > 0
  1393.         dotTime -= 1
  1394.         for i : 1 .. 10
  1395.         if not eaten (i) then
  1396.             drawDot (dotx (i), doty (i), black)
  1397.             drawDot (dotx (i), doty (i), white)
  1398.         end if
  1399.         end for
  1400.         if dotTime = 0 then
  1401.         dotStill := false
  1402.         end if
  1403.     else
  1404.         for i : 1 .. 10
  1405.         if not eaten (i) then
  1406.             moveDot (dotx (i), doty (i), white)
  1407.         end if
  1408.         end for
  1409.     end if
  1410.  
  1411.     if pageType = 5 and frame >= maxTime then
  1412.         drawBonusBox
  1413.         grafix.text (25, 19, 14, "Sorry ... No Bonus")
  1414.         delay (2000)
  1415.         add
  1416.     end if
  1417.  
  1418.     xill
  1419.     clock (t1)
  1420.     waittime := 330 - t1 + t0
  1421.     delay (waittime)
  1422.     if frame <= maxTime then
  1423.         grafix.text (30, 1, cyan, "Time: " + intstr (maxTime - frame) +
  1424.         "  ")
  1425.     end if
  1426.  
  1427.     end loop
  1428.     var theGhost : int
  1429.     for i : 1 .. 3
  1430.     if ghostx (i) = x and ghosty (i) = y then
  1431.         theGhost := i
  1432.         exit
  1433.     end if
  1434.     end for
  1435.     assert theGhost <= 3
  1436.     drawGhost (ghostx (theGhost), ghosty (theGhost), 0)
  1437.     drawKC (x, y, 1, frame, dir)
  1438.     drawGhost (ghostx (theGhost), ghosty (theGhost), theGhost)
  1439.     for decreasing j : 20 .. 1
  1440.     sound (j * 1000, 100)
  1441.     drawGhost (ghostx (theGhost), ghosty (theGhost), theGhost)
  1442.     end for
  1443.     drawGhost (ghostx (theGhost), ghosty (theGhost), 0)
  1444.     drawGhost (ghostx (theGhost), ghosty (theGhost), theGhost)
  1445. end MainProgram
  1446.  
  1447.  
  1448. loop
  1449.     var c : int := 22
  1450.     var cc : int := 0
  1451.     var w : string (1)
  1452.     grafix.start
  1453.     setscreen ("graphics:v16")
  1454.     var s : string := "SCORE=" + intstr (score)
  1455.     grafix.text (0, 0, 15, s)
  1456.     s := "HIGH SCORE=" + intstr (hscore)
  1457.     grafix.text (60, 0, yellow + 8, s)
  1458.     grafix.text (30, 19, c mod (40), "K.C. Munchkin")
  1459.     grafix.text (26, 21, white, "Press any key to play")
  1460.     grafix.text (28, 22, white, "Press 'c' to end")
  1461.     grafix.text (40 - 16, 26, white, "Copyright 1994: Zolt Inc.")
  1462.     %drawpic (c mod 580, 60, ghostgraphic (1, c mod 6).bitmap, 1)
  1463.     %drawpic ( (c + 100) mod 580, 60, graphic ( (cc mod 2) * 2 +
  1464.     %    1).bitmap, 1)
  1465.     loop
  1466.     if cc mod 2 = 0 and c not= 22 then
  1467.         drawpic ( (c - 20) mod 580, 60, ghostgraphic (1, (c - 20) mod
  1468.         6).bitmap, 1)
  1469.     end if
  1470.     if c not= 22 then
  1471.         drawpic ( (c + 100) mod 580, 60, graphic ( (cc mod 2) * 2 +
  1472.         1).bitmap, 1)
  1473.     end if
  1474.     c += 20
  1475.     cc += 1
  1476.     if cc mod 2 = 1 then
  1477.         drawpic ( (c) mod 580, 60, ghostgraphic (1, (c) mod
  1478.         6).bitmap, 1)
  1479.     end if
  1480.     drawpic ( (c + 100) mod 580, 60, graphic ( (cc mod 2) * 2 +
  1481.         1).bitmap, 1)
  1482.     delay (300)
  1483.     exit when grafix.haskey
  1484.     end loop
  1485.     getLastChar (w)
  1486.     if w = "c" then
  1487.     cls
  1488.     return
  1489.     end if
  1490.     score := 0
  1491.     cls
  1492.     grafix.text (28, 19, white, "Enter Level(1-3):")
  1493.     loop
  1494.     loop
  1495.         exit when hasch
  1496.     end loop
  1497.     getLastChar (w)
  1498.     exit when 49 <= ord (w) and ord (w) <= 51
  1499.     end loop
  1500.     score := strint (w)
  1501.     put w
  1502.     pageNo := (noOfPages)*(score)-(noOfPages-1)
  1503.     score := 0
  1504.  
  1505.     if not Color then
  1506.     %curses.standend
  1507.     end if
  1508.  
  1509.     men := 3
  1510.     loop
  1511.     MainProgram (men)
  1512.     men -= 1
  1513.     newPage := false
  1514.     exit when men = 0
  1515.     end loop
  1516.  
  1517.     grafix.text (30, 20, white, "GAME OVER")
  1518.     if score > hscore then
  1519.     hscore := score
  1520.     open : file, "kc.dat", write
  1521.     write : file, hscore
  1522.     close : file
  1523.     end if
  1524.     delay (5000)
  1525.     getLastChar (w)
  1526.  
  1527.     newGame := true
  1528.     exit when w = "c"
  1529.     %.. score := 0
  1530.     pageNo := 1
  1531.  
  1532. end loop
  1533.