Professional Documents
Culture Documents
HISTORY:
An early variation of the game was played in the Roman Empire, around the 1st
century B.C. It was called terni lapilli, which means "three pebbles at a time." The
game's grid markings have been found chalked all over Roman ruins.
The first print reference to "noughts and crosses," the British name for the game,
appeared in 1864. The first print reference to a game called "tick-tack-toe"
occurred in 1884 but referred to a children's game played on a slate.
STRATEGY:
This game is very popular and is fairly simple by itself. It is actually a two player
game. In this game, there is a board with n x n squares. In my game, it is 3x3
squares .
The goal of Tic-Tac-Toe is to be one of the players to get three same symbols in a
row - horizontally, vertically or diagonally - on a 3 x 3 grid.
PROJECT FUNCTIONALITIES:
CLICK_BUTTON
CHECK_WINNER
NEW_ROUND
START_OVER
CODE:
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
#pragma resource("*.Windows.fmx", _PLAT_MSWINDOWS)
#pragma resource("*.Surface.fmx", _PLAT_MSWINDOWS)
TForm1 * Form1;
char currentPlayerSymbol = 'X';
int Xcounter = 0, Ocounter = 0, fill = 0;
bool TForm1::CheckWinner() {
if (!Button1 -> Text.IsEmpty() && Button1 -> Text == Button2 -> Text && Button1 ->
Text == Button3 -> Text)
return true;
else if (!Button4 -> Text.IsEmpty() && Button4 -> Text == Button5 -> Text && Button4 ->
Text == Button6 -> Text)
return true;
else if (!Button7 -> Text.IsEmpty() && Button7 -> Text == Button8 -> Text && Button7 ->
Text == Button9 -> Text)
return true;
else if (!Button1 -> Text.IsEmpty() && Button1 -> Text == Button4 -> Text && Button1 ->
Text == Button7 -> Text)
return true;
else if (!Button2 -> Text.IsEmpty() && Button2 -> Text == Button5 -> Text && Button2 ->
Text == Button8 -> Text)
return true;
else if (!Button3 -> Text.IsEmpty() && Button3 -> Text == Button6 -> Text && Button3 ->
Text == Button9 -> Text)
return true;
else if (!Button1 -> Text.IsEmpty() && Button1 -> Text == Button5 -> Text && Button1 ->
Text == Button9 -> Text)
return true;
else if (!Button3 -> Text.IsEmpty() && Button3 -> Text == Button5 -> Text && Button3 ->
Text == Button7 -> Text)
return true;
else
return false;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent * Owner): TForm(Owner) {}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonClick(TObject * Sender) {
// Button1->Text=currentPlayerSymbol;
TButton * clickedButton = dynamic_cast < TButton * > (Sender);
if (clickedButton -> Text.IsEmpty() && CheckWinner() == false) {
clickedButton -> Text = currentPlayerSymbol;
CheckWinner();
if (CheckWinner()) {
fill = 0;
if (currentPlayerSymbol == 'X') {
WinText -> Text = "Player X Won";
Xcounter = Xcounter + 1;
Xcount -> Text = Xcounter;
} else {
WinText -> Text = "Player O Won";
Ocounter = Ocounter + 1;
Ocount -> Text = Ocounter;
}
} else {
fill++;
if (fill == 9)
WinText -> Text = "MATCH DRAWN!";
if (currentPlayerSymbol == 'X') {
currentPlayerSymbol = 'O';
Label1 -> Text = "___";
Label2 -> Text = "";
} else {
currentPlayerSymbol = 'X';
Label2 -> Text = "___";
Label1 -> Text = "";
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button10Click(TObject * Sender) {
Button1 -> Text = "";
Button2 -> Text = "";
Button3 -> Text = "";
Button4 -> Text = "";
Button5 -> Text = "";
Button6 -> Text = "";
Button7 -> Text = "";
Button8 -> Text = "";
Button9 -> Text = "";
WinText -> Text = "";
CheckWinner();
fill = 0;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::Button11Click(TObject * Sender) {
Button1 -> Text = "";
Button2 -> Text = "";
Button3 -> Text = "";
Button4 -> Text = "";
Button5 -> Text = "";
Button6 -> Text = "";
Button7 -> Text = "";
Button8 -> Text = "";
Button9 -> Text = "";
Ocount -> Text = "";
Xcount -> Text = "";
WinText -> Text = "";
CheckWinner();
fill = 0;
Xcounter = 0;
Ocounter = 0;
}
//---------------------------------------------------------------------------