鱼C论坛

 找回密码
 立即注册
查看: 4361|回复: 1

[吹水] 人机大战小游戏

[复制链接]
发表于 2022-3-26 20:18:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
# coding:utf-8
'''
player_name 玩家名称
choice_name 电脑名称
player_fist 玩家出拳
computer_fist 电脑出拳
answer 再次游戏变量
'''
import random
player_score=0  #玩家分数
computer_score=0 #电脑分数
#输出
print('''
***************欢迎来到4399游戏平台*********
                石头  剪刀  布   
*****************************************''')
player_name = input("请输入玩家姓名:")
print("1.雷电将军 2.摩拉克斯 3.巴巴托斯")
choice=eval(input("请选择电脑角色:"))
if choice==1:
    choice_name='雷电将军'
elif choice==2:
    choice_name='摩拉克斯'
elif choice==3:
    choice_name='巴巴托斯'
else:
    choice_name='匿名玩家'
print(player_name,'vs',choice_name)
while True:
    #玩家出拳
    player_fist=eval(input("----请出拳:1.石头    2.剪刀     3.布-----\n"))
    if player_fist==1:
        player_fist_name='石头'
    elif player_fist==2:
        player_fist_name='剪刀'
    elif player_fist==3:
        player_fist_name='布'
    else:
        player_fist_name='石头'
        player_fist=1
    #电脑角色出拳
    computer_fist=random.randint(1,3)
    if computer_fist==1:
        choice_fist_name='石头'
    elif computer_fist==2:
        choice_fist_name='剪刀'
    else:
        choice_fist_name='布'
    print(player_name,"出拳:",player_fist_name)
    print()
    print(choice_name,'出拳:',choice_fist_name)
    if player_fist==computer_fist:
        print("平局")
    elif player_fist==1 and computer_fist==2:
        print(player_name,"胜")
    elif player_fist==2 and computer_fist==3:
        print(player_name,"胜")
    elif player_fist==3 and computer_fist==1:
        print(player_name,"胜")
        player_score+=1
    else:
        print(choice_name,"胜")
        computer_score+=1
    answer=input('再来一局不?y/n')
    if answer!='y':
        break
print('---------------------')
print(player_name,'获得',player_score,'分')
print(choice_name,'获得',computer_score,'分')
print('---------------------')
if player_score==computer_score:
    print("平局")
elif player_score<computer_score:
    print(choice_name,"胜利")
else:
    print(player_name,'胜利')
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-3-26 20:44:42 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-31 05:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表