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)
The self. The attack=random. Randint (30, 50)
# 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. 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 you/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) :
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 the number 1 ~ 3) '% self. The players [I] name))
Order_dict [order]=self. Players [I]
Self. Players=[]
For I in range (1, 4) :
Self. Players. Append (order_dict [I])
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))
# 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')
Self. Enemies [I] fight_buff (self. The players [I], 'enemy', 'us')
Input (' \ n battle ready, please press enter key to continue, ')
Print (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ')
While the self. The players [I] life & gt; 0 and the self. The enemies [I] life> 0:
The self. The enemies [I] life -=self. Players [I] attack
The self. The players [I] life -=self. Enemies [I] attack
Print (' attacked our % s, % s enemy remaining HP % s' %
(self. Players [I]. The name, the self. The enemies [I] the name, the self. The enemies [I] life))
Print (' launched an attack enemy % s, % s our remaining HP % s' %
(self. Enemies [I]. The name, the self. The players [I] the name, the self. The players [I] life))
Print (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ')
Time. Sleep (1)
If the self. The players [I] life & lt;=0 and the self. The enemies [I] life> 0:
Print (' \ n regret, our % s hang up! '% (self. Players [I] name))
The self. The score -=1
Elif self. Players [I] life & gt; 0 and the self. The enemies [I] life<=0:
Print (' \ n congratulations, we survived, % s' % (self. The players [I] name))
The self. The score +=1
The else:
Print (' \ n my day, they were both dead! ')
# to show the end
Def show_result (self) :
Input (' \ n please press enter to see the final result, \ n ')
If the self. The score & gt; 0:
Print (' [results] \ n you won, and eventually all the treasure you! ')
Elif self. Score==0:
Print (' [results] \ n you didn't win, but without failure, flew away in the darkness the oulu empire, ')
The else:
Print (' [results] \ n you lose, purgatory arenas has some skeletons, ')
Game=game ()
This string of code other all understand, is a line don't understand: (pictured)
nullnullnullnullnullnull