;;; File:
;;;   bizz-buzz-one.ss
;;; Version:
;;;   1.0 of February 2002
;;; Author:
;;;   Samuel A. Rebelsky
;;; Contents:
;;;   A starting point for a version of the Bizz-Buzz game.  In this
;;;   version, the program reports on all the things to say for numbers
;;;   between two values (start and finish), inclusive.
;;; Organization:
;;;   Preparation - Stuff I need to do to get started
;;;   Page Generators - Procedures for generating specific kinds of
;;;     pages (when given particular values)
;;;   Interface - Stuff to extract important values and then
;;;     call the page generators.  You'll find (page) here.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Preparation

;;; Look!  We're going to use Sam's Web Utilities!
(load "/home/rebelsky/Web/Scheme/webutils.ss")


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Page Generators

;;; Procedure:
;;;   bizz-buzz-page
;;; Parameters:
;;;   buzzer, the value used in selecting bizzes and buzzes
;;;   start, the initial value
;;;   finish, the final value
;;; Purpose:
;;;   Generates an HTML page that plays Bizz-Buzz for all numbers
;;;   between start and finish, using buzzer as the number to
;;;   select when to say "Bizz" and when to say "Buzz".
;;; Produces:
;;;   page-code, a string that corresponds to that page.
;;; Preconditions:
;;;   buzzer must be an integer between 1 and 9, inclusive.
;;;   start and finish must be positive integers.
;;;   start <= finish.
;;; Postconditions:
;;;   page-code is valid HTML.
;;;   page-code describes a game of Bizz-Buzz for numbers between
;;;     start and finish.
(define bizz-buzz-page
  (lambda (buzzer start finish)
    (make-page 
      (head "Bizz Buzz")
      (body (string-append
              (heading 1 "Bizz Buzz")
              (string #\newline)
              (paragraph (string-append "Um ... I don't know how to play "
                                        "the game Bizz-Buzz with buzzer "
                                        (number->string buzzer)
                                        ", starting value "
                                        (number->string start)
                                        ", and final value "
                                        (number->string finish)
                                        ".")))))))
               
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Interface

;;; Procedure:
;;;   page
;;; Parameters:
;;;   None
;;; Purpose:
;;;   Builds an HTML page according to specifications.
;;; Produces:
;;;   A string that corresponds to the HTML page.
;;; Preconditions:
;;;   [Standard]
;;; Postconditions:
;;;   The returned page is valid HTML.
;;;   The returned page shows multiple rounds of bizz-buzz.
(define page
  (lambda ()
    (bizz-buzz-page 
      (string->number (get-nonempty-cgi-variable 'buzzer "3"))
      (string->number (get-nonempty-cgi-variable 'start "1"))
      (string->number (get-nonempty-cgi-variable 'finish "1")))))
