当前位置: 首页 > 编程日记 > 正文

iOS开发实战-基于SpriteKit的FlappyBird小游戏

写在前面

最近一直在忙自己的维P恩的事情
公司项目也是一团乱
于是...随手找了个游戏项目改了改就上线了,就当充数了.

1240

SpriteKit简介

SpriteKit是iOS 7之后苹果推出的2D游戏框架。它支持2D游戏中各种功能,如物理引擎,地图编辑,粒子,视频,声音精灵化,光照等。

SpriteKit中常用的类

  • SKSpriteNode 用于绘制精灵纹理
  • SKVideoNode 用于播放视频
  • SKLabelNode 用于渲染文本
  • SKShapeNode 用于渲染基于Core Graphics路径的形状
  • SKEmitterNode 用于创建和渲染粒子系统
  • SKView 对象执行动画和渲染
  • SKScene 游戏内容组织成的场景
  • SKAction 节点动画

效果

这是一个类似于FlappyBird的小游戏
集成GameCenter

catcat.gif

分析

结构很简单
设计思路就是障碍物不断的移动.当把角色卡死时游戏结束

结构

代码

1.预加载游戏结束时的弹出广告
2.加载背景
3.设置physicsBody
4.设置障碍物移动Action
5.设置开始面板角色及初始Action
6.加载所有内容节点

  • 初始化
- (void)initalize
{[super initalize];SKSpriteNode* background=[SKSpriteNode spriteNodeWithImageNamed:@"sky.png"];background.size = self.view.frame.size;background.position=CGPointMake(background.size.width/2, background.size.height/2);[self addChild:background];self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];self.physicsBody.categoryBitMask = edgeCategory;self.physicsWorld.contactDelegate = self;self.moveWallAction = [SKAction sequence:@[[SKAction moveToX:-WALL_WIDTH duration:TIMEINTERVAL_MOVEWALL],[SKAction removeFromParent]]];SKAction *upHeadAction = [SKAction rotateToAngle:M_PI / 6 duration:0.2f];upHeadAction.timingMode = SKActionTimingEaseOut;SKAction *downHeadAction = [SKAction rotateToAngle:-M_PI / 2 duration:0.8f];downHeadAction.timingMode = SKActionTimingEaseOut;self.moveHeadAction = [SKAction sequence:@[upHeadAction, downHeadAction,]];[self addGroundNode];[self addCeiling];[self addHeroNode];[self addResultLabelNode];[self addInstruction];[self runAction:[SKAction repeatActionForever:[SKAction sequence:@[[SKAction performSelector:@selector(addFish) onTarget:self],[SKAction waitForDuration:0.3f],]]] withKey:ACTIONKEY_ADDFISH];_interstitialObj = [[GDTMobInterstitial alloc]initWithAppkey:@"1106301022"placementId:@"2080622474511184"];_interstitialObj.delegate = self;//设置委托 _interstitialObj.isGpsOn = NO; //【可选】设置GPS开关//预加载广告[_interstitialObj loadAd];}
  • 加载角色,设置飞行动作,触摸事件
- (void)addHeroNode
{self.hero=[SKSpriteNode spriteNodeWithImageNamed:@"player"];SKTexture* texture=[SKTexture textureWithImageNamed:@"player"];_hero.physicsBody=[SKPhysicsBody bodyWithTexture:texture size:_hero.size];_hero.anchorPoint = CGPointMake(0.5, 0.5);_hero.position = CGPointMake(self.frame.size.width / 2, CGRectGetMidY(self.frame));_hero.name = NODENAME_HERO;_hero.physicsBody.categoryBitMask = heroCategory;_hero.physicsBody.collisionBitMask = wallCategory | groundCategory|edgeCategory;_hero.physicsBody.contactTestBitMask = holeCategory | wallCategory | groundCategory|fishCategory;_hero.physicsBody.dynamic = YES;_hero.physicsBody.affectedByGravity = NO;_hero.physicsBody.allowsRotation = NO;_hero.physicsBody.restitution = 0.4;_hero.physicsBody.usesPreciseCollisionDetection = NO;[self addChild:_hero];
//    SKTexture* texture1=[SKTexture textureWithImageNamed:@"player"];
//    SKTexture* texture2=[SKTexture textureWithImageNamed:@"player3"];
//
//    SKAction *animate = [SKAction animateWithTextures:@[texture1,texture2] timePerFrame:0.1];
//    [_hero runAction:[SKAction repeatActionForever:animate]];[_hero runAction:[SKAction repeatActionForever:[self getFlyAction]]withKey:ACTIONKEY_FLY];
}- (SKAction *)getFlyAction
{SKAction *flyUp = [SKAction moveToY:_hero.position.y + 10 duration:0.3f];flyUp.timingMode = SKActionTimingEaseOut;SKAction *flyDown = [SKAction moveToY:_hero.position.y - 10 duration:0.3f];flyDown.timingMode = SKActionTimingEaseOut;SKAction *fly = [SKAction sequence:@[flyUp, flyDown]];return fly;
}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{if (_isGameOver) {return;}if (!_isGameStart) {[self startGame];}_hero.physicsBody.velocity = CGVectorMake(100, 500);[_hero runAction:_moveHeadAction withKey:ACTIONKEY_MOVEHEAD];
}
  • 加载开始说明和结束说明
- (void)addResultLabelNode
{self.labelNode = [SKLabelNode labelNodeWithFontNamed:@"PingFangSC-Regular"];_labelNode.fontSize = 30.0f;_labelNode.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeLeft;_labelNode.verticalAlignmentMode = SKLabelVerticalAlignmentModeTop;_labelNode.position = CGPointMake(10, self.frame.size.height - 20);_labelNode.fontColor = COLOR_LABEL;_labelNode.zPosition=100;[self addChild:_labelNode];
}
- (void)addInstruction{self.hitSakuraToScore = [SKLabelNode labelNodeWithFontNamed:@"AmericanTypewriter"];_hitSakuraToScore.fontSize = 20.0f;_hitSakuraToScore.position = CGPointMake(self.frame.size.width / 2, CGRectGetMidY(self.frame)-60);_hitSakuraToScore.fontColor = COLOR_LABEL;_hitSakuraToScore.zPosition=100;_hitSakuraToScore.text=@"Hit fish to Score";
//    _hitSakuraToScore.text=NSLocalizedString(@"Hit Sakura to Score", nil);[self addChild:_hitSakuraToScore];self.tapToStart = [SKLabelNode labelNodeWithFontNamed:@"PingFangSC-Regular"];_tapToStart.fontSize = 20.0f;_tapToStart.position = CGPointMake(self.frame.size.width / 2, CGRectGetMidY(self.frame)-100);_tapToStart.fontColor = COLOR_LABEL;_tapToStart.zPosition=100;_tapToStart.text=@"Tap to Jump";[self addChild:_tapToStart];
}
  • 加载障碍物
- (void)addWall
{CGFloat spaceHeigh = self.frame.size.height - GROUND_HEIGHT;float random= arc4random() % 4;CGFloat holeLength = HERO_SIZE.height * (2.0+random*0.1);int holePosition = arc4random() % (int)((spaceHeigh - holeLength) / HERO_SIZE.height);CGFloat x = self.frame.size.width;CGFloat upHeight = holePosition * HERO_SIZE.height;if (upHeight > 0) {SKSpriteNode *upWall = [SKSpriteNode spriteNodeWithColor:COLOR_WALL size:CGSizeMake(WALL_WIDTH, upHeight)];upWall.anchorPoint = CGPointMake(0, 0);upWall.position = CGPointMake(x, self.frame.size.height - upHeight);upWall.name = NODENAME_WALL;upWall.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:upWall.size center:CGPointMake(upWall.size.width / 2.0f, upWall.size.height / 2.0f)];upWall.physicsBody.categoryBitMask = wallCategory;upWall.physicsBody.dynamic = NO;upWall.physicsBody.friction = 0;[upWall runAction:_moveWallAction withKey:ACTIONKEY_MOVEWALL];[self addChild:upWall];}CGFloat downHeight = spaceHeigh - upHeight - holeLength;if (downHeight > 0) {SKSpriteNode *downWall = [SKSpriteNode spriteNodeWithColor:COLOR_WALL size:CGSizeMake(WALL_WIDTH, downHeight)];downWall.anchorPoint = CGPointMake(0, 0);downWall.position = CGPointMake(x, GROUND_HEIGHT);downWall.name = NODENAME_WALL;downWall.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:downWall.size center:CGPointMake(downWall.size.width / 2.0f, downWall.size.height / 2.0f)];downWall.physicsBody.categoryBitMask = wallCategory;downWall.physicsBody.dynamic = NO;downWall.physicsBody.friction = 0;[downWall runAction:_moveWallAction withKey:ACTIONKEY_MOVEWALL];[self addChild:downWall];}SKSpriteNode *hole = [SKSpriteNode spriteNodeWithColor:[UIColor clearColor] size:CGSizeMake(WALL_WIDTH, holeLength)];hole.anchorPoint = CGPointMake(0, 0);hole.position = CGPointMake(x, self.frame.size.height - upHeight - holeLength);hole.name = NODENAME_HOLE;hole.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:hole.size center:CGPointMake(hole.size.width / 2.0f, hole.size.height / 2.0f)];hole.physicsBody.categoryBitMask = holeCategory;hole.physicsBody.dynamic = NO;[hole runAction:_moveWallAction withKey:ACTIONKEY_MOVEWALL];[self addChild:hole];
}
  • 游戏开始时 不断增加障碍物
- (void)startGame
{self.isGameStart = YES;_hero.physicsBody.affectedByGravity = YES;[_hero removeActionForKey:ACTIONKEY_FLY];[_tapToStart removeFromParent];[_hitSakuraToScore removeFromParent];[self addResultLabelNode];SKAction *addWall = [SKAction sequence:@[[SKAction performSelector:@selector(addWall) onTarget:self],[SKAction waitForDuration:TIMEINTERVAL_ADDWALL],]];[self runAction:[SKAction repeatActionForever:addWall] withKey:ACTIONKEY_ADDWALL];
}
  • 实时更新内容
- (void)update:(NSTimeInterval)currentTime
{if(self.hero&&!_isGameOver){if ( self.hero.position.x<10) {[self gameOver];}else if(self.hero.position.x>self.frame.size.width){self.hero.position =CGPointMake(self.hero.position.x-20, self.hero.position.y);}}__block int wallCount = 0;[self enumerateChildNodesWithName:NODENAME_WALL usingBlock:^(SKNode *node, BOOL *stop) {if (wallCount >= 2) {*stop = YES;return;}if (node.position.x <= -WALL_WIDTH) {wallCount++;[node removeFromParent];}}];[self enumerateChildNodesWithName:NODENAME_HOLE usingBlock:^(SKNode *node, BOOL *stop) {if (node.position.x <= -WALL_WIDTH) {[node removeFromParent];*stop = YES;}}];[self enumerateChildNodesWithName:NODENAME_FISH usingBlock:^(SKNode *node, BOOL *stop) {if (node.position.x <= -node.frame.size.width) {[node removeFromParent];}}];
}
  • 设置物体碰撞效果
- (void)didBeginContact:(SKPhysicsContact *)contact
{if (_isGameOver) {return;}SKPhysicsBody *firstBody, *secondBody;if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask) {firstBody = contact.bodyA;secondBody = contact.bodyB;} else {firstBody = contact.bodyB;secondBody = contact.bodyA;}if ((firstBody.categoryBitMask & heroCategory) && (secondBody.categoryBitMask & fishCategory)) {if(secondBody.node.parent&&self.isGameStart){int currentPoint = [_labelNode.text intValue];_labelNode.text = [NSString stringWithFormat:@"%d", currentPoint + 1];[self playSoundWithName:@"sfx_wing.caf"];NSString *burstPath =[[NSBundle mainBundle]pathForResource:@"MyParticle" ofType:@"sks"];SKEmitterNode *burstNode =[NSKeyedUnarchiver unarchiveObjectWithFile:burstPath];burstNode.position = secondBody.node.position;[secondBody.node removeFromParent];[self addChild:burstNode];dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{[burstNode runAction:[SKAction removeFromParent]];});}}
}
- (void) didEndContact:(SKPhysicsContact *)contact{if (_isGameOver) {return;}SKPhysicsBody *firstBody, *secondBody;if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask) {firstBody = contact.bodyA;secondBody = contact.bodyB;} else {firstBody = contact.bodyB;secondBody = contact.bodyA;}return;}- (void)playSoundWithName:(NSString *)fileName
{dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{[self runAction:[SKAction playSoundFileNamed:fileName waitForCompletion:YES]];});
}
  • 游戏结束与重新开始
- (void)gameOver
{self.isGameOver = YES;self.isGameStart=NO;[_hero removeActionForKey:ACTIONKEY_MOVEHEAD];[self removeActionForKey:ACTIONKEY_ADDWALL];[self enumerateChildNodesWithName:NODENAME_WALL usingBlock:^(SKNode *node, BOOL *stop) {[node removeActionForKey:ACTIONKEY_MOVEWALL];}];[self enumerateChildNodesWithName:NODENAME_HOLE usingBlock:^(SKNode *node, BOOL *stop) {[node removeActionForKey:ACTIONKEY_MOVEWALL];}];if([_labelNode.text isEqualToString:@""])_labelNode.text=@"0";NSString *result=_labelNode.text;RestartLabel *restartView = [RestartLabel getInstanceWithSize:self.size Point:result];restartView.delegate = self;[restartView showInScene:self];_labelNode.text=@"";if (_interstitialObj.isReady) {UIViewController *vc = [[[UIApplication sharedApplication] keyWindow] rootViewController];//vc = [self navigationController];[_interstitialObj presentFromRootViewController:vc];}}- (void)restart
{[self addInstruction];self.labelNode.text = @"";[self enumerateChildNodesWithName:NODENAME_HOLE usingBlock:^(SKNode *node, BOOL *stop) {[node removeFromParent];}];[self enumerateChildNodesWithName:NODENAME_WALL usingBlock:^(SKNode *node, BOOL *stop) {[node removeFromParent];}];[_hero removeFromParent];self.hero = nil;[self addHeroNode];[self runAction:[SKAction repeatActionForever:[SKAction sequence:@[[SKAction performSelector:@selector(addFish) onTarget:self],[SKAction waitForDuration:0.3f],]]] withKey:ACTIONKEY_ADDFISH];self.isGameStart = NO;self.isGameOver = NO;
}- (void)restartView:(RestartLabel *)restartView didPressRestartButton:(SKSpriteNode *)restartButton
{[restartView dismiss];[self restart];}
- (void)restartView:(RestartLabel *)restartView didPressLeaderboardButton:(SKSpriteNode *)restartButton{[self showLeaderboard];
}
  • 游戏结束可以调期GameCenter排行榜
-(void)showLeaderboard{GKGameCenterViewController *gcViewController = [[GKGameCenterViewController alloc] init];gcViewController.gameCenterDelegate = self;gcViewController.viewState = GKGameCenterViewControllerStateLeaderboards;gcViewController.leaderboardIdentifier = @"MyFirstLeaderboard";[self.view.window.rootViewController presentViewController:gcViewController animated:YES completion:nil];}
-(void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController
{[gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
}
  • 积分框
@interface ScoreLabel : SKSpriteNode@property(nonatomic, copy) NSString* finalPoint;@end#import "ScoreLabel.h"@implementation ScoreLabel- (id)initWithColor:(UIColor *)color size:(CGSize)size
{if (self = [super initWithColor:color size:size]) {SKLabelNode* scoreLabelNode = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];scoreLabelNode.text=_finalPoint;scoreLabelNode.fontSize = 20.0f;scoreLabelNode.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;scoreLabelNode.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;scoreLabelNode.position = CGPointMake(size.width / 2.0f, size.height - 300);scoreLabelNode.fontColor = [UIColor whiteColor];[self addChild:scoreLabelNode];    }return self;
}@end
  • 游戏结束节点内容
@class RestartLabel;
@protocol RestartViewDelegate <NSObject>- (void)restartView:(RestartLabel *)restartView didPressRestartButton:(SKSpriteNode *)restartButton;
- (void)restartView:(RestartLabel *)restartView didPressLeaderboardButton:(SKSpriteNode *)restartButton;
@end@interface RestartLabel : SKSpriteNode@property (weak, nonatomic) id <RestartViewDelegate> delegate;
@property (copy, nonatomic) NSString* finalPoint;
+ (RestartLabel *)getInstanceWithSize:(CGSize)size Point:(NSString *)point;
- (void)dismiss;
- (void)showInScene:(SKScene *)scene;@end#define NODENAME_BUTTON @"button"
#import "RestartLabel.h"
#import "MainViewController.h"@import GameKit;
@interface RestartLabel()
@property (strong, nonatomic) SKSpriteNode *button;
@property (strong, nonatomic) SKLabelNode *labelNode;
@property (strong, nonatomic) SKLabelNode *scoreLabelNode;
@property (strong, nonatomic) SKLabelNode *highestLabelNode;
@property (strong, nonatomic) SKSpriteNode *gameCenterNode;
@property (strong, nonatomic) SKLabelNode *gameCenterLabel;
@end@implementation RestartLabel- (id)initWithColor:(UIColor *)color size:(CGSize)size
{if (self = [super initWithColor:color size:size]) {self.userInteractionEnabled = YES;self.button = [SKSpriteNode spriteNodeWithColor:[UIColor colorWithRed:0.608 green:0.349 blue:0.714 alpha:1] size:CGSizeMake(100, 50)];_button.position = CGPointMake(size.width / 2.0f, size.height - 350);_button.name = NODENAME_BUTTON;[self addChild:_button];self.labelNode = [SKLabelNode labelNodeWithFontNamed:@"PingFangSC-Regular"];_labelNode.text = @"Restart";_labelNode.fontSize = 20.0f;_labelNode.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;_labelNode.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;_labelNode.position = CGPointMake(0, 0);_labelNode.fontColor = [UIColor whiteColor];[_button addChild:_labelNode];self.gameCenterNode = [SKSpriteNode spriteNodeWithColor:[UIColor colorWithRed:0.608 green:0.349 blue:0.714 alpha:1]size:CGSizeMake(150, 50)];_gameCenterNode.position = CGPointMake(size.width / 2.0f, size.height - 280);[self addChild:_gameCenterNode];self. gameCenterLabel=[SKLabelNode labelNodeWithFontNamed:@"PingFangSC-Regular"];_gameCenterLabel.text = @"Leaderboard";_gameCenterLabel.fontSize = 20.0f;_gameCenterLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;_gameCenterLabel.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;_gameCenterLabel.position = CGPointMake(0, 0);_gameCenterLabel.fontColor = [UIColor whiteColor];[_gameCenterNode addChild:_gameCenterLabel];}return self;
}
-(void)addScoreLabelSize:(CGSize)size{_scoreLabelNode = [SKLabelNode labelNodeWithFontNamed:@"PingFangSC-Regular"];_scoreLabelNode.text=[NSString stringWithFormat:@"Your Score: \r%@",_finalPoint? _finalPoint: @"0"];_scoreLabelNode.fontSize = 20.0f;_scoreLabelNode.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;_scoreLabelNode.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;_scoreLabelNode.position = CGPointMake(size.width / 2.0f, size.height - 170);_scoreLabelNode.fontColor = [UIColor colorWithRed:0.173 green:0.243 blue:0.314 alpha:1];[self addChild:_scoreLabelNode];
}-(void)addHighestLabelSize:(CGSize)size{_highestLabelNode = [SKLabelNode labelNodeWithFontNamed:@"PingFangSC-Regular"];_highestLabelNode.fontColor = [UIColor colorWithRed:0.173 green:0.243 blue:0.314 alpha:1];NSString* showText;NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];NSNumber* highestScore=[defaults objectForKey:@"HighScore"];NSNumber* currentPoint= [NSNumber numberWithInt: [_finalPoint intValue]];if(highestScore==nil||[currentPoint integerValue]>[highestScore integerValue]){[defaults setObject:currentPoint forKey:@"HighScore"];highestScore=currentPoint;showText=@"New Record!";_highestLabelNode.fontColor=[UIColor colorWithRed:0.753 green:0.224 blue:0.169 alpha:1];[defaults synchronize];}else{showText=[NSString stringWithFormat:@"High Score: \r%lu",(long)[highestScore integerValue]];}if(highestScore!=nil){[self reportScore:[highestScore integerValue]];}_highestLabelNode.text=showText;_highestLabelNode.fontSize = 20.0f;_highestLabelNode.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;_highestLabelNode.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;_highestLabelNode.position = CGPointMake(size.width / 2.0f, size.height - 220);[self addChild:_highestLabelNode];
}+ (RestartLabel *)getInstanceWithSize:(CGSize)size Point:(NSString *)point
{RestartLabel *restartView = [RestartLabel spriteNodeWithColor:color(255, 255, 255, 0.6) size:size];restartView.anchorPoint = CGPointMake(0, 0);restartView.finalPoint=point;[restartView addScoreLabelSize:size];[restartView addHighestLabelSize:size];return restartView;
}- (void)showInScene:(SKScene *)scene
{self.alpha = 0.0f;[scene addChild:self];[self runAction:[SKAction fadeInWithDuration:0.3f]];
}- (void)dismiss
{[self runAction:[SKAction fadeOutWithDuration:0.3f] completion:^{[self removeFromParent];}];
}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{UITouch *touch = [touches anyObject];CGPoint location = [touch locationInNode:self];SKNode *touchNode = [self nodeAtPoint:location];if (touchNode == _button || touchNode == _labelNode) {if ([_delegate respondsToSelector:@selector(restartView:didPressRestartButton:)]) {[_delegate restartView:self didPressRestartButton:_button];}}else if(touchNode==_gameCenterNode || touchNode==_gameCenterLabel){if ([_delegate respondsToSelector:@selector(restartView:didPressLeaderboardButton:)]) {[_delegate restartView:self didPressLeaderboardButton:_button];}
}
}
-(void)reportScore:(NSInteger)inputScore{GKScore *score = [[GKScore alloc] initWithLeaderboardIdentifier:@"MyFirstLeaderboard"];score.value = inputScore;[GKScore reportScores:@[score] withCompletionHandler:^(NSError *error) {if (error != nil) {NSLog(@"%@", [error localizedDescription]);}}];
}@end

关于游戏上架Tips

1240
蛋疼广电粽菊要求国内游戏必须备案...
我们只是想上个小游戏而已~难道还要再等个大半个月去备案么?
Apple也妥协了 在备注那里要求中国区上架游戏必须填写备案号

But!!!上有政策,下有对策嘛~

  • 填写App分类时直接选择娱乐类型上架,就不会要求填写备案号了~
  • 销售范围,不选择中国地区,这样也不会要求填写备案号,等过审了,再将销售范围改回所有地区,基本上是实时生效~

以上两种方式屡试不爽哈~对于我们个人小开发来说也算是个小福利了.

Demo地址

Github地址,欢迎Star (由于集成了广告,广点通的静态库需要单独下载下完直接扔到项目里就行)
已上架Appstore 猫爷快吃 喜欢就支持下吧~
欢迎光顾自己的小站,内容都是同步更新的~
大家低调支持下自己的 牛牛数据 Half-price~~

还没结束

1240
快来猜猜我放的背景音乐是啥~

转载于:https://www.cnblogs.com/gongxiaokai/p/7247644.html

相关文章:

2018年12月14日 函数 总结

map() 处理序列中每个元素&#xff0c;得到迭代器&#xff0c;该迭代器 元素个数和位置与原来一致 filter() 遍历序列中的每个元素&#xff0c;判断每个元素得到布尔值&#xff0c;如果是true则留下来 people[{name:"abc","age":100},{"name":&…

UML类图新手入门级介绍

UML类图新手入门级介绍 看了大话设计模式&#xff0c;觉得很生动形象&#xff0c;比较适合于我这种初学者理解面向对象&#xff0c;所以就记录了一下。 举一个简单的例子&#xff0c;来看这样一副图&#xff0c;其中就包括了UML类图中的基本图示法。 首先&#xff0c;看动物矩形…

SQL中获取刚插入记录时对应的自增列的值

--创建数据库和表create database MyDataBaseuse MyDataBasecreate table mytable(id int identity(1,1),name varchar(20))--执行这个SQL,就能查出来刚插入记录对应的自增列的值insert into mytable values(李四)select identity转载于:https://www.cnblogs.com/bnjbl/archive…

SQL Server开发人员应聘常被问的问题妙解汇总

目前在职场中很难找到非常合格的数据库开发人员。我的一个同事曾经说过:“SQL开发是一门语言&#xff0c;它很容易学&#xff0c;但是很难掌握。” 在面试应聘的SQL Server数据库开发人员时&#xff0c;我运用了一套标准的基准技术问题。下面这些问题是我觉得能够真正有助于淘汰…

little w and Soda(思维题)

链接&#xff1a;https://ac.nowcoder.com/acm/contest/297/A 来源&#xff1a;牛客网 时间限制&#xff1a;C/C 1秒&#xff0c;其他语言2秒 空间限制&#xff1a;C/C 262144K&#xff0c;其他语言524288K 64bit IO Format: %lld 题目描述 不知道你听没听说过这样一个脑筋急…

[导入]实时数据库的经典书

有个朋友给我来了一封邮件&#xff0c;在邮件中&#xff0c;他这样写到&#xff1a;“国外的实时数据库来势汹汹&#xff0c;价格一路上扬&#xff1b;想当初eDNA 2003年刚到中国时也就是二、三十万左右&#xff0c;现在报价已经百万以前了。心里也总个一个结&#xff0c;难道这…

关于CSS(3)

盒子模型 盒子 盒子关系&#xff08;标准文档流&#xff09; 行内元素。 只可以设置左右外边距。 上下内边距会影响相邻的圆块状元素呢 垂直margin会合并(margin坍陷)元素嵌套的时候&#xff0c;设置子元素的上margin会被父元素抢走&#xff0c; 解决方案&#xff1a;设置父元素…

jMonkey Engine SDK3 中文乱码问题

1. 升级到了jMonkey Engine SDK 3之后出现了一些方框&#xff0c;乱码问题 官方推荐初学者使用jME3 SDK来开发游戏。官方下载地址为&#xff1a; https://github.com/jMonkeyEngine/sdk/releases 2. 问题分析和解决办法 在jME3.1.0之后SDK就有一个bug&#xff0c;菜单上的中文…

第四天上午 休闲假日

第四天晚上要离开沙巴&#xff0c;赶往吉隆坡了&#xff0c;所以这天的活动安排非常简单。 睡了一个舒服觉&#xff0c;起床吃早饭&#xff0c;我胃口还是不好&#xff0c;吃不下Magellan的美味早餐。早餐后我们来到酒店的游泳池旁休息&#xff0c;晒晒太阳、吹吹海风、看看风景…

expect--自动批量分发公钥脚本

1.在使用之前&#xff0c;先安装epel源&#xff0c;yum install expect -y2.写分发脚本&#xff0c;后缀为exp #!/usr/bin/expect set host_ip [lindex $argv 0] spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $host_ip expect {-timeout 60"(yes/no)?" { send "…

java报错MalformedURLException: unknown protocol: c

java报错&#xff1a;MalformedURLException: unknown protocol: c 1. 报错情况&#xff1a; 部分代码&#xff1a; //打开图片path"C:/Users/MyUser/image.jpg" openPictrues(path);public void openPictures(String path,String picName) throws IOException {F…

3.commonjs模块

1.首先建一个math.js exports.add function(a, b){return a b; } exports.sub function(a, b){return a - b; } exports.mul function(a, b){return a * b; } 2.然后建一个app.js 引人math.js var math require(./math); console.log(math);//{ add: [Function], sub: [Fu…

推荐一个关于.NET平台数据结构和算法的好项目

http://www.codeplex.com/NGenerics这是一个类库&#xff0c;它提供了标准的.NET框架没有实现的通用的数据结构和算法。值得大家研究。转载于:https://www.cnblogs.com/didasoft/archive/2007/07/05/806758.html

JSF和Struts的区别概述

据说JSF的主要负责人就是struts的主要作者&#xff0c;所以二者的相似点还是有很多的。 都采用taglib来处理表示层&#xff1a;在jsp页面中&#xff0c;二者都是采用一套标记库来处理页面的表示和model层的交互。 二者都采用了bean来作为和jsp页面对应的model层。该model层保存…

This和Super关键字的对比

this和Super关键字this和Super关键字的对比Super关键字的用法如下&#xff1a;1. super关键字代表了父类空间的引用&#xff1b;2. super关键字的作用&#xff1a;3. super关键字调用父类构造方法要注意的事项&#xff1a;this关键字的用法如下&#xff1a;1.了解没有 this 关键…

SQL Server 2005下的分页SQL

其实基本上有三种方法&#xff1a;1、使用SQL Server 2005中新增的ROW_NUMBER几种写法分别如下&#xff1a; 1SELECTTOP20*FROM(SELECT2ROW_NUMBER() OVER(ORDERBYNamec) ASRowNumber,3*4FROM5dbo.mem_member) _myResults6WHERE7RowNumber >1000081SELECT*FROM(SELECT2ROW_N…

Oozie 配合 sqoop hive 实现数据分析输出到 mysql

文件/RDBMS -> flume/sqoop -> HDFS -> Hive -> HDFS -> Sqoop -> RDBMS 其中&#xff0c;本文实现了 使用 sqoop 从 RDBMS 中读取数据(非Oozie实现&#xff0c;具体错误将在本文最后说明)从 Hive 处理数据存储到 HDFS使用 sqoop 将 HDFS 存储到 RDBMS 中 1.…

关于eclipse的注释和反注释的快捷键

使用eclipse那么久了额&#xff0c;对注释和反注释的快捷键一直很模糊&#xff0c;现在记下来&#xff0c;方便查看。 注释和反注释有两种方式。如对下面这段代码片段&#xff08;①&#xff09;进行注释&#xff1a; private String value; private String count; public voi…

DNN和IBatis.Net几乎同时发布新版本

DotNetNuke发布了最新的版本4.5.0&#xff0c;确实让人期待了很久&#xff0c;据说这个版本在性能上有很大的提升。 IBatis.NET几乎在同一时间也发布了新版本DataMapper 1.6.1&#xff0c;也有不少的改进。 项目中使用到的这两个东西几乎同时发布新版本&#xff0c;振奋人心啊&…

Unity 2D物体移动

一&#xff0c;设置 二&#xff0c;脚本 1&#xff0c;PlayerController using System.Collections; using System.Collections.Generic; using UnityEngine;public class PlayerController : MonoBehaviour {private Rigidbody2D m_rg;public float MoveSpeed;public float J…

朱敏:40岁创业如何成就绝代明星?(五)

来源 中国企业家 东方元素是网讯内涵里不可忽视的一部分 如果有机会拜访网讯的美国总部&#xff0c;你会发现这是 一家带着醒目美国特色IT公司&#xff0c;很难说出它与其他 硅谷公司的不同。但在你视野所不能及的地方&#xff0c;朱敏 与苏布拉在驾驭它的方式中输入…

print、printf、println在Java中的使用

print、printf、println在Java中的使用 文章目录print、printf、println在Java中的使用一、println在JAVA中常常使用System.out.pirntf()&#xff1b;的输出格式。二、print在JAVA中常常使用System.out.pirnt();的输出格式。三、printf在JAVA中常常使用System.out.printf();的格…

(转) SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解

springboot采纳了建立生产就绪spring应用程序的观点。 Spring Boot优先于配置的惯例&#xff0c;旨在让您尽快启动和运行。在一般情况下&#xff0c;我们不需要做太多的配置就能够让spring boot正常运行。在一些特殊的情况下&#xff0c;我们需要做修改一些配置&#xff0c;或者…

iexpress全力打造“免检”***

IExpress小档案出身:Microsoft功能:专用于制作各种 CAB 压缩与自解压缩包的工具。由于是Windows自带的程序&#xff0c;所以制作出来的安装包具有很好的兼容性。它可以帮助***传播者制造不被杀毒软件查杀的自解压包&#xff0c;而且一般情况下还可伪装成某个系统软件的补丁(如I…

java 稀疏数组和二维数组转换,并保存稀疏数组到文件后可以读取

稀疏数组和二维数组转换 稀疏数组&#xff1a;当一个数组中大部分元素为0&#xff0c;或者为同一个值的数组时&#xff0c;可以使用稀疏数组来保存该数组 稀疏数组的处理方法&#xff1a; 记录数组一共有多少行&#xff0c;有多少个不同的值把具有不同值得元素的行列及值记录在…

springboot redis配置

1、引入maven依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId> </dependency> 2、redis连接配置 spring:redis:host: 10.220.1.41port: 6379timeout: 10000passwor…

C# 根据节点索引访问XML配置文件

查了一些&#xff0c;都是根据XML属性来访问指定节点&#xff0c;我这想根据节点索引来访问XML 首先上XML样式 1 <?xml version"1.0" encoding"utf-8" ?> 2 <FeatureClasses> 3 <FeatureClass name "t_room"></Feat…

ASP.NET DEMO 14: 如何在 GridView/DataGrid 模板列中使用自动回发的 CheckBox/DropDownList

有时候希望在 GridView 模板中使用自动回发的 CheckBox &#xff08;autopostbacktrue) &#xff0c;但是 CheckBox 没有 CommandName 属性&#xff0c;因此也就无法在 GridView.RowCommand 事件中处理&#xff0c;并且如何获取当前 GridView 行信息呢&#xff1f;我们可以选择…

BI.寒号鸟请吃烧烤/意外入手“speed- dear friends vol.1”/入手“鲍家街43号”/我爱红红/我爱红红...

先说&#xff0c;昨天下午&#xff0c;在逛完西北政法的乐图后&#xff0c;辗转到了高新区&#xff0c;见到了在经典论坛认识的热情的热心的热烈的寒号鸟兄弟&#xff0c;而notus本人则感动的热泪盈眶&#xff0c;想不到在遥远的西安&#xff0c;都有人惦记着我 T_T附上我们的合…

数据结构----单链表增删改查

单链表的增删改查 一、链表&#xff08;Linked List&#xff09; 链表是有序列表&#xff0c;以节点的方式来存储的&#xff0c;链式存储&#xff1b;每个节点包含data域&#xff0c;next域&#xff1a;指向下一节点&#xff1b;链表的各个节点不一定是连续存储&#xff1b;链…