Home > other >  The small white for help
The small white for help

Time:05-02

Code line 111 cooperat_role function run times wrong prompt no life in the Game or attack attribute,, but the Game other functions also call the two class attribute, and strives for the bosses, I wish a happy big 51 ~
Import the random
The import time

# create a class that can be instance into specific characters
The class Role:
Def __init__ (self, name='[role]) : #
the role name as the default parametersThe self. The name=name
Self. Life=random. Randint (100150) # HP
The self. The attack=random. Randint (30, 50) # damage

# to create three subclasses, and can be instantiated into three different career

The class Knight (Role) :
Def __init__ (self, name='knight of light) : # subclasses role name as the default parameter
Role. __init__ (self, name) # use the parent class initialization function
Self. Life=self. The cavaliers have life * 5 # 5 HP
Self. Attack=self. Attack the cavaliers have * 3 # 3 damage

# professional restraint relationship
Def fight_buff (self, the opponent, str1, str2) :
If opponent. Name=='[shadow assassin] :
Self. Attack=int (self. Attack * 1.5)
Print (' (% s) knight of light on (% s) [shadow assassin] said: "let the endless light sanctions you fallen!" '% (str1, str2))

The class Assassin (Role) :
Def __init__ (self, name='[shadow assassin]) :
Role. __init__ (self, name)
Self. Life=self. Life * 3
The self. The attack=self. Attack * 5

# professional restraint relationship
Def fight_buff (self, the opponent, str1, str2) :
If opponent. Name=='[elves crossbowman] :
Self. Attack=int (self. Attack * 1.5)
Print (' (% s) [shadow assassin] for (% s) [elves crossbowman] said: "actively courting death, don't blame me for terminating," '% (str1, str2))

The class Bowman (Role) :
Def __init__ (self, name='[elves crossbowman]) :
Role. __init__ (self, name)
Self. Life=self. Life * 4
The self. The attack=self. Attack * 4

# professional restraint relationship
Def fight_buff (self, the opponent, str1, str2) :
If opponent. Name=='knight of light:
Self. Attack=int (self. Attack * 1.5)
Print (' (% s) [elves crossbowman] of knight of light (% s) said: "what about riding a stubborn donkey? You touch my clothes, "' % (str1, str2))

# create a class that can generate 3 v3 and show: language can be divided into: welcome to randomly generated, display roles
The class Game () :
Def __init__ (self) :
Self. Players=[] # to save the player order
Self. Enemies=[] # to save the enemy order
The self. The score=0 # match score
Self. I=0 # remember rounds

#, in turn, perform the following functionsSelf. Game_start () #
welcome languageSelf. Born_role () # randomly generated six characters
Self. Show_role () # show roles
Self. Order_role sort () # and show
Self. Cooperat_role # () to test whether the formation formed by
Self. Pk_role () # let both sides Pk and show the results
Self. Show_result () # show the end

# welcome
Def game_start (self) :
Print (" -- -- -- -- -- -- -- -- -- -- -- -- welcome to "purgatory arenas" -- -- -- -- -- -- -- -- -- -- -- -- ')
Print (' mountains, in the evening on the old, the empire's northern borders, there are the legendary "purgatory arenas," ')
Print (' blood and is gladiator's home to return to combat, money and honor is gladiator's faith! ')
Print (' today, as long as your team can win, you will get a enough wealth in 500, ')
Time. Sleep (2)
Print (' will be randomly generated [you] and [] the enemy team! ')
Input (' \ n for the wins, press any key to continue, \ n ')

# randomly generated six characters
Def born_role (self) : # each one randomly generated role, role allowed to repeat,
For I in range (3) :
Self. Players. Append (random choice ([Knight (), Assassin (), Bowman ())))
Self. Enemies. Append (random choice ([Knight (), Assassin (), Bowman ())))

# show roles
Def show_role (self) :
Print (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the role information -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ')
Print (' your team:)
For I in range (3) :
Print (' blood (our) % s: % s attacks: % s' %
(self. Players [I]. The name, the self. The players [I] life, the self. The players [I] attack))
Print (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ')

Print (' the enemy team:)
For I in range (3) :
Print (' blood volume (an enemy) % s: % s attacks: % s' %
(self. Enemies [I]. The name, the self. The enemies [I] life, the self. The enemies [I] attack))
Print (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ')
Input (please press enter key to continue, '\ n')

# sort and show
Def order_role (self) :
Order_dict={}
For I in range (3) :
The order=int (input (' what do you want to put how many % s a play? (input number 1 ~ 3) '% self. The players [I] name)) # (Knight from born_role function (), Assassin (), Bowman () the name of the class attribute)
Order_dict [order]=self. Players [I] # stored in the form of a dictionary (storage is born_role function to generate the classes Knight (), Assassin (), Bowman (), and generate the number of user input data)
Self. Players=[] # reset players list
For I in range (1, 4) :
Self. Players. Append (order_dict [I]) # (according to a key value is put forward, from order_dict dictionary)
Print (' \ n your team lineup is: % s, % s, % s'
% (self. Players [0]. The name, the self. The players [1]. The name, the self. The players [2]. The name))
Print (' the enemy team lineup is: % s, % s, % s'
% (self. Enemies [0]. The name, the self. The enemies [1]. The name, the self. The enemies [2]. The name))
# test whether both sides form a team buff
Def cooperat_role (self) :
If the self. The players [0]. Name==self. The players [1]. The name==self. The players [2]. Name:
For I in range (3) :
The self. The players [I] life=int (self. Life * 1.25)
Print (' congratulations you get team buff, blood volume rose 25% ')
If the self. The players [0] name!=self. Players [1]. The name!=self. Players [2]. Name:
For I in range (3) :
The self. The players [I]. Attack=int (self. Attack * 1.25)
Print (' congratulations for team buff, up 25% damage ')
If the self. The enemies [0]. Name==self. The enemies [1]. The name==self. Enemies [2]. Name:
For I in range (3) :
The self. The enemies [I] life=int (self. Life * 1.25)
Print (' the enemy team buff, HP rise 25%)
If the self. The enemies [0] name!=self. Enemies [1]. The name!=self. Enemies [2]. Name:
For I in range (3) :
The self. The enemies [I]. Attack=int (self. Attack * 1.25)
Print (' the enemy get team buff, up 25% damage)
The else:
Print (' everybody doesn't win the team buff? ')
# let both sides Pk and show the results
Def pk_role (self) :
For I in range (3) :
Print (' \ n -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the first % s [round] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- '% (I + 1))
# to add buff before the start of every game
Self. Players [I] fight_buff (self. The enemies [I], 'we', 'enemy') # we here, the enemy corresponds to the above methods fight_buff enemy player attributes and str1, str2
Self. Enemies [I] fight_buff (self. The players [I], 'enemy', 'us')
Input (' \ n battle ready, please press enter key to continue, ')
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related