Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My 2nd GUI-based Game
#1
Well I have made another "game" with TkInter, this one is a little better and less repetitive then my previous one. I got the idea from the "anagrams" game created by Sun Microsystems, it comes standard with Net Beans. The only source code I have actually taken from the original game is the word list, because I was too lazy to write my own ;). Basically it takes a random word from the list, randomly scrambles it, and you have to guess the word. Of course mine is harder then the Java version, because it randomly scrambles the word, instead of having a scrambled words list. Feel free to use this code however you like (give me some credit) and feel free to use your own word list. Here is the source
Code:
from Tkinter import *
from tkMessageBox import showinfo
import random

class game(Frame):
    def __init__(self):
        top = Tk()
        top.title('Game v2.0')
        Frame.__init__(self)
        global scrambled, guess, original
        original = '' #incase the person presses "guess" before pressing "new word"
        Label(text='Scrambled Word:').pack(side=TOP)
        scrambled = Entry()
        scrambled.pack()
        guess = Entry()
        guess.pack()
        Button(self, text='Guess', command=self.match).pack(side=LEFT)
        Button(self, text='New Word', command=self.new).pack(side=LEFT)

    def new(self): #Chooses a random word from the list, stores the original
        global scrambled, wordlist, original
        original = random.choice(wordlist)
        mixedup = self.scramble(original)
        scrambled.delete(0, END)
        scrambled.insert(0, mixedup)

    def match(self): #Matches the guess with original(unscrambled) word
        global guess, original
        if guess.get() == original:
            showinfo(title='Result', message='Correct! Try a new word.')
        else:
            showinfo(title='Result', message='Wrong! Try again')
            
    def scramble(self, string): #randomly scrambles the given string
        scrambled = ''
        used = []
        for x in range(len(string)):
            while True:
                y = random.randrange(len(string))
                if y not in used:
                    used.append(y)
                    break
            scrambled += string[y]
        if scrambled == string:
            scramble(string)
        else:
            return scrambled
#wordlist, credits goes to Sun Microsystems (Anagram game, comes standard with netbeans)
global wordlist  
wordlist = ["abstraction", "ambiguous", "arithmetic", "backslash", "bitmap",
            "circumstance", "combination","consequently","consortium",
            "decrementing","dependency","disambiguate","dynamic",
            "encapsulation","equivalent", "expression","facilitate",
            "fragment","hexadecimal","implementation","indistinguishable",
            "inheritance","internet","java","localization","microprocessor",
            "navigation","optimization","parameter","patrick","pickle",
            "polymorphic","rigorously","simultaneously","specification",
            "structure","lexical","likewise","management","manipulate",
            "mathematics","hotjava","vertex","unsigned","traditional"]

if __name__ == '__main__':
    window = game()
    window.pack()
    window.mainloop()
Of course you can look at the source to guess the words, but that is cheating Nono. Hint: All the words in the wordlist are in someway related to programming(or math).
Didn't bother making it look pretty(not that tkinter can look pretty Sad ), just liked the concept. If you have any questions about how the program works PM me, reply to this thread, or add me on msn (ub3rl33t@msn.com) Blackhat

EDIT:
Download:
Link
Click Gamev2.exe inside the folder to run the program.
[Image: izsyo6.jpg]


Reply


Messages In This Thread
My 2nd GUI-based Game - by uber1337 - 02-27-2010, 08:13 PM
RE: My 2nd GUI-based Game - by Don Panzer - 04-11-2010, 03:40 AM
RE: My 2nd GUI-based Game - by uber1337 - 04-11-2010, 11:53 AM
RE: My 2nd GUI-based Game - by Unspoken - 04-22-2010, 01:21 AM
RE: My 2nd GUI-based Game - by xerotic - 12-06-2010, 03:31 PM
RE: My 2nd GUI-based Game - by Cyandelta - 05-05-2010, 10:28 AM
RE: My 2nd GUI-based Game - by delme - 05-22-2010, 10:15 PM
RE: My 2nd GUI-based Game - by alfonzo1955 - 06-17-2010, 12:25 PM
RE: My 2nd GUI-based Game - by Crysis. - 06-17-2010, 01:26 PM
RE: My 2nd GUI-based Game - by Daniel Faraday - 08-09-2010, 10:28 PM
RE: My 2nd GUI-based Game - by Chimi - 12-06-2010, 01:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  My First GUI Game "Falling Squares" nevets04 19 5,302 04-11-2010, 03:39 AM
Last Post: Don Panzer
  My first GUI uber1337 10 3,539 01-06-2010, 02:27 PM
Last Post: Gaijin

Forum Jump:


Users browsing this thread: 1 Guest(s)