-- Mobile version of Medusa

deferred class MOBILE_MEDUSA

inherit

  AUTO_MOBILE
  undefine
    react
  redefine
    init, strategy, win, build_record, 
    customized_init, time_remaining, restart  
  end

  MEDUSA
  rename
    vacate as depart, occupy as visit
  undefine
    depart, init, clear, react_to_first_movement
  redefine
    restart, win, build_record, customized_init
  end


feature{NONE}

  strategy : SENTRY

  period : INTEGER is 200

  init( r : like room ; c : like northwest ) is
  do
    {AUTO_MOBILE}precursor( r, c )
    !!strategy.make( Current )
    strategy.set_direction( initial_direction )
--    !!move_event.make_periodic( Current, period )
  end

  can_move : BOOLEAN is
  do
     Result := is_moving and not is_rock
  end

feature -- save/restore

  build_record is
-- 1 through ( 6 or 7 ) from AUTO_MOBILE
-- 8  vanished from MEDUSA
-- 9  is_rock from MEDUSA
-- 10 strategy direction
-- 11 initial_direction
  do
    {AUTO_MOBILE}precursor
    {MEDUSA}precursor
    record.extend( strategy.direction )
    record.extend( initial_direction )
  ensure then
    proper_num_rec: record.count > 9
  end

feature{NONE} -- save/restore

  customized_init( r : like room ; pr : like record ) is
  do
    {AUTO_MOBILE}precursor( r, pr )
    {MEDUSA}precursor( r, pr )
    !!strategy.make( Current )

    if is_moving then
      pr.forth
      strategy.set_direction( pr.item )
    end
    pr.forth
    initial_direction := pr.item
  end

  time_remaining : INTEGER is
  -- Time remaining before my current event occurs.
  do
    Result := move_event.absolute_time - clock.milliseconds
  end

feature

  initial_direction : INTEGER

  win is
  do
    {AUTO_MOBILE}precursor
    {MEDUSA}precursor
  end

  restart is
  do
    {AUTO_MOBILE}precursor
    become_medusa
    appear
    strategy.set_direction( initial_direction )
  end

end 
