SimpleScript Adventure Game
Here's a sample program in SimpleScript that implements an interactive text adventure game:
# SimpleScript Adventure Game
# A text-based virtual environment simulation
# Initialize game state
set location "forest"
set has_key false
set door_locked true
# Main game loop
while {true} {
# Display current location description
if {$location == "forest"} {
print "You are in a dark forest. Tall trees surround you."
print "To the north, you see a small cabin."
print "To the east, there is a path leading deeper into the woods."
print "Available commands: go north, go east, look, quit"
} else if {$location == "cabin"} {
print "You are in a small, dusty cabin. There's a locked door on the west wall."
if {$has_key == "false"} {
print "You notice a shiny key under the table."
}
print "Available commands: go south, take key, use key, look, quit"
} else if {$location == "clearing"} {
print "You are in a sunny clearing. Wildflowers bloom around you."
print "The forest is to the west."
print "Available commands: go west, look, quit"
} else if {$location == "treasure_room"} {
print "You are in a hidden treasure room! Gold and jewels sparkle in the dim light."
print "You've found the treasure! Congratulations!"
print "Available commands: quit"
}
# Get user input
print ""
print "What would you like to do? "
set action [input]
print ""
# Process user command
if {$action == "quit"} {
print "Thanks for playing!"
break
} else if {$action == "look"} {
print "You look around carefully..."
} else if {$location == "forest"} {
if {$action == "go north"} {
set location "cabin"
print "You walk to the cabin."
} else if {$action == "go east"} {
set location "clearing"
print "You follow the path into a sunny clearing."
} else {
print "You can't do that here."
}
} else if {$location == "cabin"} {
if {$action == "go south"} {
set location "forest"
print "You return to the forest."
} else if {$action == "take key" && $has_key == "false"} {
set has_key "true"
print "You pick up the key."
} else if {$action == "use key" && $has_key == "true" && $door_locked == "true"} {
set door_locked "false"
set location "treasure_room"
print "The key turns in the lock. You open the door to reveal a treasure room!"
} else if {$action == "use key" && $has_key == "false"} {
print "You don't have a key to use."
} else if {$action == "use key" && $door_locked == "false"} {
print "The door is already open."
} else {
print "You can't do that here."
}
} else if {$location == "clearing"} {
if {$action == "go west"} {
set location "forest"
print "You return to the dark forest."
} else {
print "You can't do that here."
}
} else if {$location == "treasure_room"} {
print "You're already in the treasure room! The adventure is complete."
} else {
print "Invalid command. Try again."
}
print ""
}
This program creates a simple interactive adventure game where the player can navigate between different locations, pick up items, and solve a basic puzzle (finding a key to unlock a door). The game state is tracked using variables, and the program responds to user input by updating the state and providing appropriate feedback.
The implementation leverages SimpleScript's simplicity:
- Everything is a command or string
- Variables are dynamically typed
- The control flow is straightforward with
while and if statements
- Input and output are handled by built-in commands
- The entire program can be interpreted line by line without complex parsing