int main(int argc, char const* argv[]) { node *tree = prepare_tree(); printf("max path sum = %d\n",max_path_sum(tree)); printf("expected value = 20\n"); return 0; }
/* **level\_data** is created and populated with * level specific entities. Some entities require further * initialization, such as the timeline. * A timeline allows creating a sequence of events * on a, well.. time line. Each event has a start time, * duration and callback function the will get called * each time the timeline is updated and if the event * is active. * We use a timeline to animate the title, creating 3 * events: (1) slide the title into the screen (2) * make the title "bling" and (3) slide the title out * of the screen. * Using the SECOND and SECONDS constant is for * the sake of readability only. */ static struct level_data* create_level_data(void) { struct level_data* ldata = calloc(1, sizeof(*ldata)); if (ldata == NULL) goto error; ldata->wizard = create_wizard(); if (ldata->wizard == NULL) goto cleanup_level_data; if (prepare_title(&ldata->title) != 0) goto cleanup_level_data; if (prepare_tree(&ldata->tree) != 0) goto cleanup_level_data; ldata->grass_tile = create_image("res/grass_tile.png"); if (ldata->grass_tile == NULL) goto cleanup_level_data; ldata->earth_tile = create_image("res/earth_tile.png"); if (ldata->earth_tile == NULL) goto cleanup_level_data; play_animation(ldata->tree.sprite, ldata->tree.windblow); ldata->timeline = create_timeline(); if (ldata->timeline == NULL) goto cleanup_level_data; append_event(ldata->timeline, 0, 1 * SECOND, before_title_in); append_event(ldata->timeline, 0, 1 * SECOND, slide_title_in); append_event(ldata->timeline, 0, 4 * SECONDS, bling_title); append_event(ldata->timeline, 0, 1 * SECOND, slide_title_out); ldata->font = create_font("res/font.png", 32, 4); if (ldata->font == NULL) goto cleanup_level_data; ldata->music = create_sound("res/wizard.ogg"); play_sound(ldata->music, -1); return ldata; cleanup_level_data: destroy_level_data(ldata); error: ERROR("Unable to create level data"); return NULL; }