-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implementation Risiko #300
base: main
Are you sure you want to change the base?
Conversation
|
||
|
||
int attacker_Dices[3]; | ||
int defender_Dices[3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Evita di usare variabili globali perchè sono "rischiose" e ci si può accedere da qualsiasi punto del codice. Piuttosto potresti creare questi array nel main e passarli alla funzione compare
, tipo:
// Definisco la costante della dimensione degli array
#define DIM 3
void compare (int* attacker_Dices, int* defender_Dices){
//...
}
//...
int main(){
int* attacker_Dices = new int[DIM];
int* defender_Dices = new int[DIM];
//...
compare(attacker_Dices, defender_Dices);
}
E ovviamente si dovrebbe adattare il codice con la costante definita DIM che incrementa la leggibilità del codice.
|
||
|
||
cout<<"Blue Dices:\n"; | ||
for(int i=0; i<3; i++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potresti eliminare questo for e utilizzare il precedente per fare le operazioni sul secondo array visto che esse sono indipendenti fra loro, quindi evitare una serie di cicli.
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consiglio di mettere l'istruzione di return
del main
e di rimuovere eventuali spazi bianchi (o ritorni a capo) che allungano il codice, quindi migliorare l'indentazione per migliorare la leggibilità del codice.
|
||
cout<<"Red Dices:\n"; | ||
for(int i=0; i<3; i++){ | ||
attacker_Dices[i]= rand() % 5+1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potresti mettere attacker_Dices[i] = rand() % 6;
piuttosto che lasciare esplicitamente 5+1
No description provided.