python编程猜拳游戏_求助,用python编写一个猜拳游戏程序,要求有这样的开头

匿名用户

1级

2016-07-27 回答

#coding=utf8

import random

changes = ["", "石头", "剪子", "布"]

integral = 0

def show_changes():

message = "\n"

for index, value in enumerate(changes):

if index == 0:

continue

message += "{0}. {1}".format(index, value)

if index != len(changes) - 1:

message += "  "

return message

def compute_result(_me, _ra):

global integral

result = "错误"

result = "平局" if _me == _ra else result

result = "胜利" if _me == "1" and _ra == "2" or \

_me == "2" and _ra == "3" or \

_me == "3" and _ra == "1" else result

result = "失败" if _me == "1" and _ra == "3" or \

_me == "2" and _ra == "1" or \

_me == "3" and _ra == "2" else result

if result == "胜利":

integral += 1

if result == "失败":

integral -= 1

return result

def run_game():

while 1:

print show_changes()

_me = str(raw_input("请出拳:").strip())

_ra = str(random.randint(1, len(changes) - 1))

res = compute_result(_me, _ra)

try:

changes[int(_me)]

except:

print "出拳错误!"

continue

print "你出<{0}> 对方出<{1}> 本次对战<{2}> 当前积分<{3}>".format(

changes[int(_me)],

changes[int(_ra)],

res,

integral

)

tp = raw_input("\n请选择是否退出(yes/no): ").strip()

if tp == "no":

continue

elif tp == "yes":

print "已退出 !"

else:

print "输入错误,已退出游戏!"

break

print "游戏开始"

while 1:

print

print "*********************"

print "1. 开始新游戏"

print "2. 载入游戏"

print "3. 退出"

print "*********************"

change = raw_input("请选择:").strip()

print

if change == "1":

print "正在载入新游戏 ..."

integral = 0

run_game()

print "您当前的得分是:{0}".format(integral)

elif change == "2":

print "正在载入 ..."

run_game()

print "您当前的得分是:{0}".format(integral)

elif change == "3":

break

else:

print "输入错误 ! 请重新输入 !"

print "游戏结束"

这可是我自己手打的 要采纳呦

有什么问题可以追问 或许我也可以教教你写代码的思路

学会了思路 你就知道怎样自己写程序了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值