Memory game application
[Applications]

The memory game application is a simple game where the user has to find pairs of game pieces, i.e., ones that have the same image. It demonstrates usage of the button and label widgets in the Widget toolkit, drawing text with the Graphical display system and basic use of the Window System. More...

Collaboration diagram for Memory game application:

Data Structures

struct  memgame_piece
 Game piece data. More...
struct  memgame_context
 Context for the memory game application. More...

Defines

#define memgame_print_helper(str, x, y, color)   gfx_draw_string(str, x, y, &sysfont, color, GFX_COLOR_TRANSPARENT)
 Convenience macro for drawing text.

Enumerations

enum  memgame_command_id { CMD_NONE, CMD_NEW_GAME, CMD_EXIT }
 

Event command IDs for application widgets.

More...
enum  memgame_state {
  DRAW_ALL_PIECES, SELECT_FIRST_PIECE, SHOWN_FIRST_PIECE, SELECT_SECOND_PIECE,
  SHOWN_SECOND_PIECE, HIDE_FIRST_PIECE, HIDE_SECOND_PIECE, HIDDEN_BOTH_PIECES,
  GAME_OVER
}
 

States of the memory game.

More...

Functions

static uint16_t memgame_rand (void)
 Simple pseudo-random number generator.
static void memgame_print_game_over (void)
 Print game over-message.
static void memgame_print_tries (void)
 Print user's number of tries.
static void memgame_get_piece_coordinates (uint8_t position, gfx_coord_t *pos_x, gfx_coord_t *pos_y)
 Get the coordinates for specified piece.
static void memgame_draw_piece (uint8_t index, bool show)
 Enqueue drawing of specified piece.
static uint8_t memgame_get_random_index (uint8_t indexes[])
 Pick a random piece index from array.
static void memgame_start_new_game (void)
 Start new game.
static void memgame_update (uint8_t new_piece)
 Update the game.
static void memgame_handle_command_event (win_command_t data)
 Command event handler for application.
static void memgame_handle_pointer_event (struct win_pointer_event const *data)
 Pointer event handler for application.
static bool memgame_window_handler (struct win_window *win, enum win_event_type type, void const *data)
 Window event handler for application.
static void memgame_worker (struct workqueue_task *task)
 Application task worker.
static void memgame_timer_callback (struct timer *timer)
 Timer callback function.
void app_memgame_launch (struct workqueue_task *task)
 Memory game application launcher.

Variables

static struct memgame_contextgame_ctx
 Pointer to memory game application context.

General game board configuration



#define NR_OF_PIECE_PAIRS   6
 Number of piece pairs in the game.
#define NR_OF_PIECES   (2 * NR_OF_PIECE_PAIRS)
 Number of pieces in the game.
#define NR_OF_BOARD_COLUMNS   4
 Number of pieces per row on the board.
#define BOARD_POS_X   30
 X-coordinate to start drawing first piece at.
#define BOARD_POS_Y   5
 Y-coordinate to start drawing first piece at.
#define BACKGROUND_COLOR   GFX_COLOR(0, 0, 0)
 Background color for the game.
#define WIDGET_FONT_SCALE   2
 Font scaling for button widgets.

Game piece configuration



#define PIECE_PAIR_FILE_0   "i_fonts"
 Image file to load when showing piece pair 0.
#define PIECE_PAIR_FILE_1   "i_pics"
 Image file to load when showing piece pair 1.
#define PIECE_PAIR_FILE_2   "i_avr"
 Image file to load when showing piece pair 2.
#define PIECE_PAIR_FILE_3   "i_clock"
 Image file to load when showing piece pair 3.
#define PIECE_PAIR_FILE_4   "i_files"
 Image file to load when showing piece pair 4.
#define PIECE_PAIR_FILE_5   "i_games"
 Image file to load when showing piece pair 5.
#define PIECE_BACK_FILE   "cardback"
 Image file to load when showing the back of game pieces.
#define PIECE_SIZE_X   57
 Width of piece images.
