home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-04 | 32.6 KB | 1,533 lines |
- include "%grafix2.int"
- include "%music.int"
-
- setscreen ("graphics:e16")
- setscreen ("noecho")
- const kkk := 41
- const kkkover2 := 20
-
- const noOfPages := 5
-
- const chase := true
- const flee := false
- const TilesNo := 8 * 13
-
- var maxTime : int
-
- %.. This boolean makes sure the display message before each page is shown
- % only once.
- var messShown : array 1 .. noOfPages - 1 of boolean
- for i : 1 .. noOfPages - 1
- messShown (i) := false
- end for
-
- %.. This variable makes sure there is exactly
- var noOfTilesFilled : int
-
- var Color : boolean := true
- var C : string (1)
-
- var smartTheta : int
-
- var pageType : int
- var newGame := true
- var newPage := true
-
- var men : int
-
- var file, file2 : int
- var size : int
- open : file, "kc.gfx", read
- read : file, size
-
- type figure :
- record
- bitmap : array 1 .. 187 of int
- end record
-
- const kcright := 1
- const kcleft := 2
- const kcrightclosed := 3
- const kcleftclosed := 4
-
- var graphic : array 1 .. 4 of figure
- var ghostgraphic : array 1 .. 3, 0 .. 6 of figure
- var ghosteye : array 0 .. 5 of figure
- var warp : array 0 .. 15 of figure
- var blueghost : figure
- var Blank : figure
-
- var ghostEaten : array 1 .. 3 of boolean
- var noOfGhostsEaten : int
- for i : 1 .. 4
- read : file, graphic (i).bitmap
- end for
- read : file, blueghost.bitmap
- read : file, Blank.bitmap
- for i : 1 .. 3
- for j : 0 .. 5
- read : file, ghostgraphic (i, j).bitmap
- end for
- end for
- for j : 0 .. 5
- read : file, ghosteye (j).bitmap
- end for
-
- read : file, size
- var dotgraf : array 1 .. size of int
- read : file, dotgraf
-
- read : file, size
- var pillgraf : array 1 .. size of int
- read : file, pillgraf
- for i : 0 .. 15
- read : file, warp (i).bitmap
- end for
- close : file
-
- %.. This is the wall matrix
- var area : array 1 .. 13, 1 .. 8, 1 .. 4 of boolean
-
- var movex : array 3 .. 4 of int := init ( - 1, 1)
- var movey : array 1 .. 2 of int := init ( - 1, 1)
-
- var pillPresent : boolean
- var pillTime := 0
-
- const up := 1
- const down := 2
- const left := 3
- const right := 4
- const wall := 5
- const dot := 6
- const pill := 7
- const KC := 8
- const ghost := 9
- const zip := 10
-
- var pageNo : int := 1
-
- var x, y, xx, yy, aa, bb : int
-
- var ghostx, ghosty, ghostxx, ghostyy : array 1 .. 3 of int
- var pillx, pilly, pillxx, pillyy, pillDir, warpx, warpy : int
-
- var dotx, doty, dotxx, dotyy : array 1 .. 10 of int
- var eaten : array 1 .. 10 of boolean
- for i : 1 .. 10
- eaten (i) := false
- end for
-
- var object : array 0 .. 14, 0 .. 9 of int
- for i : 0 .. 14
- for j : 0 .. 9
- object (i, j) := 0
- end for
- end for
-
-
- var key : string (1)
-
- var frame : int
-
- var dir : int
-
- var score : int := 0
- var hscore : int := 0
- open : file, "kc.dat", read
- if file not= 0 then
- read : file, hscore
- close : file
- else
- open : file, "kc.dat", write
- hscore := 0
- write : file, hscore
- close : file
- end if
-
-
- var dotsEaten : int := 0
- const maxDots := 10
-
- %.. These are the bonus variables
- var ghostStill, dotStill, kcStill : boolean := false
- var ghostTime, dotTime, kcTime : int
-
- proc eatGhost
- for i : 1 .. 15
- sound (100 * i, 1)
- end for
- end eatGhost
-
- proc blueGhost
- for i : 1 .. 10
- sound (100, 1)
- sound (0, 1)
- end for
- end blueGhost
-
- procedure waka
- for i : 1 .. 3
- sound (100 * i, 1)
- end for
- % music.sing ("o6 f")
- end waka
-
- proc eatPill
- for i : 1 .. 3
- for decreasing j : 3 .. 1
- sound (500 * j, 1)
- end for
- end for
- end eatPill
-
- procedure randsing (l : int)
- var riff := "o6 "
-
- var note : int
- for i : 1 .. l
- randint (note, 97, 103)
- riff := riff + chr (note)
- end for
-
- music.sing (riff)
- end randsing
-
- procedure pause
- var q : int := 0
- for i : 1 .. 10000
- q += 1
- end for
- end pause
-
-
- procedure getLastChar (var s : string (1))
- s := ""
- loop
- exit when not grafix.haskey
- grafix.getkey (s)
- end loop
- end getLastChar
-
- procedure initialize
- pillPresent := false
-
- for i : 1 .. 13
- area (i, 1, up) := true
- area (i, 8, down) := true
-
- for j : 1 .. 8
- if j not= 1 then
- area (i, j, up) := false
- end if
-
- if j not= 8 then
- area (i, j, down) := false
- end if
-
- if i = 1 then
- area (i, j, left) := true
- else
- area (i, j, left) := false
- end if
-
- if i = 13 then
- area (i, j, right) := true
- else
- area (i, j, right) := false
- end if
-
- end for
-
- end for
-
- if newGame or newPage then
- for i : 1 .. 5
- dotx (i) := i
- dotx (i + 5) := i + 8
- doty (i) := 2
- doty (i + 5) := 2
- eaten (i) := false
- eaten (i + 5) := false
- end for
- dotsEaten := 0
- end if
- if newPage and pageNo not= 1 and men < 10 then
- men := men + 1
- newPage := not newPage
- end if
- for i : 1 .. 3
- ghostx (i) := i + 5
- ghosty (i) := 2
- end for
-
- x := 7
- y := 7
-
- for i : 1 .. 13
- for j : 1 .. 8
- object (i, j) := zip
- end for
- end for
-
- for i : 1 .. 13
- object (i, 0) := wall
- object (i, 9) := wall
- end for
-
- for i : 1 .. 8
- object (0, i) := wall
- object (14, i) := wall
- end for
-
- for i : 1 .. 10
- object (dotx (i), doty (i)) := dot
- end for
-
-
-
- key := kleftarrow
- dir := left
-
- if newGame then
- newPage := true
- score := 0
- newGame := false
- end if
-
- if newGame or newPage then
- frame := 0
- end if
-
- end initialize
-
- procedure ValidateMaze (X : int, Y : int)
- object (X, Y) := KC
- noOfTilesFilled += 1
- if Y > 1 and not area (X, Y, up) and object (X, Y - 1) not= KC then
- ValidateMaze (X, Y - 1)
- end if
- if Y < 8 and not area (X, Y, down) and object (X, Y + 1) not= KC then
- ValidateMaze (X, Y + 1)
- end if
- if X > 1 and not area (X, Y, left) and object (X - 1, Y) not= KC then
- ValidateMaze (X - 1, Y)
- end if
- if X < 13 and not area (X, Y, right) and object (X + 1, Y) not= KC then
- ValidateMaze (X + 1, Y)
- end if
- end ValidateMaze
-
-
-
- procedure drawMaze
- cls
- for x : 1 .. 13
- for y : 1 .. 8
-
- var a := (x - 1) * kkk
- var b := (y - 1) * kkk
-
- if area (x, y, up) then
- grafix.hlin (a, a + kkk, b, blue + 8)
- end if
-
- if area (x, y, down) then
- grafix.hlin (a, a + kkk, b + kkk, blue + 8)
- end if
-
- if area (x, y, left) then
- grafix.vlin (b, b + kkk, a, blue + 8)
- end if
-
- if area (x, y, right) then
- grafix.vlin (b, b + kkk, a + kkk, blue + 8)
- end if
-
-
- end for
- end for
- end drawMaze
-
- procedure generateMaze
- loop
- for x : 1 .. 13
- for dummy : 1 .. 4
-
- var y := dummy * 2
-
- var q : int
- randint (q, 1, 4)
- area (x, y, q) := true
-
- if area (x, y, 1) and area (x, y, 2) and area (x, y, 3)
- and area (x, y, 4) then
- area (x, y, q) := false
- else
-
- if q = up and y not= 1 then
- area (x, y - 1, down) := true
- elsif q = down and y not= 8 then
- area (x, y + 1, up) := true
- elsif q = left and x not= 1 then
- area (x - 1, y, right) := true
- elsif q = right and x not= 13 then
- area (x + 1, y, left) := true
- end if
-
- end if
-
-
- end for
- end for
-
- for dummy : 1 .. 4
-
- var y := (dummy * 2) - 1
-
- var x, z : int
-
- randint (x, 3, 11)
- randint (z, 3, 4)
-
- area (x, y, z) := true
-
- if z = left then
- area (x - 1, y, right) := true
- else
- area (x + 1, y, left) := true
- end if
-
- end for
- noOfTilesFilled := 0
- ValidateMaze (4, 6)
- for i : 1 .. 13
- for j : 1 .. 8
- object (i, j) := zip
- end for
- end for
- exit when noOfTilesFilled = TilesNo
- for i : 1 .. 13
- for j : 1 .. 8
- for k : 1 .. 4
- area (i, j, k) := false
- end for
- end for
- end for
- initialize
- end loop
- end generateMaze
-
- procedure drawEye (a, b, c : int)
- var x := (a - 1) * kkk
- var y := (b - 1) * kkk
-
- if c = 0 then
- drawpic (x + 3, y + 3, Blank.bitmap, 0)
- elsif kcStill and ghostEaten (c) then
- drawpic (x + 3, y + 3, ghosteye (frame mod 6).bitmap, 0)
- end if
- end drawEye
-
- procedure drawGhost (a, b, c : int)
- var x := (a - 1) * kkk
- var y := (b - 1) * kkk
-
- if c = 0 then
- drawpic (x + 3, y + 3, Blank.bitmap, 0)
- elsif kcStill then
- drawpic (x + 3, y + 3, blueghost.bitmap, 1)
- else
- drawpic (x + 3, y + 3, ghostgraphic (c, frame mod 6).bitmap, 1)
- end if
- end drawGhost
-
- procedure drawKCHalfway (dir : int)
-
- %drawpic (x + 3, y + 3, Blank.bitmap, 0)
- if frame mod 2 = 0 then
- if dir = left or dir = up then
- drawpic (aa + 2, bb + 2, graphic (kcleft).bitmap, 1)
- else
- drawpic (aa + 2, bb + 2, graphic (kcright).bitmap, 1)
- end if
- else
- if dir = left or dir = up then
- drawpic (aa + 2, bb + 2, graphic (kcleftclosed).bitmap, 1)
- else
- drawpic (aa + 2, bb + 2, graphic (kcrightclosed).bitmap, 1)
- end if
- end if
- end drawKCHalfway
-
- procedure drawKC (a, b, c, frame, dir : int)
- var x := (a - 1) * kkk
- var y := (b - 1) * kkk
- if c = 0 then
- drawpic (x + 3, y + 3, Blank.bitmap, 0)
- elsif frame mod 2 = 0 then
- if dir = left or dir = up then
- drawpic (x + 3, y + 3, graphic (kcleft).bitmap, 0)
- elsif dir = right or dir = down then
- drawpic (x + 3, y + 3, graphic (kcright).bitmap, 0)
- elsif dir = left + 4 or dir = up + 4 then
- drawpic (x + 3, y + 3, graphic (kcleft).bitmap, 1)
- else
- drawpic (x + 3, y + 3, graphic (kcright).bitmap, 1)
- end if
- else
- if dir = left or dir = up then
- drawpic (x + 3, y + 3, graphic (kcleftclosed).bitmap, 0)
- elsif dir = right or dir = down then
- drawpic (x + 3, y + 3, graphic (kcrightclosed).bitmap, 0)
- elsif dir = left + 4 or dir = up + 4 then
- drawpic (x + 3, y + 3, graphic (kcleftclosed).bitmap, 1)
- else
- drawpic (x + 3, y + 3, graphic (kcrightclosed).bitmap, 1)
- end if
- end if
- end drawKC
-
- procedure chooseBonus
- var r : int
- randint (r, 1, 8)
- if r = 1 then
- drawKC (x, y, black, 2, up)
- object (x, y) := zip
- randint (x, 1, 13)
- randint (y, 1, 8)
- drawKC (x, y, yellow, frame, dir)
- elsif r = 2 or r = 6 or r = 7 or r = 8 then
- kcStill := true
- ghostStill := false
- ghostTime := 0
- kcTime := 50
- noOfGhostsEaten := 0
- for i : 1 .. 3
- ghostEaten (i) := false
- end for
- blueGhost
- elsif r = 3 then
- dotStill := true
- dotTime := 50
- elsif r = 4 then
- ghostStill := true
- ghostTime := 50
- kcStill := false
- kcTime := 0
- elsif r = 5 then
- if men < 10 then
- men += 1
- end if
- end if
- end chooseBonus
-
- procedure addscore (x, y : int, var object : int)
- if object = dot then
- object := zip
- score += 10 * pageNo
-
- var found : boolean := false
- for i : 1 .. 10
- if dotx (i) = x and doty (i) = y and not eaten (i) then
- found := true
- eaten (i) := true
- %.. drawDot(dotx(i),doty(i),black)
- waka
- %music.sing ("o6 f")
- drawKC (x, y, yellow, frame, dir)
- end if
- exit when found
- end for
-
-
- if found then
- dotsEaten += 1
- end if
-
- elsif object = pill then
- var points : int
- points := pageNo * 200
- score += points
- var v, w : int
- grafix.text (0, 0, white, "")
- locatexy ( (x - 1) * kkk + (kkk div 2), (y - 1) * kkk + (kkk div
- 2))
- put intstr (points)
-
- eatPill
- locatexy ( (x - 1) * kkk + (kkk div 2), (y - 1) * kkk + (kkk div
- 2))
- put repeat (" ", length (intstr (points)))
- drawKC (x, y, yellow, frame, dir)
-
- pillPresent := false
- if pageType not= 5 then
- chooseBonus
- end if
- elsif object = ghost then
- var points : int
- points := 100 * (2 ** noOfGhostsEaten) * pageNo
- score += points
- var v, w : int
- grafix.text (0, 0, white, "")
- locatexy ( (x - 1) * kkk + (kkk div 2), (y - 1) * kkk + (kkk div
- 2))
- put intstr (points)
-
- eatGhost
- locatexy ( (x - 1) * kkk + (kkk div 2), (y - 1) * kkk + (kkk div
- 2))
- put repeat (" ", length (intstr (points)))
- drawKC (x, y, yellow, frame, dir)
- end if
-
- var s : string := "SCORE=" + intstr (score) + " "
- for i : 1 .. men
- s := s + chr (7)
- end for
-
- grafix.text (0, 0, 15, s)
-
-
- end addscore
-
- procedure moveKCHalfway
- aa := (x - 1) * kkk
- bb := (y - 1) * kkk
-
- if grafix.haskey then
- grafix.move (79, 25)
- getLastChar (key)
- end if
-
- drawKC (x, y, black, frame, dir)
- object (x, y) := zip
- %frame += 1
-
- if key = kdownarrow then
- dir := up
- if not area (x, y, up) then
- bb -= kkkover2
- elsif pageType = 4 then
- grafix.hlin (aa, aa + kkk - 1, bb, blue)
- end if
- elsif key = kuparrow then
- dir := down
- if not area (x, y, down) then
- bb += kkkover2
- elsif pageType = 4 then
- grafix.hlin (aa, aa + kkk - 1, bb + kkk, blue)
- end if
- elsif key = kleftarrow then
- dir := left
- if not area (x, y, left) then
- aa -= kkkover2
- elsif pageType = 4 then
- grafix.vlin (bb, bb + kkk - 1, aa, blue)
- end if
- elsif key = krightarrow then
- dir := right
- if not area (x, y, right) then
- aa += kkkover2
- elsif pageType = 4 then
- grafix.vlin (bb, bb + kkk - 1, aa + kkk, blue)
- end if
- end if
-
- drawKCHalfway (dir)
-
- end moveKCHalfway
-
- procedure moveKC (var endMan : boolean)
- var a := (x - 1) * kkk
- var b := (y - 1) * kkk
- %if grafix.haskey then
- % grafix.move (79, 25)
- % getLastChar (key)
- %end if
-
- drawKC (x, y, black, frame, dir)
- object (x, y) := zip
- frame += 1
-
- if key = kdownarrow then
- dir := up
- if not area (x, y, up) then
- y -= 1
- elsif pageType = 4 then
- grafix.hlin (a, a + kkk - 1, b, blue)
- end if
- elsif key = kuparrow then
- dir := down
- if not area (x, y, down) then
- y += 1
- elsif pageType = 4 then
- grafix.hlin (a, a + kkk - 1, b + kkk, blue)
- end if
- elsif key = kleftarrow then
- dir := left
- if not area (x, y, left) then
- x -= 1
- elsif pageType = 4 then
- grafix.vlin (b, b + kkk - 1, a, blue)
- end if
- elsif key = krightarrow then
- dir := right
- if not area (x, y, right) then
- x += 1
- elsif pageType = 4 then
- grafix.vlin (b, b + kkk - 1, a + kkk, blue)
- end if
- end if
-
- drawKC (x, y, yellow, frame, dir)
-
- if object (x, y) = ghost then
- endMan := true
- elsif object (x, y) not= zip then
- addscore (x, y, object (x, y))
- end if
-
- if endMan then
- endMan := false
- for i : 1 .. 3
- if ghostx (i) = x and ghosty (i) = y then
- if kcStill and not ghostEaten (i) then
- ghostEaten (i) := true
- noOfGhostsEaten += 1
- addscore (x, y, object (x, y))
- elsif not kcStill then
- endMan := true
- end if
- end if
- exit when endMan
- end for
- end if
-
- if not endMan then
- object (x, y) := KC
- end if
-
- if pillPresent and x = pillx and y = pilly then
- pillPresent := false
- %ghostStop:=true
- var zz := pill
- addscore (pillx, pilly, zz)
- end if
- end moveKC
-
- function blank (o : int) : boolean
- if o = zip or o = KC then
- result true
- else
- result false
- end if
- end blank
-
- function surrounded (x, y : int) : boolean
- %.. problem here RIGHT below area(x,y, left)
- if x < 1 or x > 13 or y < 1 or y > 8 then
- grafix.text (0, 0, white, "Problem: " + intstr (x) + "," + intstr
- (y))
- loop
- end loop
- end if
- if (area (x, y, left) or
- not blank (object (x - 1, y)))
- and (area (x, y, right) or
- not blank (object (x + 1, y)))
- and (area (x, y, up) or
- not blank (object (x, y - 1)))
- and (area (x, y, down) or
- not blank (object (x, y + 1))) then
- result true
- else
- result false
- end if
- end surrounded
-
- procedure moveIfCan (var gx, gy, gd : int, var moved : boolean)
- if gd = up and not area (gx, gy, up) and
- (object (gx, gy - 1) = zip or object (gx, gy - 1) = KC) then
- gy -= 1
- moved := true
- elsif gy not= 8 and gd = down and not area (gx, gy, down) and
- (object (gx, gy + 1) = zip or object (gx, gy + 1) = KC)
- then
- gy += 1
- moved := true
- elsif gd = left and not area (gx, gy, left) and (object (gx - 1,
- gy) = zip or
- object (gx - 1, gy) = KC) then
- gx -= 1
- moved := true
- elsif gd = right and not area (gx, gy, right) and (object (gx +
- 1, gy) = zip or
- object (gx + 1, gy) = KC) then
- gx += 1
- moved := true
- else
- moved := false
- end if
- end moveIfCan
-
- procedure moveSmartGhost (var gx, gy, gc : int, var endMan : boolean,
- chasing : boolean)
-
- var gd : int
- object (gx, gy) := zip
- drawGhost (gx, gy, black)
- if not surrounded (gx, gy) then
-
- randint (gd, 1, 2)
-
- %..Start
- var ranNo : int
-
- var toDir : array 1 .. 2 of int
-
- if x < gx then
- if chasing then
- toDir (1) := left
- else
- toDir (1) := right
- end if
- else
- if chasing then
- toDir (1) := right
- else
- toDir (1) := left
- end if
- end if
-
- if y < gy then
- if chasing then
- toDir (2) := up
- else
- toDir (2) := down
- end if
- else
- if chasing then
- toDir (2) := down
- else
- toDir (2) := up
- end if
- end if
-
- var dd : int
- randint (ranNo, 1, 2)
- dd := toDir (ranNo)
-
- var moved := false
-
- %.. optimal dir
- moveIfCan (gx, gy, dd, moved)
-
- if not moved then
- %.. second optimal dir
- moveIfCan (gx, gy, toDir ( (ranNo mod 2) + 1), moved)
-
- if not moved then
- toDir (1) := (toDir (1) mod 2) + 3
- toDir (2) := (toDir (2) mod 2) + 1
- moveIfCan (gx, gy, toDir (ranNo), moved)
- if not moved then
- moveIfCan (gx, gy, toDir ( (ranNo mod 2) + 1), moved)
- end if
- end if
- end if
-
- object (gx, gy) := ghost
- %..End
- end if
-
- if kcStill and ghostEaten (gc) then
- drawEye (gx, gy, gc)
- else
- drawGhost (gx, gy, gc)
- end if
-
- if gx = x and gy = y then
- if kcStill and not ghostEaten (gc) then
- ghostEaten (gc) := true
- noOfGhostsEaten += 1
- addscore (x, y, object (x, y))
- elsif not kcStill then
- endMan := true
- end if
- end if
-
- end moveSmartGhost
-
- procedure moveGhost (var gx, gy, gc : int, var endMan : boolean)
-
- var gd : int
-
- object (gx, gy) := zip
- drawGhost (gx, gy, black)
- if not surrounded (gx, gy) then
-
- randint (gd, 1, 4)
-
- var moved : boolean := false
- for i : 1 .. 4
- moveIfCan (gx, gy, gd, moved)
- exit when moved
- gd := (gd mod 4) + 1
- end for
-
- assert moved
- object (gx, gy) := ghost
-
- end if
-
- if kcStill and ghostEaten (gc) then
- drawEye (gx, gy, gc)
- else
- drawGhost (gx, gy, gc)
- end if
-
- if gx = x and gy = y then
- if kcStill and not ghostEaten (gc) then
- ghostEaten (gc) := true
- noOfGhostsEaten += 1
- addscore (x, y, object (x, y))
- elsif not kcStill then
- endMan := true
- end if
- end if
- end moveGhost
-
-
- %procedure%increase (var dir : int, var dirArray : array 1 .. 2 of int,
- % dirInt : int)
- % dir+=1
- % dirArray (dir) := dirInt
- %end%increase
-
- function opposite (a : int) : int
- if a = 1 then
- result 2
- else
- result 1
- end if
- end opposite
-
- procedure drawDot (x, y, c : int)
- var a := ( (x - 1) * kkk) + (kkk div 2)
- var b := ( (y - 1) * kkk) + (kkk div 2)
-
- if c = 0 then
- drawpic (a - (kkk div 2) + 3, b - (kkk div 2) + 3, Blank.bitmap,
- 0)
- elsif c = white then
- drawpic (a, b, dotgraf, 1)
- else
- drawpic (a - 3, b - 3, pillgraf, 1)
- end if
- %drawoval (a, b, 5, 5, c)
-
- end drawDot
-
- procedure moveDot (var dx, dy : int, dc : int)
- if not surrounded (dx, dy) then
-
- drawDot (dx, dy, 0)
- object (dx, dy) := zip
- var ranNo : int
-
- var awayDir : array 1 .. 2 of int
-
- if x > dx then
- awayDir (1) := left
- else
- awayDir (1) := right
- end if
-
- if y > dy then
- awayDir (2) := up
- else
- awayDir (2) := down
- end if
-
- var dd : int
- randint (ranNo, 1, 2)
- dd := awayDir (ranNo)
-
- var moved := false
-
- %.. optimal dir
- moveIfCan (dx, dy, dd, moved)
-
- if not moved then
- %.. second optimal dir
- moveIfCan (dx, dy, awayDir ( (ranNo mod 2) + 1), moved)
-
- if not moved then
- awayDir (1) := (awayDir (1) mod 2) + 3
- awayDir (2) := (awayDir (2) mod 2) + 1
- moveIfCan (dx, dy, awayDir (ranNo), moved)
- if not moved then
- moveIfCan (dx, dy, awayDir ( (ranNo mod 2) + 1),
- moved)
- end if
- end if
- end if
- drawDot (dx, dy, dc)
-
- if object (dx, dy) not= zip then
- var Dot := dot
- addscore (x, y, Dot)
- else
- object (dx, dy) := dot
- end if
-
- end if
-
- end moveDot
-
- procedure movePill (var s, t, dir : int)
-
- var canMove : boolean := true
- pillTime += 1
- if pillTime = 26 then
- if dir = left then
- dir := right
- else
- dir := left
- end if
- pillTime := 0
- end if
- drawDot (s, t, black)
- if (s = 1 and dir = left) or (s = 13 and dir = right) then
- pillPresent := false
- else
- if not area (s, t, dir) then
- s += movex (dir)
- else
- var randir : int
-
- randint (randir, 1, 2)
- if area (s, t, randir) then
- randir := randir mod 2 + 1
- end if
- if area (s, t, randir) then
- if (s = 1 and dir = right) or (s = 13 and dir = left)
- then
- canMove := false
- else
- randir := dir mod 2 + 3
- end if
- end if
- if area (s, t, randir) then
- canMove := false
- end if
- if canMove then
- if randir = 3 or randir = 4 then
- s += movex (randir)
- else
- t += movey (randir)
- end if
- end if
- end if
-
- if object (s, t) = KC then
- var dum : int := pill
- addscore (s, t, dum)
- else
- drawDot (s, t, red)
- end if
- end if
- end movePill
-
- procedure startPage
- ghostTime := 0
- dotTime := 0
- kcTime := 0
- dotStill := false
- kcStill := false
-
- for i : 0 .. 14
- for j : 0 .. 9
- object (i, j) := 0
- end for
- end for
- initialize
- pageType := ((pageNo - 1) mod noOfPages) + 1
-
-
- if pageType = 1 and not messShown (1) then
- cls
- grafix.text (30, 10, 15, "THE BEGINNING")
- grafix.text (20, 12, 15, "Avoid the monsters, eat the dots.")
- maxTime := 400
- if pageNo > noOfPages * 3 then
- grafix.text (11, 18, 15,
- "BEWARE: All three monsters have the IQ of Einstien.")
- elsif pageNo > noOfPages * 2 then
- grafix.text (5, 18, 15,
- "BEWARE: The red AND the purple monsters have just received Ph.D.'s.")
-
- elsif pageNo > noOfPages then
- grafix.text (13, 18, 15,
- "BEWARE: The red monster is now very intelligent.")
- end if
- elsif pageType = 2 and not messShown (2) then
- cls
- grafix.text (31, 10, 15, "MOVING MAZE")
- grafix.text (17, 12, 15, "Be careful! Walls disappear and reappear.")
- maxTime := 400
- elsif pageType = 3 and not messShown (3) then
- cls
- grafix.text (33, 10, 15, "NO WALLS")
- grafix.text (19, 12, 15, "Dots will be extremely hards to eat.")
- maxTime := 400
- elsif pageType = 4 and not messShown (4) then
- cls
- grafix.text (30, 10, 15, "INVISIBLE MAZE")
- grafix.text (22, 12, 15, "Walls appear when you hit them.")
- maxTime := 400
- elsif pageType = 5 then
- cls
- maxTime := 100
- ghostTime := 200
- grafix.text (32, 10, 15, "BONUS PAGE")
- grafix.text (22, 12, 15, "Clear Board as fast as you can")
- end if
-
- if pageType not=5 then
- messShown(pageType):=true
- end if
-
- delay (2000)
-
- ghostStill := (pageType = 5)
- if pageType not= 3 then
- generateMaze
- end if
-
- grafix.start
-
- if pageType not= 4 then
- drawMaze
- end if
-
- var s : string := "SCORE=" + intstr (score) + " "
- for i : 1 .. men
- s := s + chr (7)
- end for
-
- grafix.text (0, 0, 15, s)
- grafix.text (30, 1, cyan, "Time: " + intstr (maxTime - frame) + " ")
-
- end startPage
-
- proc drawBonusBox
- drawbox (50, 100, 483, 278, red)
- drawfill (320, 200, red, red)
- drawbox (55, 105, 478, 273, black)
- drawfill (320, 200, black, black)
- end drawBonusBox
-
- %.. The add procedure goes to the next page
- procedure add
- var s : string
- var X : int := 259 - ( (kkk * men) div 2)
- pageNo += 1
- if pageType not= 5 then
- music.sing ("O6 ccddccffeeeeeeccddccggffffff")
- end if
- grafix.move (79, 49)
- if pageType = 5 and frame not= maxTime then
- drawBonusBox
- grafix.text (20, 19, 14, "BONUS FOR COMPLETING MAZE:")
- var TIME : int := maxTime - frame
- for i : 1 .. TIME
- grafix.text (30, 20, 15, intstr (i * pageNo * 1000))
- grafix.text (30, 1, cyan, "Time: " + intstr (TIME - i) + " ")
- score += pageNo * 1000
- s := "SCORE=" + intstr (score) + " "
- for j : 1 .. men
- s := s + chr (7)
- end for
- grafix.text (0, 0, 15, s)
- music.sing ("O6 f")
- end for
- delay (2000)
- elsif pageType not= 5 then
- drawBonusBox
- grafix.text (21, 19, 14, "BONUS FOR COMPLETING MAZE:")
- for i : 1 .. men
- drawpic (X, 140, graphic (kcleft).bitmap, 1)
- grafix.text (30, 20, 15, intstr (i * pageNo * 1000))
- waka
- % music.sing ("O6 f")
- score += pageNo * 1000
- s := "SCORE=" + intstr (score) + " "
- for j : 1 .. men
- s := s + chr (7)
- end for
-
- grafix.text (0, 0, 15, s)
- delay (100)
- X += kkk
- end for
- delay (400)
- end if
-
- frame := 0
- newPage := true
- startPage
- drawKC (x, y, yellow, 0, 1)
-
- for i : 1 .. 10
- if not eaten (i) then
- drawDot (dotx (i), doty (i), white)
- end if
- end for
-
- if pageType not= 5 then
- for i : 5 .. 7
- object (i, 2) := ghost
- drawGhost (ghostx (i - 4), ghosty (i - 4), i - 4)
- end for
- end if
- s := "HIGH SCORE=" + intstr (hscore)
- grafix.text (50, 0, yellow + 8, s)
- grafix.text (31, 34, white, "READY")
- delay (3000)
- grafix.text (31, 34, black, " ")
- smartTheta := ( (pageNo - 1) div 4)
- end add
-
- function abs2 (z : int) : int
- if z > 0 then
- result z
- else
- result 1
- end if
- end abs2
-
- %.. routine to see if pill appears/moves or not
- procedure xill
- if not pillPresent then
- var r : int
- randint (r, 1, 50 - pageNo * 2)
- if r = 1 then
- pillPresent := true
- pillTime := 0
- eatPill
-
- randint (pillDir, 3, 4)
- if pillDir = 3 then
- pillx := 13
- else
- pillx := 1
- end if
- randint (pilly, 2, 7)
- drawDot (pillx, pilly, red)
- end if
- else
- movePill (pillx, pilly, pillDir)
- end if
- if dotsEaten = 10 then
- add
- end if
- end xill
-
- procedure playTheme
- music.sing ("O6 L5ab-agafc ")
- music.sing ("O6 L5cfagab-a ")
- music.sing ("O6 L5ab-agafc ")
- music.sing ("O6 L5cfagab-af")
- end playTheme
-
- procedure changeWalls
- var wallColour : int
- var wallx, wally, wallz : int
-
- randint (wallx, 2, 12)
- randint (wally, 2, 7)
- randint (wallz, 1, 4)
-
- if area (wallx, wally, wallz) then
- wallColour := black
- else
- wallColour := cyan
- end if
-
- area (wallx, wally, wallz) := not area (wallx, wally, wallz)
-
- var Wallx := (wallx - 1) * kkk
- var Wally := (wally - 1) * kkk
-
- if wallz = up then
- grafix.hlin (Wallx, Wallx + kkk - 1, Wally, wallColour)
- area (wallx, wally - 1, down) := not area (wallx, wally - 1,
- down)
- elsif wallz = down then
- grafix.hlin (Wallx, Wallx + kkk - 1, Wally + kkk, wallColour)
- area (wallx, wally + 1, up) := not area (wallx, wally + 1, up)
- elsif wallz = left then
- grafix.vlin (Wally, Wally + kkk - 1, Wallx, wallColour)
- area (wallx - 1, wally, right) := not area (wallx - 1, wally,
- right)
- elsif wallz = right then
- grafix.vlin (Wally, Wally + kkk - 1, Wallx + kkk, wallColour)
- area (wallx + 1, wally, left) := not area (wallx + 1, wally,
- left)
- end if
-
- end changeWalls
-
-
-
- procedure MainProgram (men : int)
- randomize
- startPage
- var s : string := "SCORE=" + intstr (score) + " "
- for i : 1 .. men
- s := s + chr (7)
- end for
-
- grafix.text (0, 0, 15, s)
-
-
- object (x, y) := KC
- aa := (x - 1) * kkk
- bb := (y - 1) * kkk
- drawKC (x, y, yellow, 0, 1)
-
- for i : 1 .. 10
- if not eaten (i) then
- drawDot (dotx (i), doty (i), white)
- object(dotx(i),doty(i)):=dot
- end if
- end for
-
- if pageType not= 5 then
- for i : 5 .. 7
- object (i, 2) := ghost
- drawGhost (ghostx (i - 4), ghosty (i - 4), i - 4)
- end for
- end if
- s := "HIGH SCORE=" + intstr (hscore)
- grafix.text (50, 0, yellow + 8, s)
- grafix.text (31, 34, 15, "READY")
- if men = 3 and score = 0 and pageNo = 1 then
- playTheme
- else
- delay (3000)
- end if
- grafix.text (31, 34, black, " ")
-
- var endMan : boolean := false
- var t0, t1, waittime : int := 0
- smartTheta := ( (pageNo - 1) div 4)
- loop
- clock (t0)
- %.. Test to see if ghost eating pill is eaten
- if kcStill then
- kcTime -= 1
- if kcTime = 0 then
- blueGhost
- kcStill := false
- end if
- end if
-
- moveKCHalfway
- drawKCHalfway (dir)
- moveKC (endMan)
-
- exit when endMan
-
- if pageType = 2 then
- changeWalls
- end if
-
- if ghostStill then
- assert ghostTime > 0
- ghostTime -= 1
- if pageType not= 5 then
- for i : 1 .. 3
- var gc := i
- drawGhost (ghostx (i), ghosty (i), black)
- drawGhost (ghostx (i), ghosty (i), gc)
- end for
- end if
- if ghostTime = 0 then
- ghostStill := false
- blueGhost
- end if
- else
-
- if kcStill then
- for i : 1 .. 3
- var gc := i
- moveSmartGhost (ghostx (i), ghosty (i), gc, endMan,
- flee)
- exit when endMan
- end for
- else
- for i : 1 .. smartTheta
- var gc := i
- moveSmartGhost (ghostx (i), ghosty (i), gc, endMan,
- chase)
- end for
-
- if frame > 400 and smartTheta < 3 then
- smartTheta += 1
- end if
- for i : smartTheta + 1 .. 3
- var gc := i
- moveGhost (ghostx (i), ghosty (i), gc, endMan)
- exit when endMan
- end for
- end if
- end if
- exit when endMan
-
- if dotStill then
- assert dotTime > 0
- dotTime -= 1
- for i : 1 .. 10
- if not eaten (i) then
- drawDot (dotx (i), doty (i), black)
- drawDot (dotx (i), doty (i), white)
- end if
- end for
- if dotTime = 0 then
- dotStill := false
- end if
- else
- for i : 1 .. 10
- if not eaten (i) then
- moveDot (dotx (i), doty (i), white)
- end if
- end for
- end if
-
- if pageType = 5 and frame >= maxTime then
- drawBonusBox
- grafix.text (25, 19, 14, "Sorry ... No Bonus")
- delay (2000)
- add
- end if
-
- xill
- clock (t1)
- waittime := 330 - t1 + t0
- delay (waittime)
- if frame <= maxTime then
- grafix.text (30, 1, cyan, "Time: " + intstr (maxTime - frame) +
- " ")
- end if
-
- end loop
- var theGhost : int
- for i : 1 .. 3
- if ghostx (i) = x and ghosty (i) = y then
- theGhost := i
- exit
- end if
- end for
- assert theGhost <= 3
- drawGhost (ghostx (theGhost), ghosty (theGhost), 0)
- drawKC (x, y, 1, frame, dir)
- drawGhost (ghostx (theGhost), ghosty (theGhost), theGhost)
- for decreasing j : 20 .. 1
- sound (j * 1000, 100)
- drawGhost (ghostx (theGhost), ghosty (theGhost), theGhost)
- end for
- drawGhost (ghostx (theGhost), ghosty (theGhost), 0)
- drawGhost (ghostx (theGhost), ghosty (theGhost), theGhost)
- end MainProgram
-
-
- loop
- var c : int := 22
- var cc : int := 0
- var w : string (1)
- grafix.start
- setscreen ("graphics:v16")
- var s : string := "SCORE=" + intstr (score)
- grafix.text (0, 0, 15, s)
- s := "HIGH SCORE=" + intstr (hscore)
- grafix.text (60, 0, yellow + 8, s)
- grafix.text (30, 19, c mod (40), "K.C. Munchkin")
- grafix.text (26, 21, white, "Press any key to play")
- grafix.text (28, 22, white, "Press 'c' to end")
- grafix.text (40 - 16, 26, white, "Copyright 1994: Zolt Inc.")
- %drawpic (c mod 580, 60, ghostgraphic (1, c mod 6).bitmap, 1)
- %drawpic ( (c + 100) mod 580, 60, graphic ( (cc mod 2) * 2 +
- % 1).bitmap, 1)
- loop
- if cc mod 2 = 0 and c not= 22 then
- drawpic ( (c - 20) mod 580, 60, ghostgraphic (1, (c - 20) mod
- 6).bitmap, 1)
- end if
- if c not= 22 then
- drawpic ( (c + 100) mod 580, 60, graphic ( (cc mod 2) * 2 +
- 1).bitmap, 1)
- end if
- c += 20
- cc += 1
- if cc mod 2 = 1 then
- drawpic ( (c) mod 580, 60, ghostgraphic (1, (c) mod
- 6).bitmap, 1)
- end if
- drawpic ( (c + 100) mod 580, 60, graphic ( (cc mod 2) * 2 +
- 1).bitmap, 1)
- delay (300)
- exit when grafix.haskey
- end loop
- getLastChar (w)
- if w = "c" then
- cls
- return
- end if
- score := 0
- cls
- grafix.text (28, 19, white, "Enter Level(1-3):")
- loop
- loop
- exit when hasch
- end loop
- getLastChar (w)
- exit when 49 <= ord (w) and ord (w) <= 51
- end loop
- score := strint (w)
- put w
- pageNo := (noOfPages)*(score)-(noOfPages-1)
- score := 0
-
- if not Color then
- %curses.standend
- end if
-
- men := 3
- loop
- MainProgram (men)
- men -= 1
- newPage := false
- exit when men = 0
- end loop
-
- grafix.text (30, 20, white, "GAME OVER")
- if score > hscore then
- hscore := score
- open : file, "kc.dat", write
- write : file, hscore
- close : file
- end if
- delay (5000)
- getLastChar (w)
-
- newGame := true
- exit when w = "c"
- %.. score := 0
- pageNo := 1
-
- end loop
-