Splinterlands Hangman with holoz0r - a development in Python

avatar

A few days ago, I said that I was starting to learn Python. I am doing exactly that.

image.png

I have published this game on GitHub, and while it has many issues, Please remember that I am at day 7 of my journey to learning Python.

I might come back to this project as I get better, and improve upon it; but for the time being, it is a fun little project built out from the skeleton of the course I am following.

If you're a crazy experienced developer, please poke holes in my code and tell me why and how it can be improved. I'd love to know!

import random
from hangmanart import *
from hangmanwords import word_list

end_of_game = False
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
lives = 6
print(logo)
#Testing code
# print(f'Pssst, the solution is {chosen_word}.')

display = []
for _ in range(word_length):
    display += "_"

while not end_of_game:
    guess = input("Guess a letter: ").lower()

    for position in range(word_length):
        letter = chosen_word[position]
        if letter == guess:
            display[position] = letter 

    if guess not in chosen_word and lives >0:
      lives -= 1
      print(f"You have {lives} lives left.")
      if lives == 0:
        end_of_game = True
        print("You Lose!")
        print(f"The Correct answer was {chosen_word}.")
    print(f"{' '.join(display)}")

    if "_" not in display:
      end_of_game = True
      print("You win.")

    print(stages[lives])

image.png

Until next time...


Want more holoz0r and Splinterlands?



If you want to see my Splinterlands antics and rants live, Find me on Twitch

If you prefer sleeping in your designated time zone, go watch replays on YouTube.

If you haven't started playing Splinterlands, you should do that immediately. It's very good fun.

Go and watch me open season rewards and packs on YouTube!


Want more content from me?

Witness my futile efforts to play my Steam Game collection in alphabetical order.

Are you aware that I love photography? Check out my work in a collection.


Thanks as always for your time!



0
0
0.000
3 comments
avatar

I've already improved the code further.

import random
from hangmanart import *
from hangmanwords import word_list

end_of_game = False
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
lives = 6
print(logo)
#Testing code
# print(f'Pssst, the solution is {chosen_word}.')
failures=[]
display = []
for _ in range(word_length):
    display += "_"
    
print("Your word to solve is: ",display)

while not end_of_game:
    guess = input("Guess a letter: ").lower()

    for position in range(word_length):
        letter = chosen_word[position]
        if letter == guess:
            display[position] = letter
    
    if guess in display:
        print("You already guessed this letter, its in the word!")
    
    if guess in failures:
        print(f"You have already guessed these letters: ", failures)
    
    if guess not in chosen_word and lives >0:
      lives -= 1
      failures.append(guess)
      print(f"You entered {guess} and that isn't in the word.")
      print(f"You have already guessed these letters: ", failures)
      print(f"You have {lives} lives left.")
      if lives == 0:
        end_of_game = True
        print("You Lose!")
        print(f"The Correct answer was {chosen_word}.")
    print(f"{' '.join(display)}")

    if "_" not in display:
      end_of_game = True
      print("You win.")

    print(stages[lives])
0
0
0.000
avatar

Fun game and great job.

0
0
0.000
avatar

Thanks mate! Need to get a lot better at coding to make some more creative things! :D

0
0
0.000