-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPictionaryModel.m
More file actions
executable file
·67 lines (54 loc) · 1.59 KB
/
Copy pathPictionaryModel.m
File metadata and controls
executable file
·67 lines (54 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// PictionaryModel.m
// CocoaPictionary
//
// Created by Jason on 10/17/09.
// Copyright 2009 TokBox Inc.. All rights reserved.
//
#import "PictionaryModel.h"
@implementation PictionaryModel
-(id)init
{
self = [super init];
categories = [[NSArray arrayWithObjects: @"AP - All Play", @"D - Difficult", @"A - Action", @"P - Person/Place/Animal", @"O - Object", @"? - Pick",nil] retain];
players = [[NSArray arrayWithObjects: @"Jason", @"Alex", @"Matt",@"Alli",@"Ganz",@"Harry"] retain];
// NSArray *objects = [NSArray arrayWithObjects:[NSNumber numberWithInt:0],[NSNumber numberWithInt:0],[NSNumber numberWithInt:0], nil];
// scores= [[NSMutableDictionary dictionaryWithObjects:objects forKeys:players] retain];
scores = calloc(sizeof(int), [players count]);
current_player_idx = arc4random() % [players count];
current_category_idx = arc4random() % [categories count];
return self;
}
-(NSString *)get_current_player
{
return [players objectAtIndex:current_player_idx];
}
-(NSString *)get_current_category
{
return [categories objectAtIndex:current_category_idx];
}
-(BOOL)next_round:(NSString *)winner
{
if(winner != nil) {
if([players indexOfObject:winner] == current_player_idx) {
NSLog(@"Player can't win!");
return false;
}
scores[[players indexOfObject:winner]] += 2;
scores[current_player_idx] += 1;
} else {
scores[current_player_idx]--;
}
current_player_idx = (current_player_idx + 1) % [players count];
current_category_idx = arc4random() % [categories count];
return true;
}
-(int*)get_scores
{
return scores;
}
-(NSArray*)get_players
{
return players;
}
@end