A simple Tic Tac Toe application for Android devices. This repo purpose is for learning and practice only.
This is a game of Tic Tac Toe with a 3*3 playing field. Player 1 go first.
If anyone got 3 markers in a row, column or 2 cross lines, that player wins. A draw can happen.
Press the RESET button to erase all data of the game (player's score, the state of the button X/O, ...)
All data are kept when orientation changed (e.g portrait -> landscape)
- Android Studio version 3.5
- Java
- clone this repo
- run it using Android Studio
This was intentionally left blank.
All buttons are named like this: button_xy
to access it ez when calling it from a loop.
What is View
- View is like elements in HTML where components like buttons, text inputs are view
What does this line mean buttons[i][j].setOnClickListener(this);
- calling the class itself (here is MainActivity)
- we saw
MainActivity implements View.OnClickListener
-> this class now has a met calledonClick(View v){}
- -> we write logic code inside that new override method inherited from super class
How to save data when change orientation
- in
activity_main.xml
, have this lineandroid:freezesText="true"
in each element that wanna keep the text unchanged - save data using this func
protected void onSaveInstanceState(Bundle outState){ // code in here}
- take data using this func
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState){ // code in here}
- use appropriate mets for data type (e.g
putInt
andgetInt
;putBoolean
andgetBoolean
)
- use appropriate mets for data type (e.g
This was intentionally left blank.
Check Credits
This was intentionally left blank.
This exercise was done using this tutorial