aoc-2015/jour14/raindeer.m

67 lines
1.3 KiB
Mathematica
Raw Normal View History

2021-03-25 18:35:10 +01:00
#import "raindeer.h"
#import <Foundation/Foundation.h>
@implementation Raindeer
// permet de créer les getters et setters à partir de property
2021-03-26 16:53:45 +01:00
@synthesize name, speed, boostTime, pause, points, cooldown, hypervitesse, distance;
2021-03-25 18:35:10 +01:00
+ (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)boostTime LunchTime:(int)pause
{
Raindeer *new;
if ((new = [[Raindeer alloc] init]))
{
new.name = name;
new.speed = speed;
new.boostTime = boostTime;
new.pause = pause;
2021-03-30 01:49:26 +02:00
new.points = 1; //pas sur que ce soit la bonne méthode mais chut
2021-03-26 16:53:45 +01:00
new.cooldown = 0;
new.hypervitesse = boostTime;
new.distance = 0;
2021-03-25 18:35:10 +01:00
}
return new;
}
- (int) calculDistance:(int) time
{
int ret = 0;
while (time > 0)
{
int rest = boostTime - time;
ret += (rest > 0) ? speed * rest : speed * boostTime;
time -= boostTime + pause;
}
return ret;
}
2021-03-30 01:49:26 +02:00
- (void) updateDistance
2021-03-26 16:53:45 +01:00
{
if (cooldown > 0)
2021-03-29 16:26:13 +02:00
{
2021-03-26 16:53:45 +01:00
cooldown--;
if (cooldown == 0)
hypervitesse = boostTime;
2021-03-29 16:26:13 +02:00
}
2021-03-26 16:53:45 +01:00
else
{
2021-03-29 16:26:13 +02:00
distance = distance + speed;
2021-03-26 16:53:45 +01:00
hypervitesse--;
if (hypervitesse == 0)
cooldown = pause;
}
}
- (void) updatePoints
{
points++;
}
2021-03-25 18:35:10 +01:00
- (void) dealloc
{
[name release];
[super dealloc];
}
@end