我如何循环代码直到创建某个数字? [英] How do i loop a code until a certain number is created?

查看:41
本文介绍了我如何循环代码直到创建某个数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此任务是从游戏角色中确定力量和技能这两个属性之间的差异.这个过程是:

This task is to determine the difference between two attributes, strength and skill, from game characters. The process for this is:

  • 确定强度属性之间的差异.
  • 将差值除以 5 并向下取整以创建强度修饰符".
  • 对技能属性执行相同的过程并命名为技能修饰符".
  • 然后游戏开始:
    • 两名玩家都掷出一个六面骰子.
    • 如果值相同,则不会发生任何变化.
    • 如果数值不同,那么具有最高数值的玩家会获得之前计算出的力量和技能,然后将其添加到他们的总数中.数值最低的玩家将计算出的力量和技能从他们的总数中扣除.

    这必须重复,直到强度属性等于或低于 0,然而,这部分我不能做,我知道如何循环,但这总是通过询问用户他们是否愿意再去来完成.

    This must repeat until the strength attribute is equal or below 0, however, this part I cant do, I know how to loop but this is always done by asking the user if they wish to go again.

    c1sc=random.randint(1,6)
    c2sc=random.randint(1,6)
    if c1sc > c2sc:
        c1st=c1st+strengthmodifier
        c2st=c2st-strengthmodifier
        c1sk=c1sk+skillmodifier
        c2sk=c2sk-skillmodifier
        print('Character 1, your strength attribute is: '+(str(c1st))+' and your skill attribute is: '+(str(c1sk)))
        print('Character 2, your strength attribute is: '+(str(c2st))+' and your skill attribute is: '+(str(c2sk)))
    elif c2sc > c1sc:
        c1st=c1st-strengthmodifier
        c2st=c2st+strengthmodifier
        c1sk=c1sk-skillmodifier
        c2sk=c2sk+skillmodifier
        print('Character 1, your strength attribute is: '+(str(c1st))+' and your skill attribute is: '+(str(c1sk)))
        print('Character 2, your strength attribute is: '+(str(c2st))+' and your skill attribute is: '+(str(c2sk)))
    else:
        print('It\'s a draw, no changes were made.')
    if c1sk < 0:
        c1sk=0
    elif c2sk < 0:
        c2sk=0
    
    if c1st < 0:
        print('Character 1 died. Game over.')
    elif c2st < 0:
        print('Character 2 died. Game over.')
    

    请帮忙!

    推荐答案

    只是为了让你得到图片:(在伪代码中)

    Just so you get the picture: (in pseudocode)

    while (c2sk > 0 && c1sk > 0)
        //do complete everything up until the if statements
    if c1st <0
        print "c1st died" 
    elif c2st <0
        print "c2st died"
    

    不确定这是否正是您要寻找的.如果每次都应该随机重新分配 c2sk 和 c1sk 应该在循环内.

    Not sure if this is what you are looking for exactly. If the c2sk and c1sk is supposed to be randomly reassigned each time it should be inside the loop.

    这篇关于我如何循环代码直到创建某个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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