Last active
December 28, 2015 19:19
-
-
Save dreamr/7549827 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'io/console' | |
# Adventure game in MatzLISP :) | |
COMMANDS = %w{quit} | |
DRAGON = File.read("dragon.txt") | |
get_input = -> { STDIN.gets.chomp } | |
prompt_user = ->(msg) { STDOUT.puts msg } | |
make_command= ->(cmd) { | |
begin | |
eval("do_#{cmd}").() | |
rescue NameError => e | |
if cmd != "" | |
prompt_user.("#{cmd} is not a valid command.") | |
end | |
end | |
} | |
query_user = ->(quest) { prompt_user.(quest); get_input.() } | |
do_command = ->(cmd) { make_command.(cmd) } | |
is_command = ->(cmd) { COMMANDS.include?(make_command.(cmd)) } | |
do_quit = -> { prompt_user.("goodbye") ; exit(0) } | |
do_help = -> { prompt_user.(File.read("help.txt"))} | |
get_valid_command = ->(prompt, getter) { | |
prompt.() | |
cmd = getter.() | |
return do_command.(cmd) if is_command.(cmd) | |
get_valid_command.(prompt, getter) | |
} | |
get_player_name = -> { | |
name = query_user.("What is your name, traveller?") | |
answer = query_user.("Are you sure #{name} is what you want to "+ | |
"be called? (y/n)") | |
return name if answer == "y" | |
get_player_name.() | |
} | |
show_motd = ->(player_name) { | |
prompt_user.(DRAGON) | |
prompt_user.("Welcome to your DOOM, #{player_name}!") | |
} | |
show_game_prompt = -> { | |
prompt_user.("Commands: (quit) (help)") | |
} | |
player_name = get_player_name.() | |
show_motd.(player_name) | |
prompt = -> { show_game_prompt.() } | |
get_valid_command.(prompt, get_input) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
___ | |
.~))>> | |
.~)>> | |
.~))))>>> | |
.~))>> ___ | |
.~))>>)))>> .-~))>> | |
.~)))))>> .-~))>>)> | |
.~)))>>))))>> .-~)>>)> | |
) .~))>>))))>> .-~)))))>>)> | |
( )@@*) //)>)))))) .-~))))>>)> | |
).@(@@ //))>>))) .-~))>>)))))>>)> | |
(( @.@). //))))) .-~)>>)))))>>)> | |
)) )@@*.@@ ) //)>))) //))))))>>))))>>)> | |
(( ((@@@.@@ |/))))) //)))))>>)))>>)> | |
)) @@*. )@@ ) (\_(\-\b |))>)) //)))>>)))))))>>)> | |
(( @@@(.@(@ . _/`-` ~|b |>))) //)>>)))))))>>)> | |
)* @@@ )@* (@) (@) /\b|))) //))))))>>))))>> | |
(( @. )@( @ . _/ / \b)) //))>>)))))>>>_._ | |
)@@ (@@*)@@. (6, 6) / ^ \b)//))))))>>)))>> ~~-. | |
( @jgs@@. @@@.*@_ ~^~^~, /\ ^ \b/)>>))))>> _. `, | |
((@@ @@@*.(@@ . \^^^/' ( ^ \b)))>> .' `, | |
((@@).*@@ )@ ) `-' (( ^ ~)_ / `, | |
(@@. (@@ ). ((( ^ `\ | `. | |
(*.@* / (((( \ \ . `. | |
/ ((((( \ \ _.-~\ Y, ; | |
/ / (((((( \ \.-~ _.`" _.-~`, ; | |
/ / `(((((() ) (((((~ `, ; | |
_/ _/ `"""/ /' ; ; | |
_.-~_.-~ / /' _.-~ _.' | |
((((~~ / /' _.-~ __.--~ | |
(((( __.-~ _.-~ | |
.' .~~ | |
: ,' | |
~~~~~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To play: | |
At the game prompt you can enter a command. The commands available | |
will be displayed on the prompt. Type a command to issue that | |
action. | |
quit - Quits the game | |
help - displays this file | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you 'squint' this is very similar to the repl in dikumud! macros are fun and useful