| 
View.Set ("nocursor,graphics:700,600")
 Mouse.ButtonChoose ("multibutton")
 
 var x, y, button, left, middle, right : int
 var xColour := brightred
 var oColour := brightblue
 var backColour := white
 var gridColour := black
 var X, O : array 1 .. 9 of boolean
 for i : 1 .. 9
 X (i) := false
 O (i) := false
 end for
 
 process BackgroundMusic
 loop
 for i : 1 .. 1000
 var x : int := Rand.Int (0, 400)
 Music.Sound (i * x, 40)
 end for
 end loop
 end BackgroundMusic
 
 %fork BackgroundMusic
 
 process XSound
 Music.Sound (5, 1)
 end XSound
 
 process OSound
 Music.Sound (54, 12)
 end OSound
 
 process BlankSound
 Music.Sound (1, 19)
 end BlankSound
 
 % GRID
 procedure Grid
 drawbox (0, 0, maxx - 100, maxy, gridColour)
 Draw.ThickLine (0, 200, maxx - 100, 200, 2, gridColour)
 Draw.ThickLine (0, 400, maxx - 100, 400, 2, gridColour)
 Draw.ThickLine (200, 0, 200, maxy, 2, gridColour)
 Draw.ThickLine (400, 0, 400, maxy, 2, gridColour)
 end Grid
 
 drawfillbox (0, 0, maxx, maxy, backColour)
 
 loop
 Grid
 Mouse.Where (x, y, button)
 left := button mod 10
 middle := (button - left) mod 100
 right := button - middle - left
 
 % BOX 1
 if (x < 200) and (x > 0) and (y > 400) and (y < 600) and (left = 1) then
 drawfillbox (0, 600, 200, 400, backColour)
 Draw.ThickLine (0, 400, 200, maxy, 3, xColour)
 Draw.ThickLine (200, 400, 0, maxy, 3, xColour)
 X (1) := true
 O (1) := false
 fork XSound
 elsif (x < 200) and (x > 0) and (y > 400) and (y < 600) and (right = 100) then
 drawfillbox (0, 600, 200, 400, backColour)
 drawoval (100, 500, 100, 100, oColour)
 O (1) := true
 X (1) := false
 fork OSound
 elsif (x < 200) and (x > 0) and (y > 400) and (y < 600) and (middle = 10) then
 drawfillbox (0, 600, 200, 400, backColour)
 X (1) := false
 O (1) := false
 fork BlankSound
 end if
 
 % BOX 2
 if (x > 200) and (x < 400) and (y > 400) and (y < 600) and (left = 1) then
 drawfillbox (200, 600, 400, 400, backColour)
 Draw.ThickLine (200, 400, 400, maxy, 3, xColour)
 Draw.ThickLine (400, 400, 200, maxy, 3, xColour)
 X (2) := true
 O (2) := false
 fork XSound
 elsif (x > 200) and (x < 400) and (y > 400) and (y < 600) and (right = 100) then
 drawfillbox (200, 600, 400, 400, backColour)
 drawoval (300, 500, 100, 100, oColour)
 O (2) := true
 X (2) := false
 fork OSound
 elsif (x > 200) and (x < 400) and (y > 400) and (y < 600) and (middle = 10) then
 drawfillbox (200, 600, 400, 400, backColour)
 X (2) := false
 O (2) := false
 fork BlankSound
 end if
 
 % BOX 3
 if (x > 400) and (x < 600) and (y > 400) and (y < 600) and (left = 1) then
 drawfillbox (400, 600, 600, 400, backColour)
 Draw.ThickLine (400, 400, 600, maxy, 3, xColour)
 Draw.ThickLine (600, 400, 400, maxy, 3, xColour)
 X (3) := true
 O (3) := false
 fork XSound
 elsif (x > 400) and (x < 600) and (y > 400) and (y < 600) and (right = 100) then
 drawfillbox (400, 600, 600, 400, backColour)
 drawoval (500, 500, 100, 100, oColour)
 O (3) := true
 X (3) := false
 fork OSound
 Music.SoundOff
 elsif (x > 400) and (x < 600) and (y > 400) and (y < 600) and (middle = 10) then
 drawfillbox (400, 600, 600, 400, backColour)
 X (3) := false
 O (3) := false
 fork BlankSound
 end if
 
 % BOX 4
 if (x < 200) and (x > 0) and (y < 400) and (y > 200) and (left = 1) then
 drawfillbox (0, 200, 200, 400, backColour)
 Draw.ThickLine (0, 200, 200, 400, 3, xColour)
 Draw.ThickLine (0, 400, 200, 200, 3, xColour)
 X (4) := true
 O (4) := false
 fork XSound
 elsif (x < 200) and (x > 0) and (y < 400) and (y > 200) and (right = 100) then
 drawfillbox (0, 200, 200, 400, backColour)
 drawoval (100, 300, 100, 100, oColour)
 O (4) := true
 X (4) := false
 fork OSound
 elsif (x < 200) and (x > 0) and (y < 400) and (y > 200) and (middle = 10) then
 drawfillbox (0, 200, 200, 400, backColour)
 X (4) := false
 O (4) := false
 fork BlankSound
 end if
 
 % BOX 5
 if (x > 200) and (x < 400) and (y > 200) and (y < 400) and (left = 1) then
 drawfillbox (200, 200, 400, 400, backColour)
 Draw.ThickLine (200, 200, 400, 400, 3, xColour)
 Draw.ThickLine (400, 200, 200, 400, 3, xColour)
 X (5) := true
 O (5) := false
 fork XSound
 elsif (x > 200) and (x < 400) and (y > 200) and (y < 400) and (right = 100) then
 drawfillbox (200, 200, 400, 400, backColour)
 drawoval (300, 300, 100, 100, oColour)
 O (5) := true
 X (5) := false
 fork OSound
 elsif (x > 200) and (x < 400) and (y > 200) and (y < 400) and (middle = 10) then
 drawfillbox (200, 200, 400, 400, backColour)
 X (5) := false
 O (5) := false
 fork BlankSound
 end if
 
 % BOX 6
 if (x > 400) and (x < 600) and (y > 200) and (y < 400) and (left = 1) then
 drawfillbox (600, 200, 400, 400, backColour)
 Draw.ThickLine (400, 200, 600, 400, 3, xColour)
 Draw.ThickLine (600, 200, 400, 400, 3, xColour)
 X (6) := true
 O (6) := false
 fork XSound
 elsif (x > 400) and (x < 600) and (y > 200) and (y < 400) and (right = 100) then
 drawfillbox (600, 200, 400, 400, backColour)
 drawoval (500, 300, 100, 100, oColour)
 O (6) := true
 X (6) := false
 fork OSound
 elsif (x > 400) and (x < 600) and (y > 200) and (y < 400) and (middle = 10) then
 drawfillbox (600, 200, 400, 400, backColour)
 X (6) := false
 O (6) := false
 fork BlankSound
 end if
 
 % BOX 7
 if (x > 0) and (x < 200) and (y > 0) and (y < 200) and (left = 1) then
 drawfillbox (0, 0, 200, 200, backColour)
 Draw.ThickLine (0, 0, 200, 200, 3, xColour)
 Draw.ThickLine (0, 200, 200, 0, 3, xColour)
 X (7) := true
 O (7) := false
 fork XSound
 elsif (x > 0) and (x < 200) and (y > 0) and (y < 200) and (right = 100) then
 drawfillbox (0, 0, 200, 200, backColour)
 drawoval (100, 100, 100, 100, oColour)
 O (7) := true
 X (7) := false
 fork OSound
 elsif (x > 0) and (x < 200) and (y > 0) and (y < 200) and (middle = 10) then
 drawfillbox (0, 0, 200, 200, backColour)
 X (7) := false
 O (7) := false
 fork BlankSound
 end if
 
 % BOX 8
 if (x > 200) and (x < 400) and (y > 0) and (y < 200) and (left = 1) then
 drawfillbox (200, 0, 400, 200, backColour)
 Draw.ThickLine (200, 0, 400, 200, 3, xColour)
 Draw.ThickLine (200, 200, 400, 0, 3, xColour)
 X (8) := true
 O (8) := false
 fork XSound
 elsif (x > 200) and (x < 400) and (y > 0) and (y < 200) and (right = 100) then
 drawfillbox (200, 0, 400, 200, backColour)
 drawoval (300, 100, 100, 100, oColour)
 O (8) := true
 X (8) := false
 fork OSound
 elsif (x > 200) and (x < 400) and (y > 0) and (y < 200) and (middle = 10) then
 drawfillbox (200, 0, 400, 200, backColour)
 X (8) := false
 O (8) := false
 fork BlankSound
 end if
 
 % BOX 9
 if (x > 400) and (x < 600) and (y > 0) and (y < 200) and (left = 1) then
 drawfillbox (600, 0, 400, 200, backColour)
 Draw.ThickLine (400, 0, 600, 200, 3, xColour)
 Draw.ThickLine (600, 0, 400, 200, 3, xColour)
 X (9) := true
 O (9) := false
 fork XSound
 elsif (x > 400) and (x < 600) and (y > 0) and (y < 200) and (y < 400) and (right = 100) then
 drawfillbox (600, 0, 400, 200, backColour)
 drawoval (500, 100, 100, 100, oColour)
 O (9) := true
 X (9) := false
 fork OSound
 elsif (x > 400) and (x < 600) and (y > 0) and (y < 200) and (y < 400) and (middle = 10) then
 drawfillbox (600, 0, 400, 200, backColour)
 X (9) := false
 O (9) := false
 fork BlankSound
 end if
 
 % SCORES
 var xScore, oScore : int := 0
 
 % X's
 if (X (1) = true) and (X (2) = true) and (X (3) = true) then
 xScore += 1
 end if
 if (X (4) = true) and (X (5) = true) and (X (6) = true) then
 xScore += 1
 end if
 if (X (7) = true) and (X (8) = true) and (X (9) = true) then
 xScore += 1
 end if
 if (X (1) = true) and (X (4) = true) and (X (7) = true) then
 xScore += 1
 end if
 if (X (2) = true) and (X (5) = true) and (X (8) = true) then
 xScore += 1
 end if
 if (X (3) = true) and (X (6) = true) and (X (9) = true) then
 xScore += 1
 end if
 if (X (1) = true) and (X (5) = true) and (X (9) = true) then
 xScore += 1
 end if
 if (X (3) = true) and (X (5) = true) and (X (7) = true) then
 xScore += 1
 end if
 
 % O's
 if (O (1) = true) and (O (2) = true) and (O (3) = true) then
 oScore += 1
 end if
 if (O (4) = true) and (O (5) = true) and (O (6) = true) then
 oScore += 1
 end if
 if (O (7) = true) and (O (8) = true) and (O (9) = true) then
 oScore += 1
 end if
 if (O (1) = true) and (O (4) = true) and (O (7) = true) then
 oScore += 1
 end if
 if (O (2) = true) and (O (5) = true) and (O (8) = true) then
 oScore += 1
 end if
 if (O (3) = true) and (O (6) = true) and (O (9) = true) then
 oScore += 1
 end if
 if (O (1) = true) and (O (5) = true) and (O (9) = true) then
 oScore += 1
 end if
 if (O (3) = true) and (O (5) = true) and (O (7) = true) then
 oScore += 1
 end if
 
 % PLACES SCORES
 locate (1, 80)
 colour (xColour)
 colourback (backColour)
 put "X:  ", xScore
 colour (oColour)
 locate (2, 80)
 put "O:  ", oScore
 
 var getKey : array char of boolean
 var clr : int
 Input.KeyDown (getKey)
 % CLEARS SCORE
 if getKey ('c') then
 for n : 1 .. 9
 X (n) := false
 O (n) := false
 end for
 xScore := 0
 oScore := 0
 cls
 % CHANGING X/O COLOUR
 elsif getKey ('x') and getKey (KEY_UP_ARROW) then
 xColour += 1
 elsif getKey ('x') and getKey (KEY_DOWN_ARROW) then
 xColour -= 1
 elsif getKey ('o') and getKey (KEY_UP_ARROW) then
 oColour += 1
 elsif getKey ('o') and getKey (KEY_DOWN_ARROW) then
 oColour -= 1
 end if
 if (gridColour = backColour) then
 backColour := gridColour + 1
 end if
 if (xColour = 256) then
 xColour := 1
 elsif (xColour = 0) then
 xColour := 255
 elsif (oColour = 256) then
 oColour := 1
 elsif (oColour = 0) then
 oColour := 255
 % GET NEW COLOUR
 elsif getKey ('x') and getKey ('g') then
 colour (black)
 locate (15, 80)
 get clr
 if (clr > 255) then
 clr := 255
 elsif (clr < 0) then
 clr := 0
 end if
 xColour := clr
 cls
 elsif getKey ('o') and getKey ('g') then
 colour (black)
 locate (15, 80)
 get clr
 if (clr > 255) then
 clr := 255
 elsif (clr < 0) then
 clr := 0
 end if
 oColour := clr
 cls
 end if
 Music.SoundOff
 end loop
 
 
 
 |