定向越野(添加任务信息和根据坐标位置触发游戏)

1.首先获取任务地点的实际坐标值,用hashmap存储

HashMap<Integer, double[]> hashMap = new HashMap<>();
hashMap.put(0, new double[]{xxx.xxxx,36.xxxx});//三区
hashMap.put(1, new double[]{xxx.xxxx,36.xxxx});//一号食堂
hashMap.put(2, new double[]{xxx.xxxx,36.xxxx});//图书馆


2.创建任务提示弹窗

使用户接受任务之后随机定位目标地点,

missionButton = (Button) findViewById(R.id.missionButton);
        missionButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!jieshourenwu){
                    dia1 = new AlertDialog.Builder(LocationDemo.this).setTitle("是否接受任务?")
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton) {
                                    jieshourenwu = true;
                                    dia2 = new AlertDialog.Builder(LocationDemo.this).setTitle("任务地点").setMessage(missionLocation[didian])
                                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                                public void onClick(DialogInterface dialog, int whichButton) {

                                                }
                                            })
                                            .show();
                                }
                            })
                            .show();
                }

3.每隔一段时间获取自己的位置,判断是否在任务地点的区域内

for(int i = 0;i<missionLocation.length;i++){
    //                double longtitude = hashMap.get(i)[0];
    //                double latitude = hashMap.get(i)[1];
                    if(Math.abs(location.getLongitude()-hashMap.get(i)[0])<=0.0003 && Math.abs(location.getLatitude()-hashMap.get(i)[1])<=0.0003) {
                        if((!kaishirenwuDialog.isShowing())&&i==didian){
                            Toast.makeText(LocationDemo.this, "你已到达"+missionLocation[i],Toast.LENGTH_SHORT).show();
                            kaishirenwuDialog.show();
                        }

                        break;
                    } else{
                        //Toast.makeText(LocationDemo.this, location.getLongitude()+"  ,  "+location.getLatitude(),Toast.LENGTH_SHORT).show();
                    }
                }

如果到达地点,弹出开始任务框

//开始任务
        AlertDialog.Builder kaishirenwuDialogBuilder = new AlertDialog.Builder(LocationDemo.this).setTitle("是否开始任务?")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        double mi = Math.random() * 3;
                        int missiond = (int) mi;//3个任务
                        switch (missiond){
                            case 0: {
                                kaishirenwuDialog.dismiss();
                                dia1.dismiss();
                                dia2.dismiss();
                                startActivityForResult(new Intent(LocationDemo.this, unityactivity.class), 1);
                                break;
                            }
                            case 1: {
                                kaishirenwuDialog.dismiss();
                                dia1.dismiss();
                                dia2.dismiss();
                                startActivityForResult(new Intent(LocationDemo.this, HandgestureActivity.class), 4);

                                break;
                            }
                            case 2: {

                                break;
                            }
                        }
                    }
                });
        kaishirenwuDialog = kaishirenwuDialogBuilder.create();

最后进行页面跳转



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值