Skip to content

Instantly share code, notes, and snippets.

@alice
Forked from gulnara/gist:5392641
Last active December 16, 2015 06:39
Show Gist options
  • Save alice/5393050 to your computer and use it in GitHub Desktop.
Save alice/5393050 to your computer and use it in GitHub Desktop.
list HANGMAN
// Did you consider using any different syntax for multi-line strings, instead of the Python syntax?
// I like this array syntax!
HANGMAN:0 <- '''
+---+
| |
|
|
|
|
========='''
HANGMAN:1 <- '''
+---+
| |
O |
|
|
|
========='''
HANGMAN:2 <- '''
+---+
| |
O |
| |
|
|
========='''
HANGMAN:3 <- '''
+---+
| |
O |
/| |
|
|
========='''
HANGMAN:4 <- '''
+---+
| |
O |
/|\ |
|
|
========='''
HANGMAN:5 '''
+---+
| |
O |
/|\ |
/ |
|
========='''
HANGMAN:6 '''
+---+
| |
O |
/|\ |
/ \ |
|
========='''
// Is there any syntactic significance to ALL_CAPS, or is it just a convention for values which won't be changed?
MAX_WRONG <- length of HANGMAN
list WORDS
WORDS:0 <- 'animal'
WORDS:1 <- 'chicken'
WORDS:2 <- 'python'
// Is |from| syntactic sugar for |using|? Or is it specific to |choose_random|?
word <- choose_random from WORDS
// Similarly, is |of| syntactic sugar for |using|? Will you allow interchanging |using|, |from| and |of|, or will you have classes of functions that take each one?
word_len <- length of word
so_far <- repeat using '-' and word_len
show 'Welcome to Hangman'
loop first:
starting with
wrong <- 0
list used // What does this syntax do? Given you usually put the variable on the left, might this be more consistent if it were something like "used: list"?
end
show HANGMAN: wrong // Is there an extra space here? Is this syntatically acceptable, or a typo?
show 'you used the following letters:' list used // Why is the |list| keyword needed here?
show 'so far the word is ' so_far
guess <- user_input using 'enter your guess'
guess <- lowercase of guess
is wrong < MAX_WRONG and so_far != word ? // I think you're using the wrong comparison operator here.
stop first
end
loop second:
show 'you already guess the letter', guess
guess <- user_input using 'enter a guess'
guess <- lowercase of guess
is guess not in list used?
stop second
end
end
// This is a bit confusing - I assume this appends |guess| to the end of |list used|, but you'll have to be careful to increment the |:END| pointer when you assign to it. Perhaps this needs some more explicit syntax?
list used:END <- guess
is guess in word ?
then show 'yes ' guess ' is in the word!' // Why |then| here? And here it looks like you are not joining with spaces.
loop three:
starting with
new <- ''
i <-0
end
is guess = word:i?
then new <- new + guess
// Do you not allow assigning to single characters of strings? i.e. is the reason this isn't |so_far:i = guess| simply a stylistic choice, or is it a limitation of the new language?
otherwise
new <- new + so_far:i
stop three
so_far <- new
end
end
otherwise
show 'sorry', guess, 'isn't in the word'
wrong <- wrong + 1
end
end
is wrong <- MAX_WRONG ? // I think <- is a typo here. Also, do you ignore spaces between the condition and ? or not?
then show list HANGMAN:wrong
show 'you hav been hanged'
otherwise
show 'u guessed it', word
end
show 'the word was', word
user_input using 'press enter to exit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment