/** * Get the random value argument from a value expression and put it into the * appropriate place in an array * \param value the target array of values * \param value_type the possible value strings * \param name_and_value the value expression being matched * \return 0 if successful, otherwise an error value */ errr grab_rand_value(random_value *value, const char **value_type, const char *name_and_value) { int i = 0; char value_name[80]; char dice_string[40]; dice_t *dice; /* Get a rewritable string */ my_strcpy(value_name, name_and_value, strlen(name_and_value)); /* Parse the value expression */ if (!find_value_arg(value_name, dice_string, NULL)) return PARSE_ERROR_INVALID_VALUE; dice = dice_new(); while (value_type[i] && !streq(value_type[i], value_name)) i++; if (value_type[i]) { if (!dice_parse_string(dice, dice_string)) { dice_free(dice); return PARSE_ERROR_NOT_RANDOM; } dice_random_value(dice, &value[i]); } dice_free(dice); return value_type[i] ? PARSE_ERROR_NONE : PARSE_ERROR_INTERNAL; }
int main (int argc, char *argv[]) { SDL_Surface *screen; printf ("Initializing SDL.\n"); /* Initializes Audio and the CDROM, add SDL_INIT_VIDEO for Video */ if (SDL_Init(SDL_INIT_VIDEO)< 0) { printf("Could not initialize SDL:%s\n", SDL_GetError()); SDL_Quit(); return 1; } if(TTF_Init() != 0) { printf("Could not initialize TTF:%s\n", SDL_GetError()); return 1; } printf("Video initialized correctly\n"); atexit( SDL_Quit ); printf("SCREENW : %d, SCREENH : %d\n", SCREENW, SCREENW); screen = SDL_SetVideoMode( SCREENW, SCREENH, 16, SDL_HWSURFACE ); SDL_WM_SetCaption( "421", 0 ); if( screen == NULL ) { printf( "Can't set video mode: %s\n", SDL_GetError( ) ); return EXIT_FAILURE; } // Part of the bitmap that we want to draw SDL_Rect bgsource; bgsource.x = 0; bgsource.y = 0; bgsource.w = 1000; bgsource.h = 903; // Part of the screen we want to draw the sprite to SDL_Rect bgdestination; bgdestination.x = 0; bgdestination.y = 0; bgdestination.w = 1000; bgdestination.h = 903; SDL_Surface *background; background = (SDL_Surface*) IMG_Load("pixs/background.png"); background = SDL_DisplayFormat(background); SDL_BlitSurface(background, &bgsource, screen, &bgdestination); SDL_Flip(screen); // Part of the bitmap that we want to draw SDL_Rect d1source; d1source.x = 0; d1source.y = 0; d1source.w = 189; d1source.h = 199; // Part of the screen we want to draw the sprite to SDL_Rect d1destination; d1destination.x = 0; d1destination.y = 0; d1destination.w = 189; d1destination.h = 199; SDL_Surface *dice; dice = (SDL_Surface*) IMG_Load("pixs/dices.png"); dice = SDL_DisplayFormat(dice); Uint32 colorkey = SDL_MapRGB(dice->format, 0, 255, 0); SDL_SetColorKey(dice, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey ); bool quit = false; SDL_Event event; struct dice *d1, *d2, *d3; d1 = NULL; d2 = NULL; d3 = NULL; hands *ah; ah = hands_new(); ah = hands_init(ah); hands_print(ah); while(quit == false) { while( SDL_PollEvent( &event ) ) { int x = 0; int y = 0; if(event.type == SDL_MOUSEBUTTONDOWN) { x = event.motion.x; y = event.motion.y; printf("Down (%d, %d)!!!! \n", x, y); //board_click(bd, x/24, y/24); d1 = dice_new(490, 240); d2 = dice_new(340, 340); d3 = dice_new(650, 440); if(!d1->rolling) d1 = dice_roll(d1); if(!d2->rolling) d2 = dice_roll(d2); if(!d3->rolling) d3 = dice_roll(d3); } // User press key if( event.type == SDL_KEYDOWN ) { Uint8 *keystates = SDL_GetKeyState( NULL ); // User press ESCAPE if( keystates[ SDLK_ESCAPE ] ) { quit = true; } } // User press X if( event.type == SDL_QUIT ) { quit = true; } } if(d1 && d2 && d3) if(d1->rolling || d2->rolling || d3->rolling) { SDL_BlitSurface(background, &bgsource, screen, &bgdestination); d1 = dice_check_dices_collisions(d1, d2, d3); d2 = dice_check_dices_collisions(d2, d3, d1); d3 = dice_check_dices_collisions(d3, d1, d2); } if(d1) { if(d1->rolling) d1 = dice_update(d1); d1source.x = d1->imgoffset; d1destination.x = d1->position->x; d1destination.y = d1->position->y; SDL_BlitSurface(dice, &d1source, screen, &d1destination); } if(d2) { if(d2->rolling) d2 = dice_update(d2); d1source.x = d2->imgoffset; d1destination.x = d2->position->x; d1destination.y = d2->position->y; SDL_BlitSurface(dice, &d1source, screen, &d1destination); } if(d3) { if(d3->rolling) d3 = dice_update(d3); d1source.x = d3->imgoffset; d1destination.x = d3->position->x; d1destination.y = d3->position->y; SDL_BlitSurface(dice, &d1source, screen, &d1destination); } SDL_Flip(screen); } return 0; }