This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let num1:Int? = "10".toInt() | |
let num2:Int? = "20".toInt() | |
let type:Int = 0 // + | |
func calc(n1:Int?, n2:Int?, type:Int) -> Int? { | |
switch (n1,n2,type) { | |
case (.Some(let n1), .Some(0) , 3): return .None | |
case (.Some(let n1), .Some(let n2), let idx): | |
// return [(+),(-),(*),(/)][idx](n1,n2) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)parser:(NSXMLParser *)parser | |
didStartElement:(NSString *)elementName | |
namespaceURI:(NSString *)namespaceURI | |
qualifiedName:(NSString *)qName | |
attributes:(NSDictionary *)attributeDict | |
{ | |
currentElement_ = [elementName copy]; | |
if ([elementName isEqualToString:@"title"]) { | |
currentTitle_ = [[NSMutableString alloc] init]; | |
}else if ([elementName isEqualToString:@"link"]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <SpriteKit/SpriteKit.h> | |
@interface MyScene : SKScene | |
{ | |
NSMutableArray *moles_; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MyScene.h" | |
// オブジェクト名 | |
#define kMoleName @"Mole" // もぐら | |
#define kGround1Name @"Ground1" // 地面1 | |
#define kGround2Name @"Ground2" // 地面2 | |
#define kGround3Name @"Ground3" // 地面3 | |
#define kGround4Name @"Ground4" // 地面4 | |
@implementation MyScene |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(id)initWithSize:(CGSize)size { | |
if (self = [super initWithSize:size]) { | |
/* Setup your scene here */ | |
self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0]; | |
SKSpriteNode *ground1 = [SKSpriteNode spriteNodeWithImageNamed:@"GroundTop"]; | |
ground1.name = kGround1Name; | |
ground1.zPosition = 0.1; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)addMole | |
{ | |
NSLog(@"%s", __func__); | |
// 今動いていないもぐらのインデックスの配列を作る | |
NSMutableArray *targetMolesIndex = [NSMutableArray array]; | |
for(int i = 0; i < moles_.count; i++){ | |
NSObject *object = moles_[i]; | |
if(object == [NSNull null]){ | |
[targetMolesIndex addObject:@(i)]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { | |
/* Called when a touch begins */ | |
for (UITouch *touch in touches) { | |
CGPoint location = [touch locationInNode:self]; | |
NSArray *nodes = [self nodesAtPoint:location]; | |
for (SKNode *node in nodes) { | |
if([node.name isEqualToString:kMoleName]){ | |
if([node hasActions]){ | |
[node removeAllActions]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline CGFloat skRand(CGFloat l, CGFloat h) | |
{ | |
return skRandf() * (h - l) + l; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline CGFloat skRandf() | |
{ | |
return rand() / (CGFloat) RAND_MAX; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 画面の外枠に物理的な枠を設定する | |
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame]; |
OlderNewer