猜拳2.0(优化后)

import random


def menu():
    print("-" * 30)
    print("-" * 10, "1.开始游戏", "-" * 10)
    print("-" * 10, "2.低级作弊游戏", "-" * 10)
    print("-" * 9, "3.中级作弊游戏", "-" * 9)
    print("-" * 9, "4.高级作弊游戏", "-" * 9)
    print("-" * 7, "其他任意键退出游戏", "-" * 7)
    print("-" * 30)


def stop():
    while 1:
        global ch2
        global ch1
        print("-" * 20)
        print("继续游戏输入:1")
        print("返回主菜单:9")
        print("查询战绩输入:5")
        print("开启低级作弊器输入:6")
        print("关闭作弊器输入:33")
        if ch2 == 0:
            print("开启中级作弊器输入:7")
        print("开启高级作弊器输入:8")
        print("-" * 20)
        ii = input()
        if ii == "1":
            game()
            break
        elif ii == "5":
            print("-" * 20)
            print("总游戏场数为:", a - 1, "胜场为:", x, "败场为:", y, "平局为:", z)
            if x == 0 and y == 0:
                print("一直为平局无胜负")
            elif x == 0:
                print("胜率为0,你真菜,别玩了")
            else:
                print("胜率为", x / (x + y))
            print("-" * 20)
        elif ii == "6":
            print("低级作弊器已开启")
            ch2 = 0
            ch1 = 0
            cheat1()
        elif ii == "7":
            print("中级作弊器已开启")
            ch2 = 0
            ch1 = 0
            cheat2()
        elif ii == "8":
            print("高级作弊器已开启")
            ch2 = 0
            ch1 = 0
            cheat3()
        elif ii == "9":
            print("返回主菜单")
            ch2 = 0
            ch1 = 0
            break
        elif ii == "33":
            ch2 = 0
            ch1 = 0
            print("作弊器已关闭")
        else:
            print("输入错误请重新选择")


def game():
    global a
    global ch2
    global ch1
    global jd
    global st
    global bu
    computer = random.randint(0, 2)
    # computer = 1
    if computer == 0:
        st = st + 1
    elif computer == 1:
        jd = jd + 1
    elif computer == 2:
        bu = bu + 1
    while 1:
        print("第", a, "局游戏")
        if ch2 == 1:
            if computer == 0:
                print("机器人接下来会出石头")
            elif computer == 1:
                print("机器人接下来会出剪刀")
            elif computer == 2:
                print("机器人接下来会出布")
        if ch1 == 1:
            if st <= jd and st <= bu:
                print("下一把出石头的获胜概率更大")
            elif jd <= st and jd <= bu:
                print("下一把出剪刀的获胜概率更大")
            elif bu <= st and bu <= jd:
                print("下一把出布的获胜概率更大")
            else:
                print("下一把出石头的获胜概率更大")
        print("请出拳 石头(0)/剪刀(1)/布(2)")
        player = input()
        if player == "0" or player == "1" or player == "2":
            player = int(player)
            if (player == 0) or (player == 1) or (player == 2):
                if (player == 0 and computer == 0) or (player == 1 and computer == 1) or (
                        player == 2 and computer == 2):
                    print("你出的是:%s" % player + ",计算机出的是%s" % computer)
                    print("平局")
                    a = a + 1
                    global z
                    z = z + 1
                    break
                elif (player == 0 and computer == 1) or (player == 1 and computer == 2) or (
                        player == 2 and computer == 0):
                    print("你出的是:%s" % player + ",计算机出的是%s" % computer)
                    print("我赢了")
                    global x
                    x += 1
                    a = a + 1
                    break
                else:
                    print("你出的是:%s" % player + ",计算机出的是%s" % computer)
                    print("你输了")
                    global y
                    y += 1
                    a = a + 1
                    break
        else:
            print("输入错误,请重新输入")
    stop()


def cheat1():
    global ch1
    ch1 = 1


def stop3():
    while 1:
        print("-" * 20)
        print("继续游戏输入:1")
        print("返回主菜单:9")
        print("查询战绩输入:5")
        print("-" * 20)
        ii = input()
        if ii == "1":
            cheat3()
            break
        elif ii == "5":
            print("-" * 20)
            print("总游戏场数为", a - 1, "胜场为", x, "败场为", y, "平局为", z)
            if x == 0 and y == 0:
                print("一直为平局无胜负")
            elif x == 0:
                print("胜率为0,你真菜,别玩了")
            else:
                print("胜率为", x / (x + y))
            print("-" * 20)
        elif ii == "9":
            print("返回主菜单")
            break
        else:
            print("输入错误请重新选择")


def cheat3():
    global a
    while 1:
        print("第", a, "局游戏")
        print("请出拳 石头(0)/剪刀(1)/布(2)")
        player = input()
        if player == "0" or player == "1" or player == "2":
            player = int(player)
            if (player == 0) or (player == 1) or (player == 2):
                if player == 0:
                    computer = 1
                elif player == 1:
                    computer = 2
                elif player == 2:
                    computer = 0
                if (player == 0 and computer == 1) or (player == 1 and computer == 2) or (
                        player == 2 and computer == 0):
                    print("你出的是:%s" % player + ",计算机出的是%s" % computer)
                    print("我赢了")
                    global x
                    x += 1
                    a = a + 1
                    break
        else:
            print("输入错误,请重新输入")
    stop3()


def cheat2():
    global ch2
    ch2 = 1


a = 1  # 游戏总局数 == a
a = int(a)
z = 0
z = int(z)
x = 0  # 游戏总胜场 x
x = int(x)
y = 0  # 游戏总败场 y
y = int(y)
ch2 = 0
ch2 = int(ch2)
ch1 = 0
ch1 = int(ch1)
jd = int(0)
st = int(0)
bu = int(0)

while 1:
    menu()
    i = input()
    if i == "1":
        game()
    elif i == "2":
        print("低级作弊器已开启")
        cheat1()
    elif i == "3":
        print("中级作弊器已开启")
        cheat2()
    elif i == "4":
        print("高级作弊器已开启")
        cheat3()
    else:
        break

 添加了三个小型的作弊环节

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值