14
Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley [email protected]

Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley [email protected]

Embed Size (px)

Citation preview

Page 1: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

Programming of Mobile and Handheld Devices

Lecture 7: Programming OXO for Palm OS

Rob Pooley

[email protected]

Page 2: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

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]

Page 3: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

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.

Page 4: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

Initial state – black filled circle

Welcome to noughts and crosses.Would you like to play a game?

Play Exit

Page 5: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

X to move state – buttons only

Click on a square to plant a cross

Done

Page 6: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

Or draw a bitmap over invisible buttons

Page 7: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

Buttons set to not usable are invisible

Page 8: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

X has moved state

Your X move was valid/invalid

OK

Show an alert?

Page 9: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

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?

Page 10: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

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

Page 11: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

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)

Page 12: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

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:

Page 13: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

Setting up the files for a build

Page 14: Programming of Mobile and Handheld Devices Lecture 7: Programming OXO for Palm OS Rob Pooley rjp@macs.hw.ac.uk

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 =