var takenx : array 1 .. 9 of boolean
var takeny : array 1 .. 9 of int
var boxx, boxy : array 1 .. 9 of int
var turn, who_won_game : string := "nobody"
var x, y, b : int := 0
var answer : string
var u, c : array 1 .. 5 of int
%process playstuff
% loop
% Music.PlayFile ("Zelda 2  Majora's Mask  Deku Palace.mp3")
% end loop
%end playstuff
%fork playstuff
procedure Initialize (var c, u : array 1 .. 5 of int)
for initial : 1 .. 5
u (initial) := 999
c (initial) := 999
end for
end Initialize
for i : 1 .. 9
takenx (i) := false
takeny (i) := 0
turn := "player 1"
end for
boxx (1) := 60
boxx (2) := 160
boxx (3) := 260
boxy (1) := 60
boxy (2) := 60
boxy (3) := 60
boxx (4) := 60
boxx (5) := 160
boxx (6) := 260
boxy (4) := 160
boxy (5) := 160
boxy (6) := 160
boxx (7) := 60
boxx (8) := 160
boxx (9) := 260
boxy (7) := 260
boxy (8) := 260
boxy (9) := 260
procedure Draw_Screen
for i : 1 .. 9
Draw.Box (boxx (i)  50, boxy (i)  50, boxx (i) + 50, boxy (i) + 50, 255)
end for
end Draw_Screen
function Get_Users_Move:int
for i : 1 .. 9
if (turn = "player 1") and (x > boxx (i)  50 and x < boxx (i) + 50) and (y > boxy (i)  50 and y < boxy (i) + 50) and (b = 1) then
takenx (i) := true
takeny (i) := 1
turn := "computer"
end if
end for
end Get_Users_Move
procedure Plot_Move
for i : 1 .. 9
if (takenx (i) = true) and (takeny (i) = 1) then
Draw.Line (boxx (i)  50, boxy (i) + 50, boxx (i) + 50, boxy (i)  50, 12)
Draw.Line (boxx (i)  50, boxy (i)  50, boxx (i) + 50, boxy (i) + 50, 12)
elsif (takenx (i) = true) and (takeny (i) = 2) then
Draw.Oval (boxx (i), boxy (i), 45, 45, 2)
end if
end for
end Plot_Move
%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function Block_User :int
if (takenx (2) = true and takenx (3) = true) and (takeny (2) = 1 and takeny (3) = 1) then
Draw.Oval (boxx (1), boxy (1), 45, 45, 2)
elsif (takenx (1) = true and takenx (3) = true) and (takeny (1) = 1 and takeny (3) = 1) then
Draw.Oval (boxx (4), boxy (2), 45, 45, 2)
elsif (takenx (1) = true and takenx (2) = true) and (takeny (1) = 1 and takeny (2) = 1) then
Draw.Oval (boxx (7), boxy (3), 45, 45, 2)
elsif (takenx (5) = true and takenx (6) = true) and (takeny (5) = 1 and takeny (6) = 1) then
Draw.Oval (boxx (2), boxy (4), 45, 45, 2)
elsif (takenx (4) = true and takenx (6) = true) and (takeny (4) = 1 and takeny (6) = 1) then
Draw.Oval (boxx (5), boxy (5), 45, 45, 2)
elsif (takenx (4) = true and takenx (5) = true) and (takeny (4) = 1 and takeny (5) = 1) then
Draw.Oval (boxx (8), boxy (6), 45, 45, 2)
elsif (takenx (8) = true and takenx (9) = true) and (takeny (8) = 1 and takeny (9) = 1) then
Draw.Oval (boxx (3), boxy (7), 45, 45, 2)
elsif (takenx (7) = true and takenx (9) = true) and (takeny (7) = 1 and takeny (9) = 1) then
Draw.Oval (boxx (6), boxy (8), 45, 45, 2)
elsif (takenx (7) = true and takenx (8) = true) and (takeny (7) = 1 and takeny (8) = 1) then
Draw.Oval (boxx (9), boxy (9), 45, 45, 2)
elsif (takenx (5) = true and takenx (9) = true) and (takeny (5) = 1 and takeny (9) = 1) then
Draw.Oval (boxx (1), boxy (1), 45, 45, 2)
elsif (takenx (1) = true and takenx (9) = true) and (takeny (1) = 1 and takeny (9) = 1) then
Draw.Oval (boxx (5), boxy (5), 45, 45, 2)
elsif (takenx (1) = true and takenx (5) = true) and (takeny (1) = 1 and takeny (5) = 1) then
Draw.Oval (boxx (9), boxy (9), 45, 45, 2)
elsif (takenx (5) = true and takenx (3) = true) and (takeny (5) = 1 and takeny (3) = 1) then
Draw.Oval (boxx (3), boxy (7), 45, 45, 2)
elsif (takenx (7) = true and takenx (3) = true) and (takeny (7) = 1 and takeny (3) = 1) then
Draw.Oval (boxx (5), boxy (5), 45, 45, 2)
elsif (takenx (7) = true and takenx (5) = true) and (takeny (7) = 1 and takeny (5) = 1) then
Draw.Oval (boxx (7), boxy (3), 45, 45, 2)
elsif (takenx (4) = true and takenx (7) = true) and (takeny (4) = 1 and takeny (7) = 1) then
Draw.Oval (boxx (1), boxy (1), 45, 45, 2)
elsif (takenx (1) = true and takenx (7) = true) and (takeny (1) = 1 and takeny (7) = 1) then
Draw.Oval (boxx (2), boxy (4), 45, 45, 2)
elsif (takenx (1) = true and takenx (4) = true) and (takeny (1) = 1 and takeny (4) = 1) then
Draw.Oval (boxx (3), boxy (7), 45, 45, 2)
elsif (takenx (5) = true and takenx (8) = true) and (takeny (5) = 1 and takeny (8) = 1) then
Draw.Oval (boxx (2), boxy (4), 45, 45, 2)
elsif (takenx (2) = true and takenx (8) = true) and (takeny (2) = 1 and takeny (8) = 1) then
Draw.Oval (boxx (5), boxy (5), 45, 45, 2)
elsif (takenx (2) = true and takenx (5) = true) and (takeny (2) = 1 and takeny (5) = 1) then
Draw.Oval (boxx (6), boxy (8), 45, 45, 2)
elsif (takenx (6) = true and takenx (9) = true) and (takeny (6) = 1 and takeny (9) = 1) then
Draw.Oval (boxx (7), boxy (3), 45, 45, 2)
elsif (takenx (3) = true and takenx (9) = true) and (takeny (3) = 1 and takeny (9) = 1) then
Draw.Oval (boxx (8), boxy (6), 45, 45, 2)
elsif (takenx (3) = true and takenx (6) = true) and (takeny (3) = 1 and takeny (6) = 1) then
Draw.Oval (boxx (9), boxy (9), 45, 45, 2)
end if
end Block_User
%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function Get_Computers_Move :int
for i : 1 .. 5
if u (i) not= 999 and u (i) = 5 then
Draw.Oval (boxx (i), boxy (i), 45, 45, 2)
turn := "player 1"
end if
end for
end Get_Computers_Move
function User_Won : boolean
if (takenx (1) = true and takenx (2) = true and takenx (3) = true) and (takeny (1) = 1 and takeny (2) = 1 and takeny (3) = 1)
or (takenx (4) = true and takenx (5) = true and takenx (6) = true) and (takeny (4) = 1 and takeny (5) = 1 and takeny (6) = 1)
or (takenx (7) = true and takenx (8) = true and takenx (9) = true) and (takeny (7) = 1 and takeny (8) = 1 and takeny (9) = 1)
or (takenx (1) = true and takenx (5) = true and takenx (9) = true) and (takeny (1) = 1 and takeny (5) = 1 and takeny (9) = 1)
or (takenx (7) = true and takenx (5) = true and takenx (3) = true) and (takeny (7) = 1 and takeny (5) = 1 and takeny (3) = 1)
or (takenx (1) = true and takenx (4) = true and takenx (7) = true) and (takeny (1) = 1 and takeny (4) = 1 and takeny (7) = 1)
or (takenx (2) = true and takenx (5) = true and takenx (8) = true) and (takeny (2) = 1 and takeny (5) = 1 and takeny (8) = 1)
or (takenx (3) = true and takenx (6) = true and takenx (9) = true) and (takeny (3) = 1 and takeny (6) = 1 and takeny (9) = 1) then
who_won_game := "player 1"
end if
end User_Won
function Computer_Won : boolean
if (takenx (1) = true and takenx (2) = true and takenx (3) = true) and (takeny (1) = 2 and takeny (2) = 2 and takeny (3) = 2)
or (takenx (4) = true and takenx (5) = true and takenx (6) = true) and (takeny (4) = 2 and takeny (5) = 2 and takeny (6) = 2)
or (takenx (7) = true and takenx (8) = true and takenx (9) = true) and (takeny (7) = 2 and takeny (8) = 2 and takeny (9) = 2)
or (takenx (1) = true and takenx (5) = true and takenx (9) = true) and (takeny (1) = 2 and takeny (5) = 2 and takeny (9) = 2)
or (takenx (7) = true and takenx (5) = true and takenx (3) = true) and (takeny (7) = 2 and takeny (5) = 2 and takeny (3) = 2)
or (takenx (1) = true and takenx (4) = true and takenx (7) = true) and (takeny (1) = 2 and takeny (4) = 2 and takeny (7) = 2)
or (takenx (2) = true and takenx (5) = true and takenx (8) = true) and (takeny (2) = 2 and takeny (5) = 2 and takeny (8) = 2)
or (takenx (3) = true and takenx (6) = true and takenx (9) = true) and (takeny (3) = 2 and takeny (6) = 2 and takeny (9) = 2) then
who_won_game := "computer"
end if
end Computer_Won
%=====================
%=====================
loop
setscreen ("offscreenonly")
mousewhere (x, y, b)
Draw_Screen
Initialize (c, u)
Plot_Move
exit when who_won_game not= "nobody"
end loop
locate (3, 1)
if who_won_game = "player 1" then
put "You Won!!!"
elsif who_won_game = "computer" then
put "The computer won... Oh well. Try again next time"
end if
