Click here to Skip to main content
15,886,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all, I am currently trying to make the game Hangman using Python in Processing. I have the code to run the game, as well as code for some visuals. The problem is combining the code I've written so far. The game code is written in standard Python, while the visuals code is written in Processing. Can someone please help me combine the two and make a working Hangman game in Processing? Thank you in advance.

Code for game

Python
import time
import random
name = input("What is your name? ")
print ("Hello, " + name, "Time to play hangman!")
print ('')
time.sleep(2)
print ("Start guessing...")
bank = ["ironman", "hulk", "captain america", "black widow", "thor", "hawkeye"]
r = (random.randint(0,5))
word = bank[r]
guesses = ''
turns = 10
while turns > 0:         
    failed = 0             
    for char in word:      
        if char in guesses:    
            print (char, )
        else:
            print ("_", )   
            failed += 1
    if failed == 0:
        print  ("You won")  
        break              
    print
    guess = input("guess a character:") 
    guesses += guess                    
    if guess not in word:  
        turns -= 1        
        print ("Wrong")   
        print ("You have", + turns, 'more guesses' )
        if turns == 0:           
            print ("You Lose")


Code for visuals (in processing)

Processing
def setup():
    size(250,350)
    background(102,204,255)
    fill(17,214,11)
    rect(0,201,250,350)
   
def draw():
    strokeWeight(2)
    line(100,100,100,200)
    line(100,100,150,100)
    line(150,100,150,125)
    line(75,200,125,200)
    line(85,200,100,175)
    line(115,200,100,175)


What I have tried:

I have tried covering the code to the best of my abilities, but I am still learning so my efforts haven't done much. As stated above I have written code to make a basic game, as well as some visuals. I just need help combining the two.
Posted
Comments
Richard MacCutchan 7-Jun-21 3:41am    
I have not heard of Processing, so cannot make a suggestion there. But you may find that Tkinter is a better choice for a Python GUI, Take a look at tkinter — Python interface to Tcl/Tk — Python 3.9.5 documentation[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900