Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

kotlin - How do i create a function that adds already drawn blocks to a list?

currently i have an uni project which involves on building a simpler version of the game arkanoid (ball that reflects on racket destroying blocks) on canvas using kotlin. We use intelij. Im trying to create a function that based on a mutable list of bricks, builds a brick on canvas and adds it to the list, and when the ball hits it , it disapears and gets removed from that list.

So far i have this

enum class TypeOfBrick(val color: Int, val points: Int){
    Sb(SILVER,0),
    Wb(WHITE,1),
    Ob(ORANGE,2),
    Cb(CYAN,3),
    Gb(GREEN,4),
    Rb(RED,6),
    Bb(BLUE,7),
    Mb(MAGENTA,8),
    Yb(YELLOW,9),
}

data class Brick(val x: Int, val y: Int, val height: Int = Brick_Height, val width: Int = Brick_Width, val typeOfBrick: TypeOfBrick)

val brickList = mutableListOf<TypeOfBrick>()

fun createBrick(x: Int = Random.nextInt(32, Width-Brick_Width), y: Int = Random.nextInt(3*Brick_Height, 9*Brick_Height), typeOfBrick: TypeOfBrick): Brick{
    return Brick(x, y, Brick_Height, Brick_Width, typeOfBrick)
}

fun Canvas.drawBrick(brick: Brick){
    this.drawRect(brick.x, brick.y, Brick_Width, Brick_Height, brick.typeOfBrick.color)
}

fun addBricksToList(canvas: Canvas, brick: Brick) {
    /*
     * HERE: I know inside here i can use the for loop,
     * but i just cant seem to do it.
     */
}
question from:https://stackoverflow.com/questions/65859322/how-do-i-create-a-function-that-adds-already-drawn-blocks-to-a-list

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...