""" stop_pieces.py Some pieces of the STOP game project """ sign = [ '─────▄▄▄▄▄▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▄ ', # line 0 7 wrong '───▄▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▄ ', # line 1 7 '──▐░░██████░░███████░░█████░░░██████░░▌ ', # line 2 7 '──▐░░██░░░░░░░░██░░░░██░░░██░░██░░░██░▌ ', # line 3 6 wrong '──▐░░██████░░░░██░░░░██░░░██░░██████░░▌ ', # line 4 6 '──▐░░░░░░██░░░░██░░░░██░░░██░░██░░░░░░▌ ', # line 5 6 '──▐░░██████░░░░██░░░░░████░░░░██░░░░░░▌ ', # line 6 5 wrong '───▀▄░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▀ ', # line 7 5 '─────▀▀▀▀▀▀▀▀▀▀▀▀██████▀▀▀▀▀▀▀▀▀▀▀▀▀ ', # line 8 5 '──────────────────█▀▀█ ', # line 9 4 wrong '──────────────────█▀▀█ ', # line 10 4 '──────────────────█▀▀█ ', # line 11 4 '──────────────────█▀▀█ ', # line 12 3 wrong '──────────────────█▀▀█ ', # line 13 3 '──────────────────█▀▀█ ', # line 14 3 '──────────────────█▀▀█ ', # line 15 2 wrong '─────────────────█▀▀▀▀█ ', # line 16 2 '─────────────────█▀▀▀▀█ ', # line 17 2 '─────────────────█▀▀▀▀█ ', # line 18 1 wrong '─────────────────▀████▀ ', # line 19 1 '───────────────── █ █ ', # line 20 1 ] # The ASCII art is from # https://textart4u.blogspot.com/2012/03/stop-sign-text-art-ascii-art.html # which I found by googling "ASCII stop sign" def print_partial_stop(n_wrong): """ Given n_wrong from 0 to 7, print part of an ASCII stop sign """ transition = 20 - 3 * n_wrong # (i=0,1,2,... => transition=20,17,13,...) print('.'*50) print('. ') for i in range(21): if i > transition: print('. ', sign[i]) else: print('. ') print('.'*50) def reveal_word(secret, guesses): """ Given a secret word (i.e. "steeple") and a list of guessed letters (i.e. ["e, "s", "y"]) return a list of "partially revealed" letters, (i.e. ['s', '_', 'e', 'e' '_', '_', 'e']) """ # Note that this is another example of the "accumulator pattern"; # we build up what we want in the result[] list, letter by letter. result = [] # Start with nothing written down. for letter in secret: # Loop over letters in secret word. if letter in guesses: # Is this letter one of our guesses? result.append(letter) # Yes, so write down that letter. else: # result.append('_') # No, so write down _ . return result # def count_wrong_guesses(secret, guesses): """ Return number of wrong guesses """ # secret is the secret word, for example "greener" # guesses is a list of guessed letters, for example ['e', 'a', 't'] # Another "accumulator pattern" example count = 0 # Start with nothing in the counter. for guess in guesses: # Loop over each guess letter. if not guess in secret: # Not in in the secret word? count = count + 1 # Add 1 to counter. return count # def testing(secret, guesses): """ Just for testing, print details ofreveal_word & count_guesses""" print("Testing ... ") print(" secret is ", secret) print(" guesses is ", guesses) print(" reveal_word is ", reveal_word(secret, guesses)) print(" count_wrong_guesses is ", count_wrong_guesses(secret, guesses)) def test_stop_signs(wrong_lowest, wrong_highest): """ Just for testing, print a number of partial stop signs """ for wrong in range(wrong_lowest, wrong_highest+1): print() print(" *** wrong guesses = ", wrong, " *** ") print_partial_stop(wrong) print() def main(): test_stop_signs(0, 7) testing('steeple', ['e', 's', 'y']) testing('steeple', ['a', 'i']) if __name__ == '__main__': main()