home *** CD-ROM | disk | FTP | other *** search
- program Tic_Tac_Toe_2_Players(Input,Output);
- uses Dos,CRT,Graph,Doms;
-
- var
- Won,Mouse,OneTwo : Boolean;
- Board : Array[1..9]of string[1];
- Put : Integer;
- Regs : Registers;
-
- procedure Exit;
- begin
- CloseGraph;
- RestoreCRTMode;
- ClrScr;
- Halt;
- end;
-
- procedure NumberBoard;
- begin
- SetTextStyle(DefaultFont,HorizDir,1);
- SetColor(63);
- OutTextXY(65,15,'1');
- OutTextXY(131,15,'2');
- OutTextXY(211,15,'3');
- OutTextXY(65,61,'4');
- OutTextXY(131,61,'5');
- OutTextXY(211,61,'6');
- OutTextXY(65,101,'7');
- OutTextXY(131,101,'8');
- OutTextXY(211,101,'9');
- end;
-
- procedure LoadBoard(Page : Integer);
- begin
- SetActivePage(Page);
- SetColor(62);
- Line(65,60,275,60);{First Cross Bar}
- Line(65,100,275,100);{Second Cross Bar}
- Line(130,15,130,145);{First Down Bar}
- Line(210,15,210,145);{Second Down Bar}
- SetVisualPage(Page);
- end;
-
- procedure ClearBoard;
- var
- i : integer;
- begin
- for i := 1 to 9 do
- board[i] := '';
- end;
-
- procedure Start; forward;
- procedure Start2; forward;
-
- procedure Title;{Creates Title Screen}
- var
- ch : char;
- cool1,cool2 : boolean;
- begin
- SetActivePage(0);
- SetFillStyle(1,2);
- FloodFill(1,1,4);
- SetTextStyle(DefaultFont,HorizDir,5);
- SetColor(56);
- OutTextXY(70,20,'T I C');
- SetColor(7);
- OutTextXY(150,61,'T A C');
- SetColor(63);
- OutTextXY(230,101,'T O E');
- SetColor(62);
- Line(67,18,261,130);
- LoadBoard(0);
- SetVisualPage(0);
- SetActivePage(1);
- SetColor(63);{Start Box}
- Line(340,20,500,20);
- Line(500,20,500,44);
- Line(500,44,340,44);
- Line(340,44,340,20);
- SetFillStyle(1,0);
- FloodFill(341,21,63);
- SetTextStyle(DefaultFont,HorizDir,1);
- SetColor(63);
- OutTextXY(342,22,'[1]Player');
- OutTextXY(426,22,'[2]Player');
- OutTextXY(396,32,'[Q]uit');
- delay(500);
- FadeIn(340,20,500,44,1,0);
- if Mouse then
- begin
- Regs.AX := 1;
- Intr($33,Regs);
- end;
- cool1 := false;
- cool2 := False;
- repeat
- Regs.AX := 0;
- Intr($33,Regs);
- Regs.AX := 1;
- Intr($33,Regs);
- repeat
- setvisualPage(0);
- if Mouse then
- begin
- Regs.AX := 3;
- Intr($33,Regs);
- if keypressed then
- begin
- ch := readkey;
- if (ch = '1')or(ch = '2')or(ch = 'Q')or(ch = 'q') then
- begin
- if (ch = '1') then begin Start; cool2 := true; end;
- if (ch = '2') then begin Start2; cool2 := true; end;
- if (ch = 'Q')or(ch = 'q') then begin Exit; cool2 := true; end;begin Start; cool2 := true; end;
- end;
- end;
- if (Mouse) and (Regs.BX = 1) then
- begin
- if (regs.cx > 341)and(Regs.cx < 367)and(regs.DX > 21)and(regs.DX < 32) then
- begin Start; cool2 := true; end;
- if (regs.cx > 425)and(regs.cx < 452)and(regs.dx > 21)and(regs.dx < 32) then
- begin Start2; cool2 := true; end;
- if (regs.cx > 395)and(regs.cx < 422)and(regs.dx > 31)and(regs.dx < 42) then
- begin Exit; cool2 := true; end;
- end;
- end
- else
- begin
- ch := readkey;
- if (ch = 'B')or(ch = 'b')or(ch = 'Q')or(ch = 'q') then
- begin
- if (ch = 'B')or(ch = 'b') then begin Start; cool2 := true; end;
- if (ch = 'Q')or(ch = 'q') then begin Exit; cool2 := true; end;
- end
- else
- begin
- sound(200);
- delay(200);
- nosound;
- end;
- end;
- until cool2;
- cool2 := false;
- until cool1;
- end;
-
- procedure Check(Team : Char);
- var
- i,n : integer;
- Temp : Array[1..3,1..3]of string[1];
-
- begin
- for i := 1 to 3 do
- for n := 1 to 3 do
- Temp[i,n] := '';
- For i := 1 to 3 do
- Temp[1,i] := Board[i];
- for i := 4 to 6 do
- Temp[2,i-3] := Board[i];
- for i := 7 to 9 do
- Temp[3,i-6] := Board[i];
- won := false;
- for i := 1 to 3 do
- begin
- for n := 1 to 3 do
- begin
- if (Temp[i,n] = Team)and(not(won)) then
- begin
- if (i = 1)and(n = 1) then
- begin
- if (temp[i,n+1] = Team)and(Temp[i,n+2] = Team) then Won := True;
- if (temp[i+1,n] = Team)and(temp[i+2,n] = Team) then Won := True;
- if (temp[i+1,n+1] = Team)and(temp[i+2,n+2] = Team) then won := true;
- end;
- if (i = 1)and(n = 2) then
- if (temp[i+1,n] = Team)and(temp[i+2,n] = Team) then won := true;
- if (i = 1)and(n = 3) then
- begin
- if (temp[i+1,n-1] = Team)and(temp[i+2,n-2] = Team) then Won := True;
- if (temp[i+1,n] = Team)and(temp[i+2,n] = Team) then won := true;
- end;
- if (i = 2)and(n = 1) then
- if (temp[i,n+1] = Team)and(temp[i,n+2] = Team) then won := true;
- if (i = 3)and(n = 1) then
- if (temp[i,n+1] = Team)and(temp[i,n+2] = Team) then won := true;
- end;
- end;
- end;
- end;
-
- procedure Place(Team:Char;Spot: integer);
- begin
- SetTextStyle(DefaultFont,HorizDir,5);
- SetColor(63);
- If Spot in [1,2,3,4,5,6,7,8,9] then
- case spot of
- 1 : OutTextXY(70,15,Team);
- 2 : OutTextXY(150,15,Team);
- 3 : OutTextXY(230,15,Team);
- 4 : OutTextXY(70,61,Team);
- 5 : OutTextXY(150,61,Team);
- 6 : OutTextXY(230,61,Team);
- 7 : OutTextXY(70,101,Team);
- 8 : OutTextXY(150,101,Team);
- 9 : OutTextXY(230,101,Team);
- end;{Case}
- SetTextStyle(DefaultFont,HorizDir,1);
- end;
-
- procedure Start2;
- var
- Spot,Code,OSpot,Chose,i,yn : Integer;
- ch : Char;
- choice : string[1];
- Done : Boolean;
-
- begin
- Regs.AX := 2;
- Intr($33,Regs);
- Won := False;
- ClearBoard;
- SetActivepage(1);
- ClearViewPort;
- LoadBoard(1);
- NumberBoard;
- SetTextStyle(DefaultFont,HorizDir,1);
- OutTextXY(5,150,'You will be X''s and I will be O''s!');
- Chose := 9;
- Randomize;
- Done := False;
- repeat
- SetTextStyle(DefaultFont,HorizDir,1);
- OutTextXY(5,160,'Please Enter Your Spot: ');
- repeat
- Done := False;
- repeat
- Regs.AX := 1;
- Intr($33,Regs);
- if mouse then
- begin
- Regs.AX := 3;
- Intr($33,Regs);
- if keypressed then
- begin
- ch := readkey;
- if ch = #27 then Exit;
- OutTextXY(197,160,ch);
- choice := ch;
- Val(Choice,Spot,Code);
- Done := True;
- end;
- if regs.BX = 1 then
- begin
- if (regs.cx > 64)and(regs.cx < 131)and(regs.DX > 14)and(regs.dx < 62)then
- begin Spot := 1; Done := true; end;
- if (regs.cx > 130)and(regs.cx < 212)and(regs.DX > 14)and(regs.dx < 62)then
- begin Spot := 2; done := true; end;
- if (regs.cx > 212)and(regs.cx < 294)and(regs.DX > 14)and(regs.dx < 62)then
- begin Spot := 3; done := true; end;
- if (regs.cx > 64)and(regs.cx < 131)and(regs.DX > 62)and(regs.dx < 101)then
- begin Spot := 4; done := true; end;
- if (regs.cx > 130)and(regs.cx < 212)and(regs.DX > 62)and(regs.dx < 101)then
- begin Spot := 5; done := true; end;
- if (regs.cx > 212)and(regs.cx < 294)and(regs.DX > 62)and(regs.dx < 101)then
- begin Spot := 6; done := true; end;
- if (regs.cx > 64)and(regs.cx < 131)and(regs.DX > 101)and(regs.dx < 148)then
- begin Spot := 7; done := true; end;
- if (regs.cx > 130)and(regs.cx < 212)and(regs.DX > 101)and(regs.dx < 148)then
- begin Spot := 8; done := true; end;
- if (regs.cx > 212)and(regs.cx < 294)and(regs.DX > 101)and(regs.dx < 148)then
- begin Spot := 9; done := true; end;
- end;
- end
- else
- begin
- ch := readkey;
- if ch = #27 then exit;
- OutTextXY(197,160,ch);
- choice := ch;
- Val(Choice,Spot,Code);
- Done := True;
- end;
- until Done;
- until (Board[Spot] = '');
- Regs.AX := 2;
- Intr($33,Regs);
- Place('X',Spot);
- Board[Spot] := 'X';
- chose := 0;
- for i := 1 to 9 do
- if Board[i] = '' then chose := chose + 1;
- Check('X');
- Done := False;
- Regs.AX := 0;
- Intr($33,Regs);
- if not(won) and (chose > 0) then
- begin
- Done := False;
- repeat
- Regs.AX := 1;
- Intr($33,Regs);
- if mouse then
- begin
- Regs.AX := 3;
- Intr($33,Regs);
- if keypressed then
- begin
- ch := readkey;
- if ch = #27 then exit;
- OutTextXY(197,160,ch);
- choice := ch;
- Val(Choice,Spot,Code);
- Done := True;
- end;
- if regs.BX = 1 then
- begin
- if (regs.cx > 64)and(regs.cx < 131)and(regs.DX > 14)and(regs.dx < 62)then
- begin Spot := 1; Done := true; end;
- if (regs.cx > 130)and(regs.cx < 212)and(regs.DX > 14)and(regs.dx < 62)then
- begin Spot := 2; done := true; end;
- if (regs.cx > 212)and(regs.cx < 294)and(regs.DX > 14)and(regs.dx < 62)then
- begin Spot := 3; done := true; end;
- if (regs.cx > 64)and(regs.cx < 131)and(regs.DX > 62)and(regs.dx < 101)then
- begin Spot := 4; done := true; end;
- if (regs.cx > 130)and(regs.cx < 212)and(regs.DX > 62)and(regs.dx < 101)then
- begin Spot := 5; done := true; end;
- if (regs.cx > 212)and(regs.cx < 294)and(regs.DX > 62)and(regs.dx < 101)then
- begin Spot := 6; done := true; end;
- if (regs.cx > 64)and(regs.cx < 131)and(regs.DX > 101)and(regs.dx < 148)then
- begin Spot := 7; done := true; end;
- if (regs.cx > 130)and(regs.cx < 212)and(regs.DX > 101)and(regs.dx < 148)then
- begin Spot := 8; done := true; end;
- if (regs.cx > 212)and(regs.cx < 294)and(regs.DX > 101)and(regs.dx < 148)then
- begin Spot := 9; done := true; end;
- end;
- end
- else
- begin
- Ch := Readkey;
- if ch = #27 then Exit;
- OutTextXY(197,160,ch);
- choice := ch;
- Val(Choice,Spot,Code);
- Done := True;
- end;
- until Done;
- end;
- if Board[Spot] = '' then
- begin
- Board[Spot] := 'O';
- Regs.AX := 2;
- Intr($33,Regs);
- Place('O',Spot);
- end;
- if not(won)then Check('O');
- chose := 0;
- for i := 1 to 9 do
- if Board[i] = '' then chose := chose + 1;
- Regs.AX := 0;
- Intr($33,Regs);
- until (chose = 0)or Won;
- SetTextStyle(DefaultFont,HorizDir,1);
- OutTextXY(5,170,'Game Over!');
- OutTextXY(10,180,'Press ENTER');
- readln;
- end;
-
- procedure CheckForX;
- var
- Temp : Array[1..3,1..3]of string[1];
- i,n : integer;
-
- begin
- for i := 1 to 3 do
- for n := 1 to 3 do
- Temp[i,n] := '';
- for i := 1 to 3 do
- Temp[1,i] := Board[i];
- for i := 4 to 6 do
- Temp[2,i-3] := Board[i];
- for i := 7 to 9 do
- Temp[3,i-6] := Board[i];
- Put := 0;
- for i := 1 to 3 do {Check for 2}
- begin
- for n := 1 to 3 do
- if (Put > 0)and(Board[Put] <> '') then Put := 0;
- if ((Temp[i,n] = 'X')and(Put < 1))or((Temp[i,n] = 'X')and(Put > 9)) then
- begin
- if (Temp[i,n+1] = 'X') then Put := n+2;
- if (Temp[i,n-1] = 'X') then Put := n-2;
- if (Temp[i+1,n] = 'X') then Put := n+6;
- if (Temp[i-1,n] = 'X') then Put := n-6;
- if (Temp[i+1,n+1] = 'X') then begin Put := n+8; if Put > 9 then Put := 1; end;
- if (Temp[i+1,n-1] = 'X') then begin Put := n+4; if Put > 9 then Put := 3; end;
- if (Temp[i-1,n+1] = 'X') then Put := n-4;
- if (Temp[i-1,n-1] = 'X') then Put := n-8;
- end;
- end;
- if (Put < 1)and(Put > 9) Then Put := 0;
- end;
-
- procedure Start;
- var
- Spot,Code,OSpot,Chose,i,yn : Integer;
- ch : Char;
- choice : string[1];
- Done : Boolean;
-
- begin
- Regs.AX := 2;
- Intr($33,Regs);
- Won := False;
- ClearBoard;
- SetActivepage(1);
- ClearViewPort;
- LoadBoard(1);
- NumberBoard;
- SetTextStyle(DefaultFont,HorizDir,1);
- OutTextXY(5,150,'You will be X''s and I will be O''s!');
- Chose := 9;
- Randomize;
- Done := False;
- repeat
- SetTextStyle(DefaultFont,HorizDir,1);
- OutTextXY(5,160,'Please Enter Your Spot: ');
- repeat
- repeat
- Regs.AX := 1;
- Intr($33,Regs);
- if mouse then
- begin
- Regs.AX := 3;
- Intr($33,Regs);
- if keypressed then
- begin
- ch := readkey;
- if ch = #27 then Exit;
- OutTextXY(197,160,ch);
- choice := ch;
- Val(Choice,Spot,Code);
- Done := True;
- end;
- if regs.BX = 1 then
- begin
- if (regs.cx > 64)and(regs.cx < 131)and(regs.DX > 14)and(regs.dx < 62)then
- begin Spot := 1; Done := true; end;
- if (regs.cx > 130)and(regs.cx < 212)and(regs.DX > 14)and(regs.dx < 62)then
- begin Spot := 2; done := true; end;
- if (regs.cx > 212)and(regs.cx < 294)and(regs.DX > 14)and(regs.dx < 62)then
- begin Spot := 3; done := true; end;
- if (regs.cx > 64)and(regs.cx < 131)and(regs.DX > 62)and(regs.dx < 101)then
- begin Spot := 4; done := true; end;
- if (regs.cx > 130)and(regs.cx < 212)and(regs.DX > 62)and(regs.dx < 101)then
- begin Spot := 5; done := true; end;
- if (regs.cx > 212)and(regs.cx < 294)and(regs.DX > 62)and(regs.dx < 101)then
- begin Spot := 6; done := true; end;
- if (regs.cx > 64)and(regs.cx < 131)and(regs.DX > 101)and(regs.dx < 148)then
- begin Spot := 7; done := true; end;
- if (regs.cx > 130)and(regs.cx < 212)and(regs.DX > 101)and(regs.dx < 148)then
- begin Spot := 8; done := true; end;
- if (regs.cx > 212)and(regs.cx < 294)and(regs.DX > 101)and(regs.dx < 148)then
- begin Spot := 9; done := true; end;
- end;
- end
- else
- begin
- ch := readkey;
- if ch = #27 then Exit;
- OutTextXY(197,160,ch);
- choice := ch;
- Val(Choice,Spot,Code);
- end;
- until Done;
- until (Board[Spot] = '');
- Regs.AX := 2;
- Intr($33,Regs);
- Place('X',Spot);
- Board[Spot] := 'X';
- Check('X');
- chose := 0;
- for i := 1 to 9 do
- if board[i] = '' then chose := i;
- Delay(500);
- CheckForX;
- if (chose <> 0)and(not(won)) then
- begin
- yn := 0;
- for i := 1 to 9 do
- if board[i] = '' then yn := yn + 1;
- if (put > 0)and(Board[Put] = '') then ospot := put;
- CheckForX;
- if (yn > 1)and(Put < 1 )or(Put > 9) then
- begin
- repeat
- OSpot := Random(Chose+1);
- until (OSpot <> Spot)and(OSpot <> 0)and(Board[OSpot] = '');
- end
- else
- begin
- if put = 0 then
- for i := 1 to 9 do
- if board[i] = '' then ospot := i;
- end;
- Place('O',OSpot);
- Board[OSpot] := 'O';
- Check('O');
- end;
- chose := 0;
- for i := 1 to 9 do
- if board[i] = '' then chose := i;
- until (chose = 0)or Won;
- SetTextStyle(DefaultFont,HorizDir,1);
- OutTextXY(5,170,'Game Over!');
- OutTextXY(10,180,'Press ENTER');
- readln;
- end;
-
- begin
- StartGraph(EGA,EGALO,'d:\tp\bgi');
- Mouse := true;
- Regs.AX := 0;
- Intr($33,Regs);
- If Regs.AX = 0 then Mouse := False;
- Title;
- end.