// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // isFlirting: false,
        // timer: 0,
    },
    
    flirtingAction: function() {
        // 1.把手放上去 3.过不定时时间，女生showMessage ‘老师，这里有人骚扰’
        return cc.moveTo(0.1, cc.p(-30, 70))
        // 2.加分
        // let intervalId = setInterval(()=> {
        //     // 加上跟老师的判断

        //     if(isFlirting && !teachers.isSwivel) {
        //         this.config.score = this.config.score + this.timer++
        //     } else {
        //         clearInterval(intervalId)
        //     }
        // }, 1000)
        // 3
        // femaleStudent.showMessage(messageList[0,1,2])
    },

    endFlirtingAction: function() {
        return cc.moveTo(0.1, cc.p(0, 0))
    },

    setTouchScreenControl: function() {
        var self = this
        // 添加屏幕点击事件监听
        // 当触碰到屏幕时，设置抚摸开关打开，并执行抚摸方法
        self.node.on(cc.Node.EventType.TOUCH_START, (event) => {
        // self.node.on(cc.Node.EventType.MOUSE_DOWN, (event) => {
            self.isFlirting = true
            self.node.runAction(self.flirtingAction)
        })

        // 停止触摸屏幕时，设置抚摸开关关闭，停止抚摸
        self.node.on(cc.Node.EventType.TOUCH_END, (event) => {
        // self.node.on(cc.Node.EventType.MOUSE_UP, (event) => {
            self.isFlirting = false
            self.node.runAction(self.endFlirtingAction)
        })
    },

    // LIFE-CYCLE CALLBACKS:
    onLoad () {
        // 初始化抚摸的动作
        this.flirtingAction = this.flirtingAction()
        // 初始化停止抚摸的动作
        this.endFlirtingAction = this.endFlirtingAction()
        // this.node.runAction(this.flirtingAction)
        // 抚摸的开关
        this.isFlirting = false
        // 抚摸停留时常
        this.timer = 0

        // 初始化屏幕点击监听
        this.setTouchScreenControl()

    },

    start () {

    },

    update (dt) {
        if (this.isFlirting) {
            this.game.gainScore()
        }
    },
});
