python homework完成

https://favour-link.feishu.cn/docx/XKLgd0BlZoinJ8x4eL5cqh95ngb
帮我完成这个python homework,OOP的架构如链接内部的链接所示,可以使用GPT完成,但要保证正确性。
要求:不仅要在游戏结束时输出谁输谁赢,还要在每个回合结束时输出两个玩家的分数与本回合掷出的骰子数值,

有点难

以下是使用Python实现的一个掷骰子游戏,符合上述规则:

import random
 def roll_dice():
    """掷骰子函数,返回两个骰子的点数之和"""
    dice1 = random.randint(1, 6)
    dice2 = random.randint(1, 6)
    return dice1 + dice2
 def play_game():
    """游戏主函数"""
    ship = False  # 是否已经掷出6
    captain = False  # 是否已经掷出5
    crew = False  # 是否已经掷出4
    player_score = 0  # 玩家得分
    computer_score = 0  # 电脑得分
     while not (ship and captain and crew):
        input("按回车键掷骰子:")
        cargo = roll_dice()  # 计算货物得分
        print("货物得分:", cargo)
         # 判断是否掷出6、5、4,并更新标志变量
        dice1 = random.randint(1, 6)
        dice2 = random.randint(1, 6)
        print("掷出的点数:", dice1, dice2)
        if dice1 == 6 or dice2 == 6:
            print("掷出6")
            ship = True
        if dice1 == 5 or dice2 == 5:
            print("掷出5")
            captain = True
        if dice1 == 4 or dice2 == 4:
            print("掷出4")
            crew = True
         # 更新玩家得分和电脑得分
        if ship and captain and crew:
            player_score += cargo
            computer_score += roll_dice()
        else:
            computer_score += cargo
     # 输出游戏结果
    print("玩家得分:", player_score)
    print("电脑得分:", computer_score)
    if player_score > computer_score:
        print("恭喜你,你赢了!")
    elif player_score < computer_score:
        print("很遗憾,你输了。")
    else:
        print("平局。")
 play_game()

该程序实现了一个简单的掷骰子游戏,玩家和电脑轮流掷骰子,直到玩家掷出6、5、4(船长、船长和船员),然后计算剩余两个骰子的点数之和作为货物得分,最终比较玩家和电脑的得分,得分高者获胜。

运行结果

img


import random


def fight(my_hp, enemy_hp, my_power, enemy_power):
    while True:
        my_hp -= enemy_power
        enemy_hp -= my_power
        print(f"my_hp is {my_hp} now.")
        print(f"enemy_hp is {enemy_hp} now.")
        print()

        if my_hp <= 0 or enemy_hp <= 0:
            print("win") if my_hp > enemy_hp else print("loss")
            print(my_hp)
            print(enemy_hp)
            break


# 得到血量
def get_hp():
    # 列表推导式
    # 从列表中随机挑选一个数作为血量
    hp = [x for x in range(800, 1200)]
    return random.choice(hp)


# 得到攻击力
def get_power():
    power = random.randint(180, 220)
    return power


if __name__ == '__main__':

    my_hp = get_hp()
    enemy_hp = get_hp()

    # 随机生成我方攻击力
    my_power = get_power()
    enemy_power = get_power()

    fight(my_hp, enemy_hp, my_power, enemy_power)