Foreword
Hello! Hello, everyone. I'm chestnut.
Plot is the core element of the game and one of the main sources of game immersion.
No matter what type of game it is, whether it takes the plot as the main playing point or not, excellent plot can always make a game shine.
I find 🎄
Which plot of the tiktok game is pretty funny recently, and that's the way it is. I found a fear when I was shaking my voice.
Horror game anchor, the horror game is very interesting. I forgot its name: it seems to be a very hot horror game.
I only remember this short plot - a scary old woman, and then the player's words are small, hiding can't be found.
Recently, I have been studying it, and then I have developed a simple version of the plot war game!
Because it's too difficult to write plot game + interface, so let's make do with learning this simple version! twenty-three thousand three hundred and thirty-three
"The top of the purple ban"
1, Game settings
[1] Story background [2] character introduction [3] start the game [4] exit the game
Environment configuration:
Python3, Pycharm ,Pygame.
Installation of third-party libraries: pip # install pygame
Effect display:
Â
Â
Code demonstration:
Main program menu:
from conf import setting from conf import templates from module import games from module import common if __name__ == "__main__": exit_flag = False while not exit_flag: # opening menu print(templates.GAME_MENU) func = input("\n Please select the function number:[1-4]") if func not in ("1", "2", "3", "4"): continue # Quit if func == "4": exit_flag = True continue # Game background if func == "1": print(templates.GAME_TITLE.format(currrole="", apponent="")) common.load_begin() # View person information if func == "2": cui_str = common.format_info(common.load_info("xmcx")) ye_str = common.format_info(common.load_info("ygc")) print(templates.ROLE_INFO.format(cui=cui_str, ye=ye_str)) # Start the game if func == "3": games.start()
All static display template file resources used in the program:
# Game start title menu GAME_TITLE = ''' --------------------------------------------------------- | | | Decisive battle on the top of the Forbidden City | | | --------------------------------------------------------- [[story background] ''' # Main program system menu template GAME_MENU = '''\033[1;32m --------------------------------------------------------- | | | Decisive battle on the top of the Forbidden City | | | --------------------------------------------------------- [1]Story background [2] character introduction [3] start the game [4] exit the game \033[0m;''' # Character introduction display template ROLE_INFO = '''\033[1;30m [[introduction] ---------------------------------------------------------- ximen chuixue: {cui} Ye Gucheng: {ye} \033[0m;'''
This module is used to initialize user information xml:
from xml.etree import ElementTree as ET root = ET.Element("game-user") user1 = ET.SubElement(root, "user", attrib={"key": "xmcx"}) name1 = ET.SubElement(user1, "name") alias1 = ET.SubElement(user1, "alias") blood1 = ET.SubElement(user1, "blood") sword1 = ET.SubElement(user1, "sword") introduct1 = ET.SubElement(user1, "introduce") kongfu = ET.SubElement(user1,"kongfu") name1.text = "ximen chuixue" alias1.text = "Sword God" blood1.text = "200" sword1.text = "Black scabbard sword" kongfu.text = '{"Snow dyed rainbow":15, "The sword God smiled":30 ,"Snow and ice":20, "It snowed all over the world": 25 }' introduct1.text = "Ximen chuixue is based in the Jianghu with his excellent sword technique. He is withdrawn by nature. He is not funny. He is fond of sword as his life. He takes people's lives between lightning and flint. He regards killing as an art." \ "Standing upright and white as snow, the sword around the waist is black, dark, narrow and ancient. It is a sharp weapon in the world. The blade is three feet and seven inches, and the net weight is seven kilograms and thirteen Liang" user2 = ET.SubElement(root, "user", attrib={"key": "ygc"}) name2 = ET.SubElement(user2, "name") alias2 = ET.SubElement(user2, "alias") blood2 = ET.SubElement(user2, "blood") sword2 = ET.SubElement(user2, "sword") kongfu = ET.SubElement(user2,"kongfu") introduct2 = ET.SubElement(user2, "introduce") name2.text = " Ye Gucheng" alias2.text = "Blademaster" blood2.text = "200" sword2.text = "Ancient long sword" kongfu.text = '{"Tianwaifeixian":20, "Dugu Jiujian":30 ,"A throw of heaven and earth":15, "Concentrate and return to the yuan": 10 }' introduct2.text = "His appearance is beautiful and dignified. He has been obsessed with the sword since he was a child, and his talent is very high. He has learned excellent sword skills. Ye Gucheng has created his own brilliant sword moves「Tianwaifeixian」" \ "Unique swordsmanship created by Yan Nantian「Magic sword formula」They are all sword techniques that stand out in the world and are famous at home. The sword is an overseas cold bottle elite, blowing hair and breaking hair," \ "The blade is three feet three, and the net weight is six kilograms and four Liang" xmlfile = ET.ElementTree(root) xmlfile.write("users.xml", encoding="utf-8", xml_declaration=True)
It is used to define the opponent dialogue list resource after both sides attack. It is randomly selected from the list during the actual dialogue
attack_succ_msg = ["The sword technique really deserves its reputation", "Good cow B My sword technique", "oh dear!I couldn't stop it", "I got another knife"] attack_fail_msg = ["It seems so", "I hide, I hide, I hide", "How can't you hit it!", "Just practice your sword skills"]
ending
okay! That's it! (didi can get all the source code for free)
Come and get it from me~
Article collection series——
1.0 Python article collection | (Introduction to actual combat, games, Turtle, cases, etc.)
(welcome to read ~ the source materials of the articles written before are all in it)