~ubuntu-branches/ubuntu/vivid/inform/vivid

« back to all changes in this revision

Viewing changes to html/answers1/answer39.html

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2008-05-26 22:09:44 UTC
  • mfrom: (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526220944-ba7phz0d1k4vo7wx
Tags: 6.31.1+dfsg-1
* Remove a considerable number of files from the package
  due to unacceptable licensing terms.
* Repair library symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<HTML><HEAD><TITLE>Answer to Exercise 39</TITLE></HEAD>
2
 
<BODY BGCOLOR="#FFFFFF">
3
 
<TABLE><TR><TD Valign="top"><IMG SRC="../icons/exercise.gif" ALT="??"><TD bgcolor="#FAA89B"><B>ANSWER TO EXERCISE 39</B><TR><TD><TD>
4
 
<P>
5
 
 
6
 
 
7
 
A minimal solution is as follows:
8
 
<PRE>
9
 
Constant SUNRISE  360;  ! i.e., 6 am
10
 
Constant SUNSET  1140;  ! i.e., 7 pm
11
 
Attribute outdoors;     ! Give this to external locations
12
 
Attribute lit;          ! And this to artificially lit ones
13
 
Global day_state = 2;
14
 
[ TimePasses f obj;
15
 
  if (the_time &#62;= SUNRISE &#38;&#38; the_time &#60; SUNSET) f=1;
16
 
  if (day_state == f) rfalse;
17
 
  objectloop (obj)
18
 
  {   if (obj has lit) give obj light;
19
 
      if (obj has outdoors &#38;&#38; obj hasnt lit)
20
 
      {   if (f==0) give obj ~light; else give obj light;
21
 
      }
22
 
  }
23
 
  if (day_state==2) { day_state = f; return; }
24
 
  day_state = f; if (location hasnt outdoors) return;
25
 
  if (f==1) "^The sun rises, illuminating the landscape!";
26
 
 "^As the sun sets, the landscape is plunged into darkness.";
27
 
];
28
 
</PRE>
29
 
 
30
 
In the <TT>Initialise</TT> routine, set the time (using <TT>SetTime</TT>)
31
 
and then call <TT>TimePasses</TT> to set all the <TT>light</TT> attributes
32
 
accordingly.  Note that with this system, there's no need to
33
 
set <TT>light</TT> at all: that's automatic.
34
 
</TABLE>
35
 
<HR>Back to <A HREF="../section18.html#ex39">the exercise in section 18</A><HR>
36
 
<SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright &#169; Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>