#define PIECE_SIZE_Y   PIECE_SIZE_X
 Height of piece images.
#define PIECE_SPACING_X   10
 Spacing between pieces in X-dimension.
#define PIECE_SPACING_Y   PIECE_SPACING_X
 Spacing between pieces in Y-dimension.
#define PIECE_INVALID_INDEX   0xFF
 Index to use to indicate no piece is selected.

New game-button configuration



#define BTN_NEW_GAME_TEXT   "New"
 Text to draw on button.
#define BTN_NEW_GAME_POS_X
 X-coordinate of button.
#define BTN_NEW_GAME_POS_Y   APP_EXIT_BUTTON_POS_Y
 Y-coordinate of button.
#define BTN_NEW_GAME_SIZE_X   (2 * APP_EXIT_BUTTON_SIZE_X)
 Width of button.
#define BTN_NEW_GAME_SIZE_Y   APP_EXIT_BUTTON_SIZE_Y
 Height of button.

Number of tries-counter configuration



#define MSG_TRIES_TEXT   "Tries: %i"
 Text to print, for use with snprintf().
#define MSG_TRIES_LENGTH   10
 Maximum number of characters in text string.
#define MSG_TRIES_POS_X   0
 X-coordinate of label.
#define MSG_TRIES_POS_Y
 Y-coordinate of label, vertically centered on buttons.
#define MSG_TRIES_SIZE_X
 Width of label widget.
#define MSG_TRIES_SIZE_Y   gfx_font_get_height(&sysfont)
 Height of label widget.

Game over-message configuration



#define MSG_GAME_OVER_TEXT   "Well done!"
 Text to print when game is completed.
#define MSG_GAME_OVER_SCALE   4
 Font scaling for text string.
#define MSG_GAME_OVER_POS_X   45
 X-coordinate of game-over text.
#define MSG_GAME_OVER_POS_Y   105
 Y-coordinate of game-over text.
#define MSG_GAME_OVER_GLOW_OFFSET   1
 Offset in position to use for getting a glow-effect.
#define MSG_GAME_OVER_COLOR   GFX_COLOR(255, 160, 0)
 Color to print foreground text with.
#define MSG_GAME_OVER_GLOW_COLOR   GFX_COLOR(250, 250, 250)
 Color to print background "glow" text with.

Application timing configuration



#define TIMER_PAUSE_HALF_SECONDS   3
 Number of half seconds before hiding mismatched game pieces.
#define TIMER_CLOCK_RATE   (0x1ffffUL / 8)
 Minimum timer clock rate to use.

Detailed Description

The memory game application is a simple game where the user has to find pairs of game pieces, i.e., ones that have the same image. It demonstrates usage of the button and label widgets in the Widget toolkit, drawing text with the Graphical display system and basic use of the Window System.

The application displays 12 game pieces and the number of times the user has tried to find matching pairs of them. Two buttons allow the user to restart or end the game when the game is not busy drawing game pieces to screen. If the user selects mismatched pieces, the game will pause for 1.5 seconds to allow the user to memorize their position, before hiding them again.

This application makes use of the Timer driver for pausing the game after after mismatching game pieces have been selected, and the File loader utility for loading the game piece images directly to screen.


Define Documentation

#define BACKGROUND_COLOR   GFX_COLOR(0, 0, 0)

Background color for the game.

Definition at line 74 of file app_memgame.c.

Referenced by app_memgame_launch().

#define BOARD_POS_X   30

X-coordinate to start drawing first piece at.

Definition at line 70 of file app_memgame.c.

Referenced by memgame_get_piece_coordinates().

#define BOARD_POS_Y   5

Y-coordinate to start drawing first piece at.

Definition at line 72 of file app_memgame.c.

Referenced by memgame_get_piece_coordinates().

#define BTN_NEW_GAME_POS_X
Value:

X-coordinate of button.

Definition at line 122 of file app_memgame.c.

Referenced by app_memgame_launch().

