#if elif else import pyaudiogame spk = pyaudiogame.speak MyApp = pyaudiogame.App("My Application") #Lets check if they pressed the right keys def check_keys(key): if key == "1": spk("Great, you are correct!") elif key == "return" or key == "space": spk("This is also correct!") elif key == "f2": spk("And you found the hidden key that's correct!") else: spk("Nope, try again, I'm sorry") def logic(actions): key = actions['key'] #Lets see if there was really a key press if key: check_keys(key) MyApp.logic = logic MyApp.run()
import pyaudiogame my_app = pyaudiogame.App(title="Test app")
#Pizza please import pyaudiogame from pyaudiogame import storage spk = pyaudiogame.speak MyApp = pyaudiogame.App("Pizza Please") storage.screen = ["start"] storage.toppings = ["cheese", "olives", "mushrooms", "Pepperoni", "french fries"] storage.your_toppings = ["cheese"] storage.did_run = False def is_number(number, topping_list): """Will check that what the user enters is really a number and not a letter, also that it is within our list""" if number in "0123456789": number = int(number) if number <= len(topping_list)-1: return number def say_message(message): """Will check if the message has been read and if so, passes. Else, it will read the message""" if not storage.did_run: spk(message) storage.did_run = True def add_topping(key): """Will add a topping to your pizza""" number = is_number(key, storage.toppings) if number or number == 0: storage.your_toppings.append(storage.toppings[number]) spk("You added %s to your pizza. Your pizza currently has %s on top" % (storage.toppings[number], storage.your_toppings))
#Our import to the builtin modules import random #Our imports from pyaudiogame import pyaudiogame game = pyaudiogame.App("Pie Heavens") storage = pyaudiogame.storage spk = pyaudiogame.speak #imports from the modules created for this game import scenes, fight #Our constants between_scenes = 2 #Here we have the lists we will use scene_list = [ scenes.healroom, scenes.damageroom, scenes.room1, scenes.room2, scenes.room3, scenes.room4, scenes.room5, scenes.room6 ] last_scenes = [] def set_variables(): """Will set all the variables in storage""" #stored variables storage.text = "" storage.scene = scenes.start storage.screen = "start" #player info storage.current_foe = None storage.player_level = 1 storage.player_hp = 100
self.speak(text) return text def main(): print(current_text) while True: c = raw_input("< direction?") navigate(c) if __name__ == '__main__': f = Text("I like to dance") import pyaudiogame my_app = pyaudiogame.App("Letters and words") storage = pyaudiogame.cash storage.text = Text("I like to dance") def logic(actions): """This is using the more basic change_letter and change_word functions from the word class""" k = actions['key'] mods = actions['mods'] if k == "right" and not mods: f.change_letter(1) elif k == "left" and not mods: f.change_letter(-1) elif k == "left" and "ctrl" in mods: f.change_word(-1) elif k == "right" and "ctrl" in mods: f.change_word(1)
import pyaudiogame spk = pyaudiogame.speech.speak #First create a basic app app = pyaudiogame.App("My hello world app") #Now make some game logic def logic(actions): """Our game logic function that gets run every iteration of our app's running loop""" key = actions['key'] if key == "space": spk("Hello world") #Put our logic into the app app.logic = logic #Run our app app.run()