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

  1. ; AisleRiot - doublets.scm
  2. ; Copyright (C) 1998, 2003 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.  
  20. (define (new-game)
  21.   (initialize-playing-area)
  22.   (set-ace-low)
  23.   (make-standard-deck)
  24.   (shuffle-deck)
  25.  
  26.   (add-normal-slot DECK)
  27.   (add-normal-slot '())
  28.  
  29.   (add-blank-slot)
  30.   (add-normal-slot '())
  31.   (add-normal-slot '())
  32.   (add-normal-slot '())
  33.   (add-carriage-return-slot)
  34.  
  35.   (add-blank-slot)
  36.   (add-blank-slot)
  37.   (add-blank-slot)
  38.   (add-normal-slot '())
  39.   (add-blank-slot)
  40.   (add-normal-slot '())
  41.   (add-carriage-return-slot)
  42.  
  43.   (add-blank-slot)
  44.   (add-blank-slot)
  45.   (add-blank-slot)
  46.   (add-normal-slot '())
  47.   (add-normal-slot '())
  48.   (add-normal-slot '())
  49.  
  50.   (deal-cards-face-up 0 '(2 3 4 5 6 7 8 9))
  51.  
  52.   (check-kings '(2 3 4 5 6 7 8 9))
  53.  
  54.   (add-to-score! 1)
  55.  
  56.   (give-status-message)
  57.  
  58.   (list 6 3)
  59. )
  60.  
  61. (define (give-status-message)
  62.   (set-statusbar-message (string-append (get-stock-no-string)
  63.                     "   "
  64.                     (get-redeals-string))))
  65.  
  66. (define (get-stock-no-string)
  67.   (string-append (_"Stock left:") " "
  68.          (number->string (length (get-cards 0)))))
  69.  
  70. (define (get-redeals-string)
  71.   (string-append (_"Redeals left:") " "
  72.          (number->string (- 2 FLIP-COUNTER))))
  73.  
  74. (define (check-kings slot-list)
  75.   (if (= (get-value (get-top-card (car slot-list))) king)
  76.       (begin
  77.     (let ((new-deck (get-cards 0)))
  78.           (set-cards! 0 (reverse (cons (make-card (get-value (get-top-card (car slot-list)))
  79.                               (get-suit (get-top-card (car slot-list))))
  80.                        (reverse new-deck)))))
  81.     (remove-card (car slot-list))
  82.     (deal-cards-face-up 0 (cons (car slot-list) '()))
  83.     (check-kings slot-list))
  84.       (if (> (length slot-list) 1)
  85.       (check-kings (cdr slot-list)))))
  86.  
  87. (define (button-pressed slot-id card-list)
  88.   (and (not (empty-slot? slot-id))
  89.        (not (= slot-id 0))
  90.        (not (= slot-id 8))
  91.        (not (= (get-value (car card-list)) king))))
  92.  
  93. (define (droppable? start-slot card-list end-slot)
  94.   (and (= end-slot 8)
  95.        (= (get-value (car card-list))
  96.       (modulo (* 2 (get-value (get-top-card end-slot))) 13))))
  97.  
  98. (define (button-released start-slot card-list end-slot)
  99.   (and (droppable? start-slot card-list end-slot)
  100.        (begin
  101.      (add-to-score! 1)
  102.      (move-n-cards! start-slot end-slot card-list)
  103.      (cond ((not (empty-slot? 1))
  104.         (deal-cards 1 (cons start-slot '())))
  105.            ((not (empty-slot? 0))
  106.         (deal-cards-face-up 0 (cons start-slot '())))
  107.            (#t #t)))))
  108.  
  109. (define (button-clicked slot-id)
  110.   (if (= slot-id 0)
  111.       (flip-stock 0 1 2)))
  112.  
  113. (define (button-double-clicked slot)
  114.   (if (and (not (empty-slot? slot))
  115.        (not (= slot 0))
  116.        (not (= slot 8))
  117.        (not (= (get-value (get-top-card slot)) king))
  118.        (= (get-value (get-top-card slot))
  119.           (modulo (* 2 (get-value (get-top-card 8))) 13)))
  120.       (begin
  121.     (add-to-score! 1)
  122.     (deal-cards slot '(8))
  123.     (cond ((not (empty-slot? 1))
  124.            (deal-cards 1 (cons slot '())))
  125.           ((and (not (empty-slot? 0))
  126.             (not (= slot 1)))
  127.            (deal-cards-face-up 0 (cons slot '())))
  128.           (#t #t)))
  129.       #f))
  130.  
  131. (define (check-move slot)
  132.   (if (and (not (empty-slot? slot))
  133.        (= (get-value (get-top-card slot))
  134.           (modulo (* 2 (get-value (get-top-card 8))) 13)))
  135.       #t
  136.       (if (< slot 9)
  137.       (check-move (+ 1 slot))
  138.       #f)))
  139.  
  140. (define (game-over)
  141.   (give-status-message)
  142.   (and (not (game-won))
  143.        (or (< FLIP-COUNTER 2)
  144.        (not (empty-slot? 0))
  145.        (check-move 1))))
  146.  
  147. (define (game-won)
  148.   (= 48 (length (get-cards 8))))
  149.  
  150. (define (get-hint)
  151.   (let ((wanted (modulo (* 2 (get-value (get-top-card 8))) 
  152.             13)))
  153.     (list 4 (get-value-name wanted))))
  154.  
  155. (define (get-options) #f)
  156.  
  157. (define (apply-options options) #f)
  158.  
  159. (define (timeout) #f)
  160.  
  161. (set-features droppable-feature)
  162.  
  163. (set-lambda new-game button-pressed button-released button-clicked button-double-clicked game-over game-won get-hint get-options apply-options timeout droppable?)
  164.