Untitled
unknown
plain_text
a year ago
10 kB
6
Indexable
import tkinter as tk from tkinter import Entry, StringVar, Label, Button, Tk import random import time import playsound root = Tk() root.title("Telium") root.geometry("800x500") def play_song(file_path): playsound(file_path) def main(): song_file = "this_world_knows_no_emporer.mp3" repeat = True while True: play_song(song_file) if not repeat: break def update_textbox(): # This function updates the content of the textbox global gameinfo textbox_var.set(gameinfo) # Create the main window root = tk.Tk() root.title("info-machine") # Initialize the variable to be displayed gameinfo="welcome to telium" # Create a read-only textbox (Entry widget) textbox_var = tk.StringVar() textbox = tk.Entry(root, textvariable=textbox_var, state="readonly", width=50) textbox.pack(pady=10) # Create a button to trigger the update of the textbox button = tk.Button(root, text="Update Textbox", command=update_textbox) button.pack() def backgroundchanger(imagefilename): # Create a Label widget with the image as the background background_label = Label(root, image=imagefilename) background_label.place(x=0, y=0, relwidth=1, relheight=1) def on_medbay_button_click(AP, shipmates): # This function will be called when the button is clicked global medbay ship_location=medbay label_var.set("location") backgroundchanger(medbay.jpeg) AP=AP-1 shipmates=shipmates+2 gameinfo="you have helped 2 shipmates get back to work!" update_textbox() return ship_location # Create the main window root = tk.Tk() root.title("MED") # Initialize the variable to be changed medbay="in" # Create a label to display the variable value label_var = tk.StringVar() label_var.set("location") label = tk.Label(root, textvariable=label_var) label.pack(pady=10) # Create a button and associate the on_button_click function with its click event button1 = tk.Button(root, text="Click me for medbay", command=on_medbay_button_click) button1.pack() def on_reactor_button_click(AP,power): # This function will be called when the button is clicked global reactor ship_location=reactor label_var.set("location") backgroundchanger(reactor.jpeg) AP=AP-1 power=power+15 gameinfo="you have fired up the reactor and gained 15 power!" update_textbox() return ship_location # Create the main window root = tk.Tk() root.title("REA") # Initialize the variable to be changed reactor="in" # Create a label to display the variable value label_var = tk.StringVar() label_var.set("location") label = tk.Label(root, textvariable=label_var) label.pack(pady=10) # Create a button and associate the on_button_click function with its click event button1 = tk.Button(root, text="Click me for reactor", command=on_reactor_button_click) button1.pack() def on_armory_button_click(AP,alienhealth): # This function will be called when the button is clicked global armory ship_location=armory label_var.set("location") backgroundchanger(armoury.jpeg) AP=AP-1 alienhealth=alienhealth-17 gameinfo="you have shot at the alien and it has lost some health!" return ship_location # Create the main window root = tk.Tk() root.title("ARM") # Initialize the variable to be changed armory="in" # Create a label to display the variable value label_var = tk.StringVar() label_var.set("location") label = tk.Label(root, textvariable=label_var) label.pack(pady=10) # Create a button and associate the on_button_click function with its click event button1 = tk.Button(root, text="Click me for armory", command=on_armory_button_click) button1.pack() def on_bridge_button_click(AP,power,gameinfo,progress,progressioncounter): # This function will be called when the button is clicked global bridge ship_location=bridge label_var.set("location") backgroundchanger(bridge.jpeg) if power>20 and progressioncounter==0 and escape_possible==True: AP=AP-1 power=power-20 gameinfo="the engines are firing you are one step closer to escape!" update_textbox() progress=progress+1 progressioncounter=progressioncounter+1 return AP, power, progress, progressioncounter elif power>30 and progressioncounter==1 and escape_possible==True: AP=AP-1 power=power-30 gameinfo="the engines are firing you are one step closer to escape!" update_textbox() rogress=progress+1 progressioncounter=progressioncounter+1 return AP, power, progress, progressioncounter elif power>40 and progressioncounter==2 and escape_possible==True: AP=AP-1 power=power-40 gameinfo="the engines are firing you are one step closer to escape!" update_textbox() rogress=progress+1 progressioncounter=progressioncounter+1 return AP, power, progress, progressioncounter elif power>45 and progressioncounter==3 and escape_possible==True: AP=AP-1 power=power-45 gameinfo="the engines are firing you are one step closer to escape!" update_textbox() rogress=progress+1 progressioncounter=progressioncounter+1 return AP, power, progress, progressioncounter else: gameinfo="you can't escape yet!" update_textbox() return ship_location # Create the main window root = tk.Tk() root.title("BRI") # Initialize the variable to be changed bridge="in" # Create a label to display the variable value label_var = tk.StringVar() label_var.set("location") label = tk.Label(root, textvariable=label_var) label.pack(pady=10) # Create a button and associate the on_button_click function with its click event button1 = tk.Button(root, text="Click me for bridge",command=on_bridge_button_click) button1.pack() def on_lab_button_click(AP): # This function will be called when the button is clicked global lab ship_location=lab label_var.set("location") backgroundchanger(lab.jpeg) infoselect = ["The alien has 120 health at the start", "the more crewmates the more AP", "it takes 3 turns on the bridge to escape", "the game is only 12 rounds", "the alien has a chance to attack you"] randominfo= random.randint(0,4) AP=AP-1 return ship_location # Create the main window root = tk.Tk() root.title("LAB") # Initialize the variable to be changed lab="in" # Create a label to display the variable value label_var = tk.StringVar() label_var.set("location") label = tk.Label(root, textvariable=label_var) label.pack(pady=10) # Create a button and associate the on_button_click function with its click event button1 = tk.Button(root, text="Click me for lab", command=on_lab_button_click) button1.pack() def on_overview_button_click(): # This function will be called when the button is clicked global overview ship_location=overview label_var.set("location") backgroundchanger(overview.jpeg) return ship_location # Create the main window root = tk.Tk() root.title("OVE") # Initialize the variable to be changed overview="in" # Create a label to display the variable value label_var = tk.StringVar() label_var.set("location") label = tk.Label(root, textvariable=label_var) label.pack(pady=10) # Create a button and associate the on_button_click function with its click event button1 = tk.Button(root, text="Click me for overview", command=on_overview_button_click) button1.pack() #this is the code that selects what action the alien will take using an array to determine this def alienselect(): abilities = ["crew","grab","fire","blackout","infection"] randomability= random.randint(0,4) return randomability # this section tackles what each action is associated with, selecting the one chosen by the random array above #it also effects the relevant statistic and alerts the player of what has happened def alienturn(randomability,shipmates,hulldamage,power,AP): if randomability=="crew": shipmates=shipmates-1 gameinfo= "The alien has injured a crew member! you have ",shipmates," personnel left" update_textbox() elif randomability=="grab": escape_possible= False gameinfo= "the Alien grabs your ship, you aren't going anyway next turn" update_textbox() elif randomability=="fire": hulldamage=hulldamage-15 gameinfo= "the alien has started a fire, you have ",hulldamage," hull damage left" update_textbox() elif randomability=="blackout": power=power-10 gameinfo= "the alien has started a blackout, you have ",power," power left" update_textbox() elif randomability=="infection": AP=AP-1 gameinfo= "the alien has put the ship into quarantine, you have ",AP," AP left" update_textbox() # this creates the main loop that will run the game in root.mainloop() game= True #this is a tutorial screen to let the player know what is happening and what each button does backgroundchanger(infoscreen.jpeg) #the next part sets out initial variable values important to the game shipmates=10 randomability="" power=0 progress=0 progressioncounter=0 counter=0 hulldamage=100 escape_possible= True #the actual game loop starts here using a condition controlled loop while game ==True: AP= shipmates//3 counter=counter+1 #then a selection is made as to whether or not any of the win conditions have been met if counter==12: gameinfo="you could not escape in time, the alien destroys the ship" update_textbox() backgroundchanger(outoftime.jpeg) time.sleep(10) repeat = False game=False elif alienhealth==0: gameinfo="you have defeated the alien!" update_textbox() backgroundchanger(hunter.jpeg) time.sleep(10) repeat = False game=False elif progress==4: gameinfo="you have escaped the alien!" update_textbox() backgroundchanger(escape.jpeg) time.sleep(10) repeat = False game=False elif hulldamage==0: gameinfo="The alien destroyed your ship!" update_textbox() backgroundchanger(destroy.jpeg) time.sleep(10) repeat = False game=False #this last selection is related to the continuing of the game after the player has had there AP depleted # it allows alien action then once this action is take the loop starts again and AP is replenished elif AP==0: escape_possible= True alienselect() gameinfo= "the alien is up to something" update_textbox() time.sleep(5) alienturn(randomability,shipmates,hulldamage,power,AP)
Editor is loading...
Leave a Comment