The little game of Tang Monk vs. Bai Gujing in the first part is the notes of class , I also found a silly one that I wrote in my early school days , Now I almost laughed myself to death , Share it, too ! I still remember writing it and sharing it with my friends , I really laughed to death ! This is Xiaobai's happiness ....
Part I : Interface implementation
Select identity ------if elif else Basic cycle of
# 1, Identity selection # ① Display prompt information # Welcome xxx game ! # Please choose your identity : # 1.xxx # 2.xxx # Please select :x # ②
Assign identity based on user selection ( Display different prompt messages ) # 1. - -- # 2. - -- # 3. - -- # Define game interface def print_menu():
print('='*60) print('\t\t**** Welcome to hammer hammer games, Enjoy it !!', sep='\n') print(
'\t\t**** Please choose your identity :', sep='\n') print('\t\t\t\t1. Hammer hammer ( The embodiment of sexuality and justice ...)', sep='\n')
print('\t\t\t\t2. tearful ( Cute and cute coexist ...)', sep='\n') print('=' *60) # Print game interface print_menu()
# Player operation selection interface choice = int(input(' Please make your choice (1~2):')) # Print a split line print('--'*36) #
Print the prompt information after the player makes a choice if choice == 1: print(' Tut , How dare you choose hammer !!! How dare you ?? You can only be a flower ... Decided for you !')
elif choice == 2: print(' pretty good , Enter the game, you are Huahua , Very promising !') else: print('
Are you blind ? No, there are only two options 1 and 2 Do you ?', sep='\n') print(' Forget it, forget it ... Look at you little fool, you can choose 2 bar ! Huahua is very good , Learn to be smart later ')
Part II : Game function realization
Initial variables defining combat effectiveness and vitality
There are three options for players to operate use if elif else Loop to achieve
while True: Heng Wei True Circular statement
# 2, Game progress # ① Display basic player information ( aggressivity Life value ) # ② Displays what players can do : # 1, leveling # - Increase player's attack power and HP #
2, hit BOSS # - Player pair BOSS Attack , Players want to attack BOSS,BOSS Counterattack the player # - calculation BOSS Is it destroyed by the player , Whether the player is BOSS eliminate # -
game over # 3, escape # - Exit the game , Display prompt information , game over ! # Create variable fight = 2 # Initial combat effectiveness blood = 2 # Initial vitality #
Create a variable , preservation boss HP and attack power boss_fight = 10 boss_blood = 10 # Print a split line print('--'*36)
# Display player information print(f' tearful , What is your vitality {blood}, What is your attack power {fight}') #
Because the game options need to be displayed repeatedly , So you have to write it into a loop while True: # Print a split line print('--' * 36) print(
'\t\t**** Please select your operation (boss Very strong , If there is no hammer , It is recommended to escape directly (*^▽^*)):', sep='\n') print(
'\t\t\t\t1. leveling : It can increase your vitality and attack power !( No hammer You can only work alone )', sep='\n') print(
'\t\t\t\t2. hit boss( Let hammer do this )', sep='\n') print('\t\t\t\t3. escape ( Come on, come on , Behind the hammer , Hammer protect you )',
sep='\n') # Print a split line print('--' * 36) choice1 = int(input(' Please Huahua, little cute Select the operation you want :')) #
Process selected results if choice1 == 1: fight += 2 blood += 2 print(f' Congratulations on Huahua's successful upgrade , What is your vitality now {blood}
, Attack power is {fight}') # Print a split line print('--' * 36) elif choice1 == 2: if blood > 10 and
fight> 10: print(' You slapped me to death Boss, congratulations ! You can protect the hammer in the future !GAME OVER') break # Print a split line print(
'--' * 36) elif blood == 10 and fight == 10: print(
' You and Boss War 300 We can't decide the outcome of the round yet , Hammer hammer , A hammer blocked it boss GAME OVER') break # Print a split line print('--' * 36
) else: print('Boss Beat you into meat paste , Hammer hammer came and boss Happy to make steamed stuffed buns ! GAME OVER') break # Print a split line print(
'--' * 36) elif choice1 == 3: print(' Flower feeling boss It's too fierce , Whew, I ran behind the sledgehammer ! GAME OVER')
break # Print a split line print('--' * 36) else: print(' You blind man , Just three options ! Again only 1 2 3') #
Print a split line print('--' * 36)
Complete code :
# Define game interface def print_menu(): print('='*60) print('\t\t**** Welcome to hammer hammer games, Enjoy it !!', sep
='\n') print('\t\t**** Please choose your identity :', sep='\n') print('\t\t\t\t1. Hammer hammer ( The embodiment of sexuality and justice ...)',
sep='\n') print('\t\t\t\t2. tearful ( Cute and cute coexist ...)', sep='\n') print('=' *60) # Print game interface
print_menu() # Player operation selection interface choice = int(input(' Please make your choice (1~2):')) # Print a split line print(
'--'*36) # Print the prompt information after the player makes a choice if choice == 1: print('
Tut , How dare you choose hammer !!! How dare you ?? You can only be a flower ... I decided for you !') elif choice == 2: print('
pretty good , Enter the game, you are Huahua , Very promising !') else: print(' Are you blind ? No, there are only two options 1 and 2 Do you ?', sep='\n') print('
Forget it, forget it ... Look at you little fool, you can choose 2 bar ! Huahua is very good , Learn to be smart later ') # Create variable fight = 2 # Initial combat effectiveness blood = 2 #
Initial vitality # Create a variable , preservation boss HP and attack power boss_fight = 10 boss_blood = 10 # Print a split line print(
'--'*36) # Display player information print(f' tearful , What is your vitality {blood}, What is your attack power {fight}') #
Because the game options need to be displayed repeatedly , So you have to write it into a loop while True: # Print a split line print('--' * 36) print(
'\t\t**** Please select your operation (boss Very strong , If there is no hammer , It is recommended to escape directly (*^▽^*)):', sep='\n') print(
'\t\t\t\t1. leveling : It can increase your vitality and attack power !( No hammer You can only work alone )', sep='\n') print(
'\t\t\t\t2. hit boss( Let hammer do this )', sep='\n') print('\t\t\t\t3. escape ( Come on, come on , Behind the hammer , Hammer protect you )',
sep='\n') # Print a split line print('--' * 36) choice1 = int(input(' Please Huahua, little cute Select the operation you want :')) #
Process selected results if choice1 == 1: fight += 2 blood += 2 print(f' Congratulations on Huahua's successful upgrade , What is your vitality now {blood}
, Attack power is {fight}') # Print a split line print('--' * 36) elif choice1 == 2: if blood > 10 and
fight> 10: print(' You slapped me to death Boss, congratulations ! You can protect the hammer in the future !GAME OVER') break # Print a split line print(
'--' * 36) elif blood == 10 and fight == 10: print(
' You and Boss War 300 We can't decide the outcome of the round yet , Hammer hammer , A hammer blocked it boss GAME OVER') break # Print a split line print('--' * 36
) else: print('Boss Beat you into meat paste , Hammer hammer came and boss Happy to make steamed stuffed buns ! GAME OVER') break # Print a split line print(
'--' * 36) elif choice1 == 3: print(' Flower feeling boss It's too fierce , Whew, I ran behind the sledgehammer ! GAME OVER')
break # Print a split line print('--' * 36) else: print(' You blind man , Just three options ! Again only 1 2 3') #
Print a split line print('--' * 36)

Technology