#define BTN_NEW_GAME_POS_Y   APP_EXIT_BUTTON_POS_Y

Y-coordinate of button.

Definition at line 125 of file app_memgame.c.

Referenced by app_memgame_launch().

#define BTN_NEW_GAME_SIZE_X   (2 * APP_EXIT_BUTTON_SIZE_X)

Width of button.

Definition at line 127 of file app_memgame.c.

Referenced by app_memgame_launch().

#define BTN_NEW_GAME_SIZE_Y   APP_EXIT_BUTTON_SIZE_Y

Height of button.

Definition at line 129 of file app_memgame.c.

Referenced by app_memgame_launch().

#define BTN_NEW_GAME_TEXT   "New"

Text to draw on button.

Definition at line 120 of file app_memgame.c.

Referenced by app_memgame_launch().

#define memgame_print_helper ( str,
x,
y,
color   )     gfx_draw_string(str, x, y, &sysfont, color, GFX_COLOR_TRANSPARENT)

Convenience macro for drawing text.

Draws text string with the sysfont and specified color, with a transparent background.

Parameters:
str Text string to print.
x X-coordinate to draw text at.
y Y-coordinate to draw text at.
color Color to draw text with.

Definition at line 314 of file app_memgame.c.

Referenced by memgame_print_game_over().

#define MSG_GAME_OVER_COLOR   GFX_COLOR(255, 160, 0)

Color to print foreground text with.

Definition at line 174 of file app_memgame.c.

Referenced by memgame_print_game_over().

#define MSG_GAME_OVER_GLOW_COLOR   GFX_COLOR(250, 250, 250)

Color to print background "glow" text with.

Definition at line 176 of file app_memgame.c.

Referenced by memgame_print_game_over().

#define MSG_GAME_OVER_GLOW_OFFSET   1

Offset in position to use for getting a glow-effect.

Definition at line 172 of file app_memgame.c.

Referenced by memgame_print_game_over().

#define MSG_GAME_OVER_POS_X   45

X-coordinate of game-over text.

Definition at line 168 of file app_memgame.c.

Referenced by memgame_print_game_over().

#define MSG_GAME_OVER_POS_Y   105

Y-coordinate of game-over text.

Definition at line 170 of file app_memgame.c.

Referenced by memgame_print_game_over().

#define MSG_GAME_OVER_SCALE   4

Font scaling for text string.

Definition at line 166 of file app_memgame.c.

Referenced by memgame_print_game_over().

#define MSG_GAME_OVER_TEXT   "Well done!"

Text to print when game is completed.

Definition at line 164 of file app_memgame.c.

Referenced by memgame_print_game_over().

#define MSG_TRIES_LENGTH   10

Maximum number of characters in text string.

Definition at line 142 of file app_memgame.c.

Referenced by memgame_print_tries().

#define MSG_TRIES_POS_X   0

X-coordinate of label.

Definition at line 144 of file app_memgame.c.

Referenced by app_memgame_launch().

#define MSG_TRIES_POS_Y
Value:

Y-coordinate of label, vertically centered on buttons.

Definition at line 146 of file app_memgame.c.

Referenced by app_memgame_launch().

#define MSG_TRIES_SIZE_X
Value:

Width of label widget.

Definition at line 150 of file app_memgame.c.

Referenced by app_memgame_launch().

#define MSG_TRIES_SIZE_Y   gfx_font_get_height(&sysfont)

Height of label widget.

Definition at line 153 of file app_memgame.c.

Referenced by app_memgame_launch().

#define MSG_TRIES_TEXT   "Tries: %i"

Text to print, for use with snprintf().

Definition at line 140 of file app_memgame.c.

Referenced by memgame_print_tries().

#define NR_OF_BOARD_COLUMNS   4

Number of pieces per row on the board.

Definition at line 68 of file app_memgame.c.

Referenced by memgame_get_piece_coordinates().

#define NR_OF_PIECE_PAIRS   6

Number of piece pairs in the game.

