svn: r9438

This commit is contained in:
Matthias Felleisen 2008-04-23 22:10:18 +00:00
parent 2806c7f863
commit de717e625d
8 changed files with 179 additions and 95 deletions

View File

@ -0,0 +1,74 @@
#lang scribble/doc
@(require scribble/manual
(for-label scheme
teachpack/htdp/arrow))
@title[#:tag "arrow"]{Managing Control Arrows: arrow.ss}
@declare-exporting[teachpack/htdp/arrow]
The teachpack implements a controller for moving shapes across a canvass. A
shape is a class of data for which @scheme[move] and @scheme[draw]
operations can be drawn.
@defproc[(control-left-right
[shape Shape]
[n number?]
[move (-> number? Shape Shape)]
[draw (-> Shape true)]) true]{Moves shape @scheme[n] pixels left
(negative) or right (positive).}
@defproc[(control-up-down
[shape Shape]
[n number?]
[move (-> number? Shape Shape)]
[draw (-> Shape true)]) true]{Moves shape @scheme[n] pixels up
(negative) or down (positive).}
@defproc[(control
[shape Shape]
[n number?]
[move-lr (-> number? Shape Shape)]
[move-ud (-> number? Shape Shape)]
[draw (-> Shape true)]) true]{
Moves shape @scheme[N] pixels left or right and up or down, respectively.}
Example:
@(begin
#reader scribble/comment-reader
(schemeblock
;; A shape is a structure:
;; (make-posn num num)
;; RAD : the radius of the simple disk moving across a canvas
(define RAD 10)
;; move : number shape -> shape or false
;; to move a shape by delta according to translate
;; effect: to redraw it
(define (move delta sh)
(cond
[(and (clear-solid-disk sh RAD)
(draw-solid-disk (translate sh delta) RAD))
(translate sh delta)]
[else false]))
;; translate : shape number -> shape
;; to translate a shape by delta in the x direction
(define (translate sh delta)
(make-posn (+ (posn-x sh) delta) (posn-y sh)))
;; draw-it : shape -> true
;; to draw a shape on the canvas: a disk with radius
(define (draw-it sh)
(draw-solid-disk sh RAD))
;; RUN:
;; this creates the canvas
(start 100 50)
;; this creates the controller GUI
(control-left-right (make-posn 10 20) 10 move draw-it)
))

View File

@ -0,0 +1,42 @@
#lang scribble/doc
@(require scribble/manual
(for-label scheme
teachpack/htdp/docs))
@title[#:tag "docs"]{Manipulating Simple HTML Documents: docs.ss}
@declare-exporting[teachpack/htdp/docs]
The teachpack provides three operations for creating simple ``HTML'' documents:
@deftech{Annotation} An @tech{Annotation} is a symbol that starts with ``<''
and ends in ``>''. An end annotation is one that starts with ``</''.
@defproc[(atom? [x any/c]) boolean?]{Determines whether or not a Scheme value
is a number, a symbol, or a string.}
@defproc[(annotation? [x any/c]) boolean?]{Determines whether or not a Scheme
symbol is a document annotation.}
@defproc[(end-annotation [x (unsyntax @tech{Annotation})]) (unsyntax @tech{Annotation})]{Consumes an annotation
and produces a matching ending annotation.}
@defproc[(write-file [l (list-of atom)]) true]{
Consumes a list of symbols and annotations and prints them out as a
"file".}
Sample session: set teachpack to ``docs.ss''> and click RUN:
@(begin
#reader scribble/comment-reader
(schemeblock
> (annotation? 0)
false
> (annotation? '<bold>)
true
> (end-annotation 0)
end-annotation: not an annotation: 0
> (write-file (list 'a 'b))
a b
))

View File

@ -1,38 +0,0 @@
{ (define LIBNAME "Documents")
(include "head.tinc") }
The teachpack <code>docs.ss</code> provides three operations:
<menu>
<li> <code>{(idx atom?)} : SchemeValue -> bool</code>
<br> which determines whether or not a
Scheme value is a number, a symbol, or a string; <br>
Note: This notion of atom is different from that in the compat.ss library.
<li> <code>{(idx annotation?)} : SchemeValue -> bool</code>
<br> which determines whether or not a
Scheme symbol is a document annotation;
<li> <code>{(idx end-annotation)} : annotation -> annotation</code>
<br>which consumes an annotation and
produces a matching ending; and
<li> <code> {(idx write-file)} : (list-of atom) [string]-> void <code>
<br> which consumes a list of annotated symbols
and prints them out as a "file"; it returns nothing.
if the string argument is present, it is interpreted as a file name:
the words are written to this file; if the file exists, it is deleted
</menu>
<p>Sample session: set teachpack to <code>docs.ss</code> and execute:
<pre>
> (annotation? 0)
#f
> (annotation? '&lt;bold&gt;)
#t
> (end-annotation 0)
end-annotation: not an annotation: 0
> (write-file (list 'a 'b))
a b
</pre>
{(include "foot.tinc")}

View File

@ -0,0 +1,33 @@
#lang scribble/doc
@(require scribble/manual
(for-label scheme
teachpack/htdp/hangman))
@title[#:tag "hangman"]{Hangman : hangman.ss}
@declare-exporting[teachpack/htdp/hangman]
The teachpack implements the callback functions for playing a
@emph{Hangman} game, based on a function designed by a student. The player
guesses a letter and the program responds with an answer that indicates
how many times, if at all, the letter occurs in the secret word.
The teachpack provides all the drawing operations from @secref{draw} for
managing a canvas into which the ``hangman'' is drawn.
@defproc[(hangman [make-word (-> symbol? symbol? symbol? word?)][reveal (-> word? word? boolean?)][draw-next-part (-> symbol? true)]) true]{
Chooses a ``secret'' three-letter word and uses the given functions to
manage the @emph{Hangman} game.}
@defproc[(hangman-list
[reveal-for-list (-> symbol? (list-of symbol?) (list-of symbol?)
boolean?)]
[draw-next-part (-> symbol? true)]) true]{
Chooses a ``secret'' word---a list of symbolic letters---and uses the given
functions to manage the @emph{Hangman} game:
@scheme[reveal-for-list] determines how many times the chosen letter occurs
in the secret word;
@scheme[draw-next-part] is given the symbolic name of a body part and draws
it on a separately managed canvas.
}

View File

@ -1,22 +0,0 @@
{ (define LIBNAME "Hangman")
(include "head.tinc") }
<p>The teachpack <code>hangman.ss</code> provides all the operations that
<code>draw.ss</code> provides and the following two:
<menu>
<li><code> {(idx hangman)} : make-word reveal draw-next-part -> true</code>
<br> that is, it consumes three auxiliary functions:
<code>make-word,</code>
<code>reveal,</code> and
<code>draw-next-part</code>
<br>
<br>
<li><code>{(idx hangman-list)} : reveal-for-list draw-next-part -> true</code>
<br> that is, it consumes
the functions <code>reveal-for-list</code> and <code>draw-next-part</code>.
</menu>
</p>
{(include "foot.tinc")}

View File

@ -12,11 +12,12 @@
@include-section["convert.scrbl"]
@include-section["guess.scrbl"]
@;include-section["mastermind.scrbl"]
@include-section["master.scrbl"]
@include-section["draw.scrbl"]
@;include-section["hangman.scrbl"]
@;include-section["arrows.scrbl"]
@;include-section["documents.scrbl"]
@include-section["hangman.scrbl"]
@include-section["arrow.scrbl"]
@include-section["docs.scrbl"]
@;include-section["files-directories.scrbl"]
@;include-section["graphing.scrbl"]
@;include-section["gui.scrbl"]
@ -24,9 +25,7 @@
@;include-section["arrows-gui.scrbl"]
@;include-section["guess-gui.scrbl"]
@;include-section["elevator.scrbl"]
@;include-section["Simplified Scheme Web Servlets"
@;include-section["Scheme Web Servlets"
@;include-section["queen.scrbl"]
@;include-section["testing.scrbl"

View File

@ -0,0 +1,24 @@
#lang scribble/doc
@(require scribble/manual
(for-label scheme
teachpack/htdp/master))
@title[#:tag "master"]{MasterMinding : master.ss}
@declare-exporting[teachpack/htdp/master]
The teachpack implements GUI for playing a simple master mind-like game,
based on a function designed by a student. The player clicks on two colors
and the program responds with an answer that indicates how many colors and
places were correct.
@defproc[(master [check-guess (-> symbol? symbol? symbol? symbol? boolean?)]) symbol?]{
Chooses two ``secret'' colors and then opens a graphical user interface for
playing @emph{MasterMind}. The player is prompted to choose two colors, via
a choice tablet and mouse clicks. Once chosen, @scheme[master] uses
@scheme[check-guess] to compare them.
If the two guesses completely match the two secret colors,
@scheme[check-guess] must return @scheme['PerfectGuess]; otherwise it must
return a different, informative symbol.}

View File

@ -1,28 +0,0 @@
{ (define LIBNAME "Mastermind")
(include "head.tinc") }
<p>The teachpack <code>master.ss</code> provides the operation
<code>master</code>. It implements a GUI for playing a simple
master mind-like game. The player clicks on two colors and the
program responds with an answer that indicates how many colors
and places were correct.</p>
<p>The function <code>master</code> consumes the function
<code>check-guess</code>, which is the key component of
TeachMasterMind. The function <code>check-guess</code> consumes the two
colors that the player guessed and the two players that the master chose
(randomly at the beginning of the game). It compares the colors and
produces an appropriate symbol. </p>
<p>The teachpack provides only one operation:
<menu>
<li><code>{(idx master)} : check-guess -> symbol; </code> <br>
It prompts the user for two colors (symbols) and uses
<code>check-guess</code> to play mastermind. <br>
If the guesses completely match the set-up, <code>check-guess</code> must
return <code>'PerfectGuess</code>; otherwise it must return a different,
informative symbol.
</menu>
{(include "foot.tinc")}