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

  1. ; AisleRiot - golf.scm
  2. ; Copyright (C) 2001 Rosanna Yuen <zana@webwynk.net>
  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 extend-waste #t)
  20.  
  21. (define stock 0)
  22. (define waste 1)
  23. (define tableau '(2 3 4 5 6 7 8))
  24.  
  25. (define (new-game)
  26.   (initialize-playing-area)
  27.   (set-ace-low)
  28.   (make-standard-deck)
  29.   (shuffle-deck)
  30.  
  31.   ;; Stock
  32.   (add-normal-slot DECK)
  33.  
  34.   ;; Waste
  35.   (if extend-waste
  36.       ;; extended slot looks best but gets too big,
  37.       ;; use part extended slot instead
  38.       (add-partially-extended-slot '() right 26)
  39.       ;; normal waste, only last card is shown
  40.       (add-normal-slot '()))
  41.  
  42.   (add-carriage-return-slot)
  43.  
  44.   (add-extended-slot '() down)
  45.   (add-extended-slot '() down)
  46.   (add-extended-slot '() down)
  47.   (add-extended-slot '() down)
  48.   (add-extended-slot '() down)
  49.   (add-extended-slot '() down)
  50.   (add-extended-slot '() down)
  51.  
  52.   ;; deal five full rows to the tableau
  53.   (deal-cards-face-up stock tableau)
  54.   (deal-cards-face-up stock tableau)
  55.   (deal-cards-face-up stock tableau)
  56.   (deal-cards-face-up stock tableau)
  57.   (deal-cards-face-up stock tableau)
  58.  
  59.   (give-status-message)
  60.  
  61.   (list 7 3))
  62.  
  63. (define (give-status-message)
  64.   (set-statusbar-message (get-stock-no-string)))
  65.  
  66. (define (get-stock-no-string)
  67.   (format (_"Stock left: ~a") (number->string (length (get-cards stock)))))
  68.  
  69. (define (button-pressed slot-id card-list)
  70.   (and (not (empty-slot? slot-id))
  71.        (> slot-id waste)
  72.        (= (length card-list) 1)))
  73.  
  74. (define (droppable? start-slot card-list end-slot)
  75.   (and (= end-slot waste)
  76.        (not (empty-slot? waste))
  77.        (let ((waste-value (get-value (get-top-card waste)))) 
  78.      (and (not (= waste-value king))
  79.           (or (= (get-value (car card-list))
  80.              (+ 1 waste-value))
  81.           (= (+ 1 (get-value (car card-list)))
  82.              waste-value))))))
  83.  
  84. (define (button-released start-slot card-list end-slot)
  85.   (and (droppable? start-slot card-list end-slot)
  86.        (move-n-cards! start-slot end-slot card-list)
  87.        (add-to-score! 1)))
  88.  
  89. (define (button-clicked slot-id)
  90.   (or (and (= slot-id stock)
  91.        (not (empty-slot? slot-id))
  92.        (deal-cards-face-up stock (list waste)))
  93.       (and (> slot-id waste)
  94.        (not (empty-slot? slot-id))
  95.        (not (empty-slot? waste))
  96.        (let ((waste-value (get-value (get-top-card waste)))) 
  97.          (and (not (= waste-value king))
  98.           (or (= (get-value (get-top-card slot-id))
  99.              (+ 1 waste-value))
  100.               (= (+ 1 (get-value (get-top-card slot-id)))
  101.              waste-value))
  102.           (deal-cards slot-id (list waste))
  103.           (add-to-score! 1))))))
  104.  
  105. (define (button-double-clicked slot-id)
  106.   (button-clicked slot-id))
  107.  
  108. (define (game-continuable)
  109.   (give-status-message)
  110.   (and (not (game-won))
  111.        (get-hint)))
  112.  
  113. (define (game-won)
  114.   (and (empty-slot? 2)
  115.        (empty-slot? 3)
  116.        (empty-slot? 4)
  117.        (empty-slot? 5)
  118.        (empty-slot? 6)
  119.        (empty-slot? 7)
  120.        (empty-slot? 8)))
  121.  
  122. (define (check-slots slot)
  123.     (cond ((or (empty-slot? waste)
  124.            (= (get-value (get-top-card waste)) king)
  125.            (= slot 9))
  126.        #f)
  127.       ((let ((waste-value (get-value (get-top-card waste)))) 
  128.          (and (not (empty-slot? slot))
  129.           (or (= (get-value (get-top-card slot))
  130.              (+ 1 waste-value))
  131.               (= (+ 1 (get-value (get-top-card slot)))
  132.              waste-value))))
  133.          (list 1 (get-name (get-top-card slot)) 
  134.            (get-name (get-top-card waste))))
  135.         (#t (check-slots (+ 1 slot)))))
  136.  
  137. (define (dealable?)
  138.   (and (not (empty-slot? stock))
  139.        (list 0 (_"Deal another card"))))
  140.  
  141. (define (get-hint)
  142.   (or (check-slots (car tableau))
  143.       (dealable?)))
  144.  
  145. (define (get-options) 
  146.   #f)
  147.  
  148. (define (apply-options options) 
  149.   #f)
  150.  
  151. (define (timeout) 
  152.   #f)
  153.  
  154. (set-features droppable-feature)
  155.  
  156. (set-lambda new-game button-pressed button-released button-clicked
  157. button-double-clicked game-continuable game-won get-hint get-options
  158. apply-options timeout droppable?)
  159.