Match point + previous matches in table
This commit is contained in:
parent
7b2c35c5a6
commit
3a34e9a390
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -133,7 +133,7 @@ class MatchActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (it.ttsEnabled) {
|
if (it.ttsEnabled) {
|
||||||
if (it.matchFinished) {
|
if (it.matchFinished()) {
|
||||||
val (loser, winner) = it.players.sortedBy { player -> player.score }
|
val (loser, winner) = it.players.sortedBy { player -> player.score }
|
||||||
tts?.speak(
|
tts?.speak(
|
||||||
getString(
|
getString(
|
||||||
@ -156,16 +156,23 @@ class MatchActivity : AppCompatActivity() {
|
|||||||
TextToSpeech.QUEUE_FLUSH,
|
TextToSpeech.QUEUE_FLUSH,
|
||||||
hashMapOf(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID to "MessageId")
|
hashMapOf(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID to "MessageId")
|
||||||
)
|
)
|
||||||
|
if (it.matchPoint()) {
|
||||||
|
tts?.speak(
|
||||||
|
getString(R.string.match_point),
|
||||||
|
TextToSpeech.QUEUE_ADD,
|
||||||
|
hashMapOf(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID to "MessageId")
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it.matchFinished) endMatch()
|
if (it.matchFinished()) endMatch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateScore(view: View) {
|
fun updateScore(view: View) {
|
||||||
matchModel?.apply {
|
matchModel?.apply {
|
||||||
if (!matchFinished) {
|
if (!matchFinished()) {
|
||||||
for (side in 0..1) {
|
for (side in 0..1) {
|
||||||
if (view == buttons[side]) {
|
if (view == buttons[side]) {
|
||||||
updateScore(side)
|
updateScore(side)
|
||||||
|
@ -1,20 +1,17 @@
|
|||||||
package adrienmalin.pingpoints
|
package adrienmalin.pingpoints
|
||||||
|
|
||||||
import android.arch.lifecycle.LiveData
|
|
||||||
import android.arch.lifecycle.MutableLiveData
|
|
||||||
import android.arch.lifecycle.ViewModel
|
import android.arch.lifecycle.ViewModel
|
||||||
|
|
||||||
|
|
||||||
class MatchModel : ViewModel() {
|
class MatchModel : ViewModel() {
|
||||||
var matchStarted: Boolean = false
|
var matchStarted: Boolean = false
|
||||||
var matchFinished: Boolean = false
|
|
||||||
var players: List<Player> = emptyList()
|
var players: List<Player> = emptyList()
|
||||||
var serviceSide: Int = 0
|
var serviceSide: Int = 0
|
||||||
var relaunchSide: Int = 1
|
var relaunchSide: Int = 1
|
||||||
var ttsEnabled: Boolean = false
|
var ttsEnabled: Boolean = false
|
||||||
var sttEnabled: Boolean = false
|
var sttEnabled: Boolean = false
|
||||||
var playId: Int = 0
|
var playId: Int = 0
|
||||||
var history: MutableList<Play> = ArrayList()
|
var history: MutableList<Point> = ArrayList()
|
||||||
|
|
||||||
fun startMatch(player1Name: String, player2Name:String, starterId: Int, enableTTS: Boolean, enableSTT: Boolean) {
|
fun startMatch(player1Name: String, player2Name:String, starterId: Int, enableTTS: Boolean, enableSTT: Boolean) {
|
||||||
matchStarted = true
|
matchStarted = true
|
||||||
@ -36,14 +33,20 @@ class MatchModel : ViewModel() {
|
|||||||
serviceSide = relaunchSide.also { relaunchSide = serviceSide }
|
serviceSide = relaunchSide.also { relaunchSide = serviceSide }
|
||||||
}
|
}
|
||||||
saveState()
|
saveState()
|
||||||
|
}
|
||||||
|
|
||||||
// Is match finished?
|
fun matchFinished(): Boolean {
|
||||||
val (minScore, maxScore) = players.map { it.score }.sorted()
|
val (minScore, maxScore) = players.map { it.score }.sorted()
|
||||||
if ((maxScore >= 11) and (maxScore - minScore >= 2)) matchFinished = true
|
return (maxScore >= 11) and (maxScore - minScore >= 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun matchPoint(): Boolean {
|
||||||
|
val (minScore, maxScore) = players.map { it.score }.sorted()
|
||||||
|
return (maxScore >= 10) and (maxScore - minScore >= 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveState() {
|
fun saveState() {
|
||||||
val play = Play(players.map { it.score }, serviceSide)
|
val play = Point(players.map { it.score }, serviceSide)
|
||||||
if (playId == history.size) {
|
if (playId == history.size) {
|
||||||
history.add(play)
|
history.add(play)
|
||||||
} else {
|
} else {
|
||||||
@ -53,7 +56,6 @@ class MatchModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun undo() {
|
fun undo() {
|
||||||
matchFinished = false
|
|
||||||
playId--
|
playId--
|
||||||
reloadState()
|
reloadState()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package adrienmalin.pingpoints
|
package adrienmalin.pingpoints
|
||||||
|
|
||||||
data class Play (
|
data class Point (
|
||||||
val score: List<Int>,
|
val score: List<Int>,
|
||||||
val serviceSide: Int
|
val serviceSide: Int
|
||||||
)
|
)
|
@ -192,7 +192,6 @@ class StarterNameActivity : AppCompatActivity() {
|
|||||||
putExtra(
|
putExtra(
|
||||||
"starterId",
|
"starterId",
|
||||||
when(radioStarterId) {
|
when(radioStarterId) {
|
||||||
R.id.radioPlayer1Starts -> 0
|
|
||||||
R.id.radioPlayer2Starts -> 1
|
R.id.radioPlayer2Starts -> 1
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import android.os.Bundle
|
|||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.support.v7.app.AppCompatDelegate
|
import android.support.v7.app.AppCompatDelegate
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import android.widget.GridView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ class VictoryActivity : AppCompatActivity() {
|
|||||||
putString(
|
putString(
|
||||||
"previousMatches",
|
"previousMatches",
|
||||||
getString(
|
getString(
|
||||||
R.string.score_names,
|
R.string.result,
|
||||||
it.player1Name,
|
it.player1Name,
|
||||||
it.score,
|
it.score,
|
||||||
it.player2Name
|
it.player2Name
|
||||||
@ -50,8 +52,16 @@ class VictoryActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
// UpdateUI
|
// UpdateUI
|
||||||
findViewById<TextView>(R.id.congrats).text = getString(R.string.congrats, it.winnerName)
|
findViewById<TextView>(R.id.congrats).text = getString(R.string.congrats, it.winnerName)
|
||||||
findViewById<TextView>(R.id.scoreNames).text = getString(R.string.score_names, it.player1Name, it.score, it.player2Name)
|
findViewById<GridView>(R.id.resultGrid).adapter = ArrayAdapter<String>(
|
||||||
findViewById<TextView>(R.id.previousMatches).text = it.previousMatches
|
this,
|
||||||
|
android.R.layout.simple_list_item_1,
|
||||||
|
arrayOf(it.player1Name, it.score, it.player2Name)
|
||||||
|
)
|
||||||
|
findViewById<GridView>(R.id.previousMatchesGrid).adapter = ArrayAdapter<String>(
|
||||||
|
this,
|
||||||
|
android.R.layout.simple_list_item_1,
|
||||||
|
it.previousMatches.split("\t|\n".toRegex())
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,25 +34,25 @@
|
|||||||
android:layout_marginRight="8dp" android:layout_marginStart="8dp"
|
android:layout_marginRight="8dp" android:layout_marginStart="8dp"
|
||||||
app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp"
|
app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp"
|
||||||
android:text="@string/congrats"/>
|
android:text="@string/congrats"/>
|
||||||
<TextView
|
<GridView
|
||||||
android:text="@string/score_names"
|
android:layout_width="0dp"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/scoreNames" android:layout_marginTop="8dp"
|
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/congrats" app:layout_constraintEnd_toEndOf="parent"
|
android:layout_marginRight="8dp" app:layout_constraintStart_toStartOf="parent"
|
||||||
android:layout_marginEnd="8dp" android:layout_marginRight="8dp"
|
android:layout_marginLeft="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp"
|
||||||
app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp"
|
app:layout_constraintTop_toBottomOf="@+id/congrats" android:id="@+id/resultGrid"
|
||||||
android:layout_marginStart="8dp" android:textAppearance="@style/TextAppearance.AppCompat.Large"/>
|
android:numColumns="3"/>
|
||||||
<TextView
|
<TextView
|
||||||
android:text="@string/previous_matches"
|
android:text="@string/previous_matches"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/textView3" android:layout_marginTop="24dp"
|
android:id="@+id/textView3"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/scoreNames" app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:layout_marginEnd="8dp" android:layout_marginRight="8dp"
|
android:layout_marginEnd="8dp" android:layout_marginRight="8dp"
|
||||||
app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="7dp"
|
app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="7dp"
|
||||||
android:layout_marginStart="7dp"
|
android:layout_marginStart="7dp"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAllCaps="true"/>
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAllCaps="true"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/resultGrid" android:layout_marginTop="32dp"/>
|
||||||
<Button
|
<Button
|
||||||
android:text="@string/new_match"
|
android:text="@string/new_match"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -69,16 +69,14 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"
|
||||||
android:layout_marginLeft="8dp" android:layout_marginStart="8dp"
|
android:layout_marginLeft="8dp" android:layout_marginStart="8dp"
|
||||||
android:drawableStart="@drawable/ic_share" android:onClick="share"/>
|
android:drawableStart="@drawable/ic_share" android:onClick="share"/>
|
||||||
<TextView
|
<GridView
|
||||||
android:text="TextView"
|
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp" app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:id="@+id/previousMatches" app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintStart_toStartOf="parent" android:layout_marginTop="8dp"
|
||||||
android:layout_marginEnd="8dp"
|
app:layout_constraintTop_toBottomOf="@+id/textView3" android:layout_marginLeft="8dp"
|
||||||
android:layout_marginRight="8dp" app:layout_constraintStart_toStartOf="parent"
|
android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:layout_marginRight="8dp"
|
||||||
android:layout_marginLeft="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp"
|
android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textView3" android:layout_marginBottom="8dp"
|
android:numColumns="5" android:id="@+id/previousMatchesGrid" android:clickable="false"/>
|
||||||
android:gravity="center_horizontal" app:layout_constraintBottom_toBottomOf="parent"/>
|
|
||||||
|
|
||||||
</android.support.constraint.ConstraintLayout>
|
</android.support.constraint.ConstraintLayout>
|
||||||
|
|
||||||
|
@ -37,4 +37,5 @@ Vous pouvez à tout moment changer la permission dans les paramètres Android."
|
|||||||
<string name="share_subject">Match Ping Points : %s contre %s</string>
|
<string name="share_subject">Match Ping Points : %s contre %s</string>
|
||||||
<string name="share_message">"%s contre %s:\n%s a gagné par %s\nPing Points est disponible sur Google Play\n "</string>
|
<string name="share_message">"%s contre %s:\n%s a gagné par %s\nPing Points est disponible sur Google Play\n "</string>
|
||||||
<string name="score_only">%d - %d</string>
|
<string name="score_only">%d - %d</string>
|
||||||
|
<string name="match_point">Balle de match</string>
|
||||||
</resources>
|
</resources>
|
@ -38,9 +38,10 @@
|
|||||||
<string name="previous_matches">Previous matches</string>
|
<string name="previous_matches">Previous matches</string>
|
||||||
<string name="new_match">New match</string>
|
<string name="new_match">New match</string>
|
||||||
<string name="share">Share</string>
|
<string name="share">Share</string>
|
||||||
<string name="score_names" translatable="false">%s %s %s</string>
|
<string name="result" translatable="false">"%s\t%s\t%s"</string>
|
||||||
<string name="victory_speech">%s wins by %d to %d.</string>
|
<string name="victory_speech">%s wins by %d to %d.</string>
|
||||||
<string name="share_subject">Ping Points Match: %s vs. %s</string>
|
<string name="share_subject">Ping Points Match: %s vs. %s</string>
|
||||||
<string name="share_message">%s vs. %s:\n%s won by %s\nGet Ping Points on Google Play</string>
|
<string name="share_message">%s vs. %s:\n%s won by %s\nGet Ping Points on Google Play</string>
|
||||||
<string name="score_only">%d - %d</string>
|
<string name="score_only">"%d\t-\t%d"</string>
|
||||||
|
<string name="match_point">Match point</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user