Definition at line 64 of file app_memgame.c.

Referenced by memgame_start_new_game().

#define NR_OF_PIECES   (2 * NR_OF_PIECE_PAIRS)

Number of pieces in the game.

Definition at line 66 of file app_memgame.c.

Referenced by memgame_get_random_index(), memgame_handle_pointer_event(), memgame_start_new_game(), and memgame_update().

#define PIECE_BACK_FILE   "cardback"

Image file to load when showing the back of game pieces.

Definition at line 99 of file app_memgame.c.

Referenced by memgame_draw_piece().

#define PIECE_INVALID_INDEX   0xFF

Index to use to indicate no piece is selected.

Definition at line 109 of file app_memgame.c.

Referenced by memgame_get_random_index(), and memgame_worker().

#define PIECE_PAIR_FILE_0   "i_fonts"

Image file to load when showing piece pair 0.

Definition at line 87 of file app_memgame.c.

Referenced by memgame_draw_piece().

#define PIECE_PAIR_FILE_1   "i_pics"

Image file to load when showing piece pair 1.

Definition at line 89 of file app_memgame.c.

Referenced by memgame_draw_piece().

#define PIECE_PAIR_FILE_2   "i_avr"

Image file to load when showing piece pair 2.

Definition at line 91 of file app_memgame.c.

Referenced by memgame_draw_piece().

#define PIECE_PAIR_FILE_3   "i_clock"

Image file to load when showing piece pair 3.

Definition at line 93 of file app_memgame.c.

Referenced by memgame_draw_piece().

#define PIECE_PAIR_FILE_4   "i_files"

Image file to load when showing piece pair 4.

Definition at line 95 of file app_memgame.c.

Referenced by memgame_draw_piece().

#define PIECE_PAIR_FILE_5   "i_games"

Image file to load when showing piece pair 5.

Definition at line 97 of file app_memgame.c.

Referenced by memgame_draw_piece().

#define PIECE_SIZE_X   57

Width of piece images.

Definition at line 101 of file app_memgame.c.

Referenced by memgame_draw_piece(), memgame_get_piece_coordinates(), and memgame_handle_pointer_event().

#define PIECE_SIZE_Y   PIECE_SIZE_X

Height of piece images.

Definition at line 103 of file app_memgame.c.

Referenced by memgame_draw_piece(), memgame_get_piece_coordinates(), and memgame_handle_pointer_event().

#define PIECE_SPACING_X   10

Spacing between pieces in X-dimension.

Definition at line 105 of file app_memgame.c.

Referenced by memgame_get_piece_coordinates().

#define PIECE_SPACING_Y   PIECE_SPACING_X

Spacing between pieces in Y-dimension.

Definition at line 107 of file app_memgame.c.

Referenced by memgame_get_piece_coordinates().

#define TIMER_CLOCK_RATE   (0x1ffffUL / 8)

Minimum timer clock rate to use.

Clock rate to use for detecting elapsed half-seconds with the Timer driver.

Note:
Assuming a 16-bit timer, a clock rate below 2^17 will allow for detection of half seconds with the Timer driver. The clock rate is divided by a factor of eight to ensure that a low enough clock rate is selected by the driver during initialization.

Definition at line 199 of file app_memgame.c.

#define TIMER_PAUSE_HALF_SECONDS   3

Number of half seconds before hiding mismatched game pieces.

Definition at line 187 of file app_memgame.c.

Referenced by memgame_update().

#define WIDGET_FONT_SCALE   2

Font scaling for button widgets.

Definition at line 76 of file app_memgame.c.

Referenced by app_memgame_launch(), and memgame_print_game_over().


Enumeration Type Documentation

Event command IDs for application widgets.

Enumerator:
CMD_NONE 

Unused command event value.

CMD_NEW_GAME 

Command event value for new game-button.

CMD_EXIT 

Command event value for exit-button.

Definition at line 204 of file app_memgame.c.

States of the memory game.

Enumerator:
DRAW_ALL_PIECES 

