diff --git a/app/src/main/java/net/imshit/aircraftwar/element/aircraft/enemy/BossEnemy.kt b/app/src/main/java/net/imshit/aircraftwar/element/aircraft/enemy/BossEnemy.kt index 070b5ce..b739a66 100644 --- a/app/src/main/java/net/imshit/aircraftwar/element/aircraft/enemy/BossEnemy.kt +++ b/app/src/main/java/net/imshit/aircraftwar/element/aircraft/enemy/BossEnemy.kt @@ -13,7 +13,7 @@ class BossEnemy( maxHp: Int, power: Int, shootNum: Int, - val propGenerateStrategy: PropGenerateStrategies + private val propGenerateStrategy: PropGenerateStrategies ) : Enemies( game = game, initialX = initialX, diff --git a/app/src/main/java/net/imshit/aircraftwar/element/aircraft/enemy/EliteEnemy.kt b/app/src/main/java/net/imshit/aircraftwar/element/aircraft/enemy/EliteEnemy.kt index f490057..e959d9c 100644 --- a/app/src/main/java/net/imshit/aircraftwar/element/aircraft/enemy/EliteEnemy.kt +++ b/app/src/main/java/net/imshit/aircraftwar/element/aircraft/enemy/EliteEnemy.kt @@ -12,7 +12,7 @@ class EliteEnemy( speedY: Float, maxHp: Int, power: Int, - val propGenerateStrategy: PropGenerateStrategies + private val propGenerateStrategy: PropGenerateStrategies ) : Enemies( game = game, initialX = initialX, diff --git a/app/src/main/java/net/imshit/aircraftwar/element/animation/DyingAnimation.kt b/app/src/main/java/net/imshit/aircraftwar/element/animation/DyingAnimation.kt index 59557f4..3fd1c53 100644 --- a/app/src/main/java/net/imshit/aircraftwar/element/animation/DyingAnimation.kt +++ b/app/src/main/java/net/imshit/aircraftwar/element/animation/DyingAnimation.kt @@ -11,11 +11,13 @@ class DyingAnimation( game = aircraft.game, initialX = aircraft.x, initialY = aircraft.y, speedX = 0f, speedY = 0f ) { - val ALPHA = 0.8 - val LIVE_MS = 500 - val FLASH_MS = 100 + companion object { + const val ALPHA = 0.8 + const val LIVE_MS = 500 + const val FLASH_MS = 100 + } - fun makeLightImage(image: Bitmap): Bitmap { + private fun makeLightImage(image: Bitmap): Bitmap { val width = image.width val height = image.height val pixels = @@ -23,20 +25,20 @@ class DyingAnimation( val lightPixels = pixels.map { color -> Color.argb( Color.TRANSPARENT, - (Color.red(color) * this.ALPHA).toInt(), - (Color.green(color) * this.ALPHA).toInt(), - (Color.blue(color) * this.ALPHA).toInt() + (Color.red(color) * ALPHA).toInt(), + (Color.green(color) * ALPHA).toInt(), + (Color.blue(color) * ALPHA).toInt() ) }.toIntArray() return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) .apply { setPixels(lightPixels, 0, width, 0, 0, width, height) } } - val baseImage = aircraft.image - val lightImage = makeLightImage(this.baseImage) + private val baseImage = aircraft.image + private val lightImage = makeLightImage(this.baseImage) override var image = this.baseImage - var life = this.LIVE_MS + private var life = LIVE_MS override fun forward(timeMs: Int) { this.life -= timeMs if (this.life <= 0) { diff --git a/app/src/main/java/net/imshit/aircraftwar/gui/ScoreboardActivity.kt b/app/src/main/java/net/imshit/aircraftwar/gui/ScoreboardActivity.kt index 3661492..9bea8ce 100644 --- a/app/src/main/java/net/imshit/aircraftwar/gui/ScoreboardActivity.kt +++ b/app/src/main/java/net/imshit/aircraftwar/gui/ScoreboardActivity.kt @@ -27,7 +27,7 @@ class ScoreboardActivity : AppCompatActivity() { }) } - class ScoreInfoAdapter(val scoreInfoList: MutableList) : + class ScoreInfoAdapter(private val scoreInfoList: MutableList) : RecyclerView.Adapter() { class ScoreInfoViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val view: CardView = itemView.findViewById(R.id.sbvi_card) diff --git a/app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt b/app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt index 28d2ad4..716940a 100644 --- a/app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt +++ b/app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt @@ -41,6 +41,13 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) : Difficulty.HARD -> HardGame(context, soundMode) } } + + const val BAR_OFFSET = 15f + const val BAR_TEXT_OFFSET = 15f + const val BAR_LENGTH = 50f + const val BAR_HEIGHT = 10f + const val SCORE_X = 10f + const val SCORE_Y = 25f } /** used by design tool */ @@ -53,7 +60,7 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) : // utils lateinit var images: ImageManager private val musicStrategy: MusicStrategies = - if (soundMode) BasicMusicStrategy(context) else MuteMusicStrategy() + if (soundMode) BasicMusicStrategy(context) else MuteMusicStrategy private val logicThread = Thread { try { while (!this.isStopped) { @@ -75,9 +82,9 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) : abstract val generateStrategy: EnemyGenerateStrategies // status - var score = 0 - var time = 0 - var isGameOver = false + private var score = 0 + private var time = 0 + private var isGameOver = false private var isStopped = false // variables @@ -287,10 +294,6 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) : } private fun paintLife(canvas: Canvas) { - val BAR_OFFSET = 15f - val BAR_TEXT_OFFSET = 15f - val BAR_LENGTH = 50f - val BAR_HEIGHT = 10f this.lifeBarElementLists.flatten().forEach { val hp = it.hp val maxHp = it.maxHp @@ -298,23 +301,21 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) : val barEndX = barStartX + BAR_LENGTH val barCurrX = barStartX + BAR_LENGTH * hp / maxHp val barTopY = it.y - it.height / 2 - BAR_OFFSET - val barButtomY = barTopY + BAR_HEIGHT + val barBottomY = barTopY + BAR_HEIGHT this.paint.color = Color.BLACK this.paint.style = Paint.Style.STROKE - canvas.drawRect(barStartX, barTopY, barEndX, barButtomY, this.paint) + canvas.drawRect(barStartX, barTopY, barEndX, barBottomY, this.paint) this.paint.color = Color.WHITE this.paint.style = Paint.Style.FILL - canvas.drawRect(barStartX, barTopY, barEndX, barButtomY, this.paint) + canvas.drawRect(barStartX, barTopY, barEndX, barBottomY, this.paint) this.paint.color = Color.RED - canvas.drawRect(barStartX, barTopY, barCurrX, barButtomY, this.paint) + canvas.drawRect(barStartX, barTopY, barCurrX, barBottomY, this.paint) this.paint.textSize = 20f canvas.drawText("$hp/$maxHp", barStartX, barTopY - BAR_TEXT_OFFSET, this.paint) } } private fun paintScore(canvas: Canvas) { - val SCORE_X = 10f - val SCORE_Y = 25f this.paint.color = Color.YELLOW this.paint.textSize = 50f canvas.drawText( diff --git a/app/src/main/java/net/imshit/aircraftwar/logic/generate/enemy/EnemyGenerateStrategies.kt b/app/src/main/java/net/imshit/aircraftwar/logic/generate/enemy/EnemyGenerateStrategies.kt index 18fced2..a06da75 100644 --- a/app/src/main/java/net/imshit/aircraftwar/logic/generate/enemy/EnemyGenerateStrategies.kt +++ b/app/src/main/java/net/imshit/aircraftwar/logic/generate/enemy/EnemyGenerateStrategies.kt @@ -35,13 +35,13 @@ sealed class EnemyGenerateStrategies { abstract val bossBaseSpeed: Float - var time = 0 - var score = 0 + private var time = 0 + private var score = 0 - var lastBossSummonScore = 0 - var lastEnemySummonTime = 0 - var lastEnemyShootTime = 0 - var lastHeroShootTime = 0 + private var lastBossSummonScore = 0 + private var lastEnemySummonTime = 0 + private var lastEnemyShootTime = 0 + private var lastHeroShootTime = 0 fun inform(time: Int, score: Int) { this.time = time diff --git a/app/src/main/java/net/imshit/aircraftwar/logic/generate/prop/PropGenerateStrategies.kt b/app/src/main/java/net/imshit/aircraftwar/logic/generate/prop/PropGenerateStrategies.kt index 4132ff6..cd38fdc 100644 --- a/app/src/main/java/net/imshit/aircraftwar/logic/generate/prop/PropGenerateStrategies.kt +++ b/app/src/main/java/net/imshit/aircraftwar/logic/generate/prop/PropGenerateStrategies.kt @@ -13,9 +13,9 @@ abstract class PropGenerateStrategies(game: Games) : PropFactories(game = game) protected abstract val bombProbability: Double protected abstract val bulletProbability: Double - protected val bloodPropFactory = BloodPropFactory(game) - protected val bombPropFactory = BombPropFactory(game) - protected val bulletPropFactory = BulletPropFactory(game) + private val bloodPropFactory = BloodPropFactory(game) + private val bombPropFactory = BombPropFactory(game) + private val bulletPropFactory = BulletPropFactory(game) override fun createProp(x: Float, y: Float): Props? { val rand = random() diff --git a/app/src/main/java/net/imshit/aircraftwar/logic/music/MuteMusicStrategy.kt b/app/src/main/java/net/imshit/aircraftwar/logic/music/MuteMusicStrategy.kt index e8d3c66..0d56197 100644 --- a/app/src/main/java/net/imshit/aircraftwar/logic/music/MuteMusicStrategy.kt +++ b/app/src/main/java/net/imshit/aircraftwar/logic/music/MuteMusicStrategy.kt @@ -1,6 +1,6 @@ package net.imshit.aircraftwar.logic.music -class MuteMusicStrategy : MusicStrategies() { +object MuteMusicStrategy : MusicStrategies() { override fun setBgm(bgmType: BgmType) { }