unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls, StdCtrls, Menus, ComCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
Image7: TImage;
Image8: TImage;
Image9: TImage;
ctCross: TImage;
xLabel: TLabel;
oLabel: TLabel;
btnReset: TPanel;
ctCircle: TImage;
zone1: TLabel;
zone2: TLabel;
zone3: TLabel;
zone4: TLabel;
zone5: TLabel;
zone6: TLabel;
zone7: TLabel;
zone8: TLabel;
zone9: TLabel;
ovCross1: TImage;
ovCross2: TImage;
ovCross3: TImage;
ovCross4: TImage;
ovCross5: TImage;
ovCross6: TImage;
ovCross7: TImage;
ovCross8: TImage;
ovCross9: TImage;
zone10: TLabel;
ovCircle1: TImage;
ovCircle2: TImage;
ovCircle3: TImage;
ovCircle4: TImage;
ovCircle5: TImage;
ovCircle6: TImage;
ovCircle7: TImage;
ovCircle8: TImage;
ovCircle9: TImage;
cross1: TImage;
cross2: TImage;
cross3: TImage;
cross4: TImage;
cross5: TImage;
cross6: TImage;
cross7: TImage;
cross8: TImage;
cross9: TImage;
circle1: TImage;
circle2: TImage;
circle3: TImage;
circle4: TImage;
circle5: TImage;
circle6: TImage;
circle7: TImage;
circle8: TImage;
circle9: TImage;
MainMenu1: TMainMenu;
File1: TMenuItem;
NewGame1: TMenuItem;
NewRound1: TMenuItem;
N1: TMenuItem;
Exit1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
xWin1: TImage;
xWin2: TImage;
xWin3: TImage;
xWin4: TImage;
xWin5: TImage;
xWin6: TImage;
xWin7: TImage;
xWin8: TImage;
xWin9: TImage;
oWin1: TImage;
oWin2: TImage;
oWin3: TImage;
oWin4: TImage;
oWin5: TImage;
oWin6: TImage;
oWin7: TImage;
oWin8: TImage;
oWin9: TImage;
lockFields: TLabel;
logo: TImage;
Label1: TLabel;
Label2: TLabel;
procedure btnResetMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure btnResetMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure zone1MouseEnter(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure zone10MouseEnter(Sender: TObject);
procedure resetDisplay;
procedure zone2MouseEnter(Sender: TObject);
procedure zone3MouseEnter(Sender: TObject);
procedure zone4MouseEnter(Sender: TObject);
procedure zone5MouseEnter(Sender: TObject);
procedure zone6MouseEnter(Sender: TObject);
procedure zone7MouseEnter(Sender: TObject);
procedure zone8MouseEnter(Sender: TObject);
procedure zone9MouseEnter(Sender: TObject);
procedure ovCross1Click(Sender: TObject);
procedure ovCross2Click(Sender: TObject);
procedure ovCross3Click(Sender: TObject);
procedure ovCross4Click(Sender: TObject);
procedure ovCross5Click(Sender: TObject);
procedure ovCross6Click(Sender: TObject);
procedure ovCross7Click(Sender: TObject);
procedure ovCross8Click(Sender: TObject);
procedure ovCross9Click(Sender: TObject);
procedure setTurn(Turn: String);
procedure ovCircle1Click(Sender: TObject);
procedure ovCircle2Click(Sender: TObject);
procedure ovCircle3Click(Sender: TObject);
procedure ovCircle4Click(Sender: TObject);
procedure ovCircle5Click(Sender: TObject);
procedure ovCircle6Click(Sender: TObject);
procedure ovCircle7Click(Sender: TObject);
procedure ovCircle8Click(Sender: TObject);
procedure ovCircle9Click(Sender: TObject);
procedure btnResetClick(Sender: TObject);
procedure NewRound1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure checkWin(S : String);
procedure xWins;
procedure oWins;
procedure lockPlay;
procedure unlockPlay;
procedure NewGame1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
private
curTurn, lastWin: String;
zx: Array of Boolean;
zo: Array of Boolean;
xPoints, oPoints: Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
Const
frmHeight = 232;
implementation
uses about;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
xPoints := 0;
oPoints := 0;
lastWin := 'x';
curTurn := 'x';
ctCross.Visible := False;
logo.Visible := True;
lockPlay;
SetLength(zx, 9);
SetLength(zo, 9);
zx[0] := false;
zx[1] := false;
zx[2] := false;
zx[3] := false;
zx[4] := false;
zx[5] := false;
zx[6] := false;
zx[7] := false;
zx[8] := false;
zo[0] := false;
zo[1] := false;
zo[2] := false;
zo[3] := false;
zo[4] := false;
zo[5] := false;
zo[6] := false;
zo[7] := false;
zo[8] := false;
end;
procedure TForm1.btnResetMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then btnReset.BevelInner := bvLowered;
end;
procedure TForm1.btnResetMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
btnReset.BevelInner := bvRaised;
end;
procedure TForm1.zone1MouseEnter(Sender: TObject);
begin
if (curTurn = 'x') and (zx[0] = false) then
begin
resetDisplay;
ovCross1.Visible := True;
ovCross1.BringToFront;
end else
if (curTurn = 'o') and (zo[0] = false) then
begin
resetDisplay;
ovCircle1.Visible := True;
ovCircle1.BringToFront;
end;
end;
procedure TForm1.zone10MouseEnter(Sender: TObject);
begin
resetDisplay;
end;
procedure TForm1.resetDisplay;
begin
if curTurn = 'x' then
begin
if zx[0] = false then ovCross1.Visible := false;
if zx[1] = false then ovCross2.Visible := false;
if zx[2] = false then ovCross3.Visible := false;
if zx[3] = false then ovCross4.Visible := false;
if zx[4] = false then ovCross5.Visible := false;
if zx[5] = false then ovCross6.Visible := false;
if zx[6] = false then ovCross7.Visible := false;
if zx[7] = false then ovCross8.Visible := false;
if zx[8] = false then ovCross9.Visible := false;
end
else if curTurn = 'o' then
begin
if zo[0] = false then ovCircle1.Visible := false;
if zo[1] = false then ovCircle2.Visible := false;
if zo[2] = false then ovCircle3.Visible := false;
if zo[3] = false then ovCircle4.Visible := false;
if zo[4] = false then ovCircle5.Visible := false;
if zo[5] = false then ovCircle6.Visible := false;
if zo[6] = false then ovCircle7.Visible := false;
if zo[7] = false then ovCircle8.Visible := false;
if zo[8] = false then ovCircle9.Visible := false;
end;
end;
procedure TForm1.zone2MouseEnter(Sender: TObject);
begin
if (curTurn = 'x') and (zx[1] = false) then
begin
resetDisplay;
ovCross2.Visible := True;
ovCross2.BringToFront;
end else
if (curTurn = 'o') and (zo[1] = false) then
begin
resetDisplay;
ovCircle2.Visible := True;
ovCircle2.BringToFront;
end;
end;
procedure TForm1.zone3MouseEnter(Sender: TObject);
begin
if (curTurn = 'x') and (zx[2] = false) then
begin
resetDisplay;
ovCross3.Visible := True;
ovCross3.BringToFront;
end else
if (curTurn = 'o') and (zo[2] = false) then
begin
resetDisplay;
ovCircle3.Visible := True;
ovCircle3.BringToFront;
end;
end;
procedure TForm1.zone4MouseEnter(Sender: TObject);
begin
if (curTurn = 'x') and (zx[3] = false) then
begin
resetDisplay;
ovCross4.Visible := True;
ovCross4.BringToFront;
end else
if (curTurn = 'o') and (zo[3] = false) then
begin
resetDisplay;
ovCircle4.Visible := True;
ovCircle4.BringToFront;
end;
end;
procedure TForm1.zone5MouseEnter(Sender: TObject);
begin
if (curTurn = 'x') and (zx[4] = false) then
begin
resetDisplay;
ovCross5.Visible := True;
ovCross5.BringToFront;
end else
if (curTurn = 'o') and (zo[4] = false) then
begin
resetDisplay;
ovCircle5.Visible := True;
ovCircle5.BringToFront;
end;
end;
procedure TForm1.zone6MouseEnter(Sender: TObject);
begin
if (curTurn = 'x') and (zx[5] = false) then
begin
resetDisplay;
ovCross6.Visible := True;
ovCross6.BringToFront;
end else
if (curTurn = 'o') and (zo[5] = false) then
begin
resetDisplay;
ovCircle6.Visible := True;
ovCircle6.BringToFront;
end;
end;
procedure TForm1.zone7MouseEnter(Sender: TObject);
begin
if (curTurn = 'x') and (zx[6] = false) then
begin
resetDisplay;
ovCross7.Visible := True;
ovCross7.BringToFront;
end else
if (curTurn = 'o') and (zo[6] = false) then
begin
resetDisplay;
ovCircle7.Visible := True;
ovCircle7.BringToFront;
end;
end;
procedure TForm1.zone8MouseEnter(Sender: TObject);
begin
if (curTurn = 'x') and (zx[7] = false) then
begin
resetDisplay;
ovCross8.Visible := True;
ovCross8.BringToFront;
end else
if (curTurn = 'o') and (zo[7] = false) then
begin
resetDisplay;
ovCircle8.Visible := True;
ovCircle8.BringToFront;
end;
end;
procedure TForm1.zone9MouseEnter(Sender: TObject);
begin
if (curTurn = 'x') and (zx[8] = false) then
begin
resetDisplay;
ovCross9.Visible := True;
ovCross9.BringToFront;
end else
if (curTurn = 'o') and (zo[8] = false) then
begin
resetDisplay;
ovCircle9.Visible := True;
ovCircle9.BringToFront;
end;
end;
procedure TForm1.ovCross1Click(Sender: TObject);
begin
resetDisplay;
Cross1.Visible := True;
Cross1.BringToFront;
ovCross1.Visible := False;
zx[0] := True;
checkWin('x');
setTurn('o');
end;
procedure TForm1.ovCross2Click(Sender: TObject);
begin
resetDisplay;
Cross2.Visible := True;
Cross2.BringToFront;
ovCross2.Visible := False;
zx[1] := True;
checkWin('x');
setTurn('o');
end;
procedure TForm1.ovCross3Click(Sender: TObject);
begin
resetDisplay;
Cross3.Visible := True;
Cross3.BringToFront;
ovCross3.Visible := False;
zx[2] := True;
checkWin('x');
setTurn('o');
end;
procedure TForm1.ovCross4Click(Sender: TObject);
begin
resetDisplay;
Cross4.Visible := True;
Cross4.BringToFront;
ovCross4.Visible := False;
zx[3] := True;
checkWin('x');
setTurn('o');
end;
procedure TForm1.ovCross5Click(Sender: TObject);
begin
resetDisplay;
Cross5.Visible := True;
Cross5.BringToFront;
ovCross5.Visible := False;
zx[4] := True;
checkWin('x');
setTurn('o');
end;
procedure TForm1.ovCross6Click(Sender: TObject);
begin
resetDisplay;
Cross6.Visible := True;
Cross6.BringToFront;
ovCross6.Visible := False;
zx[5] := True;
checkWin('x');
setTurn('o');
end;
procedure TForm1.ovCross7Click(Sender: TObject);
begin
resetDisplay;
Cross7.Visible := True;
Cross7.BringToFront;
ovCross7.Visible := False;
zx[6] := True;
checkWin('x');
setTurn('o');
end;
procedure TForm1.ovCross8Click(Sender: TObject);
begin
resetDisplay;
Cross8.Visible := True;
Cross8.BringToFront;
ovCross8.Visible := False;
zx[7] := True;
checkWin('x');
setTurn('o');
end;
procedure TForm1.ovCross9Click(Sender: TObject);
begin
resetDisplay;
Cross9.Visible := True;
Cross9.BringToFront;
ovCross9.Visible := False;
zx[8] := True;
checkWin('x');
setTurn('o');
end;
procedure TForm1.setTurn(Turn: String);
begin
if Turn = 'o' then
begin
ctCross.Visible := False;
ctCircle.Visible := True;
logo.Visible := False;
curTurn := 'o';
end else
if Turn = 'x' then
begin
ctCross.Visible := True;
ctCircle.Visible := False;
logo.Visible := False;
curTurn := 'x';
end;
end;
procedure TForm1.ovCircle1Click(Sender: TObject);
begin
resetDisplay;
Circle1.Visible := True;
Circle1.BringToFront;
ovCircle1.Visible := False;
zo[0] := True;
checkWin('o');
setTurn('x');
end;
procedure TForm1.ovCircle2Click(Sender: TObject);
begin
resetDisplay;
Circle2.Visible := True;
Circle2.BringToFront;
ovCircle2.Visible := False;
zo[1] := True;
checkWin('o');
setTurn('x');
end;
procedure TForm1.ovCircle3Click(Sender: TObject);
begin
resetDisplay;
Circle3.Visible := True;
Circle3.BringToFront;
ovCircle3.Visible := False;
zo[2] := True;
checkWin('o');
setTurn('x');
end;
procedure TForm1.ovCircle4Click(Sender: TObject);
begin
resetDisplay;
Circle4.Visible := True;
Circle4.BringToFront;
ovCircle4.Visible := False;
zo[3] := True;
checkWin('o');
setTurn('x');
end;
procedure TForm1.ovCircle5Click(Sender: TObject);
begin
resetDisplay;
Circle5.Visible := True;
Circle5.BringToFront;
ovCircle5.Visible := False;
zo[4] := True;
checkWin('o');
setTurn('x');
end;
procedure TForm1.ovCircle6Click(Sender: TObject);
begin
resetDisplay;
Circle6.Visible := True;
Circle6.BringToFront;
ovCircle6.Visible := False;
zo[5] := True;
checkWin('o');
setTurn('x');
end;
procedure TForm1.ovCircle7Click(Sender: TObject);
begin
resetDisplay;
Circle7.Visible := True;
Circle7.BringToFront;
ovCircle7.Visible := False;
zo[6] := True;
checkWin('o');
setTurn('x');
end;
procedure TForm1.ovCircle8Click(Sender: TObject);
begin
resetDisplay;
Circle8.Visible := True;
Circle8.BringToFront;
ovCircle8.Visible := False;
zo[7] := True;
checkWin('o');
setTurn('x');
end;
procedure TForm1.ovCircle9Click(Sender: TObject);
begin
resetDisplay;
Circle9.Visible := True;
Circle9.BringToFront;
ovCircle9.Visible := False;
zo[8] := True;
checkWin('o');
setTurn('x');
end;
procedure TForm1.btnResetClick(Sender: TObject);
begin
btnReset.Caption := 'New Round';
if lastWin = 'x' then setTurn('x')
else setTurn('o');
unlockPlay;
Cross1.Visible := False;
Cross2.Visible := False;
Cross3.Visible := False;
Cross4.Visible := False;
Cross5.Visible := False;
Cross6.Visible := False;
Cross7.Visible := False;
Cross8.Visible := False;
Cross9.Visible := False;
Circle1.Visible := False;
Circle2.Visible := False;
Circle3.Visible := False;
Circle4.Visible := False;
Circle5.Visible := False;
Circle6.Visible := False;
Circle7.Visible := False;
Circle8.Visible := False;
Circle9.Visible := False;
Image1.BringToFront;
Image2.BringToFront;
Image3.BringToFront;
Image4.BringToFront;
Image5.BringToFront;
Image6.BringToFront;
Image7.BringToFront;
Image8.BringToFront;
Image9.BringToFront;
Zone1.BringToFront;
Zone2.BringToFront;
Zone3.BringToFront;
Zone4.BringToFront;
Zone5.BringToFront;
Zone6.BringToFront;
Zone7.BringToFront;
Zone8.BringToFront;
Zone9.BringToFront;
xWin1.Visible := False;
xWin2.Visible := False;
xWin3.Visible := False;
xWin4.Visible := False;
xWin5.Visible := False;
xWin6.Visible := False;
xWin7.Visible := False;
xWin8.Visible := False;
xWin9.Visible := False;
oWin1.Visible := False;
oWin2.Visible := False;
oWin3.Visible := False;
oWin4.Visible := False;
oWin5.Visible := False;
oWin6.Visible := False;
oWin7.Visible := False;
oWin8.Visible := False;
oWin9.Visible := False;
zx[0] := false;
zx[1] := false;
zx[2] := false;
zx[3] := false;
zx[4] := false;
zx[5] := false;
zx[6] := false;
zx[7] := false;
zx[8] := false;
zo[0] := false;
zo[1] := false;
zo[2] := false;
zo[3] := false;
zo[4] := false;
zo[5] := false;
zo[6] := false;
zo[7] := false;
zo[8] := false;
end;
procedure TForm1.NewRound1Click(Sender: TObject);
begin
btnResetClick(self);
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm1.checkWin(S : String);
begin
if S = 'x' then
begin
if (zx[0] = true) and (zx[1] = true)
and (zx[2] = true) then
begin
xWin1.Visible := True;
xWin2.Visible := True;
xWin3.Visible := True;
xWin1.BringToFront;
xWin2.BringToFront;
xWin3.BringToFront;
xWins;
end else
if (zx[3] = true) and (zx[4] = true)
and (zx[5] = true) then
begin
xWin4.Visible := True;
xWin5.Visible := True;
xWin6.Visible := True;
xWin4.BringToFront;
xWin5.BringToFront;
xWin6.BringToFront;
xWins;
end else
if (zx[6] = true) and (zx[7] = true)
and (zx[8] = true) then
begin
xWin7.Visible := True;
xWin8.Visible := True;
xWin9.Visible := True;
xWin7.BringToFront;
xWin8.BringToFront;
xWin9.BringToFront;
xWins;
end else
if (zx[0] = true) and (zx[3] = true)
and (zx[6] = true) then
begin
xWin1.Visible := True;
xWin4.Visible := True;
xWin7.Visible := True;
xWin1.BringToFront;
xWin4.BringToFront;
xWin7.BringToFront;
xWins;
end else
if (zx[1] = true) and (zx[4] = true)
and (zx[7] = true) then
begin
xWin2.Visible := True;
xWin5.Visible := True;
xWin8.Visible := True;
xWin2.BringToFront;
xWin5.BringToFront;
xWin8.BringToFront;
xWins;
end else
if (zx[2] = true) and (zx[5] = true)
and (zx[8] = true) then
begin
xWin3.Visible := True;
xWin6.Visible := True;
xWin9.Visible := True;
xWin3.BringToFront;
xWin6.BringToFront;
xWin9.BringToFront;
xWins;
end else
if (zx[0] = true) and (zx[4] = true)
and (zx[8] = true) then
begin
xWin1.Visible := True;
xWin5.Visible := True;
xWin9.Visible := True;
xWin1.BringToFront;
xWin5.BringToFront;
xWin9.BringToFront;
xWins;
end else
if (zx[2] = true) and (zx[4] = true)
and (zx[6] = true) then
begin
xWin3.Visible := True;
xWin5.Visible := True;
xWin7.Visible := True;
xWin3.BringToFront;
xWin5.BringToFront;
xWin7.BringToFront;
xWins;
end;
end else
if S = 'o' then
begin
if (zo[0] = true) and (zo[1] = true)
and (zo[2] = true) then
begin
oWin1.Visible := True;
oWin2.Visible := True;
oWin3.Visible := True;
oWin1.BringToFront;
oWin2.BringToFront;
oWin3.BringToFront;
oWins;
end else
if (zo[3] = true) and (zo[4] = true)
and (zo[5] = true) then
begin
oWin4.Visible := True;
oWin5.Visible := True;
oWin6.Visible := True;
oWin4.BringToFront;
oWin5.BringToFront;
oWin6.BringToFront;
oWins;
end else
if (zo[6] = true) and (zo[7] = true)
and (zo[8] = true) then
begin
oWin7.Visible := True;
oWin8.Visible := True;
oWin9.Visible := True;
oWin7.BringToFront;
oWin8.BringToFront;
oWin9.BringToFront;
oWins;
end else
if (zo[0] = true) and (zo[3] = true)
and (zo[6] = true) then
begin
oWin1.Visible := True;
oWin4.Visible := True;
oWin7.Visible := True;
oWin1.BringToFront;
oWin4.BringToFront;
oWin7.BringToFront;
oWins;
end else
if (zo[1] = true) and (zo[4] = true)
and (zo[7] = true) then
begin
oWin2.Visible := True;
oWin5.Visible := True;
oWin8.Visible := True;
oWin2.BringToFront;
oWin5.BringToFront;
oWin8.BringToFront;
oWins;
end else
if (zo[2] = true) and (zo[5] = true)
and (zo[8] = true) then
begin
oWin3.Visible := True;
oWin6.Visible := True;
oWin9.Visible := True;
oWin3.BringToFront;
oWin6.BringToFront;
oWin9.BringToFront;
oWins;
end else
if (zo[0] = true) and (zo[4] = true)
and (zo[8] = true) then
begin
oWin1.Visible := True;
oWin5.Visible := True;
oWin9.Visible := True;
oWin1.BringToFront;
oWin5.BringToFront;
oWin9.BringToFront;
oWins;
end else
if (zo[2] = true) and (zo[4] = true)
and (zo[6] = true) then
begin
oWin3.Visible := True;
oWin5.Visible := True;
oWin7.Visible := True;
oWin3.BringToFront;
oWin5.BringToFront;
oWin7.BringToFront;
oWins;
end;
end;
end;
procedure TForm1.xWins;
begin
xPoints := xPoints + 1;
xLabel.Caption := IntToStr(xPoints);
lastWin := 'x';
lockPlay;
end;
procedure TForm1.oWins;
begin
oPoints := oPoints + 1;
oLabel.Caption := IntToStr(oPoints);
lastWin := 'o';
lockPlay;
end;
procedure TForm1.lockPlay;
begin
lockFields.Visible := True;
lockFields.BringToFront;
end;
procedure TForm1.unlockPlay;
begin
lockFields.Visible := False;
end;
procedure TForm1.NewGame1Click(Sender: TObject);
begin
xPoints := 0;
oPoints := 0;
xLabel.Caption := '0';
oLabel.Caption := '0';
setTurn('x');
lastWin := 'x';
btnResetClick(self);
end;
procedure TForm1.About1Click(Sender: TObject);
begin
Form3 := TForm3.Create(Self);
Form3.ShowModal;
Form3.Free;
end;
end.
Tidak ada komentar:
Posting Komentar