Closed kocierik closed 3 years ago
Fate attenzione a non creare variabili all'interno di cicli! Altrimenti pensate a quello che potrebbe succedere ahahahh Cercate di generalizzare il codice il più possibile utilizzando le funzioni funzioni con i parametri! Questa cosa è molto importante perché incide sulla valutazione questo errore!
Esempio:
void EngineGame::shootPlayerBullet() { Pbullet bulletList = this->playerBullets; while (bulletList != NULL) { if (bulletList->moveFoward) bulletList->x += bulletList->speed; else bulletList->x -= bulletList->speed; move(bulletList->y, bulletList->x); init_pair(10, COLOR_YELLOW, -1); // SPARA BANANE GIALLE attron(COLOR_PAIR(10)); char tmp[2]; tmp[0] = bulletList->skin; printw(tmp); attroff(COLOR_PAIR(10)); bulletList = bulletList->next; } } void EngineGame::shootEnemyBullet() { Pbullet bulletList = this->normalEnemyBullets; while (bulletList != NULL) { if (bulletList->moveFoward) bulletList->x -= bulletList->speed; else bulletList->x += bulletList->speed; move(bulletList->y, bulletList->x); char tmpSkin[2]; tmpSkin[0] = bulletList->skin; printw(tmpSkin); bulletList = bulletList->next; } }
Questi due codici sono uguali! Quindi basterebbe una funzione. Al massimo si aggiunge un flag per eventuali modifiche
Attenzione che non sempre conviene fare questa generalizzazione! ad esempio quando si hanno due effetti diversi
Fate attenzione a non creare variabili all'interno di cicli! Altrimenti pensate a quello che potrebbe succedere ahahahh Cercate di generalizzare il codice il più possibile utilizzando le funzioni funzioni con i parametri! Questa cosa è molto importante perché incide sulla valutazione questo errore! (quello delle variabili)
Scordatevi quello che c'era nel caso lo aveste visto perché sarebbe un bel casino poi.