Example #1
0
keytable['c'] = keytable['C'] = function () {
    if (!computer.attack.isEnabled()) {
        console.write('Attack computer enabled.');
        computer.attack.enable();
    } else {
        console.write('Attack computer disabled.');
        computer.attack.disable();
    }
};
Example #2
0
/* Deals damage to a component of the starship.  */
function dealDamage() {
    var st = '';
    var rand = 0;

    candidates.length = 0;

    // Photons
    if (photons.canFireLeft()) {
        if (photons.canFireRight()) {
            candidates.push(PHOTONLEFT);
            candidates.push(PHOTONRIGHT);
            candidates.push(PHOTONS);
        } else {
            candidates.push(PHOTONLEFT);
        }
    } else {
        if (photons.canFireRight()) {
            candidates.push(PHOTONRIGHT);
        }
    }
    // Engines
    st = engines.colorState();
    if (st === 'green') {
        candidates.push(ENGINESDAMAGE);
    }
    if (st !== 'red') {
        candidates.push(ENGINESDESTROY);
    }
    // Shield
    st = shield.colorState();
    if (st === 'green' && !noviceMode) {
        candidates.push(SHIELDSDAMAGE);
    }
    if (st !== 'red' && !noviceMode) {
        candidates.push(SHIELDSDESTROY);
    }
    // Computer: As a special case, don't
    // allow computer to be destroyed if
    // LRS is already destroyed.
    if (!computer.attack.isDestroyed()) {
        if (!computer.instruments.isDestroyed()) {
            candidates.push(COMPUTERATTACK);
            candidates.push(COMPUTERINSTRUMENTS);
            if (lrs.colorState() !== 'red') {
                candidates.push(COMPUTER);
            }
        } else {
            if (lrs.colorState() !== 'red') {
	        candidates.push(COMPUTERATTACK);
            }
        }
    } else {
        if (!computer.instruments.isDestroyed()) {
            if (lrs.colorState() !== 'red') {
                candidates.push(COMPUTERINSTRUMENTS);
            }
        }
    }
    // LRS: If the computer is destroyed, don't
    // let the LRS be completely destroyed.
    st = lrs.colorState();
    if (st === 'green') {
        candidates.push(LRSDAMAGE);
    }
    if (st !== 'red' && computer.colorState() !== 'red') {
        candidates.push(LRSDESTROY);
    }
    // Radio
    st = chart.colorState();
    if (st === 'green') {
        candidates.push(RADIODAMAGE);
    }
    if (st !== 'red') {
        candidates.push(RADIODESTROY);
    }

    if (candidates.length === 0) {
        // This can only happen in NOVICE mode, where
        // the shield is "perfect".  However, if all
        // other components are damaged, then the shield
        // can be destroyed.
        if (shield.colorState() === 'green') {
            candidates.push(SHIELDSDAMAGE);
        }
        candidates.push(SHIELDSDESTROY);
    }

    rand = Math.floor(Math.random() * candidates.length);
    applyDamage[candidates[rand]]();
}
Example #3
0
applyDamage[COMPUTER] = function () {
    computer.attack.destroy();
    computer.instruments.destroy();
};