Python 2D挂人游戏图形 [英] Python 2D hang man game graphics

查看:118
本文介绍了Python 2D挂人游戏图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习python,因此我将这个游戏作为一个项目开始。问题是我不知道每次玩家做出错误猜测时如何使2D图形出现。这是代码



I started this game as a project as I just began learning python. the problem is I don't know how to make the 2D graphics appear every time the player makes a wrong guess. here is the code

import random

def update(word,letter):
    global answer
    output = ""
    for i in range(len(word)):
        if (word[i].lower()== letter.lower() ):
            output += letter.lower()
        else:
            output += answer[i]
        
    return output
Guess_list = ["london","Angel","Technology","Innovation","Understanding","Server","Intent","Distance","Time","Computer"]
User = str(input("Enter your Name: "))
random_value = random.randint(0, len(Guess_list))
size = len(Guess_list[random_value])
answer = "-"*size
print(answer)

for i in range (size):
    guess = str(input("Guess Word: "))

    if guess.lower() in Guess_list[random_value].lower():
        answer = update(Guess_list[random_value],guess)
        print(answer)
    else:
        print("wrong")
        print("________   ")
        print("|      |   ")
        print("|          ")
        print("|          ")
        print("|          ")
        print("|          ")

    if( answer.find("-") == -1):
        break





我的尝试:



我试过这个:



What I have tried:

I tried this:

if guess.lower() in Guess_list[random_value].lower():
      answer = update(Guess_list[random_value],guess)
      print(answer)
  else:
      print("wrong")
      print("________   ")
      print("|      |   ")
      print("|          ")
      print("|          ")
      print("|          ")
      print("|          ")

推荐答案

if guess.lower() in Guess_list[random_value].lower():



为什么你在这里使用 random_value ?你需要将输入的单词与列表中的每个单词进行比较。


Why are you using random_value here? You need to compare the entered word with every word in your list.


这篇关于Python 2D挂人游戏图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