人机大战小游戏
# 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,'胜利') {:5_108:}
页:
[1]