想写点东西把自己学习python的过程记录下来,于是就有了菜鸟学python
前段时间看了Crossin老师的python教程
里面有些小游戏很不错
比如这个射门游戏
我也试着写了一个
#coding:UTF-8 #注释中有中文所以要加这个
"""this is a football game"""
from random import choice
score = [0,0] #数组:分别表示com_score和you_score
direction = ['left','center','right'] #数组:电脑表示防守方向
def kick(): #函数:射门
print '=====%s kick=====' % (playername)
print 'choice one side to shoot'
print 'left center right'
you_kick = raw_input()
com_save = choice(direction)
if you_kick != com_save:
print 'goal!!!'
score[1] += 1
else:
print 'oops...'
print '=====score:(com)%d:(%s)%d====='%(score[0],playername,score[1])
def save(): #函数:防守
com_kick = choice(direction)
print '=====%s save=====' % (playername)
print 'choice one side you save'
you_save = raw_input()
print 'left center right'
if you_save != com_kick:
print 'goal!!!'
score[0] += 1
else:
print 'oops...'
print '=====score:(com)%d:(%s)%d====='%(score[0],playername,score[1])
print 'please input you name:'
playername = raw_input()
print 'please input round you want to play'
round = input()
for i in range(round): #循环
print '=====round %d====='%(i+1)
kick()
save()
while score[0] == score[1]: #平手的加时赛
i += 1
print '=====overtime====='
print '=====round %d====='%(i+1)
kick()
save()
if score[0] > score[1]: #判断输赢
print '%s lose...'%(playername)
else :
print '%s win!!!'%(playername)