Draw all pieces on the board.

SELECT_FIRST_PIECE 

Waiting for player to select first piece.

SHOWN_FIRST_PIECE 

First selected piece has been shown.

SELECT_SECOND_PIECE 

Waiting for player to select second piece.

SHOWN_SECOND_PIECE 

Second selected piece has been shown.

HIDE_FIRST_PIECE 

Hide first selected piece after mismatch.

HIDE_SECOND_PIECE 

Hide second selected piece after mismatch.

HIDDEN_BOTH_PIECES 

Both selected pieces have been hidden.

GAME_OVER 

Game is over, wait for user to restart the game.

Definition at line 214 of file app_memgame.c.


Function Documentation

void app_memgame_launch ( struct workqueue_task task  ) 

Memory game application launcher.

Allocates memory for the application context, initializes the timer and creates the window and button widgets before starting a new game.

If memory cannot be allocated, or creation of the window or any widget fails, the application exits immediately.

Parameters:
task Workqueue task to use for this application.

Definition at line 800 of file app_memgame.c.

References app_desktop_restart(), APP_EXIT_BUTTON_POS_X, APP_EXIT_BUTTON_POS_Y, APP_EXIT_BUTTON_SIZE_X, APP_EXIT_BUTTON_SIZE_Y, APP_EXIT_BUTTON_TEXT, win_attributes::area, assert, win_attributes::background, BACKGROUND_COLOR, memgame_context::bitmap, BITMAP_SOLID, BTN_NEW_GAME_POS_X, BTN_NEW_GAME_POS_Y, BTN_NEW_GAME_SIZE_X, BTN_NEW_GAME_SIZE_Y, BTN_NEW_GAME_TEXT, CMD_EXIT, CMD_NEW_GAME, gfx_bitmap::color, win_attributes::event_handler, gfx_draw_filled_rect, gfx_get_height(), gfx_get_width(), gfx_set_clipping(), membag_alloc(), membag_free(), memcpy(), memgame_start_new_game(), memgame_timer_callback(), memgame_window_handler(), memgame_worker(), MSG_TRIES_POS_X, MSG_TRIES_POS_Y, MSG_TRIES_SIZE_X, MSG_TRIES_SIZE_Y, memgame_context::old_sysfont, win_area::pos, font::scale, win_area::size, sysfont, memgame_context::task, memgame_context::timer, TIMER_CLOCK_RATE, memgame_context::timer_delay, timer_get_resolution, timer_init, timer_set_resolution, timer_write_resolution, memgame_context::tries_label, gfx_bitmap::type, WIDGET_FONT_SCALE, memgame_context::win, win_create(), win_destroy(), win_get_root(), win_show(), workqueue_task_set_work_func(), wtk_button_as_child(), wtk_button_create(), wtk_label_as_child(), and wtk_label_create().

static void memgame_draw_piece ( uint8_t  index,
bool  show 
) [static]

Enqueue drawing of specified piece.

Enqueues loading of the specified game piece's image to screen. If the piece is to be shown, the image file is determined by which pair the piece belongs to. If the piece is not to be shown, a common image for the pieces' backside is loaded.

Parameters:
index Index of piece.
show Indicates whether to draw the front (true) or back (false) of the game piece.

Definition at line 412 of file app_memgame.c.

References app_desktop_restart(), load_file_to_screen(), membag_free(), memcpy(), memgame_get_piece_coordinates(), memgame_context::old_sysfont, memgame_piece::pair, PIECE_BACK_FILE, PIECE_PAIR_FILE_0, PIECE_PAIR_FILE_1, PIECE_PAIR_FILE_2, PIECE_PAIR_FILE_3, PIECE_PAIR_FILE_4, PIECE_PAIR_FILE_5, PIECE_SIZE_X, PIECE_SIZE_Y, memgame_context::pieces, STATUS_OK, sysfont, memgame_context::task, memgame_context::win, and win_destroy().

Referenced by memgame_update().

