element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog Hangman Powered By Google App Engine
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: oneleggedredcow
  • Date Created: 29 Sep 2014 11:43 PM Date Created
  • Views 784 views
  • Likes 1 like
  • Comments 0 comments
  • raspberry_pi_projects
Related
Recommended

Hangman Powered By Google App Engine

oneleggedredcow
oneleggedredcow
29 Sep 2014

In this blog post, we are going to create a hangman game powered by the Google App Engine.  Hangman is a game where you are trying determine a secret word by guessing letters that might be in the word.

 

Hangman Cloud Backend

The first thing to do is to create a cloud service that returns back a random word that we can use as our secret word.  To do this, we first need a list of possible words to choose from.  Fortunately, there is such a list of all 109582 words in the English language.

 

After downloading that list, we can write a quick little python cloud application that chooses a random word and returns it to the caller:

This code segment is very much based on the Google App Engine Hello World example.  The code is actually very similar, but instead of returning “Hello World”, we return a random word to be used as the secret word in a game of hangman.

 

The biggest difference is the first section where we read in the text file (wordsEn.txt), and filter out any word that does not have at least four letters in it.  We filter out short words because they are not very fun to play a game of hangman with. After we have the word list, it is just a matter of picking a random index into the array and returning that word.

 

Running the application locally and publishing it to the cloud are both covered very well in the Hello World tutorial, so I won’t go into much detail here.  It requires another file to describe the application:

And then you can use the Google App Engine Launcher to run the application locally or publish (deploy) it to the cloud.

 

I published mine to http://hangman-riot.appspot.com/, so if you navigate there, you should see a random word in your browser:

image

 

Hangman Client Application

Fortunately, there’s already a great implementation of hangman in python from InventWithPython.com. So, we’ll use that as a starting point and add in some logic to use the cloud as the source of the secret word.  The code can be downloaded from: http://inventwithpython.com/hangman.py

 

I suggest running this a few times before you modify it just to get a feel of how it works.

 

Now, there are two places that we need to modify.  First, we need to remove the list of built in words that the application comes with, and replace the getRandomWord function with an implementation that grabs the word from our hangman cloud backend:

image

And then we need to add in a reference to the library that we are using the fetch the random word:

image

That’s it!  The final version of the code can be found here.

 

For a detailed description of how the code works, check out the InventWithPython website.

 

Right now the code is set up to hit the google app engine instance that I created.  If you want to hit a locally running application, just change the URL to be:

 

http://localhost:8080

 

Running Hangman on the Raspberry Pi

The hangman client python program requires python 3 in order to run.  So, if you don’t already have that installed, install it with this command:

 

sudo apt-get install python3

 

Once that completes you can run the hangman program:

 

python3.2 hangman.py

 

That should do it. Good luck, the words can be pretty tricky!

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube