Tic Tac Toe Game

Tic Tac Toe is a simple, free, fun and addictive game for 1 or 2 players.

Description:-

Tic tac toe or tiktok is a sport for two games, called ” x and o”. Each turn, a participant ratings an area in a three x 3 grid. The participant who places 3 respective marks in a horizontal, vertical or diagonal row wins the game.

Objective:-

The purpose to develop the application to implement the classic paper & pen game “Tic-Tac-Toe”.

Creating the  Game

The biggest part of the user interface of our Tic-Tac-Toe game is managed in the BoardView class. So, we just need to set our BoardView component into a TableLayout in our layout file :

<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center"
android:layout_gravity="top|center"
android:clickable="true"
android:padding="10dp"
android:id="@+id/mainBoard"
android:nestedScrollingEnabled="false"

><TableRow
style="@style/TableRow"
android:id="@+id/row1"
>

<TextView
android:layout_column="0"
style="@style/LeftCell"
>
</TextView>

<TextView
android:layout_column="1"
style="@style/MiddleCell"
>
</TextView>

<TextView
android:layout_column="2"
style="@style/RightCell"
>
</TextView>
</TableRow>

java file:-

tv_turn.setText("Turn: "+turn);
for(int i = 0; i<mainBoard.getChildCount(); i++){
TableRow row = (TableRow) mainBoard.getChildAt(i);
for(int j = 0; j<row.getChildCount(); j++){
TextView tv = (TextView) row.getChildAt(j);
tv.setText(R.string.none);
tv.setOnClickListener(Move(i, j, tv));
}}

See Project :

DOWNLOAD FULL SOURCE CODE


Noornuma Farooqui has written 33 articles