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
Of course you can look at the source to guess the words, but that is cheating . 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 ), 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)
EDIT:
Download:
Link
Click Gamev2.exe inside the folder to run the program.
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()
Didn't bother making it look pretty(not that tkinter can look pretty ), 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)
EDIT:
Download:
Link
Click Gamev2.exe inside the folder to run the program.