colossal cave WIP
This commit is contained in:
@@ -1,29 +1,91 @@
|
|||||||
namespace ColossalCave;
|
namespace ColossalCave;
|
||||||
|
|
||||||
class World() {
|
import java.io.*
|
||||||
class Room {
|
|
||||||
abstract val name: String
|
class World() {
|
||||||
}
|
class Room {
|
||||||
|
public abstract val name: String
|
||||||
val atEndOfRoad: Room
|
public val west: Room? get() = null
|
||||||
|
public val east: Room? get() = null
|
||||||
class AtEndOfRoad(): Room {
|
}
|
||||||
val name: String = "At End of Road"
|
|
||||||
}
|
public val atEndOfRoad: Room
|
||||||
|
public val atHillInRoad: Room
|
||||||
{
|
|
||||||
atEndOfRoad = new AtEndOfRoad()
|
class AtEndOfRoad(): Room {
|
||||||
}
|
public val name: String = "At End of Road"
|
||||||
|
public val west: Room? get() = atHillInRoad
|
||||||
fun startRoom() = atEndOfRoad
|
}
|
||||||
}
|
|
||||||
|
class AtHillInRoad(): Room {
|
||||||
class Player(var room: World.Room) {
|
public val name: String = "At Hill in Road"
|
||||||
|
public val east: Room? get() = atEndOfRoad
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
{
|
||||||
val w = new World()
|
atEndOfRoad = new AtEndOfRoad()
|
||||||
val p = new Player(w.startRoom())
|
atHillInRoad = new AtHillInRoad()
|
||||||
System.out?.println(p.room.name)
|
}
|
||||||
}
|
|
||||||
|
fun startRoom() = atEndOfRoad
|
||||||
|
}
|
||||||
|
|
||||||
|
class Player(var room: World.Room) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Command {
|
||||||
|
abstract fun execute(p: Player): Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
class QuitCommand() : Command {
|
||||||
|
fun execute(p: Player): Unit {
|
||||||
|
System.exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MoveCommand: Command {
|
||||||
|
fun moveTo(p: Player, room: World.Room?) {
|
||||||
|
if (room === null) {
|
||||||
|
System.out?.println("You can't go that way")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.room = room as World.Room
|
||||||
|
System.out?.println(p.room.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class WestCommand(): MoveCommand {
|
||||||
|
fun execute(p: Player): Unit {
|
||||||
|
moveTo(p, p.room.west)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EastCommand(): MoveCommand {
|
||||||
|
fun execute(p: Player): Unit {
|
||||||
|
moveTo(p, p.room.east)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun parse(cmd: String): Command? {
|
||||||
|
if (cmd == "quit") return new QuitCommand()
|
||||||
|
if (cmd == "west") return new WestCommand()
|
||||||
|
if (cmd == "east") return new EastCommand()
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
val w = new World()
|
||||||
|
val p = new Player(w.startRoom())
|
||||||
|
System.out?.println(p.room.name)
|
||||||
|
val reader = new BufferedReader(new InputStreamReader(System.`in`))
|
||||||
|
while(true) {
|
||||||
|
System.out?.print("> ")
|
||||||
|
val cmd = reader.readLine() as String
|
||||||
|
val command = parse(cmd)
|
||||||
|
if (command === null)
|
||||||
|
System.out?.println("Unrecognized command");
|
||||||
|
else
|
||||||
|
command?.execute(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user