Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ui changes #28

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".Gameplay"/>
<activity android:name=".activities.Gameplay" />
<activity android:name=".activities.PlayWithFriendActivity" />
<activity android:name=".activities.HomePageActivity">

Expand All @@ -21,8 +20,5 @@
</intent-filter>
</activity>

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.bebetterprogrammer.tictactoe.activities

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.bebetterprogrammer.tictactoe.BuildConfig
import com.bebetterprogrammer.tictactoe.R
import kotlinx.android.synthetic.main.activity_gameplay.*
import kotlinx.android.synthetic.main.activity_gameplay.appBottomLine
import kotlinx.android.synthetic.main.activity_home_page.*

class Gameplay : AppCompatActivity() {
var turn: Int = 0
var first: Int = 0
var gameState = arrayOf(2, 2, 2, 2, 2, 2, 2, 2, 2)

// 0 = O 1 = X 2 = blank
var winPosition = arrayOf(
arrayOf(0, 1, 2), arrayOf(3, 4, 5), arrayOf(6, 7, 8), arrayOf(0, 3, 6),
arrayOf(1, 4, 7), arrayOf(2, 5, 8), arrayOf(0, 4, 8), arrayOf(2, 4, 6)
)
var won = 0
fun PlayerClick(view: View) {
val img = view as ImageView
val tappedImage = img.getTag().toString().toInt()
if (gameState[tappedImage] == 2 && won == 0) {
gameState[tappedImage] = turn
img.setTranslationY(-1000f)
if (turn == 0) {
img.setImageResource(R.drawable.ic_circle_secondary)
} else if (turn == 1) {
img.setImageResource(R.drawable.ic_cross_yellow)
}
turn++
turn %= 2
img.animate().translationYBy(1000f).setDuration(100)
}
for (winPosition in winPosition) {
if (gameState[winPosition[0]] == gameState[winPosition[1]] && gameState[winPosition[1]] == gameState[winPosition[2]] && gameState[winPosition[0]] != 2) {
// won
if (turn == 1) {
if (won == 0) {
won = 1
var p1 = p1_winning.text.toString().toInt()
p1++
p1_winning.text = p1.toString()
player1_trophy.setImageResource(R.drawable.ic_trophy_golden)
}
} else {
if (won == 0) {
won = 1
var p2 = p2_winning.text.toString().toInt()
p2++
p2_winning.text = p2.toString()
player2_trophy.setImageResource(R.drawable.ic_trophy_golden)
}
}
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_gameplay)

val versionName = BuildConfig.VERSION_NAME
appBottomLine.text = "Designed @ bebetterprogrammer.com | v$versionName"

val intent = getIntent()
val P1 = intent.getStringExtra("Player1")
val P2 = intent.getStringExtra("Player2")
val Player = intent.getIntExtra("Player", 0)
Player1.text = P1
Player2.text = P2
if (Player == 0) {
first = 0
turn = 0
} else if (Player == 1) {
turn = 1
first = 1
}
quit.setOnClickListener {
val intent = Intent(this, HomePageActivity::class.java)
startActivity(intent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.bebetterprogrammer.tictactoe.BuildConfig
import com.bebetterprogrammer.tictactoe.R
import kotlinx.android.synthetic.main.activity_home_page.*

Expand All @@ -12,10 +13,10 @@ class HomePageActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home_page)

playWithJarvis.setOnClickListener {
val versionName = BuildConfig.VERSION_NAME
appBottomLine.text = "Designed @ bebetterprogrammer.com | v$versionName"

// val i = Intent(this, PlayWithFriendActivity::class.java)
// startActivity(i)
playWithJarvis.setOnClickListener {

val toast = Toast.makeText(
applicationContext,
Expand All @@ -28,13 +29,6 @@ class HomePageActivity : AppCompatActivity() {

val i = Intent(this, PlayWithFriendActivity::class.java)
startActivity(i)

val toast = Toast.makeText(
applicationContext,
"Play with Your FRIEND😀",
Toast.LENGTH_SHORT
)
toast.show()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,71 @@ import android.widget.EditText
import android.widget.ImageButton
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.bebetterprogrammer.tictactoe.Gameplay
import com.bebetterprogrammer.tictactoe.BuildConfig
import com.bebetterprogrammer.tictactoe.R
import kotlinx.android.synthetic.main.activity_play_with_friend.*

class PlayWithFriendActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_play_with_friend)

var flag: Int = 0
val p1 = findViewById<EditText>(R.id.player_one)
val p2 = findViewById<EditText>(R.id.player_two)
val btnPlay = findViewById<Button>(R.id.play)
val versionName = BuildConfig.VERSION_NAME
appBottomLine.text = "Designed @ bebetterprogrammer.com | v$versionName"

val circle = findViewById<ImageButton>(R.id.circle)
circle.setOnClickListener(View.OnClickListener {
flag = 0
})
var flag: Int = 0
val p1 = findViewById<EditText>(R.id.player_one)
val p2 = findViewById<EditText>(R.id.player_two)
val btnPlay = findViewById<Button>(R.id.play)

val cross = findViewById<ImageButton>(R.id.cross)
cross.setOnClickListener(View.OnClickListener {
flag = 1
})
val circle = findViewById<ImageButton>(R.id.circle)
val cross = findViewById<ImageButton>(R.id.cross)

btnPlay.setOnClickListener(View.OnClickListener {
if (TextUtils.isEmpty(p1.text) || TextUtils.isEmpty(p2.text)) {
if (TextUtils.isEmpty(p1.text) && TextUtils.isEmpty(p2.text)) {
Toast.makeText(this, "Enter Player Name", Toast.LENGTH_SHORT).show()
} else if (TextUtils.isEmpty(p1.text)) {
Toast.makeText(this, "Enter Player_1 Name", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "Enter Player_2 Name", Toast.LENGTH_SHORT).show()
}
circle.setImageDrawable(resources.getDrawable(R.drawable.ic_circle_secondary))

circle.setOnClickListener(View.OnClickListener {
cross.setImageDrawable(resources.getDrawable(R.drawable.ic_cross_white))
circle.setImageDrawable(resources.getDrawable(R.drawable.ic_circle_secondary))
flag = 0
})

cross.setOnClickListener(View.OnClickListener {
circle.setImageDrawable(resources.getDrawable(R.drawable.ic_circle_white))
cross.setImageDrawable(resources.getDrawable(R.drawable.ic_cross_secondary))
flag = 1
})

btnPlay.setOnClickListener(View.OnClickListener {
if (TextUtils.isEmpty(p1.text) || TextUtils.isEmpty(p2.text)) {
if (TextUtils.isEmpty(p1.text) && TextUtils.isEmpty(p2.text)) {
Toast.makeText(this, "Enter Player Name", Toast.LENGTH_SHORT).show()
} else if (TextUtils.isEmpty(p1.text)) {
Toast.makeText(this, "Enter Player_1 Name", Toast.LENGTH_SHORT).show()
} else {
if (flag == 0) {
Toast.makeText(this, " " + p1.text + " Move First", Toast.LENGTH_SHORT).show()
val intent = Intent(this, Gameplay::class.java)
intent.putExtra("Player1", p1.text.toString())
intent.putExtra("Player2", p2.text.toString())
intent.putExtra("Player", 0)
startActivity(intent)
} else if (flag == 1) {
Toast.makeText(this, " " + p2.text + " Move First", Toast.LENGTH_SHORT).show()
val intent = Intent(this, Gameplay::class.java)
intent.putExtra("Player1", p1.text.toString())
intent.putExtra("Player2", p2.text.toString())
intent.putExtra("Player", 1)
startActivity(intent)
}
Toast.makeText(this, "Enter Player_2 Name", Toast.LENGTH_SHORT).show()
}
} else {
if (flag == 0) {
Toast.makeText(this, " " + p1.text + " Move First", Toast.LENGTH_SHORT).show()
val intent = Intent(this, Gameplay::class.java)
intent.putExtra("Player1", p1.text.toString())
intent.putExtra("Player2", p2.text.toString())
intent.putExtra("Player", 0)
startActivity(intent)
} else if (flag == 1) {
Toast.makeText(this, " " + p2.text + " Move First", Toast.LENGTH_SHORT).show()
val intent = Intent(this, Gameplay::class.java)
intent.putExtra("Player1", p1.text.toString())
intent.putExtra("Player2", p2.text.toString())
intent.putExtra("Player", 1)
startActivity(intent)
}
})
var btnQuit = findViewById(R.id.quit) as Button
btnQuit.setOnClickListener(View.OnClickListener {
finish()
})
}
}
})
var btnQuit = findViewById(R.id.quit) as Button
btnQuit.setOnClickListener(View.OnClickListener {
finish()
})
}
}
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_circle_secondary.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="28"
android:viewportHeight="28">
<path
android:pathData="M14,14m-12,0a12,12 0,1 1,24 0a12,12 0,1 1,-24 0"
android:strokeWidth="3"
android:fillColor="#00000000"
android:strokeColor="#50E3C2"
android:fillType="evenOdd"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/ic_circle_white.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="28dp"
android:height="28dp"
android:width="32dp"
android:height="32dp"
android:viewportWidth="28"
android:viewportHeight="28">
<path
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_cross_secondary.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="28dp"
android:height="28dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M22.7789,1.2382C22.1116,0.571 21.0337,0.571 20.3665,1.2382L12,9.5876L3.6335,1.2211C2.9663,0.5539 1.8884,0.5539 1.2211,1.2211C0.5539,1.8884 0.5539,2.9663 1.2211,3.6335L9.5876,12L1.2211,20.3665C0.5539,21.0337 0.5539,22.1116 1.2211,22.7789C1.8884,23.4461 2.9663,23.4461 3.6335,22.7789L12,14.4124L20.3665,22.7789C21.0337,23.4461 22.1116,23.4461 22.7789,22.7789C23.4461,22.1116 23.4461,21.0337 22.7789,20.3665L14.4124,12L22.7789,3.6335C23.429,2.9834 23.429,1.8884 22.7789,1.2382Z"
android:strokeWidth="1"
android:fillColor="#50E3C2"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/ic_cross_white.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:width="28dp"
android:height="28dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_cross_yellow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M22.7789,1.2382C22.1116,0.571 21.0337,0.571 20.3665,1.2382L12,9.5876L3.6335,1.2211C2.9663,0.5539 1.8884,0.5539 1.2211,1.2211C0.5539,1.8884 0.5539,2.9663 1.2211,3.6335L9.5876,12L1.2211,20.3665C0.5539,21.0337 0.5539,22.1116 1.2211,22.7789C1.8884,23.4461 2.9663,23.4461 3.6335,22.7789L12,14.4124L20.3665,22.7789C21.0337,23.4461 22.1116,23.4461 22.7789,22.7789C23.4461,22.1116 23.4461,21.0337 22.7789,20.3665L14.4124,12L22.7789,3.6335C23.429,2.9834 23.429,1.8884 22.7789,1.2382Z"
android:strokeWidth="1"
android:fillColor="#F5A623"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/ic_game_board.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="158dp"
android:height="158dp"
android:width="220dp"
android:height="220dp"
android:viewportWidth="158"
android:viewportHeight="158">
<path
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/ic_setting_secondary.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="28dp"
android:viewportWidth="26"
android:viewportHeight="28">
<path
android:pathData="M22.7067,9.4667L21.7733,7.8533L20.08,8.5333L18.6667,9.1067L17.4533,8.1733C16.9333,7.7733 16.3867,7.4533 15.8133,7.2267L14.4,6.6533L14.1867,5.1467L13.9333,3.3333L12.0667,3.3333L11.8133,5.1333L11.6,6.64L10.1867,7.2267C9.64,7.4533 9.0933,7.7733 8.52,8.2L7.32,9.1067L5.92,8.5467L4.2267,7.8533L3.2933,9.4667L4.7333,10.5867L5.92,11.52L5.7333,13.0267C5.6933,13.4267 5.6667,13.7333 5.6667,14C5.6667,14.2667 5.6933,14.5733 5.7333,14.9733L5.92,16.48L4.7333,17.4133L3.2933,18.5333L4.2267,20.1467L5.92,19.4667L7.3333,18.8933L8.5467,19.8267C9.0667,20.2267 9.6133,20.5467 10.1867,20.7733L11.6,21.3467L11.8133,22.8533L12.0667,24.6667L13.92,24.6667L14.1733,22.8667L14.3867,21.36L15.8,20.7867C16.3467,20.56 16.8933,20.24 17.4667,19.8133L18.6667,18.9067L20.0533,19.4667L21.7467,20.1467L22.68,18.5333L21.24,17.4133L20.0533,16.48L20.24,14.9733C20.2933,14.56 20.3067,14.28 20.3067,14C20.3067,13.72 20.28,13.4267 20.24,13.0267L20.0533,11.52L21.24,10.5867L22.7067,9.4667ZM13,19.3333C10.0533,19.3333 7.6667,16.9467 7.6667,14C7.6667,11.0533 10.0533,8.6667 13,8.6667C15.9467,8.6667 18.3333,11.0533 18.3333,14C18.3333,16.9467 15.9467,19.3333 13,19.3333Z"
android:strokeAlpha="0.3"
android:strokeWidth="1"
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:strokeColor="#00000000"
android:fillAlpha="1"/>
<path
android:pathData="M22.9067,15.3067C22.96,14.88 23,14.4533 23,14C23,13.5467 22.96,13.12 22.9067,12.6933L25.72,10.4933C25.9733,10.2933 26.04,9.9333 25.88,9.64L23.2133,5.0267C23.0933,4.8133 22.8667,4.6933 22.6267,4.6933C22.5467,4.6933 22.4667,4.7067 22.4,4.7333L19.08,6.0667C18.3867,5.5333 17.64,5.0933 16.8267,4.76L16.32,1.2267C16.28,0.9067 16,0.6667 15.6667,0.6667L10.3333,0.6667C10,0.6667 9.72,0.9067 9.68,1.2267L9.1733,4.76C8.36,5.0933 7.6133,5.5467 6.92,6.0667L3.6,4.7333C3.52,4.7067 3.44,4.6933 3.36,4.6933C3.1333,4.6933 2.9067,4.8133 2.7867,5.0267L0.12,9.64C-0.0533,9.9333 0.0267,10.2933 0.28,10.4933L3.0933,12.6933C3.04,13.12 3,13.56 3,14C3,14.44 3.04,14.88 3.0933,15.3067L0.28,17.5067C0.0267,17.7067 -0.04,18.0667 0.12,18.36L2.7867,22.9733C2.9067,23.1867 3.1333,23.3067 3.3733,23.3067C3.4533,23.3067 3.5333,23.2933 3.6,23.2667L6.92,21.9333C7.6133,22.4667 8.36,22.9067 9.1733,23.24L9.68,26.7733C9.72,27.0933 10,27.3333 10.3333,27.3333L15.6667,27.3333C16,27.3333 16.28,27.0933 16.32,26.7733L16.8267,23.24C17.64,22.9067 18.3867,22.4533 19.08,21.9333L22.4,23.2667C22.48,23.2933 22.56,23.3067 22.64,23.3067C22.8667,23.3067 23.0933,23.1867 23.2133,22.9733L25.88,18.36C26.04,18.0667 25.9733,17.7067 25.72,17.5067L22.9067,15.3067ZM20.2667,13.0267C20.32,13.44 20.3333,13.72 20.3333,14C20.3333,14.28 20.3067,14.5733 20.2667,14.9733L20.08,16.48L21.2667,17.4133L22.7067,18.5333L21.7733,20.1467L20.08,19.4667L18.6933,18.9067L17.4933,19.8133C16.92,20.24 16.3733,20.56 15.8267,20.7867L14.4133,21.36L14.2,22.8667L13.9333,24.6667L12.0667,24.6667L11.8133,22.8667L11.6,21.36L10.1867,20.7867C9.6133,20.5467 9.08,20.24 8.5467,19.84L7.3333,18.9067L5.92,19.48L4.2267,20.16L3.2933,18.5467L4.7333,17.4267L5.92,16.4933L5.7333,14.9867C5.6933,14.5733 5.6667,14.2667 5.6667,14C5.6667,13.7333 5.6933,13.4267 5.7333,13.0267L5.92,11.52L4.7333,10.5867L3.2933,9.4667L4.2267,7.8533L5.92,8.5333L7.3067,9.0933L8.5067,8.1867C9.08,7.76 9.6267,7.44 10.1733,7.2133L11.5867,6.64L11.8,5.1333L12.0667,3.3333L13.92,3.3333L14.1733,5.1333L14.3867,6.64L15.8,7.2133C16.3733,7.4533 16.9067,7.76 17.44,8.16L18.6533,9.0933L20.0667,8.52L21.76,7.84L22.6933,9.4533L21.2667,10.5867L20.08,11.52L20.2667,13.0267ZM13,8.6667C10.0533,8.6667 7.6667,11.0533 7.6667,14C7.6667,16.9467 10.0533,19.3333 13,19.3333C15.9467,19.3333 18.3333,16.9467 18.3333,14C18.3333,11.0533 15.9467,8.6667 13,8.6667ZM13,16.6667C11.5333,16.6667 10.3333,15.4667 10.3333,14C10.3333,12.5333 11.5333,11.3333 13,11.3333C14.4667,11.3333 15.6667,12.5333 15.6667,14C15.6667,15.4667 14.4667,16.6667 13,16.6667Z"
android:strokeWidth="1"
android:fillColor="#0096C5"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/ic_trophy_golden.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="18dp"
android:height="18dp"
android:width="28dp"
android:height="28dp"
android:viewportWidth="18"
android:viewportHeight="18">
<path
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/ic_trophy_grey.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="18dp"
android:height="18dp"
android:width="28dp"
android:height="28dp"
android:viewportWidth="18"
android:viewportHeight="18">
<path
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/drawable/layout_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="5dp" />
<corners android:radius="6dp" />
<gradient
android:angle="0"
android:endColor="@color/colorPrimary"
android:startColor="@color/colorSecondary"
android:type="linear" />
</shape>
</item>
<item android:bottom="3dp"
android:left="3dp"
android:right="3dp"
android:top="3dp">
<item android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp">
<shape android:shape="rectangle">
<corners android:radius="5dp" />
<corners android:radius="4dp" />
<gradient
android:angle="0"
android:endColor="@color/buttonEndColor"
Expand Down
Loading