-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNNRestaurant.m
90 lines (79 loc) · 1.57 KB
/
NNRestaurant.m
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// NNRestaurant.m
// lunchd
//
// Created by MacRae Linton on 3/9/10.
// Copyright 2010 Apple Inc.. All rights reserved.
//
#import "NNRestaurant.h"
@implementation NNRestaurant
@synthesize name;
@synthesize votes;
@synthesize vetos;
@synthesize state;
- (id)initWithName:(NSString *)theName
{
self = [super init];
if (self){
[self setName:theName];
[self setVotes:0];
[self setVetos:0];
[self setState:NNUndefinedState];
}
return self;
}
-(void)dealloc
{
[name release];
[super dealloc];
}
- (void)giveVote
{
NSLog(@"GIVE VOTE: %@",name);
[self setVotes:votes +1];
if (vetos == 0 && votes == 1){
[self setState:NNVotedForState];
}
}
- (void)takeVote
{
NSLog(@"TAKE VOTE: %@",name);
[self setVotes:votes -1];
if (vetos == 0 && votes == 0){
[self setState:NNUndefinedState];
}
if (vetos == -1){
NSLog(@"WOAH NEGATIVE VOOTES--------------------------------------------------");
}
}
- (void)giveVeto
{
NSLog(@"GIVE VETO: %@",name);
[self setVetos:vetos + 1];
if (vetos == 1){
[self setState:NNVetoedState];
}
}
- (void)takeVeto
{
NSLog(@"TAKE VETO: %@",name);
[self setVetos:vetos - 1];
if (vetos == 0){
if (votes == 0){
[self setState:NNUndefinedState];
}else {
[self setState:NNVotedForState];
}
}
if (vetos == -1){
NSLog(@"WOAH NEGATIVE VETOS--------------------------------------------------");
}
}
- (id)copyWithZone:(NSZone *)zone
{
NNRestaurant *copiedRest = [[[self class] allocWithZone:zone] initWithName:[[self name] copy]];
[copiedRest setVotes:[self votes]];
[copiedRest setVetos:[self vetos]];
return copiedRest;
}
@end