/* ChoiceQuizController.m - multiple choice quiz controller for Popup.app Copyright (C) 2003, 2004 Bjorn Gohla, Rob Burns This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. */ #include "ChoiceQuizController.h" #include "NSValue+Extensions.h" @implementation ChoiceQuizController -(void)dealloc { [super dealloc]; } - (void) awakeFromNib { [super awakeFromNib]; [buttonOne setFont: [NSFont systemFontOfSize: 16]]; [buttonTwo setFont: [NSFont systemFontOfSize: 16]]; [buttonThree setFont: [NSFont systemFontOfSize: 16]]; [buttonFour setFont: [NSFont systemFontOfSize: 16]]; } - (NSString *) nibName { return @"ChoiceQuiz"; } - (NSString *) quizName { return _(@"Multiple Choice"); } -(void) displayCurrentCard: (id)sender { NSArray *alternatives = [NSArray arrayWithArray: [cardStack drawAlternatives: 3 excluding: [currentCard back]]]; int correctButton; int i,j; [cardDisplay setBackgroundColor: [NSColor whiteColor]]; [cardDisplay setTextColor: [NSColor blackColor]]; [cardDisplay setStringValue: [currentCard front]]; [buttonOne setTitle: @""]; [buttonOne setAction: @selector(wrongAnswer:)]; [buttonTwo setTitle: @""]; [buttonTwo setAction: @selector(wrongAnswer:)]; [buttonThree setTitle: @""]; [buttonThree setAction: @selector(wrongAnswer:)]; [buttonFour setTitle: @""]; [buttonFour setAction: @selector(wrongAnswer:)]; correctButton = [NSValue nextIntWithMax: 4]; switch(correctButton) { case 1: { [buttonOne setTitle: [currentCard back]]; [buttonOne setAction: @selector(correctAnswer:)]; break; } case 2: { [buttonTwo setTitle: [currentCard back]]; [buttonTwo setAction: @selector(correctAnswer:)]; break; } case 3: { [buttonThree setTitle: [currentCard back]]; [buttonThree setAction: @selector(correctAnswer:)]; break; } case 4: { [buttonFour setTitle: [currentCard back]]; [buttonFour setAction: @selector(correctAnswer:)]; break; } } i = 0; if([[buttonOne title] isEqualToString: @""]) { [buttonOne setTitle: [alternatives objectAtIndex: i]]; i = i+1; for(j=0;j<[[currentCard answers] count];j++) { if([[buttonOne title] isEqualToString: [[currentCard answers] objectAtIndex: j]]) { [buttonOne setAction: @selector(correctAnswer:)]; break; } else { [buttonOne setAction: @selector(wrongAnswer:)]; } } } if([[buttonTwo title] isEqualToString: @""]) { [buttonTwo setTitle: [alternatives objectAtIndex: i]]; i = i+1; for(j=0;j<[[currentCard answers] count];j++) { if([[buttonTwo title] isEqualToString: [[currentCard answers] objectAtIndex: j]]) { [buttonTwo setAction: @selector(correctAnswer:)]; break; } else { [buttonTwo setAction: @selector(wrongAnswer:)]; } } } if([[buttonThree title] isEqualToString: @""]) { [buttonThree setTitle: [alternatives objectAtIndex: i]]; i = i+1; for(j=0;j<[[currentCard answers] count];j++) { if([[buttonThree title] isEqualToString: [[currentCard answers] objectAtIndex: j]]) { [buttonThree setAction: @selector(correctAnswer:)]; break; } else { [buttonThree setAction: @selector(wrongAnswer:)]; } } } if([[buttonFour title] isEqualToString: @""]) { [buttonFour setTitle: [alternatives objectAtIndex: i]]; for(j=0;j<[[currentCard answers] count];j++) { if([[buttonFour title] isEqualToString: [[currentCard answers] objectAtIndex: j]]) { [buttonFour setAction: @selector(correctAnswer:)]; break; } else { [buttonFour setAction: @selector(wrongAnswer:)]; } } } } @end