
#import "HiScore.h"
#import "robotsController.h"
#import "robotView.h"
#import <appkit/Window.h>

@implementation robotsController

- appDidInit:sender
{
    [robotHiScore init];
    [robotHiScore setMaxScores:20];
    [robotHiScore load:self];
    //[myrobotView display];
    return self;
}

- appWillTerminate:sender
{
    [robotHiScore save:self];
    return self;
}

- newGame:sender
{
    [myrobotView init];
    return self;
}

- getInfo:sender
{
    if (!infoPanel)
	[NXApp loadNibSection:"Info.nib" owner:self withNames:NO];
    [infoPanel makeKeyAndOrderFront:sender];
    return self;
}

- loadPrefs:sender
{
    return self;
}

- showScores:sender
{
    [[scoreBrowser window] makeKeyAndOrderFront:self];
    [scoreBrowser loadColumnZero];
    return self;
}

- playerDead:sender
{
    NXRunAlertPanel ("Yer Dead", "Toast on level %d with %d points.",
		     "Bummer", NULL, NULL,[levelField intValue],
		     [scoreField intValue]);

    if ([robotHiScore newScoreForPlayer:nil
	 Of:[scoreField intValue] At:[levelField intValue]])
    {
	[self showScores:self];
    }
    return self;
}

- showTeleports:(int)intValue
{
    [teleportField setIntValue:intValue];
    return self;
}

- showLevel:(int)intValue
{
    [levelField setIntValue:intValue];
    return self;
}

- showScore:(int)intValue
{
    [scoreField setIntValue:intValue];
    return self;
}

- showHeaps:(int)intValue
{
    [heapsField setIntValue:intValue];
    return self;
}

- showRobots:(int)intValue
{
    [robotsField setIntValue:intValue];
    return self;
}

- showValue:(int)intValue
{
    [valueField setIntValue:intValue];
    return self;
}

- windowWillResize:sender toSize:(NXSize *)frameSize
{
    NXRect              theRect;

    if ([myrobotView playerState] != UNSTARTED)
    {
	[sender getFrame:&theRect];
	*frameSize = theRect.size;
    }
    return self;
}

@end
