Display demo memory game implementation. More...
#include <gfx/gfx.h>#include <gfx/win.h>#include <gfx/wtk.h>#include <gfx/sysfont.h>#include <stream.h>#include <string.h>#include <timer.h>#include "app_desktop.h"#include "app_memgame.h"#include <workqueue.h>#include "file_loader.h"Go to the source code of this file.
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. | |
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. | |
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_context * | game_ctx |
| Pointer to memory game application context. | |
Display demo memory game implementation.
Copyright (C) 2010 Atmel Corporation. All rights reserved.
Definition in file app_memgame.c.
1.6.3