From 3451ebba37a611f1a09d9920ca8f9b56cfdb290e Mon Sep 17 00:00:00 2001 From: nzbstn Date: Fri, 25 Oct 2024 06:25:15 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E6=81=B6=E9=AD=94?= =?UTF-8?q?=E8=BD=AE=E7=9B=98=E7=AE=80=E6=98=93=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/.keep" diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/.keep" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 857cf35916a9b3e9f5099192bdc8f0627c99ef02 Mon Sep 17 00:00:00 2001 From: nzbstn Date: Fri, 25 Oct 2024 06:36:14 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/.keep" diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/.keep" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 716b940af83ecd45a9c16b65445d1a22fe8d63af Mon Sep 17 00:00:00 2001 From: nzbstn Date: Fri, 25 Oct 2024 06:37:10 +0000 Subject: [PATCH 3/5] =?UTF-8?q?utils=20=E5=BA=93=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/ActionControl.py" | 145 +++++++++++++++ .../utils/GameControl.py" | 174 ++++++++++++++++++ .../utils/PropEffect.py" | 39 ++++ .../utils/RandomSelect.py" | 46 +++++ .../utils/__init__.py" | 13 ++ .../utils/config.py" | 38 ++++ 6 files changed, 455 insertions(+) create mode 100644 "\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/ActionControl.py" create mode 100644 "\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/GameControl.py" create mode 100644 "\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/PropEffect.py" create mode 100644 "\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/RandomSelect.py" create mode 100644 "\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/__init__.py" create mode 100644 "\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/config.py" diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/ActionControl.py" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/ActionControl.py" new file mode 100644 index 0000000..e33a367 --- /dev/null +++ "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/ActionControl.py" @@ -0,0 +1,145 @@ +""" +玩家行动, 行动前逻辑判断, 玩家状态判断 +根据道具效果对玩家状态进行修改 +""" + +from loguru import logger as log + +from .GameControl import PlayerInit, RoundInit +from .PropEffect import * + + +def UseGun(player: PlayerInit, round: RoundInit): + """ + 使用枪 + """ + log.debug(f"玩家 {player.name} 开枪") + bullet = round.gun.pop(0) + if bullet == 1: + player.life = player.life - 1*round.gun_tag + # 打出翻倍伤害后, 恢复为1倍伤害 + if round.gun_tag == 2: + round.gun_tag = 1 + + + if bullet == 0: + pass + log.debug( + f"玩家 {player.name} 开枪, 子弹 {'实弹' if bullet == 1 else '空包弹'}, 生命 {player.life}" + ) + log.debug(f"剩余子弹: {round.gun}") + return + + +def UseCiga(player: PlayerInit, round: RoundInit): + """ + 使用香烟 + """ + life = player.life + life = TheCiga() + log.debug(f"玩家 {player.name} 使用香烟, 获得效果: 生命 {life}") + player.life = life + return player + + +def UseMedicine(player: PlayerInit, round: RoundInit): + """ + 使用过期药品 + """ + + life = TheMedicine() + log.debug(f"玩家 {player.name} 使用过期药品, 获得效果: 生命 {life}") + player.life = player.life + life + if player.life <= 0: + player.life = 0 + # log.warning(f"玩家 {player.name} 使用过期药品, 生命 {player.life} 死亡") + if player.life >= 4: + player.life = 4 + + return player + + +def UseBear(player: PlayerInit, round: RoundInit): + """ + 3: 使用啤酒, 退出当前子弹 + """ + + # if len(round.gun) > 0: + bullet = round.gun.pop(0) + + log.debug(f"玩家 {player.name} 使用啤酒, 退出 {bullet} 当前弹夹 {round.gun}") + return + + +def UseMagnifier(player: PlayerInit, round: RoundInit): + """ + 4: 使用放大镜, 查看当前子弹类型 + """ + + log.debug(f"玩家 {player.name} 使用放大镜") + log.info(f"当前子弹 {round.gun[0]}") + return + + +def UseReverse(player: PlayerInit, round: RoundInit): + """ + 5: 使用逆转器, 将当前子弹类型进行逆转 + + """ + bullet = round.gun[0] + if bullet == 1: + round.gun[0] = 0 + else: + round.gun[0] = 1 + + log.debug(f"玩家 {player.name} 使用逆转器, 当前子弹 {round.gun}") + return + +from .RandomSelect import RandomSelectTools + +def UseAdrenaline(player: PlayerInit, round: RoundInit): + """ + 6: 使用肾上腺素, 获取对方一种道具, 但不能是6 + """ + prop = RandomSelectTools(1) + # log.debug(f"首次获得道具 {prop}") + while prop[0].split(":")[0] == "6": + prop = RandomSelectTools(1) + + + + player.props.append(prop[0]) + log.debug(f"玩家 {player.name} 使用肾上腺素, 获得道具 {prop}") + return + + +def UseSaw(player: PlayerInit, round: RoundInit): + """ + 7: 使用短锯, 当前子弹伤害翻倍 + 修改gun_tag 标志位为2, 伤害翻倍 + """ + log.debug(f"玩家 {player.name} 使用短锯") + round.gun_tag = 2 + return + + +def UsePhone(player: PlayerInit, round: RoundInit): + """ + 8: 使用神秘电话, 查看除当前子弹外, 随机一颗子弹类型 + """ + current_bullet_len = len(round.gun) + random_bullet = random.randint(1, current_bullet_len-1) + + log.info( + f"玩家 {player.name} 使用神秘电话, 第 {random_bullet +1} 子弹为 {round.gun[random_bullet]}" + ) + return + + +def UseHhandcuffs(player: PlayerInit, round: RoundInit): + """ + 9. 使用手铐 + """ + log.debug(f"玩家 {player.name} 使用手铐") + return + diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/GameControl.py" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/GameControl.py" new file mode 100644 index 0000000..1dc6354 --- /dev/null +++ "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/GameControl.py" @@ -0,0 +1,174 @@ +import random +from loguru import logger as log + +from .RandomSelect import RandomSelectTools + + +def RandomToolNum() -> int: + """ + 随机发放道具数量 1-5 + :return: {num:tool} + """ + result = random.randint(1, 5) + # log.debug(f"道具数量: {result}") + return result + + +def RandomLife() -> int: + """ + 本次随机生命 2-4 + + :param: l 生命 + :return: + """ + result = random.randint(1, 4) + log.debug(f"本局生命: {result}") + return result + + +def TheGun(): + """ + 准备弹夹 + 总计8发子弹, 随机填充n发, 空包弹 0, 实弹 1 当前排列 2 + 实弹 1-4 + """ + num = random.randint(2, 8) + num_ones = random.randint(1, int(num / 2)) + # log.debug(f"子弹总数: {num} 实弹数量: {num_ones}") + # 创建包含 num_ones 个 1 和 8 - num_ones 个 0 的列表 + lst = [1] * num_ones + [0] * (num - num_ones) + # log.debug(f"生成子弹lst: {lst}") + + # 打乱列表顺序,使 1 和 0 随机分布 + result = random.shuffle(lst) + log.debug(f"子弹总数: {num} 实弹数量: {num_ones} 子弹分布: {lst}") + return lst + + +class GunInit: + """ + 一次 gun 的初始化,生成道具组和弹夹 + + """ + + def __init__(self): + props_num = RandomToolNum() + self.gun = TheGun() + self.props = RandomSelectTools(props_num) + log.debug(f"发放道具 {self. props}") + + +class RoundInit: + """ + 一次回合的初始化, 绑定弹夹信息, 设定血量上限 + """ + + def __init__(self): + gun = GunInit() + self.gun = gun.gun + # self.props = RandomSelectTools(gun.tools_num) + self.props = gun.props + self.max = RandomLife() + self.life = self.max + self.gun_tag = 1 + + +class PlayerInit: + def __init__(self, round: RoundInit): + self.id: int = 0 + self.name: str = "playername" + self.life = round.life + self.props = round.props + # self.round = round + + +from .config import dct_actions + + +class PlayerActions: + """ + 玩家行动 + """ + + def __init__( + self, + player: PlayerInit, + round: RoundInit, + # gun: GunInit, + ) -> None: + self.player = player + self.round = round + + def NewGun(self, player: PlayerInit, round: RoundInit): + """ + 设置新弹夹, 继承上一个弹夹的剩余道具 + + """ + log.info(f"重新填充弹夹") + newgun = GunInit() + round.gun = newgun.gun + # player.round = newgun.gun + old_props = player.props + new_props = old_props + newgun.props + player.props = new_props[0:8] + + def GunCheck(self): + if len(self.round.gun) == 0: + self.NewGun(self.player, self.round) + pass + + def LifeCheck(self): + if self.player.life <= 0: + log.warning(f"玩家 {self.player.name} 死亡") + return False + # if self.player.life >= self.round.max: + # self.player.life = self.round.max + # log.warning(f"玩家 {self.player.name} 生命上限") + # return False + return True + + def PropsCheck(self, num): + props_key = [a.split(":")[0] for a in self.player.props] + if num == "0": + return True + if num not in props_key: + log.warning(f"玩家 {self.player.name} 使用道具 {num} 无效") + return False + + return True + + def PropsRemove(self, num): + for a in self.player.props: + if num in a: + self.player.props.remove(a) + return + + def UseProp(self, num): + """ + 使用道具 + """ + # log.debug(f"玩家 {self.player.name} 使用道具 {num}") + # if num in + # log.debug(f"道具列表: {self.player.props}") + + # 使用道具前, 玩家状态检查 + if not self.LifeCheck(): + return + if not self.PropsCheck(num): + return + + action = dct_actions.get(num, None) + if callable(action): + action(self.player, self.round) + + else: + log.warning(f"玩家 {self.player.name} 使用道具 {num} 无效") + + # 道具使用后, 移除道具 + self.PropsRemove(num) + + # 使用道具后, 检查状态 + self.LifeCheck() + self.GunCheck() + + return diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/PropEffect.py" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/PropEffect.py" new file mode 100644 index 0000000..4c2a044 --- /dev/null +++ "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/PropEffect.py" @@ -0,0 +1,39 @@ +""" +生成道具效果, 不进行效果附加 +""" + +import random + + +def TheMedicine() -> int: + """ + 过期药品, +2 or -1 生命 + 0 失败 1 成功 + + :param: l 生命 + :return: + + """ + result = 0 + r = random.choice([0, 1]) + if r == 0: + result = 2 + else: + result = -1 + return result + + +def TheCiga() -> int: + """ + 香烟效果 生命+1 总量 <=4 + """ + result = 1 + return result + + +def TheSkit(): + """ + 手锯 双倍伤害 + """ + + return 2 diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/RandomSelect.py" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/RandomSelect.py" new file mode 100644 index 0000000..35973af --- /dev/null +++ "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/RandomSelect.py" @@ -0,0 +1,46 @@ +import random +from collections import Counter +from loguru import logger as log + + +def RandmonSelector(lst, k) -> list: + """ + 从道具池抽取道具 + """ + # 将每个元素最多重复两次加入新列表 + extended_list = [item for item in lst for _ in range(2)] + + # 使用 Counter 确保结果中不会有超过两个的重复元素 + selection = [] + while len(selection) < k: + item = random.choice(extended_list) + if Counter(selection)[item] < 2: # 确保每个元素不会超过 2 次 + selection.append(item) + return selection + + +def RandomSelectTools(k: int): + """ + 随机发放道具 1-5 + :return: {num:tool} + """ + # log.debug(f"抽取道具数量:{k}") + dct_tools = { + 1: "香烟", + 2: "过期药品", + 3: "啤酒", + 4: "放大镜", + 5: "逆转器", + 6: "肾上腺素", + 7: "短锯", + 8: "神秘电话", + 9: "手铐", + } + # k = random.randint(1, 5) + r = RandmonSelector(list(dct_tools.keys()), k) + + # 生成多个道具时, 可能出现重复的道具, 改用list字典表示 + result = [] + for i in r: + result.append(str(i) + ":" + dct_tools[i]) + return result diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/__init__.py" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/__init__.py" new file mode 100644 index 0000000..9de26d6 --- /dev/null +++ "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/__init__.py" @@ -0,0 +1,13 @@ +from .GameControl import * +from .PropEffect import * +from .RandomSelect import * +# from .Player import PlayerInit +from .ActionControl import * + +from .config import dct_tools + + + +# 导入GPT +# from .PlayerActionGPT import * +from .PlayerActionDemo import * \ No newline at end of file diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/config.py" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/config.py" new file mode 100644 index 0000000..77e72ed --- /dev/null +++ "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/utils/config.py" @@ -0,0 +1,38 @@ +from .ActionControl import * + +dct_tools = { + 1: "香烟", + 2: "过期药品", + 3: "啤酒", + 4: "放大镜", + 5: "逆转器", + 6: "肾上腺素", + 7: "短锯", + 8: "神秘电话", + 9: "手铐", +} + + + + +dct_actions = { + "0": UseGun, + "1": UseCiga, + "2": UseMedicine, + "3": UseBear, + "4": UseMagnifier, + "5": UseReverse, + "6": UseAdrenaline, + "7": UseSaw, + "8": UsePhone, + "9": UseHhandcuffs, + +} + + +dct_actionsv2 = { + "0": "UseGun", + "1": "UseCiga", + "2": "UseMedicine", + "3": "UseBear", +} \ No newline at end of file -- Gitee From c093242232f7c1d2cebe1a23a44dc9914d005d7d Mon Sep 17 00:00:00 2001 From: nzbstn Date: Fri, 25 Oct 2024 06:37:53 +0000 Subject: [PATCH 4/5] =?UTF-8?q?main=E6=96=87=E4=BB=B6upload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../README.md" | 5 +++++ .../SoloPlay.py" | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 "\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/README.md" create mode 100644 "\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/SoloPlay.py" diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/README.md" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/README.md" new file mode 100644 index 0000000..1ea250c --- /dev/null +++ "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/README.md" @@ -0,0 +1,5 @@ +企图使用 python3.8 实现 Steam 游戏 恶魔轮盘(BuckshotRoulette), 只实现完全随机的单人无对战游戏逻辑基础运行, 纯娱乐代码 + +# 严正声明 +本项目中的代码仅用于学习、研究和交流之目的。所有代码均来源于互联网公开渠道或开源项目,我们不对代码的合法性、准确性、完整性、适用性等做任何保证。若该代码侵害了您的合法权益,请您立即与我们联系,我们会在第一时间核实处理。 +由于使用本项目中的代码所产生的任何直接或间接损失,责任均由使用者自行承担。本项目不对任何因代码搬运、使用不当、或其他原因引发的问题承担任何法律责任。 diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/SoloPlay.py" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/SoloPlay.py" new file mode 100644 index 0000000..1395a84 --- /dev/null +++ "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/SoloPlay.py" @@ -0,0 +1,19 @@ +""" +单人游戏:无对局NPC, 仅单人进行游戏交互 +""" + +import utils +from loguru import logger as log + +round01 = utils.RoundInit() +zhangsan = utils.PlayerInit(round01) +action = utils.PlayerActions(zhangsan, round01) + +log.info(f"开始游戏, 本回合生命: {round01.max}, 当前道具{round01.props}") + +while True: + action.GunCheck() + if not action.LifeCheck(): + break + p_slelect = input() + action.UseProp(p_slelect) \ No newline at end of file -- Gitee From e93849bc80223b91de0a5bdcb2e68144d9459973 Mon Sep 17 00:00:00 2001 From: nzbstn Date: Fri, 25 Oct 2024 06:39:06 +0000 Subject: [PATCH 5/5] =?UTF-8?q?update=20=E6=81=B6=E9=AD=94=E8=BD=AE?= =?UTF-8?q?=E7=9B=98=E7=AE=80=E6=98=93=E7=89=88/README.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../README.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/README.md" "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/README.md" index 1ea250c..b214c38 100644 --- "a/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/README.md" +++ "b/\346\201\266\351\255\224\350\275\256\347\233\230\347\256\200\346\230\223\347\211\210/README.md" @@ -1,4 +1,4 @@ -企图使用 python3.8 实现 Steam 游戏 恶魔轮盘(BuckshotRoulette), 只实现完全随机的单人无对战游戏逻辑基础运行, 纯娱乐代码 +企图使用 python3.8 实现 Steam 游戏 恶魔轮盘(BuckshotRoulette), 只实现纯 console版完全随机的单人无对战游戏逻辑基础运行(带debuglog), 纯娱乐代码 # 严正声明 本项目中的代码仅用于学习、研究和交流之目的。所有代码均来源于互联网公开渠道或开源项目,我们不对代码的合法性、准确性、完整性、适用性等做任何保证。若该代码侵害了您的合法权益,请您立即与我们联系,我们会在第一时间核实处理。 -- Gitee