diff --git a/app/src/main/kotlin/ca/bcit/comp3717/lab04/Mission.kt b/app/src/main/kotlin/ca/bcit/comp3717/lab04/Mission.kt index 12717a4..ca9bea1 100644 --- a/app/src/main/kotlin/ca/bcit/comp3717/lab04/Mission.kt +++ b/app/src/main/kotlin/ca/bcit/comp3717/lab04/Mission.kt @@ -6,7 +6,7 @@ abstract class Mission(protected val minion: Minion) { println(minion.catchphrase); } - + fun start(listener: MissionListener): Unit { val time = determineMissionTime(); diff --git a/app/src/main/kotlin/ca/bcit/comp3717/lab05/Dog.kt b/app/src/main/kotlin/ca/bcit/comp3717/lab05/Dog.kt new file mode 100644 index 0000000..f7f800d --- /dev/null +++ b/app/src/main/kotlin/ca/bcit/comp3717/lab05/Dog.kt @@ -0,0 +1,22 @@ +package ca.bcit.comp3717.lab05 + +class Dog : Pet{ + + override val name: String + get() = "Rover" + + override val sound: String + get() = "Woof woof" + + override fun play() { + println("$name is fetching the ball, $sound") + } + + override fun interact() { + println("$name is wagging their tail, $sound") + } + + override fun feed() { + println("$name ate some dog treats") + } +} \ No newline at end of file diff --git a/app/src/main/kotlin/ca/bcit/comp3717/lab05/Fish.kt b/app/src/main/kotlin/ca/bcit/comp3717/lab05/Fish.kt new file mode 100644 index 0000000..4e6dde2 --- /dev/null +++ b/app/src/main/kotlin/ca/bcit/comp3717/lab05/Fish.kt @@ -0,0 +1,22 @@ +package ca.bcit.comp3717.lab05 + +class Fish(playable: Playable?): Pet, Playable by playable as Playable +{ + override val name: String + get() = "Marlin" + + override val sound: String + get() = "\"Albert Brooks\" voice but underwater" + + override fun play() { + println("$name is swimming in circles, $sound") + } + + override fun interact() { + println("$name is looking for Nemo, $sound") + } + + override fun feed() { + println("$name ate some algae") + } +} \ No newline at end of file diff --git a/app/src/main/kotlin/ca/bcit/comp3717/lab05/Main.kt b/app/src/main/kotlin/ca/bcit/comp3717/lab05/Main.kt new file mode 100644 index 0000000..d67b003 --- /dev/null +++ b/app/src/main/kotlin/ca/bcit/comp3717/lab05/Main.kt @@ -0,0 +1,12 @@ +package ca.bcit.comp3717.lab05 + +/** + * Braeden Sowinski + * A01385066 + */ + +fun main() { + + val simulator = PetSimulator() + simulator.start() +} diff --git a/app/src/main/kotlin/ca/bcit/comp3717/lab05/Pet.kt b/app/src/main/kotlin/ca/bcit/comp3717/lab05/Pet.kt new file mode 100644 index 0000000..b8ee584 --- /dev/null +++ b/app/src/main/kotlin/ca/bcit/comp3717/lab05/Pet.kt @@ -0,0 +1,19 @@ +package ca.bcit.comp3717.lab05 + +interface Playable{ + fun play() +} + +interface Interactable{ + val sound:String + fun interact() +} + +interface Feedable{ + fun feed() +} + +interface Pet : Playable, Interactable, Feedable{ + val name:String +} + diff --git a/app/src/main/kotlin/ca/bcit/comp3717/lab05/PetSimulator.kt b/app/src/main/kotlin/ca/bcit/comp3717/lab05/PetSimulator.kt new file mode 100644 index 0000000..e72844a --- /dev/null +++ b/app/src/main/kotlin/ca/bcit/comp3717/lab05/PetSimulator.kt @@ -0,0 +1,104 @@ +package ca.bcit.comp3717.lab05; + +import kotlin.system.exitProcess; +import kotlin.properties.Delegates; + +class PetSimulator +{ + private var invalidChoiceCount: Int by Delegates.observable(0) + {_, _, newValue -> + print("Invalid Option"); + when (newValue) { + 1 -> println("Try again"); + 2 -> println("One more incorrect attempt and the program will exit"); + 3 -> { + println("Too many invalid options. exiting..."); + exitProcess(0); + } + } + } + + fun start() + { + while(true) + { + println("\nChoose pet:") + println("1. Dog\n2. Fish\n3. Exit") + when (readln().toIntOrNull()) { + 1 -> { + val pet = Dog() + adopt(pet) + } + 2 -> { + val behavior = chooseBehaviour(); + val pet = Fish(behavior) + adopt(pet) + } + 3 -> return + else -> { + invalidChoiceCount++; + } + } + } + } + + private fun chooseBehaviour() : Playable? + { + while(true) + { + println("\nChoose Play behaviour:") + println("1. Drop Tail\n2. Do a trick ") + when (readln().toIntOrNull()) { + 1 -> { + return object : Playable + { + override fun play() + { + println("Dropping their tail") + } + } + } + + 2 -> { + return object : Playable + { + override fun play() + { + println("Spinning like a beyblade") + } + } + } + + else -> { + invalidChoiceCount++ + } + } + } + return null; + } + + private fun adopt(pet: Pet) + { + while (true) + { + println("\nWhat would you like to do with ${pet.name}?") + println("1. Play\n2. Feed\n3. Interact\n4. Run\n5. Exit ") + when (readln().toIntOrNull()) { + 1 -> pet.play() + 2 -> pet.feed() + 3 -> pet.interact() + 4 -> pet.run { println("$name is running, $sound")} + 5 -> return + else -> { + invalidChoiceCount++ + } + } + } + } + + fun Pet.run(action: Pet.() -> Unit) + { + this.action(); + }; +} +