今天所讲的内容以及已制作完成的游戏

今天把猜数字的游戏做完了,计算器也制作了大部分,还讲了冒泡排序的方法。对这些内容大部分都懂,就只有一些小细节还不是很理解。


 _mainUI:null,       //场景文件
    _value:null,        //答案
    _mesLab:null,       //提示文本
    _inputLab:null ,        //输入数字
    _canleBtn:null,     //取消按钮
    _okBtn:null,        //确定按钮
    ctor:function () {
        this._super();
        this._init();
    },
    _init:function(){
        this._mainUI =ccs.load(res.main_json).node;
        this.addChild(this._mainUI);
        this._value=1500+parseInt(Math.random()*1001);      //在1500到2500之间随机取一个数
        cc.log( this._value);
        this._mesLab=this._getWidgetByName(this._mainUI,"mes_lab");
        this._inputLab=this._getWidgetByName(this._mainUI,"input_Lab");
        this._canleBtn=this._getWidgetByName(this._mainUI,"cancel_Btn");
        this._okBtn=this._getWidgetByName(this._mainUI,"ok_Btn");
        this._inputLab.setString("");       //设置文本内容
        this._mesLab.setString("");     //设置文本内容
        this._okBtn.addTouchEventListener(this._inputHandler.bind(this),this._mainUI);
        this._canleBtn.addTouchEventListener(this._inputHandler.bind(this),this._mainUI);
    },
    _inputHandler:function(sender,type){
        if(type==ccui.Widget.TOUCH_ENDED){
            if(sender.name=="ok_Btn"){
                this._checkResult();
            }else if(sender.name=="cancel_Btn"){
                this._inputLab.setString("");
            }
        }
    },
    _checkResult:function(){
        var value =parseInt(this._inputLab.getString());
        if(!value){
            this._mesLab.setString("请输入正确的格式");
            return;
        }
        if(this._value>value)this._mesLab.setString("不好意思,太小了");
        else if(this._value<value)this._mesLab.setString("不好意思,太大了");
        else this._mesLab.setString("你答对了");
    },
    //获取组件
    _getWidgetByName:function(par,name){
        return  ccui.helper.seekWidgetByName(par,name);
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值