Exemplo n.º 1
0
 def __init__(self, player_name, min_val, max_val, trials):
     #init some parameters of the game ...
     self.player_name = player_name
     self.min_val = min_val  #the minimum value to guess
     self.max_val = max_val  #the maximum value to guess
     self.init_trials = trials  #keep the original trials amount in memory
     self.trials = trials  #remaining number of trials
     #the number to guess:
     self.number = random.randint(self.min_val, self.max_val)
     self.guess = None  #the current player guess
     self.e_quit = thorpy.make_button("Quit",
                                      func=thorpy.functions.quit_menu_func)
     self.e_restart = thorpy.make_button("Restart", func=self.restart)
     #a ghost for storing quit and restart:
     self.e_group_menu = thorpy.make_group([self.e_quit, self.e_restart])
     #a counter displaying the trials and some hint/infos about the game
     self.e_counter = thorpy.make_text(text=self.get_trials_text(),
                                       font_color=(0, 0, 255))
     #the inserter element in which player can insert his guess
     self.e_insert = thorpy.Inserter(name="Try:")
     self.e_background = thorpy.Background(
         color=(200, 200, 255),
         elements=[self.e_counter, self.e_insert, self.e_group_menu])
     thorpy.store(self.e_background, gap=20)
     #reaction called each time the player has inserted something
     reaction_insert = thorpy.ConstantReaction(
         reacts_to=thorpy.constants.THORPY_EVENT,
         reac_func=self.reac_insert_func,
         event_args={
             "id": thorpy.constants.EVENT_INSERT,
             "el": self.e_insert
         })
     self.e_background.add_reaction(reaction_insert)
