创建3个游戏人物,以及三个游戏场景,模拟游戏场景

本文使用Python创建了3个游戏人物,并设计了3个不同的游戏场景,模拟了角色在不同场景中战斗、修炼和多人游戏的情况。通过用户选择人物和场景,动态调整角色的战斗力,实现游戏流程的模拟。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

class Game_person:

    def __init__(self,name,sex,age,fighting):

        self.G_name = name

        self.G_sex = sex

        self.G_age = age

        self.G_fighting = fighting

    def Game_scene1(self):

        self.G_fighting = self.G_fighting - 200

        return self.G_fighting

    def Game_scene2(self):

        self.G_fighting = self.G_fighting + 100

        return self.G_fighting

    def Game_scene3(self):

        self.G_fighting = self.G_fighting -500

        return self.G_fighting

player1 = Game_person('小A','女',18,1000)

player2 = Game_person('小B','男',20,1800)

player3 = Game_person('小C','女',19,2500)

print("-"*10 + "游戏开始" +"-"*10)

print("请选择游戏人物:")

print("1."+"小A,女,18,初始战斗力1000")

print("2."+"小B,男,20,初始战斗力1800")

print("3."+"小C,女,19,初始战斗力2500")

figure = int(input())

if figure == 1:

    print("请选择游戏场景:(1.草丛战斗 2.自我修炼 3. 多人游戏)")

    scene1 = int(input())

    while scene1 == 1:

        player1.Game_scene1()

        print("战斗结束"+"\n",player1.G_name,player1.G_sex,player1.G_age,"剩余战斗力:",player1.G_fighting)

        if player1.G_fighting <=0 :

            print("战斗力小于0,游戏结束")

            break

        print("是否继续:1.继续 2.退出")

        continue1 = int(input())

        if continue1 == 1:

            print("请选择游戏场景:(1.草丛战斗 2.自我修炼 3. 多人游戏)")

            scene1 = int(input())

            if scene1 == 2:

                player1.Game_scene2()

                print("修炼结束" + "\n", player1.G_name, player1.G_sex, player1.G_age, "剩余战斗力:", player1.G_fighting)

                print("是否继续:1.继续 2.退出")

                continue2 = int(input())

                if continue2 == 1:

                    print("请选择游戏场景:(1.草丛战斗 2.自我修炼 3. 多人游戏)")

                    scene1 = int(input())

                else : break

            if scene1 == 3:

                player1.Game_scene3()

                print("游戏结束" + "\n", player1.G_name, player1.G_sex, player1.G_age, "剩余战斗力:", player1.G_fighting)

            if scene1 == 2:

                player1.Game_scene2()

                print("修炼结束" + "\n", player1.G_name, player1.G_sex, player1.G_age, "剩余战斗力:", player1.G_fighting)

            if scene1 == 1:

                player1.Game_scene1()

                print("游戏结束" + "\n", player1.G_name, player1.G_sex, player1.G_age, "剩余战斗力:", player1.G_fighting)

            print("是否继续:1.继续 2.退出")

            continue2 = int(input())

            if continue2 == 1:

                print("请选择游戏场景:(1.草丛战斗 2.自我修炼 3. 多人游戏)")

                scene1 = int(input())

            else:

                    break

好的,我来模拟游戏场景。 首先,我们需要定义游戏人物的类: ```python class GameCharacter: def __init__(self, name, gender, age, initial_power): self.name = name self.gender = gender self.age = age self.power = initial_power ``` 接下来,我们创建三个游戏人物: ```python a = GameCharacter("小A", "女", 18, 1000) b = GameCharacter("小B", "男", 20, 1800) c = GameCharacter("小C", "女", 19, 2500) ``` 然后,我们定义游戏场景的类: ```python class GameScene: def __init__(self, name, power_change): self.name = name self.power_change = power_change def play(self, character): character.power += self.power_change ``` 其中,`power_change` 表示游戏场景对战斗力的影响,正数表示增加,负数表示减少。`play` 方法表示玩游戏场景,会让游戏人物的战斗力发生变化。 我们创建三个游戏场景: ```python scenes = [ GameScene("草丛战斗", -200), GameScene("自我修炼", 100), GameScene("多人游戏", -500) ] ``` 接下来,我们可以让游戏人物游戏了: ```python for character in [a, b, c]: print(f"{character.name} 初始战斗力为 {character.power}") for scene in scenes: scene.play(character) print(f"{character.name} 玩了 {scene.name} 后的战斗力为 {character.power}") ``` 输出结果如下: ``` 小A 初始战斗力为 1000 小A 玩了 草丛战斗 后的战斗力为 800 小A 玩了 自我修炼 后的战斗力为 900 小A 玩了 多人游戏 后的战斗力为 400 小B 初始战斗力为 1800 小B 玩了 草丛战斗 后的战斗力为 1600 小B 玩了 自我修炼 后的战斗力为 1700 小B 玩了 多人游戏 后的战斗力为 1200 小C 初始战斗力为 2500 小C 玩了 草丛战斗 后的战斗力为 2300 小C 玩了 自我修炼 后的战斗力为 2400 小C 玩了 多人游戏 后的战斗力为 1900 ``` 可以看到,游戏人物在不同的游戏场景中玩耍后,战斗力会发生相应的变化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值