clean code
This commit is contained in:
parent
00199369e8
commit
c78e159dc6
4
.gitignore
vendored
4
.gitignore
vendored
@ -10,3 +10,7 @@
|
|||||||
/captures
|
/captures
|
||||||
.externalNativeBuild
|
.externalNativeBuild
|
||||||
*.ser
|
*.ser
|
||||||
|
*.ser
|
||||||
|
*.apk
|
||||||
|
*.apk
|
||||||
|
*.ser
|
||||||
|
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
Binary file not shown.
@ -65,7 +65,7 @@ class MatchActivity : AppCompatActivity() {
|
|||||||
findViewById(R.id.imgService1)
|
findViewById(R.id.imgService1)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Init or restore ViewModel
|
// Init ViewModel
|
||||||
matchModel = ViewModelProviders.of(this).get(MatchModel::class.java)
|
matchModel = ViewModelProviders.of(this).get(MatchModel::class.java)
|
||||||
matchModel?.apply {
|
matchModel?.apply {
|
||||||
if (!matchStarted) {
|
if (!matchStarted) {
|
||||||
@ -172,10 +172,9 @@ class MatchActivity : AppCompatActivity() {
|
|||||||
fun updateScore(view: View) {
|
fun updateScore(view: View) {
|
||||||
matchModel?.apply {
|
matchModel?.apply {
|
||||||
if (!matchFinished) {
|
if (!matchFinished) {
|
||||||
for (side in 0..1) {
|
when(view) {
|
||||||
if (view == buttons[side]) {
|
buttons[0] -> updateScore(players[0])
|
||||||
updateScore(players[side])
|
buttons[1] -> updateScore(players[1])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
updateUI()
|
updateUI()
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ class MatchModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateScore(scorer: Player) {
|
fun updateScore(scorer: Player) {
|
||||||
pointId++
|
|
||||||
scorer.score++
|
scorer.score++
|
||||||
if ((players.sumBy { it.score } % 2 == 0) or (players.all { it.score >= 10 })) {
|
if ((players.sumBy { it.score } % 2 == 0) or (players.all { it.score >= 10 })) {
|
||||||
serviceSide = relaunchSide.also { relaunchSide = serviceSide }
|
serviceSide = relaunchSide.also { relaunchSide = serviceSide }
|
||||||
@ -46,7 +45,7 @@ class MatchModel : ViewModel() {
|
|||||||
|
|
||||||
fun saveState() {
|
fun saveState() {
|
||||||
val point = Point(players.map { it.score }, serviceSide)
|
val point = Point(players.map { it.score }, serviceSide)
|
||||||
if (pointId == history.size) {
|
if (++pointId == history.size) {
|
||||||
history.add(point)
|
history.add(point)
|
||||||
} else {
|
} else {
|
||||||
history[pointId] = point
|
history[pointId] = point
|
||||||
@ -54,7 +53,7 @@ class MatchModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun undo() {
|
fun undo() {
|
||||||
history[pointId--].let{
|
history[pointId--].let {
|
||||||
players.zip(it.score).forEach{(player, score) -> player.score = score}
|
players.zip(it.score).forEach{(player, score) -> player.score = score}
|
||||||
serviceSide = it.serviceSide
|
serviceSide = it.serviceSide
|
||||||
relaunchSide = when(serviceSide) {
|
relaunchSide = when(serviceSide) {
|
||||||
|
@ -44,8 +44,7 @@ class StarterNameActivity : AppCompatActivity() {
|
|||||||
enableSttSwitch = findViewById(R.id.enableSttSwitch)
|
enableSttSwitch = findViewById(R.id.enableSttSwitch)
|
||||||
|
|
||||||
// Restore previous data
|
// Restore previous data
|
||||||
previousMatch = getPreferences(Context.MODE_PRIVATE)
|
previousMatch = getPreferences(Context.MODE_PRIVATE).apply {
|
||||||
previousMatch?.apply {
|
|
||||||
previousPlayers = getStringSet("previousPlayers", emptySet())
|
previousPlayers = getStringSet("previousPlayers", emptySet())
|
||||||
val adapter = ArrayAdapter<String>(
|
val adapter = ArrayAdapter<String>(
|
||||||
this@StarterNameActivity,
|
this@StarterNameActivity,
|
||||||
|
@ -25,10 +25,8 @@ class VictoryActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
val previousMatch = getPreferences(Context.MODE_PRIVATE)
|
val previousMatch = getPreferences(Context.MODE_PRIVATE)
|
||||||
|
|
||||||
// Init victoryModel
|
// Init VictoryModel
|
||||||
victoryModel = ViewModelProviders.of(this).get(VictoryModel::class.java)
|
victoryModel = ViewModelProviders.of(this).get(VictoryModel::class.java).apply {
|
||||||
|
|
||||||
victoryModel?.apply {
|
|
||||||
if (!matchFinished) {
|
if (!matchFinished) {
|
||||||
matchFinished = true
|
matchFinished = true
|
||||||
winnerName = intent.getStringExtra("winnerName")
|
winnerName = intent.getStringExtra("winnerName")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user