Example 21: Hangman server (3/3)
box = inbox.Inbox()box.bind(message_received)
appuifw.app.exit_key_handler = quit
appuifw.app.title = u"Hangman Server"
appuifw.app.menu = [(u"New Game", new_game),
(u"Game Status", game_status)]
print "HANGMAN SERVER STARTED"
print "Select 'Options -> New Game' to initialize a new game"
app_lock = e32.Ao_lock()
app_lock.wait()
The final section of the game source code is simple: it just constructs
the application user interface using the techniques introduced earlier in
this chapter. Here we also bind the message received() function to
the Inbox, so the incoming messages are captured correctly.
Now, let us assume that you initialize a new game and choose ‘code’
as the hidden word. The game proceeds as follows – here the G lines
denote replies by the game server and P the player’s messages.
P: GUESS i
G: Status after 1 guesses: _ _ _ _
P: GUESS o
G: Status after 2 guesses: _ o _ _
P: GUESS r
G: Status after 3 guesses: _ o _ _
P: GUESS e
G: Status after 4 guesses: _ o _ e
P: GUESS c
G: Status after 5 guesses: c o _ e
P: WORD code
G: Status after 6 guesses: c o d e
The correct guess in the end triggers a dialog that shows the winning
player’s phone number. After this, you can either start a new game or close
the application. Now start spreading the word about your revolutionary
new SMS game!
Summary
In this chapter we showed how to build real S60 applications that include
titles, menus and dialogs. Without this skeleton, building highly functional
applications would be cumbersome. The application framework came
in useful immediately when we started to search and sort your SMS
inbox.
With the techniques in this chapter, especially in the concluding
example, you can start building various kinds of SMS services. If you
want some further exercises, see the Wikipedia article about word
games and use the Hangman example as a basis for implementing
other games.
In this chapter, you also learned a great deal about the Python language,
including functions, callback functions, objects, tuples and the scope of
variables – in other words, almost everything needed in this book. In
Chapter 6, two more lessons are presented. If you feel exhausted by these
lessons, we can promise that Chapter 5 will not increase your burden.
Sire, no module was imported on Line 1
ReplyDelete