Skip to content

Commit a45a2b3

Browse files
author
hussienalrubaye
committed
tic tac toy local
1 parent 8b2f60f commit a45a2b3

39 files changed

+820
-1
lines changed

Android/Assets/mapApp/bulbasaur.png

13.4 KB
Loading

Android/Assets/mapApp/charmander.png

16.3 KB
Loading

Android/Assets/mapApp/mario.png

17.4 KB
Loading

Android/Assets/mapApp/squirtle.png

15.6 KB
Loading

Android/FindMyAge/StartUp/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

Android/Tic Tac Toy Game/Tic Tac Toy Local/StartUp/.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Android/Tic Tac Toy Game/Tic Tac Toy Local/StartUp/.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Android/Tic Tac Toy Game/Tic Tac Toy Local/StartUp/.idea/misc.xml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Android/Tic Tac Toy Game/Tic Tac Toy Local/StartUp/.idea/modules.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Android/Tic Tac Toy Game/Tic Tac Toy Local/StartUp/.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
android {
5+
compileSdkVersion 25
6+
buildToolsVersion "25.0.3"
7+
defaultConfig {
8+
applicationId "com.hussein.tictactoylocal"
9+
minSdkVersion 17
10+
targetSdkVersion 25
11+
versionCode 1
12+
versionName "1.0"
13+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
compile fileTree(dir: 'libs', include: ['*.jar'])
25+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26+
exclude group: 'com.android.support', module: 'support-annotations'
27+
})
28+
compile 'com.android.support:appcompat-v7:25.3.1'
29+
testCompile 'junit:junit:4.12'
30+
compile 'com.android.support.constraint:constraint-layout:1.0.2'
31+
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
32+
}
33+
repositories {
34+
mavenCentral()
35+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/hussienalrubaye/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.hussein.startup;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.hussein.startup", appContext.getPackageName());
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hussein.startup">
3+
4+
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
5+
android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round"
6+
android:supportsRtl="true" android:theme="@style/AppTheme">
7+
<activity android:name=".MainActivity">
8+
<intent-filter>
9+
<action android:name="android.intent.action.MAIN" />
10+
11+
<category android:name="android.intent.category.LAUNCHER" />
12+
</intent-filter>
13+
</activity>
14+
</application>
15+
16+
</manifest>
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
package com.hussein.startup
2+
3+
import android.graphics.Color
4+
import android.support.v7.app.AppCompatActivity
5+
import android.os.Bundle
6+
import android.view.View
7+
import android.widget.Button
8+
import android.widget.Toast
9+
import kotlinx.android.synthetic.main.activity_main.*
10+
import java.util.*
11+
12+
class MainActivity : AppCompatActivity() {
13+
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
setContentView(R.layout.activity_main)
17+
}
18+
19+
20+
protected fun buClick(view:View){
21+
val buSelected= view as Button
22+
var cellID=0
23+
when(buSelected.id){
24+
R.id.bu1-> cellID=1
25+
R.id.bu2-> cellID=2
26+
R.id.bu3-> cellID=3
27+
R.id.bu4-> cellID=4
28+
R.id.bu5-> cellID=5
29+
R.id.bu6-> cellID=6
30+
R.id.bu7-> cellID=7
31+
R.id.bu8-> cellID=8
32+
R.id.bu9-> cellID=9
33+
34+
}
35+
// Toast.makeText(this,"ID:"+ cellID, Toast.LENGTH_LONG).show()
36+
37+
PlayGame(cellID,buSelected)
38+
}
39+
40+
var player1=ArrayList<Int>()
41+
var player2=ArrayList<Int>()
42+
var ActivePlayer=1
43+
44+
fun PlayGame(cellID:Int,buSelected:Button){
45+
46+
if(ActivePlayer==1){
47+
buSelected.text="X"
48+
buSelected.setBackgroundResource(R.color.blue)
49+
player1.add(cellID)
50+
ActivePlayer=2
51+
AutoPlay()
52+
}else{
53+
buSelected.text="O"
54+
buSelected.setBackgroundResource(R.color.darkgreen)
55+
player2.add(cellID)
56+
ActivePlayer=1
57+
}
58+
59+
60+
buSelected.isEnabled=false
61+
CheckWiner()
62+
}
63+
64+
65+
66+
fun CheckWiner(){
67+
var winer=-1
68+
69+
// row 1
70+
if(player1.contains(1) && player1.contains(2) && player1.contains(3)){
71+
winer=1
72+
}
73+
if(player2.contains(1) && player2.contains(2) && player2.contains(3)){
74+
winer=2
75+
}
76+
77+
78+
// row 2
79+
if(player1.contains(4) && player1.contains(5) && player1.contains(6)){
80+
winer=1
81+
}
82+
if(player2.contains(4) && player2.contains(5) && player2.contains(6)){
83+
winer=2
84+
}
85+
86+
87+
88+
89+
// row 3
90+
if(player1.contains(7) && player1.contains(8) && player1.contains(9)){
91+
winer=1
92+
}
93+
if(player2.contains(7) && player2.contains(8) && player2.contains(9)){
94+
winer=2
95+
}
96+
97+
98+
99+
// col 1
100+
if(player1.contains(1) && player1.contains(4) && player1.contains(7)){
101+
winer=1
102+
}
103+
if(player2.contains(1) && player2.contains(4) && player2.contains(7)){
104+
winer=2
105+
}
106+
107+
108+
109+
// col 2
110+
if(player1.contains(2) && player1.contains(5) && player1.contains(8)){
111+
winer=1
112+
}
113+
if(player2.contains(2) && player2.contains(5) && player2.contains(8)){
114+
winer=2
115+
}
116+
117+
118+
// col 3
119+
if(player1.contains(3) && player1.contains(6) && player1.contains(9)){
120+
winer=1
121+
}
122+
if(player2.contains(3) && player2.contains(6) && player2.contains(9)){
123+
winer=2
124+
}
125+
126+
127+
if( winer != -1){
128+
129+
if (winer==1){
130+
Toast.makeText(this," Player 1 win the game", Toast.LENGTH_LONG).show()
131+
}else{
132+
Toast.makeText(this," Player 2 win the game", Toast.LENGTH_LONG).show()
133+
134+
}
135+
136+
}
137+
138+
}
139+
140+
141+
fun AutoPlay(){
142+
143+
var emptyCells=ArrayList<Int>()
144+
for ( cellID in 1..9){
145+
146+
if(!( player1.contains(cellID) || player2.contains(cellID))) {
147+
emptyCells.add(cellID)
148+
}
149+
}
150+
151+
152+
val r=Random()
153+
val randIndex=r.nextInt(emptyCells.size-0)+0
154+
val cellID= emptyCells[randIndex]
155+
156+
var buSelect:Button?
157+
when(cellID){
158+
1-> buSelect=bu1
159+
2-> buSelect=bu2
160+
3-> buSelect=bu3
161+
4-> buSelect=bu4
162+
5-> buSelect=bu5
163+
6-> buSelect=bu6
164+
7-> buSelect=bu7
165+
8-> buSelect=bu8
166+
9-> buSelect=bu9
167+
else->{
168+
buSelect=bu1
169+
}
170+
}
171+
172+
PlayGame(cellID,buSelect)
173+
174+
}
175+
176+
177+
}

0 commit comments

Comments
 (0)