pythonプロジェクト実戦-ミニゲーム


プロジェクトのルール:
1、プレイヤーと敵はそれぞれ既存のキャラクターから3つのキャラクターを選択する
2、現在の血液量と攻撃量をランダムに生成する
3、游戏规则:プレイヤーが敌に攻撃をかけると、敌の现在の血量=前の血量-プレイヤーの血量、同理
4、3セット2勝
5、プレイヤーの出番と敵の出番をカスタマイズする

    python   ,      Python  ,         ,    +Q :688244617

import time,random

#             
player_list =  ['【    】','【    】','【    】','【    】','【    】','【    】']
enemy_list = ['【    】','【    】','【    】','【    】','【    】','【    】']
players = random.sample(player_list,3)  # player_list     3 
enemies = random.sample(enemy_list,3)
player_info = {}
enemy_info = {}

#          
def born_role():
    life = random.randint(100,180) # 100 180       ,  
    attack = random.randint(30,50)
    return life,attack

#          
def show_role():
    for i in range(3):
        player_info[players[i]] = born_role()
        enemy_info[enemies[i]] = born_role()
    
    #      3   
    print('-----------------      -----------------')
    print('    :')
    for i in range(3):
        print('%s    :%d    :%d' 
        %(players[i],player_info[players[i]][0],player_info[players[i]][1]))
    print('--------------------------------------------')
    print('    :')
    
    #      3   
    for i in range(3):
        print('%s    :%d    :%d' 
        %(enemies[i],enemy_info[enemies[i]][0],enemy_info[enemies[i]][1]))
    print('--------------------------------------------')
    input('       。
'
) # , 。 # , 。 def order_role(): global players order_dict = {} for i in range(3): order = int(input(' %s ?( 1~3)'% players[i])) order_dict[order] = players[i] players = [] for i in range(1,4): players.append(order_dict[i]) print('
:%s、%s、%s'
%(players[0],players[1],players[2])) print(' :%s、%s、%s' %(enemies[0],enemies[1],enemies[2])) # PK def pk_role(): round = 1 score = 0 for i in range(3): # player_name = players[i] enemy_name = enemies[i] player_life = player_info[players[i]][0] player_attack = player_info[players[i]][1] enemy_life = enemy_info[enemies[i]][0] enemy_attack = enemy_info[enemies[i]][1] # print('
----------------- 【 %d 】 -----------------'
% round) print(' :%s vs :%s ' %(player_name,enemy_name)) # print('%s :%d :%d' %(player_name,player_life,player_attack)) print('%s :%d :%d' %(enemy_name,enemy_life,enemy_attack)) print('--------------------------------------------') input(' 。
'
) # , 。 while player_life > 0 and enemy_life > 0: enemy_life = enemy_life - player_attack player_life = player_life - enemy_attack print('%s ,%s %d' % (player_name,enemy_name,enemy_life)) print('%s ,%s %d' % (enemy_name,player_name,player_life)) print('--------------------------------------------') time.sleep(1) else: # , score 。 # show_result() , result。 print(show_result(player_life,enemy_life)[1]) # show_result() , 。 score += int(show_result(player_life,enemy_life)[0]) round += 1 input('

'
) if score > 0: print('【 : !】
'
) elif score < 0: print('【 : !】
'
) else: print('【 : !】
'
) # 。 def show_result(player_life,enemy_life): # : , 。 if player_life > 0 and enemy_life <= 0: result = '
, !'
return 1,result # (1,'
, !'), 。
elif player_life <= 0 and enemy_life > 0: result = '
, !'
return -1,result else : result = '
, !'
return 0,result # ( ) def main(): show_role() order_role() pk_role() # ( )