Example #1
0
 def start_game(self, word_list):
     self.current_list = word_list
     if word_list.name != "Random List":
         word_records = self.db.getWords(word_list.name)
         self.current_list.words = [Word(word) for word in word_records]
     else:
         self.current_list.words = self.get_random_list(15)
     self.list_length = len(self.current_list.words)
     self.start_frame.pack_forget()
     self.results_frame.pack_forget()
     self.game_frame = GameFrame(self)
     self.game_frame.start()
     self.game_frame.pack()
Example #2
0
 def start_game(self, word_list):
     """Hide start screen and show game screen. Retrieve words for selected 
        list"""
     self.current_list = word_list
     if word_list.name != "Random List":
         word_records = self.db.getWords(word_list.name)
         self.current_list.words = [Word(word) for word in word_records]
     else:
         self.current_list.words = self.get_random_list(15)
     self.list_length = len(self.current_list.words)
     self.start_frame.pack_forget()
     self.results_frame.pack_forget()
     self.game_frame = GameFrame(self)
     self.game_frame.start()
     self.game_frame.pack()
Example #3
0
class SpellingGame(Tk):
    """Main class for spelling aid. Manages the other screens and holds festival       and database connections"""
    def __init__(self):

        Tk.__init__(self)
        self.title('Spelling Game')
        #Estabilish database connection
        self.db = SpellingDatabase()
        #Get words from database
        self.word_list = self.get_dictionary()
        #Retrieve list of lists from db
        self.list_list = self.get_lists()
        #Start festival process
        self.festival = FestivalInterface()
        #Create screens
        self.init_gui()

    def get_lists(self):
        """Retrieve list of lists from database"""
        list_records = self.db.sql("""SELECT * FROM lists""")
        list_list = []
        for wordlist in list_records:
            list_list.append(WordList(wordlist))
        return list_list

    def update_lists(self):
        """Refresh the list-list"""
        self.list_list = self.get_lists()
            
        
    def get_dictionary(self):
        """Get dictionary words from database"""
        word_records = self.db.sql("""SELECT * FROM words WHERE
                              difficulty LIKE 'SB%'""")
        word_list = []
        for word in word_records:
            word_list.append(Word(word))
        return word_list
 

    def get_random_list(self, length):
        """Return a random list of words"""
        words = random.sample(self.word_list, length)
        return words

    def login(self, user):
        """Show the start screen as user logs in"""
        self.user = user
        self.login_frame.pack_forget()
        self.start_frame.welcomeMessage()
        self.start_frame.pack()

    def start_game(self, word_list):
        """Hide start screen and show game screen. Retrieve words for selected 
           list"""
        self.current_list = word_list
        if word_list.name != "Random List":
            word_records = self.db.getWords(word_list.name)
            self.current_list.words = [Word(word) for word in word_records]
        else:
            self.current_list.words = self.get_random_list(15)
        self.list_length = len(self.current_list.words)
        self.start_frame.pack_forget()
        self.results_frame.pack_forget()
        self.game_frame = GameFrame(self)
        self.game_frame.start()
        self.game_frame.pack()

    def show_results(self, time_elapsed):
        """Hide game frame and show results frame"""
        self.game_frame.pack_forget()
        self.results_frame.calculate(self.current_list, time_elapsed)
        self.results_frame.pack()

    def new_list(self):
        """Show start screen, hiding either results or list editor"""
        self.results_frame.pack_forget()
        self.list_editor.pack_forget()
        self.start_frame.update_list()
        self.start_frame.pack()

    def show_editor(self):
        """Hide start frame and show list editor"""
        self.start_frame.pack_forget()
        self.list_editor.pack()

    def init_gui(self):
        """Create the screens"""
        self.login_frame = LoginFrame(self)
        self.login_frame.pack()

        self.start_frame = StartFrame(self)

        self.results_frame = ResultsFrame(self)

        self.list_editor = ListEditor(self)


        self.mainloop()
