首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在非常简单的Python游戏中创建战斗系统

在非常简单的Python游戏中创建战斗系统
EN

Stack Overflow用户
提问于 2014-03-06 20:47:42
回答 2查看 7.8K关注 0票数 0

这是密码

代码语言:javascript
复制
# TEST.PY

import sys
import random

class Fight(object):
    def enter(self):
        print "\n", "-" * 10
        print "There are two muchachos:"
        print "MUCHACHO1"
        print "MUCHACHO2"
        print "One of them looks wounded or something."

        your_hit_points = 20
        muchacho1_hit_points = 6
        muchacho2_hit_points = 11
        muchacho1 = True
        muchacho2 = True


        while your_hit_points > 0 or (not muchacho1 and not muchacho2):
            print "\n", "-" * 10
            your_attack = random.randint(4,12)
            muchacho1_attack = random.randint(1,4)
            muchacho2_attack = random.randint(4,8)


            attack = int(raw_input("Type 1 to attack MUCHACHO1, 2 to attack MUCHACHO2 >"))

            if attack == 1:
                muchacho1_hit_points - your_attack
                print "You hit MUCHACHO1 for %d hit points." % your_attack

                if muchacho1_hit_points <= 0 and muchacho1:
                    muchacho1 = False
                    print "MUCHACHO1 killed!"
                else:
                    pass

            elif attack == 2:
                muchacho2_hit_points - your_attack
                print "You hit MUCHACHO2 for %d hit points." % your_attack

                if muchacho2_hit_points <= 0 and muchacho2:
                    muchacho2 = False
                    print "MUCHACHO2 killed!"
                else:
                    pass

            else:
                print "DOES NOT COMPUTE"
                pass

            your_hit_points - muchacho1_attack
            print "MUCHACHO1 hit you for %d points, you have %d hit points left." % (muchacho1_attack, your_hit_points)

            your_hit_points - muchacho2_attack
            print "MUCHACHO2 hit you for %d points, you have %d hit points left." % (muchacho2_attack, your_hit_points)

        exit(1)

    a_fight = Fight()
    a_fight.enter()

我没有遇到什么困难。基本上,WHILE循环从未完成,似乎每个人的命中点都没有被减去。我有一种直觉,我忽略了一些非常基本的东西,因为我已经编码了几个小时,所以我可能看不到简单的东西。

我知道通过使用更多的类或函数可以做得更好,但是现在我想这样做(对于80+ char行也很抱歉)。

EN

Stack Overflow用户

发布于 2014-03-06 20:53:55

我认为您要做的是muchacho1_hit_points -= your_attackmuchacho2也是如此。现在你只是放弃了减法的结果。

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22235607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档