chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


Making Hangman (Without the Stick Figures) filter_list
Author
Message
Making Hangman (Without the Stick Figures) #1
Before you ask 'Duubz, you didn't teach me anything! It's just code!', read the comments inside the code. THat's where the tutorial's at. I'm trying something different. Full commented code tutorials.

Code:
#Programmed by Duubz
#Https://www.sinister.ly/User-Duubz
#Sinisterly; The world's #! tech forum.
import random,sys
#FUCK YOU PYTHON2
if sys.version_info[0] > 2: raw_input = input
else: input = raw_input
#We need to have a set of words.
#For the sake of simplisity, we will only have one word ok  for this tutorial.
word = 'python'
#We need a maximum number of tries, and we need to count how many the user has
#missed so far. We will set this to 0, as it will be changed later if they
#choose a letter that isn't in the word.
wrong,tries = 10,0 #We're going to make wrong 10, since this is our max.
#Now we will need a list of the letters they've used so far.
#Currently, it's empty (obviously), however more will be added when they
#play the game.
used_letters = []
#Now we will have a variable, 'won', to check if they've beaten the game.
#If they haven't, the game will continue. Otherwise, it will end..
#Also, we need to have the phrase that they spell out, hypothetically speaking
#if the user actually does get a letter right.
won,phrase = False,""
#Now we will start the actual game. There is really no need for definitions,
#however, some people like to add them. For this type of game, it's best not to
#go with defining anything because it will just get too repetitive, and we will
#have too many repeating codes. Thus, we will use a while statement.
print('_' * len(word)) #Shows length of word.
while(won != True): #Prints the status each time.
    print('TRIES {0}/{1} - PHRASE {2} - USED {3}'.format(str(tries),
                                                         str(wrong),
                                                         str(phrase),
                                                         str(', '.join(used_letters))))
    #We're going to get the user input. This will be one letter each time.
    x = raw_input('> ') #Yes, we are using Python3
    x = x.lower()
    #use.
    if x in list(word): #Assuming we've chosen our word, we are checking to
        #see uf 'x', or our letter, is in list(word). The list function will
        #split all letters.
        phrase += x #This adds our letter to the phrase/word.
        #Our tries won't go up, since we got it right in this case.
    if x in used_letters: #This just disallows them from using a common character
        print('You can\'t use {0} more than once!'.format(x)) #More than once.
        x = raw_input('> ')
        x= x.lower()
    if x not in list(word):
        tries += 1
        used_letters.append(x)        
    if int(tries) == int(wrong): #This will be executed if they run out of
        print('You lose!')       #tries.
        exit()
    for c in list(phrase): #If they win. IF.
        if (c in word)and(len(word) == len(phrase)):
            print('You won!')
            won = True
            exit()

#Now, just save your game as hangman.py on your desktop, and play it.
#If it works great. If not, there's probably an error in your code somewhere.

Reply

RE: Making Hangman (Without the Stick Figures) #2
We're the #! tech forum?

I like your tutorial. I would be better if you had the comments as actual post text, and then the code in pieces of [ code][/code] tags, but that's just me. Keep making these Duubzy
[Image: TeusoI9.png]
BACK UNDER YOUR BEDS
TRY TO GET A GOOD NIGHT'S SLEEP NOW

Reply

RE: Making Hangman (Without the Stick Figures) #3
(05-08-2014, 02:35 PM)cr33pyguy Wrote: We're the #! tech forum?

Yes, we're the Shebang tech forum Biggrin
[Image: CDUAq9d.png]

Reply

RE: Making Hangman (Without the Stick Figures) #4
(05-08-2014, 03:23 PM).Shebang Wrote: Yes, we're the Shebang tech forum Biggrin

Now we know who really owns this forum Biggrin
[Image: TeusoI9.png]
BACK UNDER YOUR BEDS
TRY TO GET A GOOD NIGHT'S SLEEP NOW

Reply

RE: Making Hangman (Without the Stick Figures) #5
(05-08-2014, 06:15 PM)cr33pyguy Wrote: Now we know who really owns this forum Biggrin

It's supposed to be the #1. :l Typo.

Reply

RE: Making Hangman (Without the Stick Figures) #6
(05-08-2014, 06:59 PM)Duubz Wrote: It's supposed to be the #1. :l Typo.

That's what I figured, it's okai
[Image: TeusoI9.png]
BACK UNDER YOUR BEDS
TRY TO GET A GOOD NIGHT'S SLEEP NOW

Reply

RE: Making Hangman (Without the Stick Figures) #7
(05-08-2014, 07:05 PM)cr33pyguy Wrote: That's what I figured, it's okai

Well this did come straight from my Github.

https://github.com/Duubz/hangman/blob/master/tut.py

Reply

RE: Making Hangman (Without the Stick Figures) #8
(05-08-2014, 07:08 PM)Duubz Wrote: Well this did come straight from my Github.

https://github.com/Duubz/hangman/blob/master/tut.py

That makes more sense.
[Image: TeusoI9.png]
BACK UNDER YOUR BEDS
TRY TO GET A GOOD NIGHT'S SLEEP NOW

Reply

RE: Making Hangman (Without the Stick Figures) #9
(05-08-2014, 06:59 PM)Duubz Wrote: It's supposed to be the #1. :l Typo.

More like... #69
[Image: lO8j80T.gif]

there's never not not nuttin

Reply






Users browsing this thread: 1 Guest(s)