home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / sol-games / hopscotch.scm < prev    next >
Encoding:
Text File  |  2006-08-22  |  4.0 KB  |  154 lines

  1. ; AisleRiot - hopscotch.scm
  2. ; Copyright (C) 1999 Rosanna Yuen <rwsy@mit.edu>
  3. ;
  4. ; This game is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2, or (at your option)
  7. ; any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  17. ; USA
  18.  
  19. (define (new-game)
  20.   (initialize-playing-area)
  21.   (set-ace-low)
  22.   (set! DECK (make-deck-list-ace-low 1 5 club))
  23.   (shuffle-deck)
  24.  
  25.   (add-normal-slot DECK)
  26.   (add-normal-slot '())
  27.  
  28.   (add-blank-slot)
  29.   (add-normal-slot '())
  30.   (add-normal-slot '())
  31.   (add-normal-slot '())
  32.   (add-normal-slot '())
  33.   (add-carriage-return-slot)
  34.   (add-blank-slot)
  35.   (add-blank-slot)
  36.   (add-blank-slot)
  37.   (add-extended-slot '() down)
  38.   (add-extended-slot '() down)
  39.   (add-extended-slot '() down)
  40.   (add-extended-slot '() down)
  41.  
  42.   (add-card! 2 (make-visible (make-card ace club)))
  43.   (add-card! 3 (make-visible (make-card 2 club)))
  44.   (add-card! 4 (make-visible (make-card 3 club)))
  45.   (add-card! 5 (make-visible (make-card 4 club)))
  46.  
  47.   (give-status-message)
  48.  
  49.   (list 7 4))
  50.  
  51. (define (give-status-message)
  52.   (set-statusbar-message (get-stock-no-string)))
  53.  
  54. (define (get-stock-no-string)
  55.   (string-append (_"Stock left:") " " 
  56.          (number->string (length (get-cards 0)))))
  57.  
  58. (define (button-pressed slot-id card-list)
  59.   (and (not (empty-slot? slot-id))
  60.        (= (length card-list) 1)
  61.        (or (= slot-id 1)
  62.        (> slot-id 5))))        
  63.  
  64. (define (droppable? start-slot card-list end-slot)
  65.   (cond ((and (> end-slot 1)
  66.           (< end-slot 6))
  67.      (= (modulo (get-value (car card-list)) 13)
  68.         (modulo (+ (- end-slot 1) (get-value (get-top-card end-slot))) 13)))
  69.     ((and (= start-slot 1)
  70.           (>= end-slot 6))
  71.      #t)
  72.     (#t #f)))
  73.  
  74. (define (button-released start-slot card-list end-slot)
  75.   (if (droppable? start-slot card-list end-slot)
  76.       (begin
  77.         (move-n-cards! start-slot end-slot card-list)
  78.         (if (and (> end-slot 1) (< end-slot 6))
  79.             (add-to-score! 1)
  80.             #t))
  81.       #f))
  82.  
  83. (define (button-clicked slot-id)
  84.   (and (= slot-id 0)
  85.        (empty-slot? 1)
  86.        (flip-stock 0 1 1)))
  87.  
  88. (define (button-double-clicked slot-id)
  89.   #f)
  90.  
  91. (define (game-continuable)
  92.   (give-status-message)
  93.   (and (not (game-won))
  94.        (get-hint)))
  95.  
  96. (define (game-won)
  97.   (and (empty-slot? 0)
  98.        (empty-slot? 1)
  99.        (empty-slot? 6)
  100.        (empty-slot? 7)
  101.        (empty-slot? 8)
  102.        (empty-slot? 9)))
  103.  
  104. (define (check-to-foundation slot-id foundation-id)
  105.   (cond ((or (> slot-id 9)
  106.          (and (> slot-id 1)
  107.           (< slot-id 6)))
  108.      #f)
  109.     ((> foundation-id 5)
  110.      (check-to-foundation (+ 1 slot-id) 2))
  111.     ((or (empty-slot?  slot-id)
  112.          (and (not (empty-slot? foundation-id))
  113.           (= (get-value (get-top-card foundation-id)) 13))
  114.          (not (= (modulo (get-value (get-top-card slot-id)) 13)
  115.              (modulo (+ (- foundation-id 1) 
  116.                 (get-value (get-top-card foundation-id)))
  117.                  13))))
  118.      (check-to-foundation slot-id (+ 1 foundation-id)))
  119.     (#t (list 1 
  120.           (get-name (get-top-card slot-id))
  121.           (get-name (get-top-card foundation-id))))))
  122.  
  123. (define (check-waste)
  124.   (cond ((empty-slot? 1)
  125.      #f)
  126.     ((check-to-foundation 1 2)
  127.      (check-to-foundation 1 2))
  128.     (#t (list 0 (_"Move card from waste")))))
  129.  
  130. (define (dealable?)
  131.   (and (not (empty-slot? 0))
  132.        (list 0 (_"Deal another card"))))
  133.  
  134. (define (get-hint)
  135.   (or (check-to-foundation 6 2)
  136.       (check-waste)
  137.       (dealable?)))
  138.  
  139. (define (get-options) 
  140.   #f)
  141.  
  142. (define (apply-options options) 
  143.   #f)
  144.  
  145. (define (timeout) 
  146.   #f)
  147.  
  148. (set-features droppable-feature)
  149.  
  150. (set-lambda new-game button-pressed button-released button-clicked
  151. button-double-clicked game-continuable game-won get-hint get-options
  152. apply-options timeout droppable?)
  153.  
  154.