Ajout partie 2 (buggé)

This commit is contained in:
rick 2021-03-29 16:26:13 +02:00
parent 8a8af36570
commit e2c541d9fd
Signed by: Rick
GPG key ID: 2B593F087240EE99
4 changed files with 15 additions and 16 deletions

View file

@ -39,8 +39,9 @@ int main()
[rd release]; [rd release];
} }
*/ */
NSLog(@"le résultat est : %d", [troupeau courseUne:1000]); int time = 2503;
NSLog(@"le résultat est : %d", [troupeau courseDeux:1000]); NSLog(@"le résultat est : %d", [troupeau courseUne:time]);
NSLog(@"le résultat est : %d", [troupeau courseDeux:time]);
//finir le main par ça //finir le main par ça
[contentFile release]; [contentFile release];

View file

@ -38,17 +38,18 @@
- (int) updateDistance - (int) updateDistance
{ {
if (cooldown > 0) if (cooldown > 0)
{
cooldown--; cooldown--;
if (cooldown == 0) if (cooldown == 0)
hypervitesse = boostTime; hypervitesse = boostTime;
}
else else
{ {
distance += speed; distance = distance + speed;
hypervitesse--; hypervitesse--;
if (hypervitesse == 0) if (hypervitesse == 0)
cooldown = pause; cooldown = pause;
} }
return distance; return distance;
} }

View file

@ -4,7 +4,7 @@
@interface Troupeau : NSObject @interface Troupeau : NSObject
{ {
NSMutableArray *troupeau; NSMutableArray *troupeau;
NSSortDescriptor *recetteTri; NSArray *recetteTriDistance;
} }
- (id) init; - (id) init;

View file

@ -8,9 +8,10 @@
self = [super init]; self = [super init];
if (self) if (self)
{ {
recetteTri = [[NSSortDescriptor alloc] initWithKey:@"distance" NSSortDescriptor *recetteTri = [[NSSortDescriptor alloc] initWithKey:@"distance"
ascending:YES]; ascending:NO];
troupeau = [[NSMutableArray alloc] init]; recetteTriDistance = [NSArray arrayWithObject:recetteTri];
troupeau = [[NSMutableArray alloc] init];
} }
return self; return self;
} }
@ -41,16 +42,12 @@
{ {
int t = [rd updateDistance]; int t = [rd updateDistance];
} }
NSArray *tmp = [NSArray arrayWithObject:recetteTri]; [troupeau sortUsingDescriptors:recetteTriDistance];
NSArray *sortedRank = [troupeau sortedArrayUsingDescriptors:tmp]; [[troupeau firstObject] updatePoints];
[[sortedRank firstObject] updatePoints];
NSLog(@"%d", [[sortedRank firstObject] points]);
NSLog(@"Rennes : %@ pour une distance de %d", [[troupeau firstObject] name], [[troupeau firstObject] distance]);
// copier dans le troupeau le tableau trié
time--; time--;
} }
NSSortDescriptor *tt = [[NSSortDescriptor alloc] initWithKey:@"points" NSSortDescriptor *tt = [[NSSortDescriptor alloc] initWithKey:@"points"
ascending:YES]; ascending:NO];
NSArray *tmpp = [NSArray arrayWithObject:tt]; NSArray *tmpp = [NSArray arrayWithObject:tt];
NSArray *sortedPonits = [troupeau sortedArrayUsingDescriptors:tmpp]; NSArray *sortedPonits = [troupeau sortedArrayUsingDescriptors:tmpp];
NSLog(@"%d", [[sortedPonits firstObject] points]); NSLog(@"%d", [[sortedPonits firstObject] points]);
@ -64,7 +61,7 @@
for (Raindeer *rd in troupeau) for (Raindeer *rd in troupeau)
[rd dealloc]; [rd dealloc];
[troupeau release]; [troupeau release];
[recetteTri release]; //[recetteTri release];
[super dealloc]; [super dealloc];
} }