简体   繁体   English

Python 中的游戏(骰子)

[英]Game in Python (Dice)

my name is Erkan and i have problem with a game of dice im trying to build.我的名字是 Erkan,我在尝试构建一个骰子游戏时遇到了问题。

The core things i want to do is:我想做的核心事情是:

Ask the player of how many dices he wants.询问玩家他想要多少个骰子。 Minimun 1(ofc) and maximum 5. Each dice should only be tossed once.最小 1(ofc) 和最大 5。每个骰子只能掷一次。

The game should then randomizes results for each individual dice, one at a time, and prints this on the screen together with the sum of the tossed dice so far.然后,游戏应将每个骰子的结果随机化,一次一个,并将其与迄今为止所掷骰子的总和一起打印在屏幕上。

If any dice gets 1, then this is not added to the sum(like yatsy where im from), but two new dices are tossed.如果任何骰子得到 1,则不会将其添加到总和中(例如 yatsy where im from),而是掷出两个新骰子。 This should be displayed on the screen when / if it happens.这应该在/如果发生时显示在屏幕上。 As long as any dice gets 1, this procedure will repeat.只要任何骰子得到 1,这个过程就会重复。

When all dice are tossed, the total sum and the number of dices tossed are printed on the screen.当所有的骰子都掷完后,总和和掷骰子的数量会打印在屏幕上。 The player should then have the choice to play again or quit the game.然后玩家应该可以选择再次玩或退出游戏。

I'm very beginner at Python and sorry for bad english.我是 Python 的初学者,很抱歉英语不好。 Is it possible to get help on what im missing?是否可以就我缺少的东西获得帮助?

My code so far is this:到目前为止,我的代码是这样的:

    from random import randint

   amount_dices=int(input("How many dices do you want to use? Min 1, max 5"))
   amount_dices_tossed = 1
    result=[]

    var1=0
    while var1<amount_dices_tossed:
     var1=var1+1
    for i in range(amount_dices):

     t=randint(1,6)
     result.append(t)
     print("Dices",i+1,":", t)
     Sum = sum(t)
     print(Sum)

    Sum_dices = int(sum())
    Sum_toss = str(sum(amount_dices_tossed))
    print("The total amount: " +Sum_dicesg + " and you tossed: " + Sum_tossed + " dices")

    choice = input("Do you want to play again? [yes/no]")
    answer1 = "yes"
    answer2 = "no"

    if choice == yes:

    else:
        print("Thanks for playing!")
        exit(0)

I dont know what it should say under "if choice == yes" when i want to start again.当我想重新开始时,我不知道在“如果选择 == 是”下应该说什么。

To repeate code use loop while True and exit() or break to finish loop and finish game.要重复代码,请使用 loop while Trueexit()break来完成循环并完成游戏。

while True:

    # ... you code ...

    choice = input("Do you want to play again? [yes/no]")

    if choice != "yes":
        print("Thanks for playing!")
        #exit(0)
        break

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM