2021-03-26 16:53:45 +01:00
|
|
|
#import "troupeau.h"
|
|
|
|
#import "raindeer.h"
|
|
|
|
|
|
|
|
@implementation Troupeau
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
2021-03-29 16:26:13 +02:00
|
|
|
NSSortDescriptor *recetteTri = [[NSSortDescriptor alloc] initWithKey:@"distance"
|
|
|
|
ascending:NO];
|
|
|
|
recetteTriDistance = [NSArray arrayWithObject:recetteTri];
|
|
|
|
troupeau = [[NSMutableArray alloc] init];
|
2021-03-26 16:53:45 +01:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) newDeer:(Raindeer*)rd
|
|
|
|
{
|
|
|
|
[troupeau addObject:rd];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) courseUne:(int)time
|
|
|
|
{
|
|
|
|
int ret = 0, tmp = 0;
|
|
|
|
for (Raindeer *rd in troupeau)
|
|
|
|
{
|
|
|
|
tmp = [rd calculDistance:time];
|
|
|
|
if (tmp > ret)
|
|
|
|
ret = tmp;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) courseDeux:(int)time
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
while (time > 0)
|
|
|
|
{
|
|
|
|
for (Raindeer *rd in troupeau)
|
|
|
|
{
|
|
|
|
int t = [rd updateDistance];
|
|
|
|
}
|
2021-03-29 16:26:13 +02:00
|
|
|
[troupeau sortUsingDescriptors:recetteTriDistance];
|
|
|
|
[[troupeau firstObject] updatePoints];
|
2021-03-26 16:53:45 +01:00
|
|
|
time--;
|
|
|
|
}
|
|
|
|
NSSortDescriptor *tt = [[NSSortDescriptor alloc] initWithKey:@"points"
|
2021-03-29 16:26:13 +02:00
|
|
|
ascending:NO];
|
2021-03-26 16:53:45 +01:00
|
|
|
NSArray *tmpp = [NSArray arrayWithObject:tt];
|
|
|
|
NSArray *sortedPonits = [troupeau sortedArrayUsingDescriptors:tmpp];
|
|
|
|
NSLog(@"%d", [[sortedPonits firstObject] points]);
|
|
|
|
ret = [[sortedPonits firstObject] points];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
for (Raindeer *rd in troupeau)
|
|
|
|
[rd dealloc];
|
|
|
|
[troupeau release];
|
2021-03-29 16:26:13 +02:00
|
|
|
//[recetteTri release];
|
2021-03-26 16:53:45 +01:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|