Computer Science Canada

Hangman - Text Part

Author:  QuantumPhysics [ Mon Oct 08, 2012 10:31 am ]
Post subject:  Hangman - Text Part

I would say im 25% done, this is the text part of the hangman game, it is fully operational just in the run-time window. It is also somewhat commented, but not fully. I will now incorporate the pyGUI into it and re-submit. There is no guess counter yet, I am looking to incorporate that with a timer in GUI, as well as the actual Hangman which I will draw onto the screen (in parts of course). Anyways Enjoy lol >>> Apparently .py extension is not allowed (obviously I can see why)

So here is the source code:


# Hangman version 1.0
# Written by: QuantumPhysics
# Date Written: 10/08/12

# import random module
import random

# word-list
x = ["hello","goodbye","test","snow","game","program","bluff","joker",
# correct guess word list
correct = []
# wrong guess word list
wrong = []
# generate random word
b = random.choice(x)
# gameplay variables
guesses =''
play = 1;
game = ''# main game loop
while play > 0:
  # missed = 0, if stays 0 game will be over at end of loop
  missed = 0
  state = ''
  # goto event after end
  while len(game) != 1:
          # prompts user to input guess
          game = raw_input("Please enter your guess: ")
  # moves user input to guesses variable
  guesses += game
  game = ''
  # determines whether user input is in word
  for letter in b:
    if letter in guesses:
      # if it is then put letter(s) in place of '-'
      state += letter
      # if it isn't then draw a '-'
      state += '-'
      missed += 1
  # outputs rephased word and cover
  print state

  # if to this point missed stay's at 1 then you win
  if missed == 0:
        print('Correct, you win!')

Author:  QuantumPhysics [ Tue Oct 09, 2012 3:26 pm ]
Post subject:  Re: Hangman - Text Part

So I got many views of my code but no replies, what are your responses to my code? I need all the feedback I can get.

Author:  Aange10 [ Wed Oct 10, 2012 7:58 am ]
Post subject:  RE:Hangman - Text Part

Alright a few things:

Why is the word list x and the chosen word b?
Since play never changes value, the while is an infinite loop.

Author:  QuantumPhysics [ Wed Oct 10, 2012 12:52 pm ]
Post subject:  RE:Hangman - Text Part

Okay thank you. The x and b, I just didnt want to come up with logical names for them so I named them that (temporarily, until I release the goo e version. I will also add in the play value but for the time being, I should change it :/