ftp.nice.ch/pub/next/games/action/ROBOTS.s.tar.gz#/ROBOTS/aSquare.m

This is aSquare.m in view mode; [Download] [Up]

#import "aSquare.h"
#import "robotView.h"

@implementation aSquare

- init
{
    [super init];
    myRobotID = NOROBOT;
    return self;
}

- setDelegate:sender
{
    myDelegate = sender;
    return self;
}

- (BOOL)takeScrap
{
    if (![self hasScrap] && ([self hasRobotID] == NOROBOT))
    {
	myRobotID = SCRAP;
	return YES;
    }
    return NO;
}

- (BOOL)moveScrap:targetSquare
{
    if ([self hasScrap] && [targetSquare takeScrap])
    {
	myRobotID = NOROBOT;
	return YES;
    }
    return NO;
}

- removeRobot:(aRobot *) theRobot
{
    if ([self hasRobotID] != theRobot->idnumber)
    {				/* printf ("Wrong robot removed!!!\n"); */
	;
    }
    myRobotID = NOROBOT;

    return self;
}

- addRobot:(aRobot *) theRobot
{
    if ([self hasScrap])
    {
	[myDelegate deleteRobotID:theRobot->idnumber];
	return self;
    }
    if ([self hasRobotID] != NOROBOT)
    {
    /* Scrap one, it's drawn scrapped, scrap the rest, they're not redrawn. */
	[myDelegate scrapRobotID:theRobot->idnumber];
	[myDelegate scrapRobotID:myRobotID];
	[myDelegate newScrap];
	myRobotID = SCRAP;
	return self;
    }
    theRobot->occupiedSquare = self;
    myRobotID = theRobot->idnumber;
    return self;
}

- (int)hasRobotID
{
    if ([self hasScrap])
    {
	return NOROBOT;
    }
    return myRobotID;
}

- (BOOL)hasScrap
{
    return (myRobotID == SCRAP);
}

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.