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
#2
Can you give us a download link?
Reply
#3
Sure, here ya go:
Link
Click Gamev2.exe inside the folder to run the program.
[Image: izsyo6.jpg]


Reply
#4
Python is really hard to code in Great job
Reply
#5
Thanks bro, looks good too.
Reply
#6
Looks cool, downloading now.
Reply
#7
Thanks for the program!
(05-24-2010, 06:15 PM)Omniscient Wrote: We take HF refugees in bulk.
Lol
Reply
#8
Good job, it's quite amazing. <3
Reply
#9
Tkinter...

What has the world come to. D:
Reply
#10
Looks pretty good, well done and nice share.
Reply


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

Forum Jump:


Users browsing this thread: 2 Guest(s)