Example #4
0
if len(argv) != 2:
    print(
        "Wrong number of arguments. Correct usage: py main.py <dictionary file>"
    )
    exit(0)

dictionary_file = argv[1]

# Initialises the root window
root = Tk()
root.title("Tkinter Scrabble")

geometry = get_geometry(root)
root.geometry(geometry)

# Initialises the game manager and packs it
gm = GameManager(root, dictionary_file)

# Initialises the game frame
gf = GameFrame(root, gm)
gf.pack()

# Initialises the options frame and packs it
of = OptionsFrame(root, gm, gf)
of.pack()

gf.setOptionsFrame(of)

# The main loop of the program
root.mainloop()
Example #5
0
class SpellingGame(Tk):

    def __init__(self):

        Tk.__init__(self)
        self.title('Spelling Game')
        self.db = SpellingDatabase()
        self.word_list = self.get_dictionary()
        self.list_list = self.get_lists()
        self.festival = FestivalInterface()
        self.init_gui()

    def get_lists(self):
        list_records = self.db.sql("""SELECT * FROM lists""")
        list_list = []
        for wordlist in list_records:
            list_list.append(WordList(wordlist))
        return list_list

    def update_lists(self):
        self.list_list = self.get_lists()
            
        
    def get_dictionary(self):
        word_records = self.db.sql("""SELECT * FROM words WHERE
                              difficulty LIKE 'SB%'""")
        word_list = []
        for word in word_records:
            word_list.append(Word(word))
        return word_list
 

    def get_random_list(self, length):
        words = random.sample(self.word_list, length)
        return words

    def login(self, user):
        self.user = user
        self.login_frame.pack_forget()
        self.start_frame.welcomeMessage()
        self.start_frame.pack()

    def start_game(self, word_list):
        self.current_list = word_list
        if word_list.name != "Random List":
            word_records = self.db.getWords(word_list.name)
            self.current_list.words = [Word(word) for word in word_records]
        else:
            self.current_list.words = self.get_random_list(15)
        self.list_length = len(self.current_list.words)
        self.start_frame.pack_forget()
        self.results_frame.pack_forget()
        self.game_frame = GameFrame(self)
        self.game_frame.start()
        self.game_frame.pack()

    def show_results(self, time_elapsed):
        self.game_frame.pack_forget()
        self.results_frame.calculate(self.current_list, time_elapsed)
        self.results_frame.pack()

    def new_list(self):
        self.results_frame.pack_forget()
        self.list_editor.pack_forget()
        self.start_frame.update_list()
        self.start_frame.pack()

    def show_editor(self):
        self.start_frame.pack_forget()
        self.list_editor.pack()

    def init_gui(self):

        self.login_frame = LoginFrame(self)
        self.login_frame.pack()

        self.start_frame = StartFrame(self)

        self.results_frame = ResultsFrame(self)

        self.list_editor = ListEditor(self)


        self.mainloop()
Example #6
0
import tkinter as tk
from ControlFrame import ControlFrame
from GameFrame import GameFrame

root = tk.Tk()

game_frame = GameFrame(root)
game_frame.pack(side="left")

for i in range(12):
    row = i // 3
    col = i % 3
    card = game_frame.deck[i]
    game_frame.add_card(card, row=row, column=col)

next_card = game_frame.get_next_card()


control_frame = ControlFrame(root)
control_frame.pack(side="right", fill="y")

root.mainloop()
Example #7
0
def game_loop(engine, main_frame):
    gc.disable()
    while main_frame.is_running():

        if engine.is_game_playing():
            engine.update()
        else:
            main_frame.display_game_over()

        main_frame.refresh()
        main_frame.update_idletasks()
        main_frame.update()

        sleep(0.2)
    gc.enable()


if __name__ == "__main__":
    engine = GameEngine(NB_PLAYERS)

    players = []
    players.append(OptimExplicitBot())
    for i in range(NB_PLAYERS - 1):
        players.append(ExplicitBot())

    main_frame = GameFrame(engine)

    engine.initialize(players)
    main_frame.initialize()
    game_loop(engine, main_frame)