projects
/
mancala
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refraction part 4
[mancala]
/
src
/
play.c
diff --git
a/src/play.c
b/src/play.c
index
51b88a9
..
cca9800
100644
(file)
--- a/
src/play.c
+++ b/
src/play.c
@@
-47,6
+47,16
@@
Mix_Chunk *pick = NULL;
// the hildon-game-wrapper context
HgwContext *hgw_context = NULL;
// the hildon-game-wrapper context
HgwContext *hgw_context = NULL;
+// void rmz_debug (char *msg){
+// FILE *pFile;
+//
+// pFile = fopen ("/home/rzingg/mancala.debug", "a");
+// if (pFile) {
+// fprintf (pFile, "rmz_debug: %s \n", msg);
+// fclose (pFile);
+// }
+// }
+
void sdl_clean_up(){
int i = 0;
void sdl_clean_up(){
int i = 0;
@@
-70,12
+80,13
@@
void sdl_clean_up(){
}
int play() {
}
int play() {
-
+// rmz_debug("play step 1");
SDL_Rect board_rect, title_rect, exit_rect;
SDL_Color font_color;
SDL_Event event;
SDL_Color font_color_exit;
SDL_Rect board_rect, title_rect, exit_rect;
SDL_Color font_color;
SDL_Event event;
SDL_Color font_color_exit;
+// rmz_debug("play step 2");
char tile_path[STRING_MAX], stone_path[STRING_MAX];
char icon_path[STRING_MAX], title_path[STRING_MAX];
char home_path[STRING_MAX], board_path[STRING_MAX];
char tile_path[STRING_MAX], stone_path[STRING_MAX];
char icon_path[STRING_MAX], title_path[STRING_MAX];
char home_path[STRING_MAX], board_path[STRING_MAX];
@@
-84,11
+95,13
@@
int play() {
int i, redraw_board, highlight, old_highlight, active;
int current_move, ai_last_move, human_last_move, state;
int i, redraw_board, highlight, old_highlight, active;
int current_move, ai_last_move, human_last_move, state;
+// rmz_debug("play step 3");
/* Set up the game board and game variables. */
gameInit(aiBoard, humanBoard);
current_move = 0;
ai_last_move = human_last_move = -99;
/* Set up the game board and game variables. */
gameInit(aiBoard, humanBoard);
current_move = 0;
ai_last_move = human_last_move = -99;
+// rmz_debug("play step 4");
/* initialize our libraries */
//if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
/* initialize our libraries */
//if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
@@
-98,6
+111,7
@@
int play() {
return 1;
}
return 1;
}
+// rmz_debug("play step 5");
if (TTF_Init() < 0) {
fprintf(stderr, "Unable to initialize SDL_ttf: %s\n",
SDL_GetError());
if (TTF_Init() < 0) {
fprintf(stderr, "Unable to initialize SDL_ttf: %s\n",
SDL_GetError());
@@
-105,17
+119,19
@@
int play() {
return 1;
}
return 1;
}
+// rmz_debug("play step 6");
//Initialize SDL_mixer
//Initialize SDL_mixer
-
if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
+ // if( Mix_OpenAudio(22050, (Uint16)AUDIO_U8, 2, 256 ) == -1 )
{
{
+// rmz_debug(g_strdup_printf("Unable to initialize Mix_OpenAudio: %s\n",SDL_GetError()));
fprintf(stderr, "Unable to initialize Mix_OpenAudio: %s\n",
SDL_GetError());
sdl_clean_up();
return 1;
}
fprintf(stderr, "Unable to initialize Mix_OpenAudio: %s\n",
SDL_GetError());
sdl_clean_up();
return 1;
}
-
+// rmz_debug("play step 7");
/* Load our images... PNGs now, maybe XPMs later */
sprintf(tile_path, "%s/tile.png", RES_PATH);
if ((tile = LoadRes(tile_path)) == NULL) {
/* Load our images... PNGs now, maybe XPMs later */
sprintf(tile_path, "%s/tile.png", RES_PATH);
if ((tile = LoadRes(tile_path)) == NULL) {
@@
-125,6
+141,7
@@
int play() {
return 1;
}
return 1;
}
+// rmz_debug("play step 8");
for (i=0; i<=STONE_MAX; i++) {
if (sprintf(stone_path, "%s/stone%02d.png", RES_PATH, i) == 0)
fprintf(stderr, "Problems assembling path.\n");
for (i=0; i<=STONE_MAX; i++) {
if (sprintf(stone_path, "%s/stone%02d.png", RES_PATH, i) == 0)
fprintf(stderr, "Problems assembling path.\n");
@@
-136,6
+153,7
@@
int play() {
}
}
}
}
+// rmz_debug("play step 9");
/* Load our font(s) */
if (sprintf(title_path, "%s/luxisr.ttf", FONT_PATH) == 0)
fprintf(stderr, "Problems assembling path.\n");
/* Load our font(s) */
if (sprintf(title_path, "%s/luxisr.ttf", FONT_PATH) == 0)
fprintf(stderr, "Problems assembling path.\n");
@@
-145,6
+163,7
@@
int play() {
return 1;
}
return 1;
}
+// rmz_debug("play step 10");
if (sprintf(board_path, "%s/luxisr.ttf", FONT_PATH) == 0)
fprintf(stderr, "Problems assembling path.\n");
if (!(board_font = TTF_OpenFont(board_path, BOARD_SIZE))) {
if (sprintf(board_path, "%s/luxisr.ttf", FONT_PATH) == 0)
fprintf(stderr, "Problems assembling path.\n");
if (!(board_font = TTF_OpenFont(board_path, BOARD_SIZE))) {
@@
-153,6
+172,7
@@
int play() {
return 1;
}
return 1;
}
+// rmz_debug("play step 11");
if (sprintf(home_path, "%s/luxisr.ttf", FONT_PATH) == 0)
fprintf(stderr, "Problems assembling path.\n");
if (!(home_font = TTF_OpenFont(home_path, HOME_SIZE))) {
if (sprintf(home_path, "%s/luxisr.ttf", FONT_PATH) == 0)
fprintf(stderr, "Problems assembling path.\n");
if (!(home_font = TTF_OpenFont(home_path, HOME_SIZE))) {
@@
-161,6
+181,7
@@
int play() {
return 1;
}
return 1;
}
+// rmz_debug("play step 12");
/* Load sound effects */
sprintf(pick_path, "%s/pick.wav", RES_PATH);
if ((pick = Mix_LoadWAV(pick_path)) == NULL) {
/* Load sound effects */
sprintf(pick_path, "%s/pick.wav", RES_PATH);
if ((pick = Mix_LoadWAV(pick_path)) == NULL) {
@@
-170,6
+191,7
@@
int play() {
return 1;
}
return 1;
}
+// rmz_debug("play step 13");
/* store the font's color */
font_color.r = 255;
font_color.b = 255;
/* store the font's color */
font_color.r = 255;
font_color.b = 255;
@@
-189,6
+211,7
@@
int play() {
board_rect.w = 0;
board_rect.h = 0;
board_rect.w = 0;
board_rect.h = 0;
+// rmz_debug("play step 14");
/* set window properties and create it */
SDL_WM_SetCaption("Mancala", "Mancala");
if (sprintf(icon_path, "%s/icon.png", RES_PATH) == 0)
/* set window properties and create it */
SDL_WM_SetCaption("Mancala", "Mancala");
if (sprintf(icon_path, "%s/icon.png", RES_PATH) == 0)
@@
-201,15
+224,16
@@
int play() {
sdl_clean_up();
return 1;
}
sdl_clean_up();
return 1;
}
+ SDL_ShowCursor(SDL_DISABLE);
-
+// rmz_debug("play step 15");
/* define the font color fot the exit text */
font_color_exit.r = 255;
font_color_exit.r = 255;
font_color_exit.r = 255;
/* define the font color fot the exit text */
font_color_exit.r = 255;
font_color_exit.r = 255;
font_color_exit.r = 255;
-
+// rmz_debug("play step 16");
if (!(exit_text = TTF_RenderText_Blended(home_font, "EXIT",
font_color_exit))) {
fprintf(stderr, "SDL_ttf: %s\n", TTF_GetError());
if (!(exit_text = TTF_RenderText_Blended(home_font, "EXIT",
font_color_exit))) {
fprintf(stderr, "SDL_ttf: %s\n", TTF_GetError());
@@
-229,6
+253,7
@@
int play() {
highlight = 0;
active = 0;
highlight = 0;
active = 0;
+// rmz_debug("play step 17");
/* GAME LOOP */
while (state != GAME_WON) {
/* GAME LOOP */
while (state != GAME_WON) {
@@
-388,10
+413,13
@@
int play() {
redraw_board = 0;
}
redraw_board = 0;
}
+ hgw_msg_compat_receive(hgw_context, 0);
+
}
SDL_Delay(DELAY_AI);
}
SDL_Delay(DELAY_AI);
+
sdl_clean_up();
return 0;
sdl_clean_up();
return 0;
@@
-399,25
+427,29
@@
int play() {
int main(int argc, char **argv) {
int main(int argc, char **argv) {
-
- fprintf(stderr, "mancala main loop\n");
+
// #if HGW_FUNC
hgw_context = hgw_context_compat_init(argc, argv);
if (!hgw_context) {
fprintf(stderr, "Cannot init hildon-games-startup!\n");
return 0;
}
// #if HGW_FUNC
hgw_context = hgw_context_compat_init(argc, argv);
if (!hgw_context) {
fprintf(stderr, "Cannot init hildon-games-startup!\n");
return 0;
}
+
hgw_compat_set_cb_exit(hgw_context, exit_callback);
hgw_compat_set_cb_quit(hgw_context, quit_callback);
hgw_compat_set_cb_exit(hgw_context, exit_callback);
hgw_compat_set_cb_quit(hgw_context, quit_callback);
- hgw_compat_set_cb_flush(hgw_context, flush_callback);
+ hgw_compat_set_cb_flush(hgw_context, flush_callback);
if(!hgw_context_compat_check(hgw_context)) return 0;
if(!hgw_context_compat_check(hgw_context)) return 0;
-
+
/* hildon-games-wrapper part */
hgw_msg_compat_receive(hgw_context, 0);
usleep(100);
// #endif
/* hildon-games-wrapper part */
hgw_msg_compat_receive(hgw_context, 0);
usleep(100);
// #endif
+
// Main game
// Main game
- play();
+
+ if ( play() > 0 ){
+// rmz_debug("play > 1");
+ }
// #if HGW_FUNC
hgw_context_compat_destroy_deinit(hgw_context);
// #if HGW_FUNC
hgw_context_compat_destroy_deinit(hgw_context);