-
Notifications
You must be signed in to change notification settings - Fork 2
/
Match.m
103 lines (82 loc) · 2.21 KB
/
Match.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
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// Match.m
// tabomb
//
// Created by Nebil Kriedi on 21/07/12.
// Copyright (c) 2012 5Knot. All rights reserved.
//
#import "Match.h"
@interface Match ()
- (NSArray *)createWires;
@end
@implementation Match
@synthesize identifier = _identifier;
@synthesize createdAt = _createdAt;
@synthesize wires = _wires;
@synthesize killerWire = _killerWire;
- (id)init
{
self = [super init];
if (self) {
self.wires = [self createWires];
}
return self;
}
- (NSMutableArray *)createWires {
NSMutableArray *wires = [NSMutableArray arrayWithCapacity:kNumberOfWires];
BombWire *wire;
wire = [[BombWire alloc] init];
wire.color = [UIColor redColor];
wire.colorName = @"red";
[wires addObject:wire];
wire = [[BombWire alloc] init];
wire.color = [UIColor greenColor];
wire.colorName = @"green";
[wires addObject:wire];
wire = [[BombWire alloc] init];
wire.color = [UIColor blueColor];
wire.colorName = @"blue";
[wires addObject:wire];
wire = [[BombWire alloc] init];
wire.color = [UIColor yellowColor];
wire.colorName = @"yellow";
[wires addObject:wire];
wire = [[BombWire alloc] init];
wire.color = [UIColor orangeColor];
wire.colorName = @"orange";
[wires addObject:wire];
wire = [[BombWire alloc] init];
wire.color = [UIColor purpleColor];
wire.colorName = @"purple";
[wires addObject:wire];
return wires;
}
- (void)shuffleWires {
srandom(time(NULL));
for (NSUInteger i = [_wires count] - 1; i > 0; i--) {
[_wires exchangeObjectAtIndex:i withObjectAtIndex:random() % (i + 1)];
}
for (BombWire *wire in self.wires) {
wire.cut = NO;
}
//BombWire *wire = [self.wires objectAtIndex:random() % self.wires.count];
//self.killerWire = wire;
for (BombWire *wire in self.wires) {
if (wire.colorName == @"red")
self.killerWire = wire;
}
}
- (BOOL)hasMoreWiresToCut {
int cuttedWires = 0;
for (BombWire *wire in self.wires) {
if (wire.cut == YES) {
cuttedWires++;
}
}
if (cuttedWires == (self.wires.count - 1)) {
return NO;
} else {
return YES;
}
}
@end