Professional Documents
Culture Documents
The Tic - Tac - Toe: Project Report Submitted in Partial Fulfilment of The Requirements For The Degree of
The Tic - Tac - Toe: Project Report Submitted in Partial Fulfilment of The Requirements For The Degree of
Bhaskar Chakrabarty
CERTIFICATE
Gaming in the Field of Software Engineering
In the fast-growing field of engineering and software development and the
fastest growing sector of game development the future is difficult to predict. A
software project is usually a project that focuses on software design. Therefore,
Success can be measured by looking at the resulting software. In a game
project, a product is a game. But here's the point: A game is more than just
software. It has to offer content to be fun. Like a web server: without content
the server is useless, and the quality cannot be measured. This has a significant
impact on the entire game project. The software component of the project is not
unique, and should be considered in relation to all other components: Game
space, story, characters, gameplay, artwork, and so on.
Objectives
The game is developed for fun and full-time enthusiasm. It teaches the Player
to be careful in all situations he encounters, because if the Player is not careful
and recognizes the fire of the sauce he must be bombed.
Although the proposed game is an action game, it does not involve direct
violence. No zombie kills, killing of animals, or killing of a person is done in a
game. Therefore, it can also be considered a non-violent game. Children can
also play this game, because the structure of the game is very simple,
controlling the game is very easy.
by pressing the neighbouring keyboard keys - our project name is Tic-Tac-Toe
game. 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 our game,
it is 3 x 3 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.
Features
1. Multi-Player game
2. Logical
3. Room comforting background
Development Process
We planned the project over a period of 9 days and divided it into four
iterations. We planned the first iteration for analysis, second iteration for game
design, third iteration for coding and the final iteration for the product.
In the first iteration, we focused on Project analysis determined as the first
planned milestone of the project. Analysis is essential for starting of upcoming
milestones and delivering a finished project on time. Successful completion of a
project is heavily dependent on effective analysis.
The second iteration started by brainstorming among group members on what
the game would be. Each
group member denoted
the attributes or properties
of the game that one
dreamed to implement.
We gathered suggestions
together and chose the
ones that was possible to
be implemented within a
9 days project time. As
soon as the game concept
became clear, we made
some early decisions on
basic requirements of the
project in order to more easily reach the development goals. Game design
document was meant to be a living document. In other words, throughout the
production process the document was updated, if needed.
In the third iteration coding in Java using Android studio was under way.
Therefore, most of time in this iteration was dedicated for internal training
sessions. In this iteration, we needed to achieve four milestones each was
dependent on the previous one.
Last iteration was planned for testing and finalizing the product. The testing
process is an iterative process. We performed the testing process in four
iterations. The successful testing process of software requires a good plan.
Therefore, after the requirements of the project are confirmed, the future testing
of the system and the code were planned. The test plan provided information on
how and when the testing will be executed. In the second iteration, test cases
were designed for the planned tests. In iteration three, the designed test cases
were executed alongside the module testing and usability testing. During the last
iteration, according to the result of the tests, the test reports were
documented properly and the bugs were reported after the testing is completed.
Risk Management
A common definition of risk is an uncertain event that if it occurs, can have a
positive or negative effect on a project’s goals. It helps us to achieve the
project’s objectives, thus ensuring the successful completion of the project. For
successful development of this project, we have to need to identify the possible
risk. The possible risk for this project is described in below:
(a) The probability of moving away our-self from this project before it is finish
is low.
(b) The probability of user acceptance is great.
(c) The probability of requirement can't come in the time is low. (d) The
probability of marketing the product system is great.
(e) The probability of technology components isn’t fit for purpose of this project
is low.
(f) The probability of selecting low quality requirements is low.
(g) The probability of take wrong decisions are low.
(h) The probability of does not complete this project within a limited time is
low.
System Specifications
Most of the computer games require high configurations of computer. But in the
case of the proposed gaming system, the system requirements are not that much.
The minimum systems requirements for the proposed project “Tic Tac Toe”
game are mentioned following.
(a) Operating System: Android 4.0
(b) Processor: 1.2 GHz
(c) RAM: 512MB
(d) Storage: 200 MB
Overview
This game can be played in a 3x3 grid (shown in the Figure 2.1). The game
can be played by two players.
Figure 2.1
Theory of Game
A player can choose between two symbols with his opponent, usual games use
‘X’ and ‘O’. If first player choose ‘X’ then the second player have to play with
‘O’ and vice versa.
A player marks any of the 3x3 squares with his symbol (may be ‘X’ or ‘O’) and
his aim is to create a straight line horizontally or vertically or diagonally with
two intensions:
In the case logically no one can create a straight line with his own symbol, the
game results a tie.
Hence there are only three possible results : a player wins, his opponent wins or
it’s a tie.
0 1 2
3 4 5
6 7 8
Figure- 3.1
If any player is able to make three X’s or three O’s in the following
combinations then that player wins. The combinations are:
a) 0, 1, 2 b) 3, 4, 5
c) 6, 7, 8 d) 0, 3, 6
e) 1, 4, 7 f) 2, 5, 8
h) 0, 4, 8 i) 2, 4, 6
Flow Chart
Application Design
Now in the activity_main.xml file in the project and click on the Text View
and change the text inside that Text View from ‘Hello world’ to ‘Welcome to
Tic Tac Toe’.
Now there will be a warning next to the TextView in the component tree which
says “Hardcoded string ‘welcome to tic tac toe’ should use @string resource”.
(showing in strings.xml file).
Download three images for it: ‘O’, ‘X’ and the image for the ‘grid’ from
internet and now copy the downloaded images of ‘O’, ‘X’ and ‘grid’ to the
drawable folder and also drawable-v24 folder of the project. It is mandatory to
copy the images in both the folder.
Now drag and drop a Image View to your screen and do the constraints and then
insert ‘grid’ image in that Image View.
Now take a Linear Layout with horizontal orientation and inside that parent
Linear Layout insert 3 child Linear Layouts with horizontal orientation and
insert 3 image views each on the child Linear Layouts.
Now insert the images (‘O’ or ‘X’ any) on the various image views and set the
positions accordingly using the attributes like padding and layout margin to set
the images properly within the grid.
Implementation
Now we have to implement a strategy that will decide that which player will
win the game.
So we will go to activity_main.xml file and give the tags (0,1,2…..8) to all the
images in the grid image so that we can differentiate between various grids
when user click on a particular grid.
Now define a method “playerTap” which will be executed when the user taps
on the particular column of the grid. First, mention method “playerTap” in the
activity_main.xml file in onClick attribute of all the ImageViews. After that
write the method body in the MainActivity.java file.
int activePlayer = 0;
We define an integer array named “gamestate” which has 9 values (as there are
9 grids). All the nine elements of the array will be initialised to ‘2’.
We have total 8 winning positions in the game and these positions are stored in
an array named “winPosition” : {0,1,2}(horizontal), {3,4,5}(horizontal ),
{6,7,8,}(horizontal ) , {0,3,6,}(vertical), {1,4,7}(vertical), {2,5,8,}(vertical),
{0,4,8}(diagonal), {2,4,6}(diagonal)..
{0,4,8}, {2,4,6}};
Active player = 0 >> x turn
The playerTap method will check the tag of the grid tapped by the player and
convert that tag into integer and if the grid contains (2,i.e null) then it will store
the value of the activePlayer in the gamestate and will change the values of the
activePlayer from 0 to 1 and vice-versa. On every turn it will set the image of
‘X’ when the value of activePlayer is 0, and will set the image of ‘O’ when the
value of activePlayer is 1.
Now drag and drop a TextView that will show the turn of the player and we will
set the text into that TextView that if the value of the activePlayer is 0 then it
will display X’s turn and when the value of the activePlayer will be 1 than it
will show O’s turn. It will also display the winner of the game.
We can set the text inside the TextView by using the code:
which is as follows:
((ImageView )findViewById(R.id.imageView0)).setImageResource(0);
((ImageView )findViewById(R.id.imageView8)).setImageResource(0);
We have also assigned a boolean data type named gameActive, whose value
will be true and when any player won, then we will set this data type
(gameActive) to false. And when the gameActive will be false our reset method
will be invoked and the grid will be reset.
Testing
Test Levels
The test approach is divided into three main phases: Module testing, integration
testing and system testing. In addition, the system testing includes two sub-
phases: functional and usability testing. These planned tests are explained
briefly below.
(a)Module testing
will perform during coding by using debug messages to check that the written
code produces wanted results. An important requirement is that the code will
compile with zero bugs.
(b)Integration testing
will perform after finish module testing in order to validate if each module can
work fine with each other. Integration Test proves that system works as
integrated unit when all the fixes are complete.
(c)System testing
includes two phases: functional testing and usability testing. These will perform
after the product reaches its final version. During functional test phase, the
tester will test if the product meets the game requirements. The tester tests the
requirements using the use cases listed below in Test Cases section. The
usability test will perform to understand how easy it is to learn to play the game.
Any person out of the team members will perform this test by playing the game
Sourse Code
activity_main.xml
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:fontFamily="cursive"
android:text="@string/heading"
android:textSize="34sp"
android:textStyle="bold"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="@string/grid"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:srcCompat="@drawable/grid" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="310dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/imageView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="18sp"
android:tag="0" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="18sp"
android:tag="1" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="18sp"
android:tag="2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="18sp"
android:tag="3" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="18sp"
android:tag="4" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="18sp"
android:tag="5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="18sp"
android:tag="6" />
<ImageView
android:id="@+id/imageView7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="18sp"
android:tag="7" />
<ImageView
android:id="@+id/imageView8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="18sp"
android:tag="8" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/status"
android:layout_width="217dp"
android:layout_height="45dp"
android:text="@string/status"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="@+id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
strings.xml
<resources>
<string name="app_name">tictactoe</string>
<string name="heading">Welcome To Tic Tac Toe</string>
<string name="grid">Our main grid</string>
<string name="status">X\' s Turn.Tap to play</string>
</resources>
MainActivity.java
package com.example.tictactoe;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
// player representation 0 - X , 1 - O
int activePlayer = 0;
int[] gameState = {2, 2, 2, 2, 2, 2, 2, 2, 2};
// State meanings 0 - X , 1 - O, 2 - null
int [][] winPositions ={{0,1,2}, {3,4,5}, {6,7,8}, {0,3,6}, {1,4,7}, {2,5,8},
{0,4,8}, {2,4,6}};
public void playerTap(View view){
ImageView img = (ImageView) view;
int tappedImage = Integer.parseInt(img.getTag().toString());
if (!gameActive){
gameReset(view);
}
if (gameState[tappedImage] == 2 && gameActive) {
gameState[tappedImage] = activePlayer;
img.setTranslationY(-1000f);
if (activePlayer == 0) {
img.setImageResource(R.drawable.x); // x.png is the image
name(path: tic tac toe\app\src\main\res\drawable)
activePlayer = 1;
TextView status = findViewById(R.id.status);
status.setText("O's Turn- Tap to play ");
} else {
img.setImageResource(R.drawable.o); // o.png is the image
name(path: tic tac toe\app\src\main\res\drawable)
activePlayer = 0;
TextView status = findViewById(R.id.status);
status.setText("X's Turn- Tap to play");
}
img.animate().translationYBy(1000f).setDuration(300);
}
// check if any player is won
for(int[] winPosition: winPositions){
if (gameState[winPosition[0]] == gameState[winPosition[1]] &&
gameState[winPosition[1]] == gameState[winPosition[2]] &&
gameState[winPosition[0]] != 2){
//somebody has won! - find out who!
String winnerstr ;
gameActive = false;
if (gameState[winPosition[0]] == 0){
winnerstr = "X is won";
}
else {
winnerstr = "O has won";
}
// update the status bar for winner announcement
TextView status = findViewById(R.id.status);
status.setText(winnerstr);
}
}
//start `
//condition when the game is draw:
boolean emptySquare = false;
for(int squareState:gameState){
if(squareState == 2){
emptySquare = true;
break;
}
}
if (!emptySquare && gameActive){
//game is a draw
gameActive = false;
String winnerStr;
winnerStr = "No one won";
TextView status = findViewById(R.id.status);
status.setText(winnerStr);
} //end ``
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Built apk
Now we can Build the apk file of the project and install it in any smartphone.
Build > Build Bundle(s)/APK(s) > Build APK(s) from the toolbar menu
Once the APK build is complete, we’ll receive a notification on the bottom right
corner of your screen. From that notification, select Locate and we will be led to
the APK file location.
locate the APK file in the following path within the project folder:
app/build/outputs/apk/debug. The file is named app-debug. apk by default.
1. Future plan:
2. Reference: