programming of mobile and handheld devices lecture 7: programming oxo for palm os rob pooley...
TRANSCRIPT
Programming of Mobile and Handheld Devices
Lecture 7: Programming OXO for Palm OS
Rob Pooley
Designing and programming a new application
• This lecture describes the design and implementation of the second game we set out in lecture 4.
• This time we are building a noughts and crosses (tic-tac-toe) game.
• Here is the statechart that we defined previously.
X to MoveX has moved
O has moved O to move
[]
[valid] [valid]
[Win or draw]
[Win or draw]
The design and implement process
• The design of a Palm OS application from a statechart follows the steps below:
1. Each state defines a distinct point in the evolution of the application and needs a screen (Form) which corresponds to it;
2. Each form needs an event handler function;3. For each successor state, each form needs one
mechanism which triggers a move to that state;4. Update the AppHandleEvent function to deal with the
Form types and their handlers defined above;5. Work out what information needs to exist across states;6. Set up the project and its makefile.
Initial state – black filled circle
Welcome to noughts and crosses.Would you like to play a game?
Play Exit
X to move state – buttons only
Click on a square to plant a cross
Done
Or draw a bitmap over invisible buttons
Buttons set to not usable are invisible
X has moved state
Your X move was valid/invalid
OK
Show an alert?
Notes as we go
• The state to date must be remembered across states for checking and display updating.
• The text should be different depending on the validity of the move made. – That is not a user determined outcome, but is
triggered by an internal check. – The grid is displayed with a cross if the move
was valid, maybe with some indication of where the invalid move appeared otherwise?
Winning state
• Alerts are for grabbing attention and giving information.
• Do we need separate forms or alerts for each outcome?
• We can use a Field and set its text if we want to.
Congratulations to X/OYou won!
Done
Control Resources
• Different resources are associated with different controls, as follows:
Button Button Resource (tBTN)
Popup trigger Popup Trigger Resource (tPUT)
Selector trigger Selector Trigger Resource (tSLT)
Repeat control Repeating Button Resource (tREP)
Push button Push Button Resource (tPBN)
Check box Check Box Resource (tCBX)
Slider Slider Resource (tsld)
Feedback sliderFeedback Slider Resource (tslf)
FldInsert Function • Replace the current selection if any with the specified string and
redraw the field. • Declared In Field.h • Prototype Boolean FldInsert(FieldType
*fldP,const Char *insertChars, UInt16 insertLen) Parameters • fldPPointer to the field object (FieldType structure) into which to insert.• insertCharsText string to be inserted.• insertLenLength in bytes of the text string to be inserted, not counting the trailing
null character.• Returns Returns true if string was successfully inserted. Returns false if:
Setting up the files for a build
Edit the makefile to reflect this
## --------------------------------------------------------------------# Sources and Resources# List all the sources (.c/.cpp) and resources (.xrd) in your project# Use project relative path names with forward slashes (src/code.cpp).# Please do not use spaces in directory names.# A note about XRD resource files: If you have existing .rsrc or .rcp, # files refer to the documentation for the GenerateXRD tool to convert # them into XRD files for use with all Palm OS SDKs.## --------------------------------------------------------------------# TODO: Update all sources and resourcesSOURCES = src/AppMain.cRESOURCES = rsc/OXO.xrdSLIB_DEF_FILE =