Skip to content

Instantly share code, notes, and snippets.

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)
- (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"]) {
#import <SpriteKit/SpriteKit.h>
@interface MyScene : SKScene
{
NSMutableArray *moles_;
}
@end
#import "MyScene.h"
// オブジェクト名
#define kMoleName @"Mole" // もぐら
#define kGround1Name @"Ground1" // 地面1
#define kGround2Name @"Ground2" // 地面2
#define kGround3Name @"Ground3" // 地面3
#define kGround4Name @"Ground4" // 地面4
@implementation MyScene
-(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;
- (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)];
-(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];
static inline CGFloat skRand(CGFloat l, CGFloat h)
{
return skRandf() * (h - l) + l;
}
static inline CGFloat skRandf()
{
return rand() / (CGFloat) RAND_MAX;
}
// 画面の外枠に物理的な枠を設定する
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];