list练习随机射门小游戏

from random import choice

def round(youround, action, score_you, score_com):
    direction = ['left', 'center', 'right']
    list1 = ['Kick!', 'shoot', 'kicked', 'saved', 'Goal!', 'Opps...']
    list2 = ['Save!', 'save', 'saved', 'kicked', 'Opps...', 'Saved!']
    if action == 'Kick':
        actionList = list1
    else:
        actionList = list2
    print('====Round %d - You %s!====' %(youround + 1, actionList[0]))
    print('choose one side to %s:' %actionList[1])
    print(str(direction))
    you = choice(direction)
    print('you %s ' %actionList[2] + you)
    com = choice(direction)
    print('computer %s ' %actionList[3] + com)
    if you != com:
        print(actionList[4])
        if action == 'Kick':
            score_you += 1
        if action == 'Save':
            score_com += 1
    else:
        print(actionList[5])
    print('score:%d(you)-%d(com)\n' %(score_you, score_com))
    return score_you, score_com

score_you = 0
score_com = 0
for i in range(5):
    score_you, score_com = round(i, 'Kick', score_you, score_com)
    score_you, score_com = round(i, 'Save', score_you, score_com)
if score_you > score_com:
    print('you win!')
elif score_you < score_com:
    print('com win!')
else:
    print('draw!')

你可能感兴趣的:(list练习随机射门小游戏)