CSc 4110/6110 Embedded Systems
Lab Experiment #2
Spring 2008
Instructor: Dr. Michael Weeks

16 pattern matching game

In this lab, you will make a small GUI-based game using Xwindows with the iPAQ. The game is a puzzle involving 16 rectangles, each with a pattern. The pattern is hidden, but the user can reveal any pattern by clicking on the rectangle. The user should tap on one rectangle (revealing its pattern) then tap on the rectangle that matches its pattern. When a match is discovered, the two rectangles show appear flashing for one second, then are removed. Any events should be processed during this time, including typing "q" to quit.

If the two rectangles selected do not match, the program should pause for 1 second, then hide both patterns again. The goal for the user is to match all patterns, and clear the screen.

You could play a similar game by yourself with a deck of cards. Just spread the cards out in front of you, and turn over any two. If they match (e.g. both are red 9's), remove them. If not, turn them back over and try again.

The patterns may be numbers, i.e. the digits 1 through 8. A better idea is to design your own patterns.

The screen size is 240 pixels wide. You may use a square board (i.e. 240x240), or you can use one of different dimensions, such as one where the whole display is used, or where the display is used only to the top of the keyboard. Use the "DrawPoint(x_position, y_position, color)" method to draw pixels on the screen.

When the player wins, show a new window that says "You won!" for 2 seconds, then re-display the board for 2 seconds, then quit.

To show a pattern, the user should tap on its rectangle.

Your game should have 2 modes, a debug mode and a play mode. The play mode should randomly mix-up the pieces and blank. The debug mode should also present the user with the puzzle, but the initial placement of the pieces should be fairly simple (requiring only 1 or 2 moves to win). This way, you can test your program. These modes can be specified by either a parameter passed to the program, or you can define a constant within your program.

When an expose event occurs, re-draw the entire board.

Write-up what you did IN YOUR OWN WORDS. Do not simply re-word the directions, but explain what is going on. Avoid listing steps. Use outside sources as appropriate, and be certain to cite your sources. Turn in one report per person. You are to work on this lab individually.

Make sure to include your source code with the write-up.

For grading, please demonstrate your program to the TA.
 

    Questions:
  1. This game has some timing elements. How did you accomplish this?
  2. How did you choose to specify the debug/play mode? Why?
  3. Once a move is made, does your program re-display the entire board, or only the 2 affected rectangles? What are the advantages and disadvantages of these methods?
  4. What screen dimensions did you choose, and why? What is the total size of the iPAQ's screen?
  5. How did you make (and display) the patterns?
  6. Experiment with the DrawPoint method, and determine how many possible colors the iPAQ can display. How did you find this? (Hint: do not get this info from a web-page. I've found that some webpages are WRONG about this.)
  7. Describe how you could change your program to be a "24 rectangle" game.
  8. Of the Xwindow events that occur, how would you rank them in priority, and why?