mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-18 02:25:21 +01:00
Fix Kotlin compilation errors and related layout issues
This commit is contained in:
parent
22fd887037
commit
ddb2707f1a
5 changed files with 66 additions and 19 deletions
|
@ -471,7 +471,7 @@ class MainActivity : AppCompatActivity(),
|
||||||
score = score,
|
score = score,
|
||||||
lines = gameBoard.lines,
|
lines = gameBoard.lines,
|
||||||
level = currentLevel,
|
level = currentLevel,
|
||||||
gameTime = gameTime,
|
timePlayedMs = gameTime,
|
||||||
quadCount = statsManager.getSessionQuads(),
|
quadCount = statsManager.getSessionQuads(),
|
||||||
perfectClearCount = 0 // Implement perfect clear tracking if needed
|
perfectClearCount = 0 // Implement perfect clear tracking if needed
|
||||||
)
|
)
|
||||||
|
@ -496,7 +496,7 @@ class MainActivity : AppCompatActivity(),
|
||||||
binding.sessionSinglesText.text = getString(R.string.singles, statsManager.getSessionSingles())
|
binding.sessionSinglesText.text = getString(R.string.singles, statsManager.getSessionSingles())
|
||||||
binding.sessionDoublesText.text = getString(R.string.doubles, statsManager.getSessionDoubles())
|
binding.sessionDoublesText.text = getString(R.string.doubles, statsManager.getSessionDoubles())
|
||||||
binding.sessionTriplesText.text = getString(R.string.triples, statsManager.getSessionTriples())
|
binding.sessionTriplesText.text = getString(R.string.triples, statsManager.getSessionTriples())
|
||||||
binding.sessionQuadsText.text = getString(R.string.quads, statsManager.getSessionQuads())
|
binding.sessionQuadsText?.text = getString(R.string.quads, statsManager.getSessionQuads())
|
||||||
|
|
||||||
// Flag to track if high score screen will be shown
|
// Flag to track if high score screen will be shown
|
||||||
var showingHighScore = false
|
var showingHighScore = false
|
||||||
|
|
|
@ -78,7 +78,7 @@ class StatsActivity : AppCompatActivity() {
|
||||||
binding.totalSinglesText.setTextColor(textColor)
|
binding.totalSinglesText.setTextColor(textColor)
|
||||||
binding.totalDoublesText.setTextColor(textColor)
|
binding.totalDoublesText.setTextColor(textColor)
|
||||||
binding.totalTriplesText.setTextColor(textColor)
|
binding.totalTriplesText.setTextColor(textColor)
|
||||||
binding.totalQuadsText.setTextColor(textColor)
|
binding.totalQuadsText?.setTextColor(textColor)
|
||||||
binding.maxLevelText.setTextColor(textColor)
|
binding.maxLevelText.setTextColor(textColor)
|
||||||
binding.maxScoreText.setTextColor(textColor)
|
binding.maxScoreText.setTextColor(textColor)
|
||||||
binding.maxLinesText.setTextColor(textColor)
|
binding.maxLinesText.setTextColor(textColor)
|
||||||
|
@ -116,7 +116,7 @@ class StatsActivity : AppCompatActivity() {
|
||||||
binding.totalSinglesText.text = getString(R.string.singles, statsManager.getTotalSingles())
|
binding.totalSinglesText.text = getString(R.string.singles, statsManager.getTotalSingles())
|
||||||
binding.totalDoublesText.text = getString(R.string.doubles, statsManager.getTotalDoubles())
|
binding.totalDoublesText.text = getString(R.string.doubles, statsManager.getTotalDoubles())
|
||||||
binding.totalTriplesText.text = getString(R.string.triples, statsManager.getTotalTriples())
|
binding.totalTriplesText.text = getString(R.string.triples, statsManager.getTotalTriples())
|
||||||
binding.totalQuadsText.text = getString(R.string.quads, statsManager.getTotalQuads())
|
binding.totalQuadsText?.text = getString(R.string.quads, statsManager.getTotalQuads())
|
||||||
|
|
||||||
// Update best performance stats
|
// Update best performance stats
|
||||||
binding.maxLevelText.text = getString(R.string.max_level, statsManager.getMaxLevel())
|
binding.maxLevelText.text = getString(R.string.max_level, statsManager.getMaxLevel())
|
||||||
|
|
|
@ -5,6 +5,10 @@ import android.content.SharedPreferences
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
import java.math.BigDecimal
|
||||||
|
import java.math.BigInteger
|
||||||
|
import kotlin.math.max
|
||||||
|
import com.pixelmintdrop.R // Assuming themes are defined elsewhere, maybe R?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages player progression, experience points, and unlockable rewards
|
* Manages player progression, experience points, and unlockable rewards
|
||||||
|
@ -95,13 +99,23 @@ class PlayerProgressionManager(context: Context) {
|
||||||
*/
|
*/
|
||||||
fun calculateGameXP(score: Int, lines: Int, level: Int, timePlayedMs: Long,
|
fun calculateGameXP(score: Int, lines: Int, level: Int, timePlayedMs: Long,
|
||||||
quadCount: Int, perfectClearCount: Int): Long {
|
quadCount: Int, perfectClearCount: Int): Long {
|
||||||
val scoreXP = score * SCORE_XP_MULTIPLIER
|
// Use Double for calculations to maintain precision with multipliers
|
||||||
val linesXP = lines * LINES_XP_MULTIPLIER * level
|
val scoreXP = score.toDouble() * SCORE_XP_MULTIPLIER
|
||||||
val quadBonus = quadCount * QUAD_XP_BONUS * (1 - (level - 1) * 0.05).coerceAtLeast(0.5)
|
// Lines XP scales with level
|
||||||
val perfectClearBonus = perfectClearCount * PERFECT_CLEAR_XP_BONUS
|
val linesXP = lines.toDouble() * LINES_XP_MULTIPLIER * level.toDouble()
|
||||||
val timeBonus = (timePlayedMs / 1000) * TIME_XP_MULTIPLIER
|
// Quad bonus scales inversely with level (harder quads at higher levels mean less relative bonus?) - capped at 0.5 minimum multiplier
|
||||||
|
val quadBonusMultiplier = (1.0 - (level - 1).toDouble() * 0.05).coerceAtLeast(0.5)
|
||||||
|
val quadBonus = quadCount.toDouble() * QUAD_XP_BONUS * quadBonusMultiplier
|
||||||
|
// Perfect clear bonus is a fixed Long value
|
||||||
|
val perfectClearBonusXP = perfectClearCount * PERFECT_CLEAR_XP_BONUS // This is already Long
|
||||||
|
// Time bonus based on seconds played
|
||||||
|
val timeBonus = (timePlayedMs / 1000.0) * TIME_XP_MULTIPLIER
|
||||||
|
|
||||||
return (scoreXP + linesXP + quadBonus + perfectClearBonus + timeBonus).toLong()
|
// Summing up components (ensure consistent types, cast bonus to Double if needed)
|
||||||
|
val totalXP = scoreXP + linesXP + quadBonus + perfectClearBonusXP.toDouble() + timeBonus
|
||||||
|
|
||||||
|
// Return the final XP as Long
|
||||||
|
return max(0L, totalXP.toLong()) // Ensure XP is not negative and return Long
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,12 +140,12 @@ class PlayerProgressionManager(context: Context) {
|
||||||
val levelRewards = checkLevelRewards(playerLevel)
|
val levelRewards = checkLevelRewards(playerLevel)
|
||||||
newRewards.addAll(levelRewards)
|
newRewards.addAll(levelRewards)
|
||||||
|
|
||||||
// Calculate XP needed for the next level
|
// Calculate XP needed for the *new* next level
|
||||||
xpForNextLevel = calculateXPForLevel(playerLevel)
|
xpForNextLevel = calculateXPForLevel(playerLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save progress if there were any changes
|
// Save progress if level changed or rewards were unlocked
|
||||||
if (oldLevel != playerLevel || newRewards.isNotEmpty()) {
|
if (oldLevel != playerLevel || newRewards.isNotEmpty() || xpAmount > 0) {
|
||||||
saveProgress()
|
saveProgress()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,32 +157,38 @@ class PlayerProgressionManager(context: Context) {
|
||||||
*/
|
*/
|
||||||
private fun checkLevelRewards(level: Int): List<String> {
|
private fun checkLevelRewards(level: Int): List<String> {
|
||||||
val newRewards = mutableListOf<String>()
|
val newRewards = mutableListOf<String>()
|
||||||
|
var newlyUnlocked = false // Track if anything was actually unlocked in this call
|
||||||
|
|
||||||
// Check for theme unlocks
|
// Check for theme unlocks
|
||||||
when (level) {
|
when (level) {
|
||||||
5 -> {
|
5 -> {
|
||||||
if (unlockedThemes.add(THEME_NEON)) {
|
if (unlockedThemes.add(THEME_NEON)) {
|
||||||
newRewards.add("Unlocked Neon Theme!")
|
newRewards.add("Unlocked Neon Theme!")
|
||||||
|
newlyUnlocked = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
10 -> {
|
10 -> {
|
||||||
if (unlockedThemes.add(THEME_MONOCHROME)) {
|
if (unlockedThemes.add(THEME_MONOCHROME)) {
|
||||||
newRewards.add("Unlocked Monochrome Theme!")
|
newRewards.add("Unlocked Monochrome Theme!")
|
||||||
|
newlyUnlocked = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
15 -> {
|
15 -> {
|
||||||
if (unlockedThemes.add(THEME_RETRO)) {
|
if (unlockedThemes.add(THEME_RETRO)) {
|
||||||
newRewards.add("Unlocked Retro Arcade Theme!")
|
newRewards.add("Unlocked Retro Arcade Theme!")
|
||||||
|
newlyUnlocked = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
20 -> {
|
20 -> {
|
||||||
if (unlockedThemes.add(THEME_MINIMALIST)) {
|
if (unlockedThemes.add(THEME_MINIMALIST)) {
|
||||||
newRewards.add("Unlocked Minimalist Theme!")
|
newRewards.add("Unlocked Minimalist Theme!")
|
||||||
|
newlyUnlocked = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
25 -> {
|
25 -> {
|
||||||
if (unlockedThemes.add(THEME_GALAXY)) {
|
if (unlockedThemes.add(THEME_GALAXY)) {
|
||||||
newRewards.add("Unlocked Galaxy Theme!")
|
newRewards.add("Unlocked Galaxy Theme!")
|
||||||
|
newlyUnlocked = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,25 +198,34 @@ class PlayerProgressionManager(context: Context) {
|
||||||
7 -> {
|
7 -> {
|
||||||
if (unlockedBlocks.add("block_skin_2")) {
|
if (unlockedBlocks.add("block_skin_2")) {
|
||||||
newRewards.add("Unlocked Neon Block Skin!")
|
newRewards.add("Unlocked Neon Block Skin!")
|
||||||
|
newlyUnlocked = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
14 -> {
|
14 -> {
|
||||||
if (unlockedBlocks.add("block_skin_3")) {
|
if (unlockedBlocks.add("block_skin_3")) {
|
||||||
newRewards.add("Unlocked Retro Block Skin!")
|
newRewards.add("Unlocked Retro Block Skin!")
|
||||||
|
newlyUnlocked = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
21 -> {
|
21 -> {
|
||||||
if (unlockedBlocks.add("block_skin_4")) {
|
if (unlockedBlocks.add("block_skin_4")) {
|
||||||
newRewards.add("Unlocked Minimalist Block Skin!")
|
newRewards.add("Unlocked Minimalist Block Skin!")
|
||||||
|
newlyUnlocked = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
28 -> {
|
28 -> {
|
||||||
if (unlockedBlocks.add("block_skin_5")) {
|
if (unlockedBlocks.add("block_skin_5")) {
|
||||||
newRewards.add("Unlocked Galaxy Block Skin!")
|
newRewards.add("Unlocked Galaxy Block Skin!")
|
||||||
|
newlyUnlocked = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save progress immediately if something was unlocked by this check
|
||||||
|
if (newlyUnlocked) {
|
||||||
|
saveProgress()
|
||||||
|
}
|
||||||
|
|
||||||
return newRewards
|
return newRewards
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,9 +267,10 @@ class PlayerProgressionManager(context: Context) {
|
||||||
fun getCurrentXP(): Long = playerXP
|
fun getCurrentXP(): Long = playerXP
|
||||||
fun getXPForNextLevel(): Long = calculateXPForLevel(playerLevel)
|
fun getXPForNextLevel(): Long = calculateXPForLevel(playerLevel)
|
||||||
fun getSessionXPGained(): Long = sessionXPGained
|
fun getSessionXPGained(): Long = sessionXPGained
|
||||||
fun getUnlockedThemes(): Set<String> = unlockedThemes.toSet()
|
fun getTotalXPEarned(): Long = totalXPEarned // Added getter for total XP
|
||||||
fun getUnlockedBlocks(): Set<String> = unlockedBlocks.toSet()
|
fun getUnlockedThemes(): Set<String> = unlockedThemes.toSet() // Return immutable copy
|
||||||
fun getUnlockedBadges(): Set<String> = unlockedBadges.toSet()
|
fun getUnlockedBlocks(): Set<String> = unlockedBlocks.toSet() // Return immutable copy
|
||||||
|
fun getUnlockedBadges(): Set<String> = unlockedBadges.toSet() // Return immutable copy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a specific theme is unlocked
|
* Check if a specific theme is unlocked
|
||||||
|
@ -288,7 +318,7 @@ class PlayerProgressionManager(context: Context) {
|
||||||
private const val KEY_TOTAL_XP_EARNED = "total_xp_earned"
|
private const val KEY_TOTAL_XP_EARNED = "total_xp_earned"
|
||||||
private const val KEY_UNLOCKED_THEMES = "unlocked_themes"
|
private const val KEY_UNLOCKED_THEMES = "unlocked_themes"
|
||||||
private const val KEY_UNLOCKED_BLOCKS = "unlocked_blocks"
|
private const val KEY_UNLOCKED_BLOCKS = "unlocked_blocks"
|
||||||
private const val KEY_UNLOCKED_BADGES = "unlocked_badges"
|
private const val KEY_UNLOCKED_BADGES = "unlockedBadges"
|
||||||
private const val KEY_SELECTED_THEME = "selected_theme"
|
private const val KEY_SELECTED_THEME = "selected_theme"
|
||||||
private const val KEY_SELECTED_BLOCK_SKIN = "selected_block_skin"
|
private const val KEY_SELECTED_BLOCK_SKIN = "selected_block_skin"
|
||||||
|
|
||||||
|
@ -318,6 +348,16 @@ class PlayerProgressionManager(context: Context) {
|
||||||
THEME_MINIMALIST to 20,
|
THEME_MINIMALIST to 20,
|
||||||
THEME_GALAXY to 25
|
THEME_GALAXY to 25
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// XP Calculation Constants (Added)
|
||||||
|
private const val BASE_XP_PER_LEVEL = 1000.0
|
||||||
|
private const val XP_LEVEL_MULTIPLIER = 1.15 // XP increases by 15% each level
|
||||||
|
|
||||||
|
// Game XP Constants (Added)
|
||||||
|
private const val SCORE_XP_MULTIPLIER = 0.05 // 1 XP per 20 points
|
||||||
|
private const val LINES_XP_MULTIPLIER = 25.0 // Base XP per line
|
||||||
|
private const val QUAD_XP_BONUS = 150.0 // Bonus XP per Quad
|
||||||
|
private const val TIME_XP_MULTIPLIER = 0.5 // 0.5 XP per second played
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -358,4 +398,11 @@ class PlayerProgressionManager(context: Context) {
|
||||||
fun getSelectedTheme(): String {
|
fun getSelectedTheme(): String {
|
||||||
return prefs.getString(KEY_SELECTED_THEME, THEME_CLASSIC) ?: THEME_CLASSIC
|
return prefs.getString(KEY_SELECTED_THEME, THEME_CLASSIC) ?: THEME_CLASSIC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a specific block skin is unlocked
|
||||||
|
*/
|
||||||
|
fun isBlockSkinUnlocked(blockSkinId: String): Boolean {
|
||||||
|
return unlockedBlocks.contains(blockSkinId)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -266,7 +266,7 @@
|
||||||
android:fontFamily="sans-serif" />
|
android:fontFamily="sans-serif" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/sessionTetrisesText"
|
android:id="@+id/sessionQuadsText"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
android:layout_marginBottom="4dp"/>
|
android:layout_marginBottom="4dp"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/totalTetrisesText"
|
android:id="@+id/totalQuadsText"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue