- 帖子
- 24
- 精华
- 0
- 积分
- 54
- 阅读权限
- 20
- 注册时间
- 2015-5-23
- 最后登录
- 2015-5-28
|
优化了一点点,不涉及技术- #coding:gbk #我的电脑用gbk才能显示汉字名字
- #football游戏,电脑随机进行扑救(左中右),你进行射门,三个方向,看能不能射进
- #football1.0
- #zzx 2015.03.12
- from random import choice
- print'------------------------欢迎来到欧冠点球的决胜时刻,请屏住呼吸,拭目以待吧---------------------------'
- #方向
- direction = ['left','middle','right']
- #电脑扑救方法
- def fight(name='computer') :
- if name == 'computer':
- dic = choice(direction)
- print'守门员%s迅速扑救,他扑向了皮球的%s方向。他能否守住呢?\n' %(name,dic)
- else :
- dic = raw_input('请输入您要扑球的方向(left,middle,right),看你能够抵挡住这世界波。\n')
- print'守门员%s迅速扑救,他扑向了球门的%s方向。他能否守住呢?\n' %(name,dic)
- return dic
- #输入射门
- def shoot(name='computer') :
- if name == 'computer':
- dic = choice(direction)
- print '\n%s发出了世界波,像球门快速飞来,你要赶快判断他的方向,守住大门!\n'%name
- else:
- dic = raw_input('请输入你要射门的方向(left,middle,right),关键一球哦!\n')
- print '\n%s发出了世界波,射向了球门的%s方向,你期待这进球的那一刻\n'%(name,dic)
- return dic
- def judge(shootDic,fightDic) :
- if shootDic == fightDic :
- print 'omg,伟大的守门员拯救了这场比赛。他将球扑出了球门。\n'
- return True
- else:
- print '球进了,恭喜你,伟大的射手!\n'
- return False
- #开始比赛
- man_point = 0 #初始化人分数,此处不需要分号
- computer_point = 0 #初始化电脑分数,此处不需要分号
- man = raw_input('请输入你的姓名:')
- for i in range(1,4):
- #人先射门,电脑守门
- print '下面由%s先主发点球,祈祷吧!'%man
- shootDic = shoot(man) #调用shoot函数,并赋值name=你的名字,执行else部分,就是crossin部分简单的,返回你的选择方向
- fightDic = fight() #调用fight函数,返回电脑的选择方向
- res = judge(shootDic,fightDic)
- if not res :
- man_point+=1
- print '好样的%s,球进了,加一分,总分为%d'%(man,man_point)
- #电脑射门,人守门
- print '交换场地,下面由电脑先发球'
- shootDic2 = shoot()
- fightDic2 = fight(man)
- res2 = judge(shootDic2,fightDic2)
- if not res2 :
- computer_point+=1
- print '好样的computer,球进了加一份,得分为%d'%computer_point
- print '总成绩是:%s--%d-----------computer--%d'%(man,man_point,computer_point)
- if man_point > computer_point :
- print '恭喜你,最终你赢得了胜利,伟大的射手----%s'%man
- elif man_point<computer_point :
- print '很遗憾,电脑赢得了胜利,你输了,再接再厉吧'
- else:
- print '平手啊,你和电脑一样厉害'
复制代码 |
|