让小车红灯停,绿灯行出现以下情况不能解决:2 \( }5 N6 F( S: k; V0 ?
1)is
( Y" P6 w7 H8 V, xdo; f. D3 G+ M% _' |% [ R; L
if light="green"
7 W6 Z, U& t. K! N then @.stopped:=false;
, x) m' }6 ^7 ]6 ]1 M6 Z else
- x7 _' R8 R6 ?- D @.stopped:=true;
; L* ^3 l3 ?5 L end;( C# {+ m' s) t
end;
+ w1 h% W/ z4 N( y6 M6 g4 F0 V% Q5 K u8 `% N4 S+ x- v: S3 r
用if else then,只会停止,不能运动,停了以后Method 不会再被调;
! J4 y! X' }6 ]( L* O; O2)is+ E1 r6 S" q0 f0 B: O d+ x
do
4 X$ ^; e6 ?( V if light="green"
% s' T9 X+ d1 |2 a then @.stopped:=false;
7 h d, S1 T, N6 t) ^ else" h9 m3 M! E, L% N( s
@.stopped:=true;8 }- a1 n% A* Q# U: M0 d7 z
end;) U$ ~9 n) @# `' b K
@.move;--加了这个以后则不管红绿灯都是一直运动的,
8 A) j, T7 _- P5 gend;3 ?4 U* u8 f/ d% K- g g' V
3)用ispect-when-when-else,出现同样的情况
( ^+ y0 ~8 I" N9 S/ f& }/ y求高手解决。 |