void test_map_pairs (void* data) { Map* map = Map_new(runtime); Map_put(map, hash_for(NIL), NIL, TRUE); Map_put(map, hash_for(TRUE), TRUE, FALSE); Map_put(map, hash_for(FALSE), FALSE, NIL); Vector* pairs = Map_pairs(map); for (uint64_t i = 0; i < Vector_length(pairs); i++) { Tuple* pair = Vector_get(pairs, i); if (is_nil(Tuple_get(pair, 0))) { tt_assert(is_true(Tuple_get(pair, 1))); } else if (is_true(Tuple_get(pair, 0))) { tt_assert(is_false(Tuple_get(pair, 1))); } else if (is_false(Tuple_get(pair, 0))) { tt_assert(is_nil(Tuple_get(pair, 1))); } } end: Map_destroy(map); }
void InGame_reinit(Context* context) { //Play the musique MusicManager_playBackground(globalVar_musics); //Init the player (gravity, button events) InGame* self = (InGame*)context; Player_setSpeedY(self->player, 0); Player_setScancode(self->player, globalVar_jumpscancode, globalVar_leftscancode, globalVar_rightscancode); //The time self->initTime = self->currentTime = SDL_GetTicks(); //Destroy a map if we have one if(self->map) { Map_destroy(self->map); self->map = NULL; } //All events of the InGame context are reinit. self->hasDied = false; self->hasActivedGameOver = false; self->hasWon = false; self->hasActivedWin = false; //The score self->score = 0; InGame_addScore(self, 0); MusicManager_playBackground(globalVar_musics); self->nbLifes = DEFAULT_LIFE; InGame_setLifeLabel(self); }
void test_map_new (void* data) { Map* map = Map_new(runtime); tt_assert(map); end: Map_destroy(map); }
void InGame_loadMap(InGame* self, const char* path) { //Check if we have a map if(self->map) Map_destroy(self->map); //Then create it self->map = Map_create(path); if(self->map == NULL) { perror("Error while loading the map \n"); return; } //Reinit the time self->initTime = self->currentTime = SDL_GetTicks(); }
void test_map_put (void* data) { Map* map = Map_new(runtime); Tuple* pair = Map_put(map, hash_for(TRUE), TRUE, FALSE); tt_assert(is_true(Tuple_get(pair, 0))); tt_assert(is_false(Tuple_get(pair, 1))); pair = Map_put(map, hash_for(TRUE), TRUE, NIL); tt_assert(is_true(Tuple_get(pair, 0))); tt_assert(is_nil(Tuple_get(pair, 1))); end: Map_destroy(map); }
void InGame_destroy(InGame* self) { //Destroy everything if(self->map != NULL) Map_destroy(self->map); if(self->player != NULL) Player_destroy((Drawable*)(self->player)); if(self->scoreLabel != NULL) Text_destroy((Drawable*)(self->scoreLabel)); if(self->timeLabel != NULL) Text_destroy((Drawable*)(self->timeLabel)); if(self->gameOver != NULL) Text_destroy((Drawable*)(self->gameOver)); if(self->winLabel != NULL) Text_destroy((Drawable*)(self->winLabel)); if(self->lifeText) Text_destroy((Drawable*)(self->lifeText)); free(self); }
void test_map_values (void* data) { Map* map = Map_new(runtime); Map_put(map, hash_for(NIL), NIL, TRUE); Map_put(map, hash_for(TRUE), TRUE, FALSE); Map_put(map, hash_for(FALSE), FALSE, NIL); Vector* values = Map_values(map); for (uint64_t i = 0; i < Vector_length(values); i++) { Value* value = Vector_get(values, i); tt_assert(is_nil(value) || is_true(value) || is_false(value)); } end: Map_destroy(map); }
void InGame_updateEvent(Context* context, SDL_Event* event) { InGame* self = (InGame*)context; //If we have die and the game over statement is activate if(self->hasDied && event->type == SDL_KEYDOWN) { self->hasActivedGameOver = true; if(self->nbLifes > 0) { if(self->map) //Destroy the map. It will be recreated in run function { Map_destroy(self->map); self->map = NULL; } } return; } //If we won and the win statement is activated else if(self->hasWon && event->type == SDL_KEYDOWN) { self->hasActivedWin = true; return; } else { //Update the player Active* player = (Active*)self->player; if(Active_updateEvents(player, event)) { if(self->player->justHasJump) MusicManager_playSound(globalVar_musics, JUMP); //Play the sound "JUMP" if we have jump return; } } }