static void memgame_get_piece_coordinates ( uint8_t  position,
gfx_coord_t pos_x,
gfx_coord_t pos_y 
) [static]

Get the coordinates for specified piece.

Computes the X and Y coordinates of the specified piece position in the game board grid.

Parameters:
position Position of piece.
pos_x Address to store X coordinate of piece at.
pos_y Address to store Y coordinate of piece at.
Returns:
Coordinates of specified piece position stored to pos_x and pos_y.

Definition at line 390 of file app_memgame.c.

References BOARD_POS_X, BOARD_POS_Y, NR_OF_BOARD_COLUMNS, PIECE_SIZE_X, PIECE_SIZE_Y, PIECE_SPACING_X, and PIECE_SPACING_Y.

Referenced by memgame_draw_piece(), and memgame_handle_pointer_event().

static uint8_t memgame_get_random_index ( uint8_t  indexes[]  )  [static]

Pick a random piece index from array.

Parameters:
indexes Array containing currently available piece indexes.
Returns:
Random entry from indexes[], which was not already taken.

Definition at line 478 of file app_memgame.c.

References memgame_rand(), NR_OF_PIECES, and PIECE_INVALID_INDEX.

Referenced by memgame_start_new_game().

static void memgame_handle_command_event ( win_command_t  data  )  [static]

Command event handler for application.

Handles the command events issued by widgets in the application window. Only the exit- and new game-buttons require handling in this application.

Parameters:
data Command event ID passed from button.

Definition at line 665 of file app_memgame.c.

References app_desktop_restart(), CMD_EXIT, CMD_NEW_GAME, membag_free(), memcpy(), memgame_start_new_game(), memgame_context::old_sysfont, sysfont, memgame_context::win, and win_destroy().

Referenced by memgame_window_handler().

static void memgame_handle_pointer_event ( struct win_pointer_event const *  data  )  [static]

Pointer event handler for application.

Handles the pointer events within the application window, but not within any of the widgets. The pointer presses are used to select game pieces, and their indexes are passed on to memgame_update.

Parameters:
data Pointer event data.

Definition at line 694 of file app_memgame.c.

References memgame_get_piece_coordinates(), memgame_update(), NR_OF_PIECES, PIECE_SIZE_X, PIECE_SIZE_Y, win_pointer_event::pos, win_pointer_event::type, and WIN_POINTER_PRESS.

Referenced by memgame_window_handler().

static void memgame_print_game_over ( void   )  [static]

Print game over-message.

Writes a text string to the screen to notify the user that the game is over. This is done several times, with different offsets and color to get a glow- or outline-effect on the text.

Definition at line 324 of file app_memgame.c.

References gfx_get_height(), gfx_get_width(), gfx_set_clipping(), memgame_print_helper, MSG_GAME_OVER_COLOR, MSG_GAME_OVER_GLOW_COLOR, MSG_GAME_OVER_GLOW_OFFSET, MSG_GAME_OVER_POS_X, MSG_GAME_OVER_POS_Y, MSG_GAME_OVER_SCALE, MSG_GAME_OVER_TEXT, font::scale, sysfont, and WIDGET_FONT_SCALE.

Referenced by memgame_update().

static void memgame_print_tries ( void   )  [static]

Print user's number of tries.

Creates a new text string that contains the number of tries, and updates the label widget with it.

Definition at line 368 of file app_memgame.c.

References MSG_TRIES_LENGTH, MSG_TRIES_TEXT, snprintf(), str, memgame_context::tries, memgame_context::tries_label, and wtk_label_change().

Referenced by memgame_update().

static uint16_t memgame_rand ( void   )  [static]

Simple pseudo-random number generator.

Returns:
Pseudo-random 16-bit number.

Definition at line 296 of file app_memgame.c.

Referenced by memgame_get_random_index().

static void memgame_start_new_game ( void   )  [static]

Start new game.

Clears the application window, reinitializes the game state and randomizes the game pieces. The application worker task is then queued to start the game.

