This commit is contained in:
SowinskiBraeden committed 2026-02-15 19:19:11 -08:00
1 parent d49a0c9298
commit 6143f6722b
6 files changed
+180 -1

No files matched your search

@@ -6,7 +6,7 @@ abstract class Mission(protected val minion: Minion)
{
println(minion.catchphrase);
}
fun start(listener: MissionListener): Unit
{
val time = determineMissionTime();
@@ -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")
}
}
@@ -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")
}
}
@@ -0,0 +1,12 @@
package ca.bcit.comp3717.lab05
/**
* Braeden Sowinski
* A01385066
*/
fun main() {
val simulator = PetSimulator()
simulator.start()
}
@@ -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
}
@@ -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();
};
}