代码之家  ›  专栏  ›  技术社区  ›  Luke

Jackpot游戏未返回结果文本

  •  0
  • Luke  · 技术社区  · 7 年前

    背景资料:

    创建的Jackpot游戏,在每轮结束时,将显示赢或输的文本

    所做的工作:

    创建了一个switch语句来检查每个插槽的元素。创建了一个条件检查语句,以检查所有3个插槽是否相同-将是赢的,否则将是输的

    问题:

    在每次旋转结束时-没有赢家或输家的更新文本:

    代码:

    var BLURB_TBL = [
    'JACKPOT!'
    ];
    switch (this.state) {
    case 1: // all slots spinning
    if (now - this.lastUpdate > RUNTIME) {
        this.state = 2;
        this.lastUpdate = now;
    }
    break;
    case 2: // slot 1
    this.stopped1 = _check_slot( this.offset1, this.result1 );
    if ( this.stopped1 ) {
        this.speed1 = 0;
        this.state++;
        this.lastUpdate = now;
    }
    break;
    case 3: // slot 1 stopped, slot 2
    this.stopped2 = _check_slot( this.offset2, this.result2 );
    if ( this.stopped2 ) {
        this.speed2 = 0;
        this.state++;
        this.lastUpdate = now;
    }
    break;
    case 4: // slot 2 stopped, slot 3
    this.stopped3 = _check_slot( this.offset3, this.result3 );
    if ( this.stopped3 ) {
        this.speed3 = 0;
        this.state++;
    }
    break;
    case 5: // slots stopped 
    if ( now - this.lastUpdate > 3000 ) {
        this.state = 6;
    }
    break;
    case 6: // check results
    
    if ((that.items1[that.result1].id == 'gold-64' && that.items2[that.result2].id == 'gold-64' && that.items3[that.result3].id == 'gold-64') || (that.items1[that.result1].id == 'cash-64' && that.items2[that.result2].id == 'cash-64' && that.items3[that.result3].id == 'cash-64') || (that.items1[that.result1].id == 'energy-64' && that.items2[that.result2].id == 'energy-64' && that.items3[that.result3].id == 'energy-64') || (that.items1[that.result1].id == 'staff-64' && that.items2[that.result2].id == 'staff-64' && that.items3[that.result3].id == 'staff-64') || (that.items1[that.result1].id == 'build-64' && that.items2[that.result2].id == 'build-64' && that.items3[that.result3].id == 'build-64') || (that.items1[that.result1].id == 'goods-64' && that.items2[that.result2].id == 'goods-64' && that.items3[that.result3].id == 'goods-64')){
        $('#status').text(BLURB_TBL);
    }else {
        $('#status').text("GOOD TRY!!");
    }
    
    
    
    
    this.state = 7;
    break;
    case 7: // game ends
    break;
    default:
    }
    this.lastupdate = now;
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   f00d    7 年前

    您缺少一个返回函数。

    对于此示例:

    function a() {
        alert('A');
    }
    //alerts 'A', returns undefined
    
    function b() {
        alert('B');
        return a;
    }
    //alerts 'B', returns function a
    
    function c() {
        alert('C');
        return a();
    }
    //alerts 'C', alerts 'A', returns undefined
    
    alert("Function 'a' returns " + a());
    alert("Function 'b' returns " + b());
    alert("Function 'c' returns " + c());