From b1e5372505bc6cbf788929c007ec6dd8f455f085 Mon Sep 17 00:00:00 2001 From: Maximilian Heymann Date: Fri, 16 Oct 2020 22:02:01 +0200 Subject: [PATCH] small improvements players shouldn't see the word in clear text when guessing :p also moves defining the fail counter out of the loop --- game.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/game.py b/game.py index 79aed01..593d155 100644 --- a/game.py +++ b/game.py @@ -1,10 +1,24 @@ -#importing the time module +#importing some useful modules import time +import sys +import os #welcoming the user print ("Hello, Time to play hangman! This is a test") print("I hope that it works!") +# define a function for clearing the screen, no peeping! +def clear_screen(): + # here, we check if this game is run on a windows system, or other + if sys.platform == "win32": + # in a windows console, you type "cls" to clear the screen... + command = "cls" + else: + # ... on linux or mac, you type "clear" instead + command = "clear" + # this will run that command and clear the screen + os.system(command) + #wait for 1 second time.sleep(1) @@ -19,19 +33,25 @@ #creates an variable with an empty value -guesses = '' +guesses = [] #determine the number of turns turns = 11 +# make a counter that starts with zero +failed = 0 + +# clear the screen so that the other person can't see the word +clear_screen() + +print("The word is", len(word), "characters long!") +print("- " * len(word)) + # Create a while loop #check if the turns are more than zero while turns > 0: - # make a counter that starts with zero - failed = 0 - # for every character in secret_word for char in word: