泰拉2048

174 阅读2分钟

泰拉2048

联系电话:13540033103

联系邮箱:765970680@qq.com

钉钉:13540033103

代码地址:GitHub/Soldoros/2048

1.png

泰拉2048是基于多年前的算法,重新架构系统,设计界面,新的页面更加清晰,整洁,方便大家玩乐,不会有多余的操作。感谢为此游戏提出宝贵的意见和建议!

使用到的第三方工具

pod 'AFNetworking'
pod 'YYKit'

#友盟
pod 'UMCommon'
pod 'UMDevice'

一、游戏整体界面

1.plist文件需要设置权限 https配置 访问相机 麦克风 相册


[App Transport Security Settings -> Allow Arbitrary Loads + YES ]

[App Transport Security Settings -> Allow Arbitrary Loads in Web Content + YES]

[Privacy - Camera Usage Description 是否允许此App使用你的相机]

[Privacy - Location Always and When In Use Usage Description 系统想要访问您的位置]

[Privacy - Location When In Use Usage Description 系统想要访问您的位置]

[Privacy - Microphone Usage Description 系统想要访问您的麦克风]

[Privacy - Photo Library Additions Usage Description 系统需要访问您的相册]

[Privacy - Photo Library Usage Description 系统需要访问您的相册]

2.在全局代理单利中直接调用解渴


self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    self.window.backgroundColor = _config.backGroundColor;

    [self.window makeKeyAndVisible];

    _config = [SSConfigManager shareManager];

    self.window.rootViewController = [GamesRootController new];

3.游戏结束界面



//游戏结束 跳转  280*340

-(void)gotoGameOver

{

    [_timer invalidate];

    for(int i=0;i<[_allTiled count];++i){

        if(_numScore < ((MoveTieldView *)_allTiled[i]).number){

            _numScore = ((MoveTieldView *)_allTiled[i]).number;

        }

    }

    NSString *str1 = numLabel[1].text;

    NSString *str2 = numLabel[0].text;

    NSString *str3 = [NSString stringWithFormat:@"%ld",(long)_numScore];

    GameUserDefault *user = [GameUserDefault shareGameUserDefault];

    user.dataArr = @[str1,str2,str3];

    _gameOver = [[GameOverView alloc]initWithFrame:makeRect(0,0,SCREEN_Width, SCREEN_Height)];

    _gameOver.delegate = self;

    [self.view addSubview:_gameOver];

}

4、核心算法 四个方向的滑动算法类似

//向上滑动

-(void)moveUp{

    for(int col=0;col<GAME_COLS;++col){

        int hit=0;

        for(int row=0;row<GAME_ROWS;++row){

            if(map[row][col]>0)

            {

                for(int row1=row;row1>0;--row1)

                {

                    if(map[row1-1][col]==0)

                    {

                        map[row1-1][col]=map[row1][col];

                        map[row1][col]=0;

                        [[_allTiled objectAtIndex:(map[row1-1][col]-1)] moveTox:row1-1 moveToy:col];

                    }

                    else

                    {

                        MoveTieldView *tiledObj = [_allTiled objectAtIndex:(map[row1-1][col]-1)];

                        int numObj = tiledObj.number;

                        MoveTieldView *tiledNow = [_allTiled objectAtIndex: (map[row1][col]-1)];

                        int numNow = tiledNow.number;

                        if(numObj==numNow && hit%2==0)

                        {

                            //消除音乐播放

                            _isMoveClearn = YES;

                            ++hit;

                            _score +=numObj*2;

                            [tiledObj doubleNumber];

                            [tiledNow removeFromSuperview];

                            [_allTiled removeObjectAtIndex:(map[row1][col]-1)];

                            _sum--;

                            NSInteger index = map[row1][col];

                            for(int r=0;r<GAME_ROWS;++r)

                            {

                                for(int c=0;c<GAME_COLS;++c)

                                {

                                    if(map[r][c]>index)

                                    {

                                        map[r][c]--;

                                    }

                                }

                            }

                            map[row1][col]=0;

                        }

                        else if(hit!=0)

                        {

                            ++hit;

                        }

                        break;

                    }

                }

            }

        }

    }

}

联系电话:13540033103

联系邮箱:765970680@qq.com

钉钉:13540033103

代码地址:GitHub/Soldoros/SSChat