-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCellButton.m
96 lines (77 loc) · 2.03 KB
/
CellButton.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
//
// CellButton.m
// MineSweeper
//
// Created by t on 09/04/18.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "CellButton.h"
@implementation CellButton
- (id) init
{
if( self = [super init]){
round_cells_ = [[NSMutableArray array] retain];
adj_cells_ = [[NSMutableArray array] retain];
isMine = NO;
isOpened = NO;
[self setBackgroundImage:[[UIImage imageNamed:@"tile1.gif"]
stretchableImageWithLeftCapWidth:18.0 topCapHeight: 0.0]
forState: UIControlStateNormal];
[self setBackgroundImage:[[UIImage imageNamed:@"tile2.gif"]
stretchableImageWithLeftCapWidth:18.0 topCapHeight: 0.0]
forState: UIControlStateHighlighted];
}
return self;
}
- (void) dealloc
{
[round_cells_ release];
[adj_cells_ release];
[super dealloc];
}
- (void) addRoundCell: (CellButton *) cell
{
[round_cells_ addObject: cell];
}
- (void) addAdjCell: (CellButton *) cell
{
[adj_cells_ addObject: cell];
}
- (int) getValue
{
if(isMine) return -1;
int value = 0;
for(CellButton * cell in round_cells_){
if([cell isMine]){
value++;
}
}
return value;
}
- (int) open
{
int value = [self getValue];
if(isOpened) return value;
isOpened = YES;
if(value > 0){
[self setTitle:[NSString stringWithFormat:@"%i", value] forState:UIControlStateNormal];
[self setTitle:[NSString stringWithFormat:@"%i", value] forState:UIControlStateHighlighted];
}else if(value == -1){
[self setTitle:@"X" forState:UIControlStateNormal];
[self setTitle:@"X" forState:UIControlStateHighlighted];
}
[self setBackgroundImage:[[UIImage imageNamed:@"tile2.gif"]
stretchableImageWithLeftCapWidth:18.0 topCapHeight: 0.0]
forState: UIControlStateNormal];
if(value == 0){
for(CellButton * cell in round_cells_){
[cell open];
}
}
return value;
}
- (void) markFlag
{
}
@synthesize isMine;
@end