Definition at line 504 of file app_memgame.c.

References memgame_context::busy, DRAW_ALL_PIECES, memgame_piece::found, main_workqueue, memgame_get_random_index(), NR_OF_PIECE_PAIRS, NR_OF_PIECES, memgame_piece::pair, memgame_context::pairs_left, memgame_context::piece_1, memgame_context::pieces, memgame_context::state, memgame_context::task, memgame_context::tries, memgame_context::win, win_redraw(), and workqueue_add_task().

Referenced by app_memgame_launch(), and memgame_handle_command_event().

static void memgame_timer_callback ( struct timer timer  )  [static]

Timer callback function.

Callback function used with the timer driver for delayed queueing of the application's workqueue task.

Parameters:
timer Pointer to timer struct associated with the callback.

Definition at line 778 of file app_memgame.c.

References main_workqueue, memgame_context::task, memgame_context::ticks_to_go, memgame_context::timer, memgame_context::timer_delay, timer_set_alarm, timer_stop, and workqueue_add_task().

Referenced by app_memgame_launch().

static void memgame_update ( uint8_t  new_piece  )  [static]

Update the game.

This is the main game function, which handles the piece selection and image loading according to the current state of the game.

The game will go through the game states in the order they are enumerated in memgame_state, but may stay in a state if the user does not select a valid game piece or the game must be restarted.

This function is called by memgame_worker once the game starts or an image is loaded, and by memgame_handle_pointer_event if the user selects a piece while the game is not busy loading images.

Parameters:
new_piece Index and position of piece that was selected.

Definition at line 555 of file app_memgame.c.

References memgame_context::busy, DRAW_ALL_PIECES, memgame_piece::found, GAME_OVER, HIDDEN_BOTH_PIECES, HIDE_FIRST_PIECE, HIDE_SECOND_PIECE, memgame_draw_piece(), memgame_print_game_over(), memgame_print_tries(), NR_OF_PIECES, memgame_piece::pair, memgame_context::pairs_left, memgame_context::piece_1, memgame_context::piece_2, memgame_context::pieces, SELECT_FIRST_PIECE, SELECT_SECOND_PIECE, SHOWN_FIRST_PIECE, SHOWN_SECOND_PIECE, memgame_context::state, memgame_context::ticks_to_go, memgame_context::timer, memgame_context::timer_delay, TIMER_PAUSE_HALF_SECONDS, timer_set_alarm, timer_start, and memgame_context::tries.

Referenced by memgame_handle_pointer_event(), and memgame_worker().

static bool memgame_window_handler ( struct win_window win,
enum win_event_type  type,
void const *  data 
) [static]

Window event handler for application.

Handles all events issued to the application window. Only command and pointer events are relevant to this application, and these are passed on to their respective handler functions if the application is not currently busy loading images.

Parameters:
win Pointer to the window receiving the event.
type Indicates the type of the event.
data Event type-specific data.
Return values:
true To accept all events from the window system.

Definition at line 733 of file app_memgame.c.

References memgame_context::busy, memgame_handle_command_event(), memgame_handle_pointer_event(), WIN_EVENT_COMMAND, and WIN_EVENT_POINTER.

Referenced by app_memgame_launch().

static void memgame_worker ( struct workqueue_task task  )  [static]

Application task worker.

This is enqueued by File loader utility after images have loaded or by memgame_timer_callback when the application alarm timer expires, and will simply update the game state.

Parameters:
task Workqueue task for this worker function.

Definition at line 765 of file app_memgame.c.

References memgame_update(), and PIECE_INVALID_INDEX.

Referenced by app_memgame_launch().


Variable Documentation

struct memgame_context* game_ctx [static]

Pointer to memory game application context.

Note:
This pointer is statically allocated, but the context itself is only allocated when the application is launched, and then destroyed upon exit to conserve memory.

Definition at line 289 of file app_memgame.c.

Generated on Thu Apr 29 14:09:59 2010 for display-demo by  doxygen 1.6.3