#include "plant.h"

@implementation Plant

- (id) initWithPosition:(int)p andGrowthRate:(int)gr andLifecycle:(NSString *)s
{
  self = [super initWithPosition:p];
  if (self)
    {
      growthRate = gr;
      age = 0;
      lifecycle = [s retain];
    }
  return self;
}

- (void) update
{
  age++;
}

- (NSString *) displayChar
{
  if ([self alive])
    {
      int stage = age / growthRate;
      if (stage >= [lifecycle length])
	{
	  stage = [lifecycle length] - 1;
	}
      return [lifecycle substringWithRange:NSMakeRange(stage, 1)];
    }
  else
    {
      return [NSString stringWithCString:"_"];
    }
}

- (BOOL) alive
{
  return true;
}

- (void) dealloc
{
  [lifecycle release];

  [super dealloc];
}

@end
