예제 #1
0
 def pref():
     #messagebox.showinfo("Missing Option", "This option needs to be continued")
     p = Preferences.Preference(pathinit=home, pt=self.dir)
     p.initialization()
     self.preferences_data = p.getData()
     #print("preferences_data:", self.preferences_data)
     self.load_data_pref()
     p.mainloop()
예제 #2
0
    def __init__(self, dev=False, directory=""):
        self.dir = directory  #path location
        p = Preferences.Preference(pathinit=home, pt=self.dir)
        if p.getData() == {}:
            self.preferences_data = {'Kick-Key':'<space>', 'GamingIntro-Init':'0', \
               'Bindings':'p;F3;s', 'DevMode':'False', 'Scales':'180;14', "Color":"#00ff00"}
        else:
            self.preferences_data = p.getData()
        self.current_pref = [self.preferences_data["Kick-Key"]] + \
          self.preferences_data['Bindings'].split(";")

        if int(self.preferences_data['GamingIntro-Init']):
            i = GamingIntro.Intro(dir=self.dir +
                                  "FlappyBird_Game/")  #Normal Intro for game
            i.start_prg()

        if self.preferences_data['DevMode'] == "True" and dev:
            raise AttributeError(
                "You can\'t set dev=True and preferences True in the same time"
            )
        elif dev:
            self.dev = True
        else:
            self.dev = True if self.preferences_data[
                'DevMode'] == 'True' else False

        self.bars_space = int(self.preferences_data['Scales'].split(";")
                              [0])  #space between bars (px)
        self.current_pref = [self.preferences_data['Kick-Key']
                             ] + self.preferences_data['Bindings'].split(";")
        self.tk = Tk()
        self.tk.bind("<Key>", self.keys)
        #self.tk.bind("<Destroy>", self.destroy)
        menu = Menu(self.tk)  #Menu for user
        self.tk.config(menu=menu)

        def callback():
            self.gameover()

        def hsc():
            #init highscore from my HighscoreManager module
            h = HighscoreManager.Highscore(users=os.listdir("/home"),
                                           pathinit=home)
            hs = h.getTable()
            shs = h.getSortedTable(hs)  #get sorted highscores
            highscore = "Highscores: \n"
            for k, v in shs.items():
                highscore += str(k) + " " + str(v) + "; "
            messagebox.showinfo("OMGames", highscore)

        def w_fe():
            f = FeedbackInterface.Feedback(pathinit=home,
                                           users=os.listdir("/home"))
            f.start()

        def s_fe():
            f = FeedbackInterface.Feedback(pathinit=home,
                                           users=os.listdir("/home"))
            f.see_feedbacks()

        def pref():
            #messagebox.showinfo("Missing Option", "This option needs to be continued")
            p = Preferences.Preference(pathinit=home, pt=self.dir)
            p.initialization()
            self.preferences_data = p.getData()
            #print("preferences_data:", self.preferences_data)
            self.load_data_pref()
            p.mainloop()

        def reset():
            for file in os.listdir(home + ".FlappyBird"):
                os.remove(home + ".FlappyBird/" + file)
            os.rmdir(home + ".FlappyBird")
            messagebox.showinfo("Info", "Game has been reset")
            self.tk.destroy()
            sys.exit()

        #pref()
        filemenu = Menu(menu, tearoff=0)
        feedmenu = Menu(menu, tearoff=0)
        prefmenu = Menu(menu, tearoff=0)
        menu.add_cascade(label="Game", menu=filemenu)
        menu.add_cascade(label="Feedback", menu=feedmenu)
        menu.add_cascade(label="Preferences", menu=prefmenu)
        feedmenu.add_command(label="Write feedback", command=w_fe)
        feedmenu.add_command(label="See feedbacks", command=s_fe)
        filemenu.add_command(label="See highscores", command=hsc)
        filemenu.add_separator()
        filemenu.add_command(label="Quit", command=callback)
        prefmenu.add_command(label="Change Settings", command=pref)
        prefmenu.add_command(label="Reset game", command=reset)
        imgicon = PhotoImage(file=os.path.join(
            self.dir, self.dir + 'FlappyBird_Game/icon.gif'),
                             master=self.tk)  #Set icon of game
        self.tk.tk.call('wm', 'iconphoto', self.tk._w, imgicon)
        self.tk.title("Flappy Bird (OMGames) V3.0.5")  #Game title
        self.canvas = Canvas(self.tk, width=600, height=500)
        self.canvas.pack()
        self.score = 0  #Default game values (score, highscore, attemps and if the game is Running)
        self.attemps = 1
        self.highscore = 0
        self.sound = True
        self.sound2 = True
        self.gameIsRunning = False
        self.score_text = self.canvas.create_text(290,20, fill="red", \
             font="Purisa 20 bold", \
             text="Score: %s Attemps: %s " \
                                "Highscore: %s" % (self.score, self.attemps, \
                                          self.highscore))
        self.canvas2 = Canvas(
            self.tk, width=600,
            height=100)  #A second canvas for the bottom image
        self.canvas2.pack()
        self.pause = False  #if game is paused