而丢失下一个回声忽略相同的值

时间:2017-06-23 14:43:00

标签: php

我尝试创建战斗但我有问题,因为我的代码忽略了当值相同或高2倍时它只显示回显1x

抱歉我的英语不好。

这里是我的代码:

$przeciwnik['predkosc'] = 2;
$gracz['predkosc'] =3;
$tura[walka] = 0;
while($tura[walka] < 30){

while($gracz['predkosc'] > $przeciwnik['predkosc']){
    $przeciwnik['predkosc'] += $przeciwnik['predkosc'];
echo'
attack player';

while($gracz['predkosc'] == $przeciwnik['predkosc']){
echo'
bonus tur';
$gracz['predkosc'] += $gracz['predkosc'];
}

while($przeciwnik['predkosc'] > $gracz['predkosc']){
echo '
other player tur';
$gracz['predkosc'] += $gracz['predkosc'];
}

}

$tura[walka] += 1;
}

输出:

attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player
other player tur
attack player

2 个答案:

答案 0 :(得分:0)

访问以下条目时,您错过了引号:

$tura[walka]

将其替换为

$tura['walka']

代码中的任何地方。

答案 1 :(得分:0)

可以更具体地询问你想问什么。我从你的问题中得到的是你应该改变的问题 while($gracz['predkosc'] > $przeciwnik['predkosc']){ $przeciwnik['predkosc'] += $przeciwnik['predkosc']; echo'attack player';
while($gracz['predkosc'] > $przeciwnik['predkosc']){ $przeciwnik['predkosc'] += $przeciwnik['predkosc']; echo'attack player'; }

从代码中删除第二个最后一个大括号,并解决您的问题。