From 44c4c73feb1d350bbb0ecbdcce06bc4dddc4d078 Mon Sep 17 00:00:00 2001 From: cmclark00 Date: Thu, 27 Mar 2025 08:51:10 -0400 Subject: [PATCH] Add combo system that tracks consecutive line clears with next piece --- app/src/main/java/com/mintris/MainActivity.kt | 1 + .../main/java/com/mintris/game/TitleScreen.kt | 26 ++++++++++++++++++- .../main/java/com/mintris/model/GameBoard.kt | 26 ++++++++++++++----- app/src/main/res/layout/activity_main.xml | 9 +++++++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/mintris/MainActivity.kt b/app/src/main/java/com/mintris/MainActivity.kt index 25f57ba..d6eac7e 100644 --- a/app/src/main/java/com/mintris/MainActivity.kt +++ b/app/src/main/java/com/mintris/MainActivity.kt @@ -203,6 +203,7 @@ class MainActivity : AppCompatActivity() { binding.scoreText.text = score.toString() binding.currentLevelText.text = level.toString() binding.linesText.text = lines.toString() + binding.comboText.text = gameBoard.getCombo().toString() // Force redraw of next piece preview binding.nextPieceView.invalidate() diff --git a/app/src/main/java/com/mintris/game/TitleScreen.kt b/app/src/main/java/com/mintris/game/TitleScreen.kt index 0c87891..379caaf 100644 --- a/app/src/main/java/com/mintris/game/TitleScreen.kt +++ b/app/src/main/java/com/mintris/game/TitleScreen.kt @@ -10,6 +10,8 @@ import android.view.MotionEvent import android.view.View import java.util.Random import android.util.Log +import com.mintris.model.HighScoreManager +import com.mintris.model.HighScore class TitleScreen @JvmOverloads constructor( context: Context, @@ -21,6 +23,7 @@ class TitleScreen @JvmOverloads constructor( private val glowPaint = Paint() private val titlePaint = Paint() private val promptPaint = Paint() + private val highScorePaint = Paint() private val cellSize = 30f private val random = Random() private var width = 0 @@ -108,6 +111,16 @@ class TitleScreen @JvmOverloads constructor( alpha = 180 } + // High scores text settings + highScorePaint.apply { + color = Color.WHITE + textSize = 35f + textAlign = Paint.Align.CENTER + typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL) + isAntiAlias = true + alpha = 200 + } + // General paint settings for tetrominos (white) paint.apply { color = Color.WHITE @@ -239,8 +252,19 @@ class TitleScreen @JvmOverloads constructor( val titleY = height * 0.4f canvas.drawText("mintris", width / 2f, titleY, titlePaint) + // Draw high scores + val highScoreManager = HighScoreManager(context) + val highScores: List = highScoreManager.getHighScores() + val highScoreY = height * 0.5f + if (highScores.isNotEmpty()) { + highScores.forEachIndexed { index: Int, score: HighScore -> + val y = highScoreY + (index * 35f) + canvas.drawText("${index + 1}. ${score.name}: ${score.score}", width / 2f, y, highScorePaint) + } + } + // Draw "touch to start" prompt - canvas.drawText("touch to start", width / 2f, height * 0.6f, promptPaint) + canvas.drawText("touch to start", width / 2f, height * 0.7f, promptPaint) // Request another frame invalidate() diff --git a/app/src/main/java/com/mintris/model/GameBoard.kt b/app/src/main/java/com/mintris/model/GameBoard.kt index 196e3f2..3119971 100644 --- a/app/src/main/java/com/mintris/model/GameBoard.kt +++ b/app/src/main/java/com/mintris/model/GameBoard.kt @@ -37,6 +37,7 @@ class GameBoard( private var lastClearWasTetris = false private var lastClearWasPerfect = false private var lastClearWasAllClear = false + private var lastPieceClearedLines = false // Track if the last piece placed cleared lines // Animation state var linesToClear = mutableListOf() @@ -326,6 +327,18 @@ class GameBoard( calculateScore(shiftAmount) }.start() } + + // Update combo based on whether this piece cleared lines + if (shiftAmount > 0) { + if (lastPieceClearedLines) { + combo++ + } else { + combo = 1 // Start new combo + } + } else { + combo = 0 // Reset combo if no lines cleared + } + lastPieceClearedLines = shiftAmount > 0 } /** @@ -397,13 +410,6 @@ class GameBoard( score += finalScore }.start() - // Update combo counter - if (clearedLines > 0) { - combo++ - } else { - combo = 0 - } - // Update line clear state lastClearWasTetris = clearedLines == 4 lastClearWasPerfect = isPerfectClear @@ -528,6 +534,7 @@ class GameBoard( lastClearWasTetris = false lastClearWasPerfect = false lastClearWasAllClear = false + lastPieceClearedLines = false // Reset piece state holdPiece = null @@ -545,4 +552,9 @@ class GameBoard( private fun clearLines(): Int { return linesToClear.size // Return the number of lines that will be cleared } + + /** + * Get the current combo count + */ + fun getCombo(): Int = combo } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d83c8aa..7271d89 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -83,6 +83,15 @@ android:textSize="24sp" android:fontFamily="sans-serif-light" tools:text="Lines: 0" /> + +