| | |
Improve scrambled text game
Thread Solved |
Anyway, sometime back, I wrote a little and simple GUI application (using wPython) which I call the Jumbled Words game. This was my first step into wxPython. Not a serious project at all, but hey, a nice project for a Python newbie like me at that time. 
You can download it (Windows executable; setup/installer) from here:
http://anurag.granularproject.org/20...ame-downloads/
Any suggestions to improve the code are welcome.
The source code goes like:
Editor: Was moved to the main Python forum, to allow posting of improvements!

You can download it (Windows executable; setup/installer) from here:
http://anurag.granularproject.org/20...ame-downloads/
Any suggestions to improve the code are welcome.
The source code goes like:
python Syntax (Toggle Plain Text)
# Author: Anurag Bhandari | Contact: anurag.bhd@gmail.com # # Program: Jumbled Words Game | Version: 1.0 | Licence: GPLv2 # # It's sure an interesting thing to do in free time import wx # First, we define a dictionary of jumbled words dict = {"special":"licapes", "verify":"rfvyie", "guava":"augav", "begin":"ngibe", "compression":"serniospmoc", "praying":"igyaprn", "linux":"uilxn", "opposite":"seopopit", "depricated": "cpdirdaete", "leonardo da vinci":"o draconian devil", "the mona lisa":"oh lame saint", "dreaming":"earimngd", "tormented":"nemortted", "flabbergasted": "tasedbgaberlaf", "meticuluos":"ecusoulmit", "rectify":"fitecry", "mobile":"ibelmo", "computer":"mertopcu", "granular":"lrgaruna", "metro":"torem", "outrageous":"gretsouauo", "nothing":"hotning", "appreciable":"celbepiapra", "vandalism":"misdanlav", "tropical":"ptorlica"} def func(): 'This is the core function of the program' # The result of popitem() method is a tuple # The following is an example of "sequence unpacking" word, jumbled = dict.popitem() return word, jumbled def guess(event): ans = input_word.GetValue() if(ans == query[0]): result.SetLabel(label="Congrats! You got it right.") else: result.SetLabel(label="Sorry, wrong answer. Better luck next time!") def next(event): # After a person clicks the Start button for the first time, this will happen nextButton.SetLabel("Next") guessButton.Enable() hintButton.Enable() input_word.SetValue("") # Unless we define the variable "query" as global, the function "guess" won't be able to access it global query query = func() if(dict!={}): question.SetLabel(label="The jumbled word is: "+query[1]) result.SetLabel(label="Waiting for your input...") else: question.SetLabel(label="Game Over!") result.SetLabel(label="Yup, the game is finally over!") guessButton.Disable() nextButton.Disable() hintButton.Disable() def hint(event): input_word.SetValue(query[0]) app = wx.App() # The definition of splash screen is done after an object for the wx.App class has been defined. Same applies to all the other widgets splash_image = wx.Image("splash.bmp", wx.BITMAP_TYPE_BMP) bmp = splash_image.ConvertToBitmap() wx.SplashScreen(bmp, wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, 2000, None, -1) wx.Yield() win = wx.Frame(None, title="Jumbled Words Game", size=(460, 345)) win.SetIcon(wx.Icon('star.ico', wx.BITMAP_TYPE_ICO)) win.CenterOnScreen() bkg = wx.Panel(win) guessButton = wx.Button(bkg, label='Guess') guessButton.Bind(wx.EVT_BUTTON, guess) guessButton.SetDefault() # Unless the player has pressed the Start button, the Guess button will be disabled guessButton.Disable() nextButton = wx.Button(bkg, label='Start') nextButton.Bind(wx.EVT_BUTTON, next) hintButton = wx.Button(bkg, label='Hint') hintButton.Bind(wx.EVT_BUTTON, hint) hintButton.Disable() input_word = wx.TextCtrl(bkg) question = wx.StaticText(bkg, label="Welcome to jumbled words game\nTotal words: 25", style=wx.ALIGN_CENTER) # We define some stylish fonts for the welcome message / game questions font = wx.Font(pointSize=18, family=wx.DECORATIVE, style=wx.NORMAL, weight=wx.NORMAL) question.SetFont(font) result = wx.StaticText(bkg, label="Waiting for the initial result...", style=wx.ALIGN_CENTER) hbox = wx.BoxSizer() hbox.Add(input_word, proportion=1, flag=wx.EXPAND) hbox.Add(guessButton, proportion=0, flag=wx.LEFT, border=5) hbox.Add(nextButton, proportion=0, flag=wx.LEFT, border=5) hbox.Add(hintButton, proportion=0, flag=wx.LEFT, border=5) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(question, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) vbox.Add(hbox, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT, border=5) vbox.Add(result, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT, border=5) bkg.SetSizer(vbox) win.Show() app.MainLoop()
Last edited by vegaseat; Sep 13th, 2008 at 6:53 pm. Reason: was moved
It would be cool if you could have a text file full of all of the words so the user could add their own.
Your text file could look like this:
Python:yothnp
spam:apms
This was the user could add their own and you could just import it to a dictionary at the start like:
Your text file could look like this:
Python:yothnp
spam:apms
This was the user could add their own and you could just import it to a dictionary at the start like:
python Syntax (Toggle Plain Text)
f = open("Words.txt") for thing in f.split(":"): dictionary[thing[0]]=thing[1]
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
You can also let Python do the jumbling of the words and create the dictionary of word:jumble pairs:
python Syntax (Toggle Plain Text)
# create a dictionary of random jumbled words for a game import random def jumble_word(word): # create a list of characters of the word char_list = list(word) # shuffle sequence in place random.shuffle(char_list) # joint to form a word again return "".join(char_list) # add more words to the list as needed words = ['armada', 'bubble', 'letter', 'banana', 'radio', 'hammer', 'spark', 'pearl', 'target', 'zappy', 'zipper', 'organist', 'kitchen', 'ruler', 'motorist', 'polar', 'garage', 'window'] # create a list of jumbled words jumbles = [] for word in words: jumbles.append(jumble_word(word)) # create a dictionary from the two list words_dict = dict(zip(words, jumbles)) print words_dict """ possible output --> {'polar': 'aropl', 'target': 'rgaett', 'ruler': 'rleur', 'garage': 'eaaggr', 'bubble': 'beblub', 'window': 'nowdiw', 'pearl': 'aprel', 'zipper': 'pperzi', 'radio': 'idoar', 'motorist': 'rtotimos', 'letter': 'rettel', 'zappy': 'pzpay', 'armada': 'ardaam', 'spark': 'akprs', 'kitchen': 'theinck', 'hammer': 'mrameh', 'banana': 'bnanaa', 'organist': 'soiatgnr'} """
drink her pretty
Automatic jumbling seems like a really nice idea. I wanted to do that earlier also, but had no clue on how to begin.
The module "random" seems an interesting lot to play with.
The module "random" seems an interesting lot to play with.
Blog - anurag.granularproject.org
I think at one time you asked about module MD5 to send on a password, you might want to take a look at this post:
http://www.daniweb.com/forums/post220840-56.html
http://www.daniweb.com/forums/post220840-56.html
May 'the Google' be with you!
•
•
•
•
I think at one time you asked about module MD5 to send on a password, you might want to take a look at this post:
http://www.daniweb.com/forums/post220840-56.html
•
•
•
•
With more and more folks thinking it their business to snoop around in your e-mail, write a little Python program to encode regular text. It is assumed that you will send this text to a friend, who has Python installed and can run a program you send beforehand to decode the encrypted text (after using the correct password of course). Use Python module md5 to encrypt the password too.
So, I guess I can assume that md5 is not reversible, right?
Last edited by iamgame; Sep 21st, 2008 at 6:13 pm.
Blog - anurag.granularproject.org
An alternative to using a password to communicate with your friend is to send them a picture of your favorite pet and to use the sha128 digest of the picture as a key, together with a standard encryption algorithm (RSA or a better one). This way, only the people with your pet's picture can decipher your messages, which is quite secure I think.
![]() |
Other Threads in the Python Forum
- Previous Thread: pygame zoom/rotate
- Next Thread: Import Main problem
| Thread Tools | Search this Thread |
abrupt accessdenied ansi anti apache application approximation argv array backend beginner book builtin calculator change converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit enter file float format function heads homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin pointer prime programming progressbar py2exe pygame pyopengl python random recursion redirect remote reverse scrolledtext session simple software sprite statictext statistics string strings syntax table terminal text textarea thread threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable wordgame wxpython






