-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLargeBoardView.m
174 lines (150 loc) · 5.47 KB
/
LargeBoardView.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//
// LargeBoardView.m
// Squares
//
// Created by Billy Irwin on 12/19/12.
// Copyright (c) 2012 BirwinApps. All rights reserved.
//
#import "LargeBoardView.h"
@implementation LargeBoardView
@synthesize topMid, topRight, topLeft, midRight, midMid, midLeft, botRight, botMid, botLeft;
@synthesize smallBoards;
@synthesize enlargedView;
@synthesize nextSquare;
#define largeTL CGRectMake(5, 5, 100, 100)
#define largeTM CGRectMake(110, 5, 100, 100)
#define largeTR CGRectMake(215, 5, 100, 100)
#define largeML CGRectMake(5, 110, 100, 100)
#define largeMM CGRectMake(110, 110, 100, 100)
#define largeMR CGRectMake(215, 110, 100, 100)
#define largeBL CGRectMake(5, 215, 100, 100)
#define largeBM CGRectMake(110, 215, 100, 100)
#define largeBR CGRectMake(215, 215, 100, 100)
#define full CGRectMake(5, 5, 310, 310)
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
topLeft = [[SmallBoardView alloc] initWithFrame:largeTL];
topMid = [[SmallBoardView alloc] initWithFrame:largeTM];
topRight = [[SmallBoardView alloc] initWithFrame:largeTR];
midLeft = [[SmallBoardView alloc] initWithFrame:largeML];
midMid = [[SmallBoardView alloc] initWithFrame:largeMM];
midRight = [[SmallBoardView alloc] initWithFrame:largeMR];
botLeft = [[SmallBoardView alloc] initWithFrame:largeBL];
botMid = [[SmallBoardView alloc] initWithFrame:largeBM];
botRight = [[SmallBoardView alloc] initWithFrame:largeBR];
[self addSubview:topLeft];
[self addSubview:topMid];
[self addSubview:topRight];
[self addSubview:midLeft];
[self addSubview:midMid];
[self addSubview:midRight];
[self addSubview:botLeft];
[self addSubview:botMid];
[self addSubview:botRight];
smallBoards = [[NSMutableArray alloc] initWithObjects:topLeft, topMid, topRight, midLeft, midMid, midRight, botLeft, botMid, botRight, nil];
int i = 0;
for (SmallBoardView *s in smallBoards) {
s.tag = i;
i++;
}
self.backgroundColor = [UIColor blackColor];
}
return self;
}
- (void)enlargeSquare:(int)board
{
enlargedView = [smallBoards objectAtIndex:board];
[self bringSubviewToFront:enlargedView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
enlargedView.frame = full;
[enlargedView sendSubviewToBack:enlargedView.coverView];
[enlargedView enlargeSquare];
[UIView commitAnimations];
}
- (void)shrinkSquare
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
enlargedView.frame = enlargedView.defaultFrame;
[enlargedView shrinkSquare];
[enlargedView bringSubviewToFront:enlargedView.coverView];
[UIView commitAnimations];
}
- (void)updateBoard:(int)board square:(int)square player:(int)player
{
UIButton *selectedSquare = [[[smallBoards objectAtIndex:board] squares] objectAtIndex:square];
selectedSquare.backgroundColor = [UIColor blackColor];
switch (player) {
case 0:
[selectedSquare setImage:[UIImage imageNamed:@"blankSquare.png"]
forState:UIControlStateNormal];
break;
case 1:
[selectedSquare setImage:[UIImage imageNamed:@"xSquare.png"]
forState:UIControlStateNormal];
break;
case 2:
[selectedSquare setImage:[UIImage imageNamed:@"oSquare.png"]
forState:UIControlStateNormal];
break;
default:
break;
}
nextSquare = [smallBoards objectAtIndex:square];
}
- (void)updateCover:(int)board player:(int)player
{
SmallBoardView *s = [smallBoards objectAtIndex:board];
switch (player) {
case 1:
[s.coverView setBackgroundImage:[UIImage imageNamed:@"xSquare.png"]
forState:UIControlStateNormal];
break;
case 2:
[s.coverView setBackgroundImage:[UIImage imageNamed:@"oSquare.png"]
forState:UIControlStateNormal];
break;
case 3:
[s.coverView setBackgroundImage:[UIImage imageNamed:@"blankSquare.png"]
forState:UIControlStateNormal];
break;
default:
break;
}
[s bringSubviewToFront:s.coverView];
}
- (void)highlightSquares:(bool)highlightAll boardVals:(NSArray *)boardVals lastMove:(int)lastMove
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.4];
[UIView setAnimationDuration:0.3];
if (highlightAll) {
int i = 0;
for (SmallBoardView *s in smallBoards) {
if ([[boardVals objectAtIndex:i] intValue] == 0) {
s.coverView.backgroundColor = [UIColor clearColor];
s.coverView.alpha = 1;
}
i++;
}
} else {
int i = 0;
for (SmallBoardView *s in smallBoards) {
if ([[boardVals objectAtIndex:i] intValue] == 0) {
if (i == lastMove % 10) {
s.coverView.alpha = 1;
s.coverView.backgroundColor = [UIColor clearColor];
} else {
s.coverView.backgroundColor = [UIColor blackColor];
s.coverView.alpha = .4;
}
}
i++;
}
}
[UIView commitAnimations];
}
@end