让小车红灯停,绿灯行出现以下情况不能解决:! Y' e% v1 t: e% A7 f. g
1)is
3 A( L$ h# M* h q% ydo
0 h( K* h$ J. O; Z: ` if light="green"0 ^1 K" T4 Z. [
then @.stopped:=false;8 h) ]7 m x, w3 f9 [" _
else
# x2 K/ h7 z9 \- k }) k& `0 V5 j @.stopped:=true;5 r4 A6 y+ _, I; d+ L% J
end; n, t4 n/ f$ G# p- w, x7 g! [
end;+ K9 W! |3 o; ?. p# b
) x) b6 G* R7 N L/ K
用if else then,只会停止,不能运动,停了以后Method 不会再被调;
1 p! D# r/ d g/ ~/ |1 q2)is: @9 w) f/ }1 v- n3 ~. p0 J* U( Q
do
2 }6 ]* N* h" r, \: r1 q* y5 V if light="green"' B4 B# U! l( f/ g! h6 t
then @.stopped:=false;
; B; g9 b e7 c3 W else
( f- t. t! a( W. Q- c2 ]7 D @.stopped:=true;, t* g" \2 r5 k; B
end;$ M' `" S. ^2 a
@.move;--加了这个以后则不管红绿灯都是一直运动的,
" V: _8 J1 N# _end;2 S: F* q5 e: k& R1 o& J
3)用ispect-when-when-else,出现同样的情况
, N1 O! ]: n0 U1 B3 G求高手解决。 |