-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrapCode
141 lines (121 loc) · 5.03 KB
/
scrapCode
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
gameOver = self.viewGameOver;
gameOver.hidden = NO;
//gameOver.backgroundColor = [UIColor whiteColor];
[self.view bringSubviewToFront:gameOver];
[self.WinnerLabel setText: [NSString stringWithFormat:@"Winner: Player %d", currentPlayer]];
[self setUpGameOverView];
//[UIView transitionFromView:viewBoard toView:gameOver duration:0.5f options:UIViewAnimationOptionTransitionCrossDissolve completion:NULL];
// CABasicAnimation* shrink = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
// shrink.toValue = [NSNumber numberWithDouble:2.0];
// shrink.duration = 0.5;
// shrink.delegate = self;
// shrink.autoreverses = YES;
//
// [gcTemp->shapeLayer addAnimation:shrink forKey:@"shrink"];
//
//fillColorAnimation.
- (int)checkForVerticalWinner{
for(int i = 0; i < shapeArray.count; i++)
{
NSMutableArray *tempArray = [shapeArray objectAtIndex: i];
GameCell *cell = (GameCell *)[tempArray objectAtIndex: 0];
int player = cell->wState;
int bWon = true;
//if the cell state isn't empty
if(player != 0)
{
//Check the array
for(int j = 0; j < tempArray.count; j++)
{
GameCell *thisCell = (GameCell *)[tempArray objectAtIndex: j];
int thisState = thisCell->wState;
//if the shape isn't the same as the player who just clicked, break out of this function
if(player != thisState)
{
bWon = false;
break;
}
}
//otherwise return the player who has won
if(bWon)
{
return player;
}
}
}
return 0;
}
- (int) checkForHorizontalWinner{
for(int j = 0; j < numberofRings; j++)
{
int cInRow = 0;
for(int i = 0; i < numberofWedges; i++)
{
NSMutableArray *tempArray = [shapeArray objectAtIndex: i];
GameCell *thisCell = [tempArray objectAtIndex: j];
int player = thisCell->wState;
GameCell *nextCell = [[shapeArray objectAtIndex: (i+1)%numberofWedges] objectAtIndex: j];
int nextState =nextCell->wState;
if(player != 0)
{
if(player == nextState)
{
cInRow++;
if(cInRow == (winningWedgeCount -1))
{
return player;
}
}
else
{
cInRow = 0;
}
}
}
}
return 0;
}
//Potentially use this method for all victory checks by changing offset x and y accordingly
- (int) checkForDiagonalWinner: (int) direction{
for(int i = 0; i < numberofWedges; i++)
{
int cInRow = 0;
GameCell *thisCell = [[shapeArray objectAtIndex: i] objectAtIndex: 0];
int thisState = thisCell->wState;
//Set the direction which is changed depending on the direction parameter
int offsety = 1, offsetx = 0;
if(direction == 1){
offsetx = 1;
}else if(direction == -1){
offsetx = (numberofWedges-1);
}
//if the place clicked isn't playerless
if(thisState != 0)
{
//Loop while the winner hasn't been found yet
for(int j = 0; j < (winningWedgeCount-1); j++)
{
GameCell *nextCell = [[shapeArray objectAtIndex: ((i + offsetx)%numberofWedges)] objectAtIndex: offsety] ;
int nextState = nextCell->wState;
//if the state matches the previous one, continue
if(thisState == nextState)
{
cInRow++;
//if the victory condition has been fulfilled, return winning player
if(cInRow == (winningWedgeCount -1))
{
return thisState;
}
//offset the current wedge pointer
offsetx += direction;
//if the pointer points to a negative value, set to the max value
if(offsetx < 0){
offsetx = (numberofWedges-1);
}
offsety ++;
}
}
}
}
return 0;
}