-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIIndexButton.m
68 lines (55 loc) · 1.59 KB
/
UIIndexButton.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
//
// UIIndexButton.m
// A_Star
//
// Created by bliss_ddo on 14-8-18.
// Copyright (c) 2014年 SELF_PRACTICE. All rights reserved.
//
#import "UIIndexButton.h"
@implementation UIIndexButton
@synthesize PathX,PathY,G_ValueCost,H_ValueCost,parentNode;
@synthesize nodeType;
-(id)initWithXpath:(NSInteger)xp andYpath:(NSInteger)yPath
{
self = [super init];
if (self) {
CGFloat originalX = xp*WIDH;
CGFloat originalY = yPath*WIDH;
CGFloat widthX = WIDH;
CGFloat widthY = WIDH;
self.PathX=xp;
self.PathY=yPath;
self.parentNode = nil;
[self setFrame:CGRectMake(originalX, originalY, widthX, widthY)];
[self setBackgroundColor:[UIColor whiteColor]];
self.layer.borderColor=[[UIColor grayColor]CGColor];
self.layer.borderWidth = 4.0f;
}
return self;
}
-(double)caculate_HValue:(UIIndexButton*)pNode
{
return fabs(pNode.PathX-self.PathX)+fabs(pNode.PathY-self.PathY);
}
-(BOOL)checkIsEqualToNode:(UIIndexButton*)pNode
{
return (pNode.PathX == self.PathX)&&(pNode.PathY==self.PathY);
}
-(void)setNodeType:(NodeType)nodeType1
{
nodeType = nodeType1;
switch (nodeType) {
case NodeTypeBlock:
[self setBackgroundColor:[UIColor blackColor]];
break;
case NodeTypeStart:
[self setBackgroundColor:[UIColor redColor]];
case NodeTypeEnd:
[self setBackgroundColor:[UIColor blueColor]];
default:
[self setBackgroundColor:[UIColor whiteColor]];
break;
}
[self setNeedsDisplay];
}
@end