Board game basics: Player

Report a typo

In our new board game, we've already specified a Player class:

class Player(val id: Int, val name: String, val hp: Int)

Now we should create a companion object for the Player class that implements a create method:

fun create(name: String): Player

The id should be unique. The default player hp equals 100.

Tip: For creating a unique id, you can create a custom variable and change its value with each function call.

Write a program in Kotlin
class Player(val id: Int, val name: String, val hp: Int)
___

Create a free account to access the full topic