0

私はこの信じられないほどの言語に慣れていないので、戦闘の進行状況をゆっくりと明らかにできる関数を作成しようとしています. 関数を早い段階で作成し、setTimeout で関数を宣言するだけで、書き直す必要はありません。私が作成したあまり良くないコードは次のとおりです。

var health=100;
var ehealth=100;
var atk;
var eatk;

function attack(x){
    x=Math.floor(Math.random()*11);
    atk=x;
    ehealth=ehealth-atk
    document.write('Enemy Health:' + '   ' + ehealth + '   ')
}

function eattack(x){
    x=Math.floor(Math.random()*11);
    eatk=x;
    health=health-eatk
    document.write('Health:' + '   ' + health )
}

function dead(){
    if(health<=0){
        document.write('You Lose');
    }else{
        if(ehealth<=0){
            document.write('You Win');
        }
    }
}

function battle(){
    document.write('Enemy Health:' + '&nbsp; &nbsp;' + ehealth + '&nbsp; &nbsp; Health: &nbsp; &nbsp;' + health + '<br/>\n')
    while(health>=0&&ehealth>=0){
        setTimeout(attack(0),400)
        setTimeout(eattack(0),400)
        document.write("<br/>\n");
        dead();
    }
}

ヘルプ!

4

1 に答える 1