Exemplo n.º 2
0
def get_intro_text():
    image = thorpy.load_image("message_in_a_bottle_by_solid_pawn.png")
    image = pygame.transform.scale(image, (parameters.S,parameters.S))
    title_text = "Dear friend,\nA few years ago, I found a message in a bottle near the sea...\n"
    title = thorpy.make_text(title_text, thorpy.style.TITLE_FONT_SIZE, gui.TCOLOR)
    text = "At that time, I was working hard on that famous Topological Astronomy Problem and I began to inattentively read the message..."+\
            "But to my great surprise, it appeared that the author of the letter, a certain Gottfried Perigeo,"+\
            " was trying to complete a mad - though so brave! - travel around the world, following West-East axis, almost one century ago.\n\n"+\
            "    Except the fact that the poor explorer sent a desperate SOS message that was obviously received hundred year too late,"+\
            " my interest was peaked by the singular axis he was travelling. Here the story joins the Topological Astronomy Problem.\n\n"+\
            "    Indeed, my dear friend, I was - and I'm still - one of the rare physicists to believe that the world has the topology of a torus"+\
            " (explain uneducated people that it's like donut). Despite several celestial hints, most of my colleagues give no credit in this theory, and invest"+\
            "all their energy in proving that our planet is spherical. The situation was the same during Perigeo's life ; since the famous"+\
            "explorer Girato Settentrio completed the South-North around the world travel, it was clear that Gottfried Perigeo thought the planet"+\
            "is a torus , otherwise the travel he initiated was a suicide, because of the absolute extreme difficulty of the West-East round trip, if it exists.\n\n"+\
            "    I know you trust in my science, my friend, and I have to admit you are one of the few ones. Here is my demand:\n"+\
            "Take all my money. Buy ship, hire mens, prepare a big exploration trip. Find Perigeo's shipwreck, pursue his travel, and finish what he began. Bring back with you a keepsake of Perigeo. He deserves it.\n"+\
            "\n        You cannot let him in here."
    end_text = "Prove the world that our planet is toroidal!"
    end = thorpy.make_text(end_text, thorpy.style.TITLE_FONT_SIZE, gui.TCOLOR)
    letter = thorpy.make_text(thorpy.pack_text(int(0.7*parameters.S),text))
    w = letter.get_fus_rect().w + 10
    boxletter = thorpy.Box.make([letter],(w,parameters.S//2))
    boxletter.set_main_color((200,200,255,50))
    boxletter.refresh_lift()
    thorpy.style.BOX_RADIUS += 10
    box = thorpy.make_ok_box([title,boxletter,end],"Accept")
    box.e_ok.user_func = thorpy.functions.quit_menu_func
    box.e_ok.user_params = {}
    box.set_main_color((200,200,255,80))
    box.center()
    background = thorpy.Background(image=image,elements=[box])
    thorpy.style.BOX_RADIUS -= 10
    return background
Exemplo n.º 3
0
def main():
    pygame.init()  # Iniciamos pygame.
    infoObject = pygame.display.Info()
    icon = pygame.image.load('images/ant.png')

    preferredSize = int(infoObject.current_h *
                        0.88)  # Obtenemos la altura de la pantalla.
    application = thorpy.Application((preferredSize, preferredSize),
                                     "Langton's Ant", "pygame")

    # Verifica si el tamaño ingresado es válido y si lo es, inicia la simulación.
    def start():
        if tamaño.get_value().isdigit() and iteraciones.get_value().isdigit():
            tam = int(tamaño.get_value())
            it = int(iteraciones.get_value())
            if tam > 0 and it > 0:
                if tam > int(0.65 * (preferredSize // 2)):
                    thorpy.launch_blocking_alert(
                        title="¡Tamaño no soportado!",
                        text=
                        "El tamaño actual generaría una grilla con celdas de tamaño cero.",
                        parent=background)
                    tamaño.set_value("")
                else:
                    simulation.simulate(tam, it, preferredSize)
            else:
                thorpy.launch_blocking_alert(title="¡Tamaño no soportado!",
                                             text="El tamaño no es válido.",
                                             parent=background)
        else:
            thorpy.launch_blocking_alert(
                title="¡Valores incorrectos!",
                text="Los valores introducidos no son válidos.",
                parent=background)
            tamaño.set_value("")
            iteraciones.set_value("")

    iteraciones = thorpy.Inserter(name="Iteraciones: ",
                                  value="1")  # Campo de número de iteraciones.
    tamaño = thorpy.Inserter(name="Tamaño: ", value="10")  # Campo de tamaño.
    boton = thorpy.make_button("Aceptar", start)  # Botón aceptar.

    title_element = thorpy.make_text("Configurar simulación", 22,
                                     (255, 255, 255))

    central_box = thorpy.Box(elements=[iteraciones, tamaño,
                                       boton])  # Contenedor central.
    central_box.fit_children(margins=(30, 30))
    central_box.center()  # center on screen
    central_box.set_main_color((220, 220, 220, 180))

    background = thorpy.Background((0, 0, 0),
                                   elements=[title_element, central_box])
    thorpy.store(background)

    menu = thorpy.Menu(background)
    menu.play()  # Lanzamos el menú.

    application.quit()
Exemplo n.º 4
0
    def displayLauncher():

        # Declare Variables
        index = None  #int
        game = None  #String
        application = None  #Application(thorpy)
        buttons = [None, None, None]  #Clickable(thorpy) Array
        scoreboardButton = None  #Clickable(thorpy)
        quitButton = None  #Clickable(thorpy)
        buttonGroup = None  #Group(thorpy)
        menu = None  #Menu(thorpy)
        background = None  #Background(thorpy)
        painter = None  #Painters(thorpy)
        title = None  #Text(thorpy)

        # Create GUI and set theme
        application = thorpy.Application(size=(1280, 800),
                                         caption="Mini-Arcade")
        thorpy.theme.set_theme("human")

        # Create title
        title = thorpy.make_text("Mini-Arcade\n", 35, (0, 0, 0))

        # Create buttons
        painter = thorpy.painters.roundrect.RoundRect(size=(150, 75),
                                                      color=(102, 204, 255),
                                                      radius=0.3)
        for index, game in enumerate(Launcher.gameTitle):
            buttons[index] = Launcher.createButton(game, index, painter)
        scoreboardButton = thorpy.Clickable("Scoreboard")
        scoreboardButton.user_func = Launcher.launchScoreboard
        scoreboardButton.set_painter(painter)
        scoreboardButton.finish()
        scoreboardButton.set_font_size(23)
        scoreboardButton.set_font_color_hover((255, 255, 255))
        quitButton = thorpy.Clickable("Exit")
        quitButton.user_func = thorpy.functions.quit_menu_func
        quitButton.set_painter(painter)
        quitButton.finish()
        quitButton.set_font_size(23)
        quitButton.set_font_color_hover((255, 255, 255))

        # Format the buttons
        buttonGroup = thorpy.make_group(buttons)

        # Set background
        background = thorpy.Background(
            color=(255, 255, 255),
            elements=[title, buttonGroup, scoreboardButton, quitButton])
        thorpy.store(background)

        # Create menu and display
        menu = thorpy.Menu(background)
        menu.play()

        # Exiting
        application.quit()
Exemplo n.º 5
0
def main_menu(width, height, func_run, func_menu):
    def func_about():
        about_text = thorpy.make_text(
            'Game of the Hyenas \n '
            'by \n\n '
            'AnDreWerDnA'
            ' \n 700y \n Pk \n\n '
            '-  Python Code Jam 5 -', 25)

        normal_about, hover_about = 'assets/back-on.png',\
                                    'assets/back-off.png',

        back_button = thorpy.make_image_button(img_normal=normal_about,
                                               img_hover=hover_about,
                                               colorkey=(0, 0, 0))
        back_button.user_func = func_menu
        about_background = thorpy.Background(
            image='map_objects/menu_bg.jpg',
            elements=[about_text, back_button])
        thorpy.store(about_background)
        about_menu = thorpy.Menu(about_background)
        about_menu.play()

    application = thorpy.Application((width, height),
                                     "Code Jam",
                                     icon='pyGame')

    normal, hover = 'assets/play-on.png', 'assets/play-off.png'
    normal_quit, hover_quit = 'assets/quit-on.png', 'assets/quit-off.png'
    normal_about, hover_about = 'assets/about-on.png', 'assets/about-off.png'

    play_button = thorpy.make_image_button(img_normal=normal,
                                           img_hover=hover,
                                           colorkey=(0, 0, 0))

    about_button = thorpy.make_image_button(img_normal=normal_about,
                                            img_hover=hover_about,
                                            colorkey=(0, 0, 0))

    quit_button = thorpy.make_image_button(img_normal=normal_quit,
                                           img_hover=hover_quit,
                                           colorkey=(0, 0, 0))

    background = thorpy.Background(
        image='map_objects/menu_bg.jpg',
        elements=[play_button, about_button, quit_button])
    # Set functions for the buttons
    play_button.user_func = func_run
    quit_button.set_as_exiter()
    about_button.user_func = func_about
    thorpy.store(background)
    menu = thorpy.Menu(background)
    menu.play()

    application.quit()
Exemplo n.º 6
0
    def quiz_resultsLoader(self):
        print("Reached Here - Quiz page")
        self.createQuizElements()
        #self.rt = RepeatedTimer(0.1246, self.startQuizGameBG) #Initiate a 1-second non-blocking timer
        self.startQuizGameBG()

        global correct
        print("Reached Here - Results page")
        print(correct)
        if correct == True:
            self.resultText = thorpy.make_text("Correct! Fantastic!", 60,
                                               (0, 0, 0, 160))
        else:
            self.resultText = thorpy.make_text(
                "Good try! \nYou might get it right next time.", 60,
                (0, 0, 0, 160))
            self.correctAns.center()
            self.correctAns.set_topleft((None, 235))
        self.resultText.center()
        self.resultText.set_topleft((None, 30))
        #self.resultsBG = thorpy.Background(image='abstract.jpg', elements=[self.resultText, self.nextQuestion, self.OKbutton1, self.correctAns, self.quit4])

        #self.resultsBG = thorpy.Background(image='abstract.jpg', elements=[self.resultText, self.nextQuestion, self.OKbutton1, self.correctAns, self.quit4])
        if correct == True:
            print("I'm supposed to be here...")
            self.resultsBG = thorpy.Background(image='abstract.jpg',
                                               elements=[
                                                   self.resultText,
                                                   self.nextQuestion,
                                                   self.OKbutton1, self.quit4
                                               ])
            correct = False
        else:
            self.resultsBG = thorpy.Background(image='abstract.jpg',
                                               elements=[
                                                   self.resultText,
                                                   self.nextQuestion,
                                                   self.OKbutton1,
                                                   self.correctAns, self.quit4
                                               ])
        self.resultsPage = thorpy.Menu(self.resultsBG)
        self.resultsPage.play()
Exemplo n.º 7
0
 def startQuizGameBG(self):
     if self.timeLeft == 0:
         self.rt.stop()
     self.timeLeft -= 0.125
     self.quizGame = thorpy.Background(image='quizAbstract.jpg',
                                       elements=[
                                           self.questionText,
                                           self.Op1Button, self.Op2Button,
                                           self.Op3Button, self.Op3Button,
                                           self.Op4Button, self.quit3
                                       ])
     self.quizGamePage = thorpy.Menu(self.quizGame)
     self.quizGamePage.play()
Exemplo n.º 8
0
 def create(self):
     self.state.append("main_menu")
     self.fill_buttons_list()
     self.fill_text_list()
     self.fill_inserters()
     self.background = thorpy.Background(
         color=None,
         image="backgrounds/login_background.png",
         elements=self.buttons + self.texts + self.inserters)
     self.place_elements_on_background()
     self.menu = thorpy.Menu(self.background)
     for element in self.menu.get_population():
         element.surface = self.window
     self.update_background()
     return self.menu
Exemplo n.º 9
0
 def create(self, which_map):
     self.fill_elements_table()
     self.fill_radio_buttons()
     self.fill_icons_table()
     buttons = self.make_buttons()
     self.radio_pool = thorpy.RadioPool(self.radio_buttons,
                                        first_value=self.radio_buttons[0],
                                        always_value=True)
     self.background = thorpy.Background(
         color=(168, 139, 50),
         image=backgrounds[str(which_map)],
         elements=self.elements + self.radio_buttons + buttons + self.icons)
     self.menu = thorpy.Menu(self.background)
     for element in self.menu.get_population():
         element.surface = self.window
     self.place_elements(buttons)
     self.buttons_appearing(0)
     self.background.blit()
     self.background.update()
Exemplo n.º 10
0
    def func_about():
        about_text = thorpy.make_text(
            'Game of the Hyenas \n '
            'by \n\n '
            'AnDreWerDnA'
            ' \n 700y \n Pk \n\n '
            '-  Python Code Jam 5 -', 25)

        normal_about, hover_about = 'assets/back-on.png',\
                                    'assets/back-off.png',

        back_button = thorpy.make_image_button(img_normal=normal_about,
                                               img_hover=hover_about,
                                               colorkey=(0, 0, 0))
        back_button.user_func = func_menu
        about_background = thorpy.Background(
            image='map_objects/menu_bg.jpg',
            elements=[about_text, back_button])
        thorpy.store(about_background)
        about_menu = thorpy.Menu(about_background)
        about_menu.play()
Exemplo n.º 11
0
    def givePrizesLoader(self):
        #This page prints the number of prizes the pupil gets
        print("Reached Here - Prize loader page")
        if self.correctQns == 0:
            self.encouragementText = thorpy.make_text(
                'Good try, but you did not get \nany questions correct.', 50,
                (0, 0, 0, 100))
        else:
            self.encouragement = 'Great job! You got ' + str(
                self.correctQns) + ' question(s) correct!'
            self.encouragementText = thorpy.make_text(self.encouragement, 50,
                                                      (0, 0, 0, 100))

        self.encouragementText.center()
        self.encouragementText.set_topleft((None, 6))

        self.prizesToGive = self.correctQns
        if self.correctQns == 2:
            self.prizesToGive = self.prizesToGive + 1
        self.textPrizesToGive = 'You get ' + str(
            self.prizesToGive) + ' prize(s)!'
        self.prizesToGiveElement = thorpy.make_text(self.textPrizesToGive, 40,
                                                    (4, 2, 158, 100))

        self.givePrizesBox = thorpy.Box(
            elements=[self.prizesToGiveElement, self.OKbutton2])
        self.givePrizesBox.fit_children(margins=(10,
                                                 10))  #We want small margins
        self.givePrizesBox.center()  #Center on screen
        self.givePrizesBox.set_topleft((None, 60))
        self.givePrizesBox.set_main_color(
            (220, 220, 220, 180))  #set box color and opacity

        self.givePrize = thorpy.Background(
            image="prize.jpg",
            elements=[self.encouragementText, self.givePrizesBox])

        self.givePrizePage = thorpy.Menu(self.givePrize)
        self.givePrizePage.play()
Exemplo n.º 12
0
def run_application():
    W, H = 300, 300
    application = thorpy.Application(size=(W, H), caption="Real life example")

    draggable = thorpy.Draggable("Drag me")
    sx = thorpy.SliderX(length=100, limvals=(0, W), text="X:", type_=int)
    sy = thorpy.SliderX(length=100, limvals=(0, H), text="Y:", type_=int)

    background = thorpy.Background(color=(200, 255, 255),
                                   elements=[draggable, sx, sy])
    thorpy.store(background, [sx, sy])

    reaction1 = thorpy.Reaction(
        reacts_to=thorpy.constants.THORPY_EVENT,
        reac_func=refresh_drag,
        event_args={"id": thorpy.constants.EVENT_SLIDE},
        params={
            "drag": draggable,
            "sx": sx,
            "sy": sy
        },
        reac_name="my reaction to slide event")

    reaction2 = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT,
                                reac_func=refresh_sliders,
                                event_args={"id": thorpy.constants.EVENT_DRAG},
                                params={
                                    "drag": draggable,
                                    "sx": sx,
                                    "sy": sy
                                },
                                reac_name="my reaction to drag event")

    background.add_reaction(reaction1)
    background.add_reaction(reaction2)

    menu = thorpy.Menu(background)  #create a menu for auto events handling
    menu.play()  #launch the menu
    application.quit()
Exemplo n.º 13
0
img_nothing.fill((50, 50, 50))

couleur2img = couleur2texte = {
    "c": img_coeur,
    "p": img_pique,
    "l": img_carreau,
    "t": img_trefle,
    "u": img_nothing
}

jeu = pomme.Jeu()
jeu.generate_initial_configuration(0)
jeu.set_atout("c")

all_cartes = {str(c): Carte(c).e for c in jeu.all_cartes}
all_cartes[str(pomme.unknown_carte)] = Carte(pomme.unknown_carte).e
all_cartes[str(pomme.unknown_carte)].set_main_color((100, 100, 100))
e_none1 = Carte(pomme.Carte("u", -1, -1)).e
e_none1.get_image().fill((50, ) * 3)
e_none2 = Carte(pomme.Carte("u", -1, -1)).e
e_none2.get_image().fill((50, ) * 3)
e_s1 = thorpy.make_text("Score j1 : 0 points")
e_s2 = thorpy.make_text("Score j2 : 0 points")

b = thorpy.Background(elements=[e_s1, e_s2, e_none1, e_none2] +
                      list(all_cartes.values()))
show_jeu()
m = thorpy.Menu(b)
m.play()

app.quit()
Exemplo n.º 14
0
        pygame.quit()
        quit()


application = thorpy.Application((500, 500), "Launching alerts")

button1 = thorpy.make_button("Fácil", func=my_choices_1)
button1.set_font_size(22)
button1.scale_to_title()
button2 = thorpy.make_button("Normal", func=my_choices_2)
button2.set_font_size(22)
button2.scale_to_title()
button3 = thorpy.make_button("Difícil", func=my_choices_3)
button3.set_font_size(22)
button3.scale_to_title()
button4 = thorpy.make_button("Sacame de Aquí!")
button4.set_font_size(22)
button4.scale_to_title()
button4.set_as_exiter()

title = thorpy.make_text("Juego Rubik's", font_size=32, font_color=(102, 0, 51))
title.stick_to("screen", "top", "top")

background = thorpy.Background(image="rubik.jpg", elements=[button1, button2, button3, button4])
thorpy.store(background)

menu = thorpy.Menu([background, title])
menu.play()

application.quit()
Exemplo n.º 15
0
    def gameLauncher(self):
        # self.firstBackground = thorpy.Background(image=thorpy.style.EXAMPLE_IMG, elements=[self.firstText, self.levelSlider, self.OKbutton, self.instructions])
        self.firstBackground = thorpy.Background(
            image='quiz.jpg', elements=[self.firstText, self.central_box])
        thorpy.store(self.firstBackground)

        # os.system("gtts-cli 'Come to out booth! We have a game to teach you not to waste food!' --output gtts.mp3")
        # os.system("omxplayer --loop gtts.mp3 &")
        self.startScreen = thorpy.Menu(self.firstBackground)
        self.startScreen.play()
        # os.system("sudo killall omxplayer")
        print("Reached Here - End of level page")

        #Write Instructions to screen
        self.instructionsPage = thorpy.Background(image='abstract.jpg',
                                                  elements=[
                                                      self.infoText,
                                                      self.instructions,
                                                      self.OKbutton, self.quit1
                                                  ])
        print("Reached Here - Background instructions page")

        self.infoScreen = thorpy.Menu(self.instructionsPage)
        self.infoScreen.play()

        print("Reached Here - Random number page")
        self.spinWheel = thorpy.Background(image='abstract.jpg',
                                           elements=[
                                               self.randomNumberText,
                                               self.randomNumberNumber,
                                               self.quit2, self.OKPlaceholder
                                           ])
        self.spinWheelPage = thorpy.Menu(self.spinWheel)
        self.spinWheelPage.play()

        self.quiz_resultsLoader()

        print("Reached Here - Second spin the wheel page")
        randomNumber = random.randint(0, 5)
        self.spinWheel = thorpy.Background(image='abstract.jpg',
                                           elements=[
                                               self.randomNumberText,
                                               self.randomNumberNumber,
                                               self.quit2, self.OKPlaceholder
                                           ])
        self.spinWheelPage = thorpy.Menu(self.spinWheel)
        self.spinWheelPage.play()

        spinSensorVal = random.randint(0, 5)
        self.randomNumber = spinSensorVal

        print("Reached Here - Second question and result")
        self.createQuizElements()
        self.quizGame = thorpy.Background(image='quizAbstract.jpg',
                                          elements=[
                                              self.questionText,
                                              self.Op1Button, self.Op2Button,
                                              self.Op3Button, self.Op3Button,
                                              self.Op4Button, self.quit3
                                          ])
        self.quizGamePage = thorpy.Menu(self.quizGame)
        self.quizGamePage.play()

        print("Reached Here - Second results page")
        global correct
        print(correct)
        if correct == True:
            self.resultText = thorpy.make_text("Correct! Fantastic!", 60,
                                               (0, 0, 0, 160))
        else:
            self.resultText = thorpy.make_text(
                "Good try! \nYou might get it right next time.", 60,
                (0, 0, 0, 160))
        self.resultText.center()
        self.resultText.set_topleft((None, 30))
        if correct == True:
            self.resultsBG = thorpy.Background(
                image='abstract.jpg',
                elements=[self.resultText, self.OKbutton1, self.quit4])
            correct = False
        else:
            self.resultsBG = thorpy.Background(image='abstract.jpg',
                                               elements=[
                                                   self.resultText,
                                                   self.OKbutton1,
                                                   self.correctAns, self.quit4
                                               ])
        self.resultsPage = thorpy.Menu(self.resultsBG)
        self.resultsPage.play()

        self.givePrizesLoader()

        if COMPUTER == False:
            self.dispensePrize()

        # Re-init some varables
        self.correctQns = 0
        self.prizesToGive = 0
        spinSensorVal = random.randint(0, 5)
        self.randomNumber = spinSensorVal

        self.gameLauncher()

        #Cleanly exit application
        print("Quitting")
        self.application.quit()
Exemplo n.º 16
0
    my_launcher.default_func_before() #default stuff
def my_func_after():
    background.set_main_color((0,100,100)) #change background color
    my_launcher.default_func_after() #default stuff

my_launcher.func_before = my_func_before
my_launcher.func_after = my_func_after

# ****************** Fourth launcher : event ******************
#This launcher is not linked to a ThorPy element, but instead user can activate
#it by pressing SPACE
unlaunch_button = thorpy.make_ok_box([thorpy.make_text("Ready to unlaunch?")])
unlaunch_button.stick_to("screen", "top", "top")
invisible_launcher = thorpy.get_launcher(unlaunch_button, autocenter=False)
# set focus to False for non-blocking behaviour:
##invisible_launcher.focus = False
#this reaction will be added to the background:
reac = thorpy.ConstantReaction(pygame.KEYDOWN, invisible_launcher.launch,
                                {"key":pygame.K_SPACE})
#add a text so user knows what to do
text4 = thorpy.make_text("Press space to launch invisible_launcher", 15)


background = thorpy.Background(elements=[text4, button1, button2, button3])
background.add_reaction(reac)
thorpy.store(background)

menu = thorpy.Menu(background)
menu.play()

application.quit()
Exemplo n.º 17
0
    game.e_background.update()
    e_background.unblit_and_reblit()  #reblit the start menu


application = thorpy.Application(size=(600, 400), caption="Guess the number")

thorpy.set_theme("human")

e_title = thorpy.make_text("My Minigame", font_size=20, font_color=(0, 0, 150))
e_title.center()  #center the title on the screen
e_title.set_topleft((None, 10))  #set the y-coord at 10

e_play = thorpy.make_button("Play!", func=launch_game)  #launch the game

varset = thorpy.VarSet()  #here we will declare options that user can set
varset.add("trials", value=5, text="Trials:", limits=(1, 20))
varset.add("minval", value=0, text="Min value:", limits=(0, 100))
varset.add("maxval", value=100, text="Max value:", limits=(0, 100))
varset.add("player name", value="Jack", text="Player name:")
e_options = thorpy.ParamSetterLauncher.make([varset], "Options", "Options")

e_quit = thorpy.make_button("Quit", func=thorpy.functions.quit_menu_func)

e_background = thorpy.Background(color=(200, 200, 255),
                                 elements=[e_title, e_play, e_options, e_quit])
thorpy.store(e_background, [e_play, e_options, e_quit])

menu = thorpy.Menu(e_background)
menu.play()

application.quit()
Exemplo n.º 18
0
    def at_press(what):
        some_text.set_text(what)  #change the element content (see below)
        thorpy.functions.quit_menu_func()  #exit the menu
        thorpy.store(background)  #align the elements (size has changed)
        background.unblit_and_reblit()

    #dynamically create elements
    elements = []
    for text in choices:
        element = thorpy.make_button(text, func=at_press)
        element.user_params = {"what": text}
        elements.append(element)
    #box to store everything
    box = thorpy.Box([title] + elements)
    box.set_main_color((200, 200, 200, 150))
    box.center()
    m = thorpy.Menu(box)
    m.play()


some_text = thorpy.make_text("Click on the button below to change the text.",
                             18)
choices = ["My new text", "Another proposition", "Blah", "blah"]
button = thorpy.make_button("Change text", launch_menu, {"choices": choices})
background = thorpy.Background(elements=[some_text, button])
thorpy.store(background)

menu = thorpy.Menu(background)
menu.play()

application.quit()
Exemplo n.º 19
0
    new_reaction = thorpy.ConstantReaction(reacts_to=pygame.MOUSEBUTTONDOWN,
                                           reac_func=my_func_reaction2)
    el.remove_reaction(reac_1)
    el.add_reaction(new_reaction)
    thorpy.functions.refresh_current_menu()  #tell menu to refresh reactions!
    info_text.set_text("Reaction 1 will never be launched again")
    info_text.center()
    background.unblit_and_reblit()
    print("reaction 1 launched - replacing reac 1 by reac 2")


application = thorpy.Application(size=(300, 300), caption="Reaction tuto")

info_text = thorpy.make_text("No reaction launched")
info_text.center()

background = thorpy.Background(elements=[info_text], color=(255, 255, 255))

reac_1 = thorpy.ConstantReaction(reacts_to=pygame.MOUSEBUTTONDOWN,
                                 reac_func=my_func_reaction1,
                                 params={
                                     "el": background,
                                     "reac_1": None
                                 })
reac_1.params["reac_1"] = reac_1
background.add_reaction(reac_1)

menu = thorpy.Menu(background)
menu.play()

application.quit()
Exemplo n.º 20
0

#Quit button
quit = thorpy.make_button("QUIT", func=thorpy.functions.quit_menu_func)
quit.set_font_size(40)
quit.set_font("Bahnschrift SemiBold")
quit.set_main_color((0,148,0))
quit.set_font_color((255,255,255))
quit.set_size((200,100))
quit.center()

def start_game(event):
    b = boardGUI.GUI()
    b.board()


game_reaction = thorpy.Reaction(reacts_to=pygame.MOUSEBUTTONDOWN, reac_func=start_game)
start.add_reaction(game_reaction)

#Setting background and adding elements to background
background = thorpy.Background(color=(0, 102, 204),
                               elements=[pic_button, title, start, quit])
thorpy.store(background)

#Adding background to menu and launching menu.
menu = thorpy.Menu(background)
menu.play()



Exemplo n.º 21
0
                           size=(150, 20))

file_browser = thorpy.Browser(path="C:/Users/", text="Please have a look.")

browser_launcher = thorpy.BrowserLauncher(browser=file_browser,
                                          const_text="Choose a file: ",
                                          var_text="")

color_setter = thorpy.ColorSetter.make()
color_launcher = thorpy.ColorSetterLauncher(color_setter,
                                            "Launch color setter")

options2 = thorpy.make_button("Useful things")
box2 = thorpy.make_ok_box([inserter, color_launcher, browser_launcher])
thorpy.set_launcher(options2, box2)

quit_button = thorpy.make_button("Quit")
quit_button.set_as_exiter()

central_box = thorpy.Box.make([options1, options2, quit_button])
central_box.set_main_color((200, 200, 200, 120))
central_box.center()

#Declaration of a background element - include your own path!
background = thorpy.Background(image=thorpy.style.EXAMPLE_IMG,
                               elements=[central_box])

menu = thorpy.Menu(elements=background, fps=45)
menu.play()

application.quit()
Exemplo n.º 22
0
painter = thorpy.painters.optionnal.human.Human(size=(200, 30),
                                                radius_ext=0.5,
                                                radius_int=0.4,
                                                border_color=(0, 0, 255),
                                                color=(100, 100, 255))
a_round_button.set_painter(painter)
a_round_button.finish()
buttons.append(a_round_button)

#Another customized style
#set default painter as ClassicFrame (same as used in theme 'classic')
thorpy.painterstyle.DEF_PAINTER = thorpy.painters.classicframe.ClassicFrame
thorpy.style.MARGINS = (50, 2)  #set default margins
thorpy.style.COLOR_TXT_HOVER = (255, 0, 0)
button = thorpy.make_button("Another custom button")
buttons.append(button)

#text button
title = thorpy.make_text("Text only", font_size=22, font_color=(255, 0, 0))
title.stick_to("screen", "top", "top")

#To add shadows to a button, see effects.py in the examples folder.

background = thorpy.Background(image=thorpy.style.EXAMPLE_IMG,
                               elements=buttons)
thorpy.store(background)

menu = thorpy.Menu([background, title])
menu.play()

application.quit()
Exemplo n.º 23
0

def my_choices_1():
    choices = [("I like blue", set_blue), ("No! red", set_red),
               ("cancel", None)]
    thorpy.launch_nonblocking_choices("This is a non-blocking choices box!\n",
                                      choices)
    print("Proof that it is non-blocking : this sentence is printing!")


def my_choices_2():
    choices = [("I like blue", set_blue), ("No! red", set_red),
               ("cancel", None)]
    thorpy.launch_blocking_choices("Blocking choices box!\n",
                                   choices,
                                   parent=background)  #for auto unblit
    print("This sentence will print only after you clicked ok")


application = thorpy.Application((500, 500), "Launching alerts")

button1 = thorpy.make_button("Non-blocking version", func=my_choices_1)
button2 = thorpy.make_button("Blocking version", func=my_choices_2)

background = thorpy.Background(elements=[button1, button2])
thorpy.store(background)

menu = thorpy.Menu(background)
menu.play()

application.quit()
Exemplo n.º 24
0
#ThorPy storage tutorial : manual placing
import thorpy, random

application = thorpy.Application(size=(400, 400), caption="Storage")

elements = [thorpy.make_button("button" + str(i)) for i in range(13)]
for e in elements:
    w, h = e.get_rect().size
    w, h = w * (1 + random.random() / 2.), h * (1 + random.random() / 2.)
    e.set_size((w, h))
elements[6] = thorpy.Element(text="")
elements[6].set_size((100, 100))

elements[0].set_topleft((10, 300))
elements[1].set_topleft(elements[0].get_rect().bottomright)
elements[2].set_center((100, 200))
elements[3].stick_to(elements[2], target_side="bottom", self_side="top")
elements[4].stick_to(elements[2], target_side="right", self_side="left")

background = thorpy.Background(color=(200, 200, 255), elements=elements)
thorpy.store(background, elements[6:12], x=380, align="right")
elements[5].center(element=elements[6])
elements[5].rank = elements[6].rank + 0.1  #be sure number 5 is blitted after 6
background.sort_children_by_rank()  #tell background to sort its children
elements[12].set_location((0.1, 0.2))  #relative placing of number 12

menu = thorpy.Menu(background)
menu.play()

application.quit()
Exemplo n.º 25
0
import pygame, thorpy

ap = thorpy.Application((500, 400), "Shadows example")

e_img = thorpy.Draggable()  # do not use 'make' !
painter = thorpy.painters.imageframe.ImageFrame("character.png",
                                                colorkey=(255, 255, 255))
e_img.set_painter(painter)
e_img.finish()  #don't forget to finish

if thorpy.constants.CAN_SHADOWS:
    thorpy.makeup.add_static_shadow(e_img, {
        "target_altitude": 0,
        "shadow_radius": 3
    })

e_background = thorpy.Background(image=thorpy.style.EXAMPLE_IMG,
                                 elements=[e_img])

menu = thorpy.Menu(e_background)
menu.play()

ap.quit()
Exemplo n.º 26
0
    def drawBoard():

        # Declare variables
        application = None  #Application(thorpy)
        title = None  #Text(thorpy)
        content = None  #Text(thorpy)
        buttons = [None, None, None]  #Clickable/Element(thorpy) Array
        quitButton = None  #Clickable(thorpy)
        painter1 = None  #Painters(thorpy)
        painter2 = None  #Painters(thorpy)
        buttonGroup = None  #Group(thorpy)
        menu = None  #Menu(thorpy)
        background = None  #Background(thorpy)
        contentString = None  #String

        # Create GUI and set theme
        application = thorpy.Application(size=(1280, 800),
                                         caption="Mini-Arcade")
        thorpy.theme.set_theme("human")

        # Create title
        title = thorpy.make_text("Scoreboard\n", 35, (0, 0, 0))

        # Create buttons
        painter1 = thorpy.painters.roundrect.RoundRect(size=(100, 50),
                                                       color=(102, 204, 255),
                                                       radius=0.3)
        painter2 = thorpy.painters.roundrect.RoundRect(size=(100, 50),
                                                       color=(57, 197, 187),
                                                       radius=0.3)
        for index, game in enumerate(Scoreboard.gameTitle):
            buttons[index] = Scoreboard.createButton(game, index, painter1,
                                                     painter2)
        quitButton = thorpy.Clickable("Return")
        quitButton.user_func = Scoreboard.exitScoreboard
        quitButton.set_painter(painter1)
        quitButton.finish()
        quitButton.set_font_size(17)
        quitButton.set_font_color_hover((255, 255, 255))

        # Create texts
        contentString = ""
        for index, score in enumerate(
                Scoreboard.scores[Scoreboard.displayGame]):
            contentString = contentString + str(index +
                                                1) + ": " + str(score) + "\n"
        contentString += "\n\n"
        content = thorpy.make_text(contentString, 20, (0, 0, 0))

        # Format the buttons and texts
        buttonGroup = thorpy.make_group(buttons)

        # Set background
        background = thorpy.Background(
            color=(255, 255, 255),
            elements=[title, buttonGroup, content, quitButton])
        thorpy.store(background)

        # Create menu and display
        menu = thorpy.Menu(background)
        menu.play()

        # Exiting
        application.quit()
Exemplo n.º 27
0
def run():
    import thorpy
    application = thorpy.Application((600, 600), "ThorPy test")

    ##thorpy.theme.set_theme("human")

    #### SIMPLE ELEMENTS ####

    ghost = thorpy.Ghost()
    ghost.finish()

    element = thorpy.Element("Element")
    element.finish()
    thorpy.makeup.add_basic_help(
        element, "Element instance:\nMost simple graphical element.")

    clickable = thorpy.Clickable("Clickable")
    clickable.finish()
    clickable.add_basic_help(
        "Clickable instance:\nCan be hovered and pressed.")

    draggable = thorpy.Draggable("Draggable")
    draggable.finish()
    thorpy.makeup.add_basic_help(draggable,
                                 "Draggable instance:\nYou can drag it.")

    #### SIMPLE Setters ####

    checker_check = thorpy.Checker("Checker")
    checker_check.finish()
    thorpy.makeup.add_basic_help(
        checker_check, "Checker instance:\nHere it is of type 'checkbox'.")

    checker_radio = thorpy.Checker("Radio", typ="radio")
    checker_radio.finish()
    thorpy.makeup.add_basic_help(
        checker_radio, "Checker instance:\nHere it is of type 'radio'.")

    browser = thorpy.Browser("../../", text="Browser")
    browser.finish()
    browser.set_prison()

    browserlauncher = thorpy.BrowserLauncher(browser,
                                             name_txt="Browser",
                                             file_txt="Nothing selected",
                                             launcher_txt="...")
    browserlauncher.finish()
    browserlauncher.scale_to_title()
    thorpy.makeup.add_basic_help(
        browserlauncher,
        "Browser instance:\nA way for user to find a file or" +
        "\na folder on the computer.")

    dropdownlist = thorpy.DropDownListLauncher(
        name_txt="DropDownListLauncher",
        file_txt="Nothing selected",
        titles=[str(i) for i in range(1, 9)])
    dropdownlist.finish()
    dropdownlist.scale_to_title()
    thorpy.makeup.add_basic_help(dropdownlist,
                                 "DropDownList:\nDisplay a list of choices.")

    slider = thorpy.SliderX(120, (5, 12),
                            "Slider: ",
                            typ=float,
                            initial_value=8.4)
    slider.finish()
    thorpy.makeup.add_basic_help(
        slider, "SliderX:\nA way for user to select a value." +
        "\nCan select any type of number (int, float, ..).")
    slider.set_center

    inserter = thorpy.Inserter(name="Inserter: ", value="Write here.")
    inserter.finish()
    thorpy.makeup.add_basic_help(
        inserter, "Inserter:\nA way for user to insert a value.")

    text_title = thorpy.make_text("Test Example", 25, (0, 0, 255))

    central_box = thorpy.Box("", [
        ghost, element, clickable, draggable, checker_check, checker_radio,
        dropdownlist, browserlauncher, slider, inserter
    ])
    central_box.finish()
    central_box.center()
    central_box.add_lift()
    central_box.set_main_color((200, 200, 255, 120))

    background = thorpy.Background(color=(200, 200, 200),
                                   elements=[text_title, central_box])
    background.finish()

    thorpy.store(background)

    menu = thorpy.Menu(background)
    menu.play()

    application.quit()
Exemplo n.º 28
0
botao_gv = thorpy.make_button("Gravacao")
botao_gv.set_font_size(17)
botao_gv.set_font_color((40, 40, 40))
botao_gv.set_size((200, 50))
botao_gv.set_main_color((230, 230, 215))
thorpy.set_launcher(botao_gv, caixa_gv)

#Botao sair
botao_sair = thorpy.make_button("Sair", func=sair)
botao_sair.set_font('Helvetica')
botao_sair.set_font_size(14)
botao_sair.set_size((56, 28))
botao_sair.set_main_color((230, 230, 215))

#Caixa do menu principal
elementos = [subtitulo, inv2, botao_cr, botao_tl, botao_gv, inv3, botao_sair]
caixa_central = thorpy.Box(elements=elementos)
caixa_central.fit_children(margins=(30, 30))
caixa_central.center()
caixa_central.set_main_color((220, 220, 220, 180))

background = thorpy.Background(color=(100, 150, 180),
                               elements=[titulo, inv1, caixa_central])

thorpy.store(background)

menu = thorpy.Menu(background)
menu.play()

application.quit()