-
Notifications
You must be signed in to change notification settings - Fork 9
/
ScoreEntity.m
69 lines (62 loc) · 1.61 KB
/
ScoreEntity.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
//
// ScoreEntity.m
// Connect5
//
// Created by Mohammed Eldehairy on 10/20/13.
// Copyright (c) 2013 Mohammed Eldehairy. All rights reserved.
//
#import "ScoreEntity.h"
@implementation ScoreEntity
-(id)init
{
self = [super init];
if(self)
{
self.score = 0;
self.numberOfConsecutiveRowCollection = 0;
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if(self)
{
self.score = ((NSNumber*)[aDecoder decodeObjectForKey:@"scoreInt"]).intValue;
self.numberOfConsecutiveRowCollection = ((NSNumber*)[aDecoder decodeObjectForKey:@"numberOfConsecutiveRowCollection"]).intValue;
}
return self;
}
-(void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:[NSNumber numberWithInt:self.score] forKey:@"scoreInt"];
[aCoder encodeObject:[NSNumber numberWithInt:self.numberOfConsecutiveRowCollection] forKey:@"numberOfConsecutiveRowCollection"];
}
-(void)ReportScoreWithNumberOfDetectedCells:(int)numberOfDetectedCells
{
_score += 2 * numberOfDetectedCells;
if(numberOfDetectedCells == 0)
{
_numberOfConsecutiveRowCollection = 0;
}else
{
_score += 3 * _numberOfConsecutiveRowCollection ;
_numberOfConsecutiveRowCollection++;
}
}
-(void)ResetScore
{
_numberOfConsecutiveRowCollection = 0;
_score = 0;
}
-(id)copyWithZone:(NSZone *)zone
{
ScoreEntity *copy = [[ScoreEntity alloc] init];
if(copy)
{
[copy setScore:self.score];
[copy setNumberOfConsecutiveRowCollection:self.numberOfConsecutiveRowCollection];
}
return copy;
}
@end