Skip to content

Commit

Permalink
refactor: 收紧访问权限
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim-shop committed May 12, 2023
1 parent 01f00f7 commit ea9a28a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BossEnemy(
maxHp: Int,
power: Int,
shootNum: Int,
val propGenerateStrategy: PropGenerateStrategies
private val propGenerateStrategy: PropGenerateStrategies
) : Enemies(
game = game,
initialX = initialX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EliteEnemy(
speedY: Float,
maxHp: Int,
power: Int,
val propGenerateStrategy: PropGenerateStrategies
private val propGenerateStrategy: PropGenerateStrategies
) : Enemies(
game = game,
initialX = initialX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,34 @@ 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 =
IntArray(width * height).also { image.getPixels(it, 0, width, 0, 0, width, height) }
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ScoreboardActivity : AppCompatActivity() {
})
}

class ScoreInfoAdapter(val scoreInfoList: MutableList<ScoreInfo>) :
class ScoreInfoAdapter(private val scoreInfoList: MutableList<ScoreInfo>) :
RecyclerView.Adapter<ScoreInfoAdapter.ScoreInfoViewHolder>() {
class ScoreInfoViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val view: CardView = itemView.findViewById(R.id.sbvi_card)
Expand Down
29 changes: 15 additions & 14 deletions app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -287,34 +294,28 @@ 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
val barStartX = it.x - BAR_LENGTH / 2
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.imshit.aircraftwar.logic.music

class MuteMusicStrategy : MusicStrategies() {
object MuteMusicStrategy : MusicStrategies() {
override fun setBgm(bgmType: BgmType) {
}

Expand Down

0 comments on commit ea9a28a

Please sign in to comment.