让小车红灯停,绿灯行出现以下情况不能解决:! ]5 x8 W7 y# C s; @
1)is
$ w. v' g$ @# W& s7 y- \7 A1 Fdo% o3 B: ~7 d! k f3 }: h6 N
if light="green"
! p5 B9 J- D7 ^- }+ `# G, c then @.stopped:=false;- S5 g+ j" a0 P) t2 j6 ?7 ]3 W) Q
else% S8 P; Q! [3 `1 R
@.stopped:=true;
$ x7 H1 a9 R8 \( _0 X {; p end;
6 d6 p# ]1 t5 S$ tend;+ F6 {6 A' p. J- ~. y
) e* a+ }/ o. c) r- I. R用if else then,只会停止,不能运动,停了以后Method 不会再被调;' ~( x( l2 N: ~4 X! y V
2)is
7 `6 n, q: z0 [5 K, p6 E/ fdo
# e4 i7 b9 c" K' }, l! h if light="green"
* C8 E' a( m. A' M5 w5 }: @ then @.stopped:=false;% R7 L3 k6 L! @5 R
else# T- B7 p( G6 s& N, U" {3 {& W" M0 m
@.stopped:=true;
. V0 n x% ~- `9 Q; p% h end;
$ r7 V, N, _5 O: s@.move;--加了这个以后则不管红绿灯都是一直运动的,7 b3 ?7 ^3 K0 d! Y
end;0 u3 o( e, Z' }0 t) T Y
3)用ispect-when-when-else,出现同样的情况
4 f2 a$ z8 K. Q/ s( t c求高手解决。 |