This is Guesser.m in view mode; [Download] [Up]
/* Simple Sound Demo Program */
#include <time.h>
#include <stdlib.h>
#import "Guesser.h"
@implementation Guesser
+ new;
{
self = [super new];
/* init random number */
srand(time(0));
real_num = rand()&100;
/* init sounds */
too_low = [Sound new];
too_high = [Sound new];
just_right = [Sound new];
instructions = [Sound new];
/* load sounds from files */
[too_low readSoundfile:"too_low.snd"];
[too_high readSoundfile:"too_high.snd"];
[just_right readSoundfile:"just_right.snd"];
[instructions readSoundfile:"instructions.snd"];
[instructions play:self];
return self;
}
- setInput_textfield:anObject
{
input_textfield = anObject;
return self;
}
- newGame:sender
{
real_num = rand()&100;
[input_textfield selectText:self];
[instructions play:self];
return self;
}
- guess:sender
{
int the_guess;
the_guess = [input_textfield intValue];
if (the_guess < real_num)
{
[too_low play:self];
[input_textfield selectText:self];
}
else if (the_guess > real_num)
{
[too_high play:self];
[input_textfield selectText:self];
}
else /* the player guessed correctly */
{
[just_right play:self];
[input_textfield selectText:self];
}
return self;
}
@end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.