You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gamejam-22/core/src/main/kotlin/com/last/commit/inventory/Inventory.kt

35 lines
864 B
Kotlin

package com.last.commit.inventory
class Inventory() {
val items: MutableList<InventoryItem> = ArrayList()
var updated = false
private val requiredItems = listOf("ram", "iphone", "ipod", "screwdriver")
/**
* @param name the name of the subTexture loaded from xml
* @return whether the item was added
*/
fun add(name: String) {
items.add(InventoryItem(name))
this.updated = true
}
fun hasItem(name: String): Boolean {
return this.items.find { it.name == name } != null
}
fun isFull(): Boolean {
return items.size >= 7
}
fun remove(name: String) {
items.removeIf { item -> item.name == name }
}
fun checkVictoryCondition(): Boolean {
return requiredItems.all { itemName ->
items.find { it.name == itemName } != null
}
}
}